Search in sources :

Example 1 with WebAuthnModelException

use of com.webauthn4j.test.authenticator.webauthn.exception.WebAuthnModelException 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);
}
Also used : SignatureAlgorithm(com.webauthn4j.data.SignatureAlgorithm) WebAuthnModelException(com.webauthn4j.test.authenticator.webauthn.exception.WebAuthnModelException) BigInteger(java.math.BigInteger) MessageDigest(java.security.MessageDigest)

Example 2 with WebAuthnModelException

use of com.webauthn4j.test.authenticator.webauthn.exception.WebAuthnModelException in project webauthn4j by webauthn4j.

the class TestDataUtil method calculateSignature.

public static byte[] calculateSignature(PrivateKey privateKey, byte[] signedData) {
    try {
        Signature signature;
        if (privateKey.getAlgorithm().equals("EC")) {
            signature = SignatureUtil.createES256();
        } else {
            signature = SignatureUtil.createRS256();
        }
        signature.initSign(privateKey);
        signature.update(signedData);
        return signature.sign();
    } catch (InvalidKeyException | SignatureException e) {
        throw new WebAuthnModelException("Signature calculation error", e);
    }
}
Also used : WebAuthnModelException(com.webauthn4j.test.authenticator.webauthn.exception.WebAuthnModelException)

Aggregations

WebAuthnModelException (com.webauthn4j.test.authenticator.webauthn.exception.WebAuthnModelException)2 SignatureAlgorithm (com.webauthn4j.data.SignatureAlgorithm)1 BigInteger (java.math.BigInteger)1 MessageDigest (java.security.MessageDigest)1