Search in sources :

Example 1 with JWSHeader

use of com.webauthn4j.data.jws.JWSHeader in project webauthn4j by webauthn4j.

the class CachingMetadataBLOBProviderTest method createMetadataBLOB.

private MetadataBLOB createMetadataBLOB(LocalDate nextUpdate) {
    JWSFactory factory = new JWSFactory(new ObjectConverter());
    JWSHeader header = new JWSHeader(JWAIdentifier.ES256, null);
    MetadataBLOBPayload payload = new MetadataBLOBPayload("", 0, nextUpdate, Collections.emptyList());
    JWS<MetadataBLOBPayload> jws = factory.create(header, payload, new byte[32]);
    return new MetadataBLOB(jws);
}
Also used : ObjectConverter(com.webauthn4j.converter.util.ObjectConverter) MetadataBLOB(com.webauthn4j.metadata.data.MetadataBLOB) JWSFactory(com.webauthn4j.data.jws.JWSFactory) JWSHeader(com.webauthn4j.data.jws.JWSHeader) MetadataBLOBPayload(com.webauthn4j.metadata.data.MetadataBLOBPayload)

Example 2 with JWSHeader

use of com.webauthn4j.data.jws.JWSHeader in project webauthn4j by webauthn4j.

the class MetadataBLOBTest method test.

@Test
void test() {
    MetadataBLOB metadataBLOB = getMetadataBLOB();
    assertThat(metadataBLOB).isNotNull();
    JWSHeader header = metadataBLOB.getHeader();
    MetadataBLOBPayload payload = metadataBLOB.getPayload();
    assertThat(header).isNotNull();
    assertThat(payload).isNotNull();
    assertThat(payload.getNo()).isEqualTo(9);
    assertThat(payload.getEntries()).hasSize(98);
    assertThat(payload.getLegalHeader()).isNotEmpty();
    assertThat(payload.getNextUpdate()).isEqualTo("2021-12-01");
    assertThat(metadataBLOB.getSignature()).isEqualTo(Base64UrlUtil.decode("CLHevWeNEwJynHqxs5-xH0wlOuhz3cu9r8UL4fyJ0T7Avbi-OdE2LnT2ZUDjJC0F8R1V6bmrUBoyR4bjTTCt5FpKNyOwfSEVf3ToK6ZR3kITEDGfJgztDxn8rjS26FpM0JHnVms9-_74AEqVas7qVoPoKq9HYQyHUkvWdeVHhziOEMIa6NYEJa7qhtzlKi8ZKTJeEYbjUWVIhgTOHNUi_jGfLFTm10HDgiFc6pa5M5-BvoOKBCztzW_tzCl96wP8K2ujVg0xHA-RRTwinGAbDiwSIDGpYymhElQ40gdpsHtRYPOPQiqZgQX7u_CRGN2CA6qykF9mOY2U2RhA3cxZpw"));
}
Also used : JWSHeader(com.webauthn4j.data.jws.JWSHeader) Test(org.junit.jupiter.api.Test)

Example 3 with JWSHeader

use of com.webauthn4j.data.jws.JWSHeader in project webauthn4j by webauthn4j.

the class JWSHeaderDeserializer method deserialize.

@Override
public JWSHeader deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    JsonNode jsonNode = p.getCodec().readTree(p);
    JWAIdentifier alg = p.getCodec().treeToValue(jsonNode.get("alg"), JWAIdentifier.class);
    JsonNode x5cNode = jsonNode.get("x5c");
    List<X509Certificate> certificates = new ArrayList<>();
    for (JsonNode node : x5cNode) {
        certificates.add(CertificateUtil.generateX509Certificate(Base64Util.decode(node.asText())));
    }
    CertPath x5c = CertificateUtil.generateCertPath(certificates);
    return new JWSHeader(alg, x5c);
}
Also used : JWAIdentifier(com.webauthn4j.data.jws.JWAIdentifier) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) CertPath(java.security.cert.CertPath) X509Certificate(java.security.cert.X509Certificate) JWSHeader(com.webauthn4j.data.jws.JWSHeader)

Example 4 with JWSHeader

use of com.webauthn4j.data.jws.JWSHeader in project webauthn4j by webauthn4j.

the class AndroidSafetyNetAttestationStatementTest method getX5c_with_x5cHeader_x5c_null_test.

