use of com.webauthn4j.data.SignatureAlgorithm in project webauthn4j by webauthn4j.
the class TPMAuthenticator method createTPMSAttest.
private TPMSAttest createTPMSAttest(AttestationStatementRequest attestationStatementRequest, COSEAlgorithmIdentifier alg, TPMTPublic pubArea) {
TPMGenerated magic = TPMGenerated.TPM_GENERATED_VALUE;
TPMISTAttest type = TPMISTAttest.TPM_ST_ATTEST_CERTIFY;
byte[] qualifiedSigner = Base64UrlUtil.decode("AAu8WfTf2aakLcO4Zq_y3w0Zgmu_AUtnqwrW67F2MGuABw");
MessageDigest messageDigest;
try {
SignatureAlgorithm signatureAlgorithm = alg.toSignatureAlgorithm();
messageDigest = signatureAlgorithm.getMessageDigestAlgorithm().createMessageDigestObject();
} catch (IllegalArgumentException e) {
throw new WebAuthnModelException("alg is not signature algorithm", e);
}
byte[] extraData = messageDigest.digest(attestationStatementRequest.getSignedData());
BigInteger clock = BigInteger.valueOf(7270451399L);
long resetCount = 1749088739L;
long restartCount = 3639844613L;
TPMSClockInfo clockInfo = new TPMSClockInfo(clock, resetCount, restartCount, true);
BigInteger firmwareVersion = new BigInteger("12241000001210926099");
byte[] nameDigest = MessageDigestUtil.createSHA256().digest(pubArea.getBytes());
TPMTHA name = new TPMTHA(TPMIAlgHash.TPM_ALG_SHA256, nameDigest);
byte[] qualifiedNameDigest = Base64UrlUtil.decode("AVI0eQ_AAZjNvrhUEMK2q4wxuwIFOnHIDF0Qljhf47Q");
TPMTHA qualifiedName = new TPMTHA(TPMIAlgHash.TPM_ALG_SHA256, qualifiedNameDigest);
TPMUAttest attested = new TPMSCertifyInfo(name, qualifiedName);
return new TPMSAttest(magic, type, qualifiedSigner, extraData, clockInfo, firmwareVersion, attested);
}
use of com.webauthn4j.data.SignatureAlgorithm in project webauthn4j by webauthn4j.
the class AbstractStatementValidator method getJcaName.
protected String getJcaName(@NonNull COSEAlgorithmIdentifier alg) {
String jcaName;
try {
SignatureAlgorithm signatureAlgorithm = alg.toSignatureAlgorithm();
jcaName = signatureAlgorithm.getJcaName();
} catch (IllegalArgumentException e) {
throw new BadAttestationStatementException("alg is not signature algorithm", e);
}
return jcaName;
}
use of com.webauthn4j.data.SignatureAlgorithm in project webauthn4j by webauthn4j.
the class AssertionSignatureValidator method verifySignature.
private boolean verifySignature(@NonNull COSEKey coseKey, @NonNull byte[] signature, @NonNull byte[] data) {
try {
PublicKey publicKey = coseKey.getPublicKey();
// noinspection ConstantConditions as null check is already done in caller
SignatureAlgorithm signatureAlgorithm = coseKey.getAlgorithm().toSignatureAlgorithm();
String jcaName = signatureAlgorithm.getJcaName();
Signature verifier = Signature.getInstance(jcaName);
verifier.initVerify(publicKey);
verifier.update(data);
return verifier.verify(signature);
} catch (IllegalArgumentException e) {
logger.debug("COSE key alg must be signature algorithm.", e);
return false;
} catch (NoSuchAlgorithmException | SignatureException | InvalidKeyException | RuntimeException e) {
logger.debug("Unexpected exception is thrown during signature verification.", e);
return false;
}
}
Aggregations