use of com.yubico.webauthn.data.AttestationObject in project java-webauthn-server by Yubico.
the class CryptoAlgorithmsTest method importEddsa.
@Test
public void importEddsa() throws IOException, CoseException, NoSuchAlgorithmException, InvalidKeySpecException {
PublicKey key = WebAuthnCodecs.importCosePublicKey(new AttestationObject(RegistrationTestData.Packed$.MODULE$.BasicAttestationEdDsa().attestationObject()).getAuthenticatorData().getAttestedCredentialData().get().getCredentialPublicKey());
assertTrue("EdDSA".equals(key.getAlgorithm()) || "Ed25519".equals(key.getAlgorithm()));
}
use of com.yubico.webauthn.data.AttestationObject in project java-webauthn-server by Yubico.
the class CryptoAlgorithmsTest method importEcdsa.
@Test
public void importEcdsa() throws IOException, CoseException, NoSuchAlgorithmException, InvalidKeySpecException {
PublicKey key = WebAuthnCodecs.importCosePublicKey(new AttestationObject(RegistrationTestData.Packed$.MODULE$.BasicAttestation().attestationObject()).getAuthenticatorData().getAttestedCredentialData().get().getCredentialPublicKey());
assertEquals(key.getAlgorithm(), "EC");
}
use of com.yubico.webauthn.data.AttestationObject in project java-webauthn-server by Yubico.
the class CryptoAlgorithmsTest method importRsa.
@Test
public void importRsa() throws IOException, CoseException, NoSuchAlgorithmException, InvalidKeySpecException {
PublicKey key = WebAuthnCodecs.importCosePublicKey(new AttestationObject(RegistrationTestData.Packed$.MODULE$.BasicAttestationRsa().attestationObject()).getAuthenticatorData().getAttestedCredentialData().get().getCredentialPublicKey());
assertEquals(key.getAlgorithm(), "RSA");
}
use of com.yubico.webauthn.data.AttestationObject in project java-webauthn-server by Yubico.
the class FidoU2fAttestationStatementVerifier method verifyAttestationSignature.
@Override
public boolean verifyAttestationSignature(AttestationObject attestationObject, ByteArray clientDataJsonHash) {
final X509Certificate attestationCertificate;
try {
attestationCertificate = getAttestationCertificate(attestationObject);
} catch (CertificateException e) {
throw new IllegalArgumentException(String.format("Failed to parse X.509 certificate from attestation object: %s", attestationObject));
}
if (!("EC".equals(attestationCertificate.getPublicKey().getAlgorithm()) && isP256(((ECPublicKey) attestationCertificate.getPublicKey()).getParams()))) {
throw new IllegalArgumentException("Attestation certificate for fido-u2f must have an ECDSA P-256 public key.");
}
final Optional<AttestedCredentialData> attData = attestationObject.getAuthenticatorData().getAttestedCredentialData();
return attData.map(attestedCredentialData -> {
JsonNode signature = attestationObject.getAttestationStatement().get("sig");
if (signature == null) {
throw new IllegalArgumentException("fido-u2f attestation statement must have a \"sig\" property set to a DER encoded signature.");
}
if (signature.isBinary()) {
final ByteArray userPublicKey;
try {
userPublicKey = getRawUserPublicKey(attestationObject);
} catch (IOException | CoseException e) {
RuntimeException err = new RuntimeException(String.format("Failed to parse public key from attestation data %s", attestedCredentialData), e);
log.error(err.getMessage(), err);
throw err;
}
ByteArray keyHandle = attestedCredentialData.getCredentialId();
U2fRawRegisterResponse u2fRegisterResponse;
try {
u2fRegisterResponse = new U2fRawRegisterResponse(userPublicKey, keyHandle, attestationCertificate, new ByteArray(signature.binaryValue()));
} catch (IOException e) {
RuntimeException err = new RuntimeException("signature.isBinary() was true but signature.binaryValue() failed", e);
log.error(err.getMessage(), err);
throw err;
}
return u2fRegisterResponse.verifySignature(attestationObject.getAuthenticatorData().getRpIdHash(), clientDataJsonHash);
} else {
throw new IllegalArgumentException("\"sig\" property of fido-u2f attestation statement must be a CBOR byte array value.");
}
}).orElseThrow(() -> new IllegalArgumentException("Attestation object for credential creation must have attestation data."));
}
Aggregations