@SuppressWarnings("unchecked")
@Test
void getX5c_with_x5cHeader_x5c_null_test() {
    JWS<Response> jws = mock(JWS.class);
    JWSHeader jwsHeader = mock(JWSHeader.class);
    when(jws.getHeader()).thenReturn(jwsHeader);
    when(jwsHeader.getX5c()).thenReturn(null);
    AndroidSafetyNetAttestationStatement attestationStatement = new AndroidSafetyNetAttestationStatement("dummy", jws);
    assertThat(attestationStatement.getX5c()).isNull();
}
Also used : JWSHeader(com.webauthn4j.data.jws.JWSHeader) Test(org.junit.jupiter.api.Test)

Example 5 with JWSHeader

use of com.webauthn4j.data.jws.JWSHeader in project webauthn4j by webauthn4j.

the class AndroidSafetyNetAuthenticator method createAttestationStatement.

@Override
public AttestationStatement createAttestationStatement(AttestationStatementRequest attestationStatementRequest, RegistrationEmulationOption registrationEmulationOption) {
    AttestationOption attestationOption = registrationEmulationOption.getAttestationOption() == null ? new AndroidSafetyNetAttestationOption() : registrationEmulationOption.getAttestationOption();
    X509Certificate attestationCertificate = getAttestationCertificate(attestationStatementRequest, attestationOption);
    List<X509Certificate> certificates = new ArrayList<>();
    certificates.add(attestationCertificate);
    certificates.addAll(this.getCACertificatePath());
    CertPath certPath = CertificateUtil.generateCertPath(certificates);
    JWSHeader jwsHeader = new JWSHeader(JWAIdentifier.ES256, certPath);
    String nonce = Base64Util.encodeToString(MessageDigestUtil.createSHA256().digest(attestationStatementRequest.getSignedData()));
    long timestampMs = Instant.now().toEpochMilli();
    String apkPackageName = "com.android.keystore.androidkeystoredemo";
    String[] apkCertificateDigestSha256 = new String[] { "bsb4/WQdaaOWYCd/j9OJiQpg7b0iwFgAc/zzA1tCfwE=" };
    String apkDigestSha256 = "dM/LUHSI9SkQhZHHpQWRnzJ3MvvB2ANSauqYAAbS2Jg=";
    boolean ctsProfileMatch = true;
    boolean basicIntegrity = true;
    String advice = null;
    Response response = new Response(nonce, timestampMs, apkPackageName, apkCertificateDigestSha256, apkDigestSha256, ctsProfileMatch, basicIntegrity, advice);
    String ver = "12685023";
    JWS<Response> jws = getJwsFactory().create(jwsHeader, response, this.getAttestationKeyPair().getPrivate());
    if (registrationEmulationOption.isSignatureOverrideEnabled()) {
        jws = getJwsFactory().create(jws.getHeader(), jws.getPayload(), registrationEmulationOption.getSignature());
    }
    return new AndroidSafetyNetAttestationStatement(ver, jws);
}
Also used : AndroidSafetyNetAttestationStatement(com.webauthn4j.data.attestation.statement.AndroidSafetyNetAttestationStatement) ArrayList(java.util.ArrayList) X509Certificate(java.security.cert.X509Certificate) Response(com.webauthn4j.data.attestation.statement.Response) CertPath(java.security.cert.CertPath) JWSHeader(com.webauthn4j.data.jws.JWSHeader)

Aggregations

JWSHeader (com.webauthn4j.data.jws.JWSHeader)6 Test (org.junit.jupiter.api.Test)3 AndroidSafetyNetAttestationStatement (com.webauthn4j.data.attestation.statement.AndroidSafetyNetAttestationStatement)2 Response (com.webauthn4j.data.attestation.statement.Response)2 JWSFactory (com.webauthn4j.data.jws.JWSFactory)2 CertPath (java.security.cert.CertPath)2 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectConverter (com.webauthn4j.converter.util.ObjectConverter)1 JWAIdentifier (com.webauthn4j.data.jws.JWAIdentifier)1 MetadataBLOB (com.webauthn4j.metadata.data.MetadataBLOB)1 MetadataBLOBPayload (com.webauthn4j.metadata.data.MetadataBLOBPayload)1