Skip to content

Commit 6f37aa3

Browse files
committed
Add enterprise attestation serial number helper
1 parent 789c74c commit 6f37aa3

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.yubico.webauthn.attestation;
2+
3+
import java.nio.ByteBuffer;
4+
import java.security.cert.X509Certificate;
5+
import java.util.Optional;
6+
7+
public class CertificateUtil {
8+
public static final String ID_FIDO_GEN_CE_SERNUM = "1.3.6.1.4.1.45724.1.1.2";
9+
10+
private static byte[] parseSerNum(byte[] bytes) {
11+
if (bytes != null) {
12+
ByteBuffer buffer = ByteBuffer.wrap(bytes);
13+
14+
if (buffer.get() == (byte) 0x04
15+
&& buffer.get() > 0
16+
&& buffer.get() == (byte) 0x04) {
17+
18+
byte length = buffer.get();
19+
byte[] serNumBytes = new byte[length];
20+
buffer.get(serNumBytes);
21+
22+
return serNumBytes;
23+
}
24+
}
25+
26+
throw new IllegalArgumentException(
27+
"X.509 extension 1.3.6.1.4.1.45724.1.1.2 (id-fido-gen-ce-sernum) is not valid.");
28+
}
29+
30+
public static Optional<byte[]> parseFidoSerNumExtension(X509Certificate cert) {
31+
return Optional.ofNullable(cert.getExtensionValue(ID_FIDO_GEN_CE_SERNUM)).map(CertificateUtil::parseSerNum);
32+
}
33+
}

0 commit comments

Comments
 (0)