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