com.webauthn4j.converter.util.CborConverter Java Examples

The following examples show how to use com.webauthn4j.converter.util.CborConverter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AttestationObjectDeserializerTest.java    From webauthn4j with Apache License 2.0 6 votes vote down vote up
@Test
void test() {
    ObjectConverter objectConverter = new ObjectConverter();
    CborConverter cborConverter = objectConverter.getCborConverter();

    //Given
    //noinspection SpellCheckingInspection
    String input = "v2hhdXRoRGF0YVi6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBAAAAAQAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv2ExYTJhMvZhMyZhNPZhNfZiLTEBYi0yWCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGItM1ggAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABhMQL_Z2F0dFN0bXS_Y3g1Y4FZAsswggLHMIIBr6ADAgECAhAg92PAQYOxBTfb6FBqIlDyMA0GCSqGSIb3DQEBCwUAMEoxEjAQBgNVBAoMCVNoYXJwTGFiLjE0MDIGA1UEAwwrc3ByaW5nLXNlY3VyaXR5LXdlYmF1dGhuIDJ0aWVyIHRlc3Qgcm9vdCBDQTAgFw0xODA1MjAwNzA5NTVaGA8yMTE4MDQyNjA3MDk1NVowfTELMAkGA1UEBhMCSlAxEjAQBgNVBAoMCVNoYXJwTGFiLjEgMB4GA1UECwwXQXR0ZXN0YXRpb24gQ2VydGlmaWNhdGUxODA2BgNVBAMML3dlYmF1dGhuNGogdGVzdCAydGllciBhdXRoZW50aWNhdG9yIGF0dGVzdGF0aW9uMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEYOdbrImOAgjZN3Xb8unfHHhJDINdIykolt-ypGxcrop4KwbujX2zvoRGZvdoQ9mu-rwjAZt4H3SMsSxPvB8z8KM_MD0wDAYDVR0TAQH_BAIwADAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFNDrzrNaaa7sdMR9uzsvO8OohdjhMA0GCSqGSIb3DQEBCwUAA4IBAQCtHcryqNSHDyszLtIByc5AzPam37vl0AVchb0qOxLFbmdUu4Nhzk-87YdA_VZuvVLInsIGaCwkP3rdqGAFY1HllglMnmWIoG2sKjmT3vpJydlDODaha9F_fVG7cq2i5Zx2KMTeUtuTkNdZDjocUUHXYVShgNnggoUWkVeLBG1ckzK1tAkbUwyChWMv4PDmIUBNv6DwkYI9oBSCSAJHpUzyxzMvCRbAFAICwPl3g-SQEUeiNlnzJuGXHnHxu-DB6JD2b0hPeYD6XxWPuI0Pq1G_6hGQmsNv3SF2ye2y_HOKnw3L-fzRHl5ksOdVZbpy9xXzTdIBUpvTmFuwcBo4HwRMY3NpZ1ggAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD_Y2ZtdGhmaWRvLXUyZv8";

    //When
    AttestationObject result = cborConverter.readValue(Base64UrlUtil.decode(input), AttestationObject.class);

    //Then
    assertAll(
            () -> assertThat(result).isNotNull(),
            () -> assertThat(result.getAuthenticatorData()).isNotNull(),
            () -> assertThat(result.getFormat()).isEqualTo("fido-u2f"),
            () -> assertThat(result.getAttestationStatement()).isNotNull(),
            () -> assertThat(result.getAttestationStatement()).isInstanceOf(FIDOU2FAttestationStatement.class)
    );
}
 
Example #2
Source File: AuthenticatorTest.java    From webauthn4j with Apache License 2.0 6 votes vote down vote up
@Test
void serialization_deserialization_test() {
    ObjectConverter objectConverter = new ObjectConverter();
    CborConverter cborConverter = objectConverter.getCborConverter();

    TestAuthenticator original = new TestAuthenticator(
            TestDataUtil.createAttestedCredentialData(),
            TestAttestationStatementUtil.createFIDOU2FAttestationStatement(),
            0,
            Collections.emptySet(),
            null,
            null);
    byte[] serialized = cborConverter.writeValueAsBytes(original);
    Authenticator deserialized = cborConverter.readValue(serialized, TestAuthenticator.class);

    assertThat(deserialized).isEqualTo(original);
}
 
Example #3
Source File: X509CertificateDeserializerTest.java    From webauthn4j with Apache License 2.0 5 votes vote down vote up
@Test
void deserialize_test() throws CertificateEncodingException {
    ObjectConverter objectConverter = new ObjectConverter();
    CborConverter cborConverter = objectConverter.getCborConverter();

    Map<String, byte[]> source = new HashMap<>();
    source.put("certificate", TestAttestationUtil.load2tierTestAuthenticatorAttestationCertificate().getEncoded());
    byte[] input = cborConverter.writeValueAsBytes(source);

    X509CertificateDeserializerTestData result = cborConverter.readValue(input, X509CertificateDeserializerTestData.class);
    assertThat(result.getCertificate()).isInstanceOf(X509Certificate.class);
}
 
Example #4
Source File: X509CertificateDeserializerTest.java    From webauthn4j with Apache License 2.0 5 votes vote down vote up
@Test
void deserialize_empty_byte_array_test() {
    ObjectConverter objectConverter = new ObjectConverter();
    CborConverter cborConverter = objectConverter.getCborConverter();

    Map<String, byte[]> source = new HashMap<>();
    source.put("certificate", new byte[0]);
    byte[] input = cborConverter.writeValueAsBytes(source);

    X509CertificateDeserializerTestData result = cborConverter.readValue(input, X509CertificateDeserializerTestData.class);
    assertThat(result.getCertificate()).isNull();
}