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);
}
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"));
}
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);
}
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();
}
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);
}
Aggregations