use of org.apache.kerby.asn1.parse.Asn1ParseResult in project webauthn4j by webauthn4j.
the class CertificateUtil method extractSubjectKeyIdentifier.
@NonNull
public static byte[] extractSubjectKeyIdentifier(X509Certificate certificate) {
try {
byte[] publicKeyEncoded = certificate.getPublicKey().getEncoded();
Asn1ParseResult result = Asn1Parser.parse(ByteBuffer.wrap(publicKeyEncoded));
List<Asn1ParseResult> children = ((Asn1Container) result).getChildren();
Asn1BitString asn1BitString = new Asn1BitString();
asn1BitString.decode(children.get(1));
byte[] publicKeyBytes = asn1BitString.getValue();
return MessageDigestUtil.createMessageDigest("SHA-1").digest(publicKeyBytes);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.apache.kerby.asn1.parse.Asn1ParseResult in project jans by JanssenProject.
the class AppleAttestationProcessor method getExtension.
/*-
[
{
"type": "OBJECT_IDENTIFIER",
"data": "1.2.840.113635.100.8.2"
},
{
"type": "OCTET_STRING",
"data": [
{
"type": "SEQUENCE",
"data": [
{
"type": "[1]",
"data": [
{
"type": "OCTET_STRING",
"data": {
"type": "Buffer",
"data": [92, 219, 157, 144, 115, 64, 69, 91, 99, 115, 230, 117, 43, 115, 252, 54, 132, 83, 96, 34, 21, 250, 234, 187, 124, 22, 95, 11, 173, 172, 7, 204]
}
}
]
}
]
}
]
}
]
*/
public byte[] getExtension(X509Certificate attestationCert) {
byte[] extensionValue = attestationCert.getExtensionValue(KEY_DESCRIPTION_OID);
byte[] extracted;
try {
Asn1OctetString extensionEnvelope = new Asn1OctetString();
extensionEnvelope.decode(extensionValue);
extensionEnvelope.getValue();
byte[] extensionEnvelopeValue = extensionEnvelope.getValue();
Asn1Container container = (Asn1Container) Asn1Parser.parse(ByteBuffer.wrap(extensionEnvelopeValue));
Asn1ParseResult firstElement = container.getChildren().get(0);
Asn1OctetString octetString = new Asn1OctetString();
octetString.decode(firstElement);
extracted = octetString.getValue();
return extracted;
} catch (IOException | RuntimeException e) {
throw new AttestationException("Failed to extract nonce from Apple anonymous attestation statement.");
}
}
use of org.apache.kerby.asn1.parse.Asn1ParseResult in project webauthn4j by webauthn4j.
the class KeyDescriptionValidator method getIntegerFromAsn1.
@Nullable
private BigInteger getIntegerFromAsn1(Asn1ParseResult asn1Value) throws IOException {
if (asn1Value == null) {
return null;
}
if (!asn1Value.isPrimitive()) {
throw new BadAttestationStatementException(String.format("ASN1Integer is expected. Found %s instead.", asn1Value.getClass().getName()));
}
Asn1Integer value = new Asn1Integer();
value.decode(asn1Value);
return value.getValue();
}
use of org.apache.kerby.asn1.parse.Asn1ParseResult in project webauthn4j by webauthn4j.
the class AppleAnonymousAttestationStatementValidator method validateNonce.
private void validateNonce(@NonNull CoreRegistrationObject registrationObject) {
AppleAnonymousAttestationStatement attestationStatement = (AppleAnonymousAttestationStatement) registrationObject.getAttestationObject().getAttestationStatement();
byte[] nonce = getNonce(registrationObject);
byte[] extensionValue = attestationStatement.getX5c().getEndEntityAttestationCertificate().getCertificate().getExtensionValue("1.2.840.113635.100.8.2");
byte[] extracted;
try {
Asn1OctetString extensionEnvelope = new Asn1OctetString();
extensionEnvelope.decode(extensionValue);
extensionEnvelope.getValue();
byte[] extensionEnvelopeValue = extensionEnvelope.getValue();
Asn1Container container = (Asn1Container) Asn1Parser.parse(ByteBuffer.wrap(extensionEnvelopeValue));
Asn1ParseResult firstElement = container.getChildren().get(0);
Asn1OctetString octetString = new Asn1OctetString();
octetString.decode(firstElement);
extracted = octetString.getValue();
} catch (IOException | RuntimeException e) {
throw new BadAttestationStatementException("Failed to extract nonce from Apple anonymous attestation statement.", e);
}
// there is no need to prevent timing attack and it is OK to use `Arrays.equals` instead of `MessageDigest.isEqual` here.
if (!Arrays.equals(extracted, nonce)) {
throw new BadAttestationStatementException("nonce doesn't match.");
}
}
Aggregations