Skip to content

Commit 81ac116

Browse files
committed
Add enterprise attestation serial number helper
1 parent 789c74c commit 81ac116

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 && buffer.get() > 0 && buffer.get() == (byte) 0x04) {
15+
16+
byte length = buffer.get();
17+
byte[] serNumBytes = new byte[length];
18+
buffer.get(serNumBytes);
19+
20+
return serNumBytes;
21+
}
22+
}
23+
24+
throw new IllegalArgumentException(
25+
"X.509 extension 1.3.6.1.4.1.45724.1.1.2 (id-fido-gen-ce-sernum) is not valid.");
26+
}
27+
28+
public static Optional<byte[]> parseFidoSerNumExtension(X509Certificate cert) {
29+
return Optional.ofNullable(cert.getExtensionValue(ID_FIDO_GEN_CE_SERNUM))
30+
.map(CertificateUtil::parseSerNum);
31+
}
32+
}

0 commit comments

Comments
 (0)