-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add enterprise attestation serial number helper
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...thn-server-attestation/src/main/java/com/yubico/webauthn/attestation/CertificateUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.yubico.webauthn.attestation; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.security.cert.X509Certificate; | ||
import java.util.Optional; | ||
|
||
public class CertificateUtil { | ||
public static final String ID_FIDO_GEN_CE_SERNUM = "1.3.6.1.4.1.45724.1.1.2"; | ||
|
||
private static byte[] parseSerNum(byte[] bytes) { | ||
if (bytes != null) { | ||
ByteBuffer buffer = ByteBuffer.wrap(bytes); | ||
|
||
if (buffer.get() == (byte) 0x04 && buffer.get() > 0 && buffer.get() == (byte) 0x04) { | ||
|
||
byte length = buffer.get(); | ||
byte[] serNumBytes = new byte[length]; | ||
buffer.get(serNumBytes); | ||
|
||
return serNumBytes; | ||
} | ||
} | ||
|
||
throw new IllegalArgumentException( | ||
"X.509 extension 1.3.6.1.4.1.45724.1.1.2 (id-fido-gen-ce-sernum) is not valid."); | ||
} | ||
|
||
public static Optional<byte[]> parseFidoSerNumExtension(X509Certificate cert) { | ||
return Optional.ofNullable(cert.getExtensionValue(ID_FIDO_GEN_CE_SERNUM)) | ||
.map(CertificateUtil::parseSerNum); | ||
} | ||
} |