File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
webauthn-server-attestation/src/main/java/com/yubico/webauthn/attestation Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments