Search in sources :

Example 6 with WebAuthnCredentialData

use of org.keycloak.models.credential.dto.WebAuthnCredentialData in project keycloak by keycloak.

the class WebAuthnCredentialModel method create.

public static WebAuthnCredentialModel create(String credentialType, String userLabel, String aaguid, String credentialId, String attestationStatement, String credentialPublicKey, long counter, String attestationStatementFormat, Set<String> transports) {
    WebAuthnCredentialData credentialData = new WebAuthnCredentialData(aaguid, credentialId, counter, attestationStatement, credentialPublicKey, attestationStatementFormat, transports);
    WebAuthnSecretData secretData = new WebAuthnSecretData();
    WebAuthnCredentialModel credentialModel = new WebAuthnCredentialModel(credentialType, credentialData, secretData);
    credentialModel.fillCredentialModelFields();
    credentialModel.setUserLabel(userLabel);
    return credentialModel;
}
Also used : WebAuthnCredentialData(org.keycloak.models.credential.dto.WebAuthnCredentialData) WebAuthnSecretData(org.keycloak.models.credential.dto.WebAuthnSecretData)

Example 7 with WebAuthnCredentialData

use of org.keycloak.models.credential.dto.WebAuthnCredentialData in project keycloak by keycloak.

the class WebAuthnCredentialModel method createFromCredentialModel.

public static WebAuthnCredentialModel createFromCredentialModel(CredentialModel credentialModel) {
    try {
        WebAuthnCredentialData credentialData = JsonSerialization.readValue(credentialModel.getCredentialData(), WebAuthnCredentialData.class);
        WebAuthnSecretData secretData = JsonSerialization.readValue(credentialModel.getSecretData(), WebAuthnSecretData.class);
        WebAuthnCredentialModel webAuthnCredentialModel = new WebAuthnCredentialModel(credentialModel.getType(), credentialData, secretData);
        webAuthnCredentialModel.setUserLabel(credentialModel.getUserLabel());
        webAuthnCredentialModel.setCreatedDate(credentialModel.getCreatedDate());
        webAuthnCredentialModel.setType(credentialModel.getType());
        webAuthnCredentialModel.setId(credentialModel.getId());
        webAuthnCredentialModel.setSecretData(credentialModel.getSecretData());
        webAuthnCredentialModel.setCredentialData(credentialModel.getCredentialData());
        return webAuthnCredentialModel;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : WebAuthnCredentialData(org.keycloak.models.credential.dto.WebAuthnCredentialData) WebAuthnSecretData(org.keycloak.models.credential.dto.WebAuthnSecretData) IOException(java.io.IOException)

Example 8 with WebAuthnCredentialData

use of org.keycloak.models.credential.dto.WebAuthnCredentialData in project keycloak by keycloak.

the class PubKeySignRegisterTest method assertPublicKeyAlgorithms.

private void assertPublicKeyAlgorithms(boolean shouldSuccess, COSEAlgorithmIdentifier selectedAlgorithm, List<String> algorithms) {
    assertThat(algorithms, notNullValue());
    try (Closeable u = getWebAuthnRealmUpdater().setWebAuthnPolicySignatureAlgorithms(algorithms).update()) {
        if (!algorithms.isEmpty()) {
            WebAuthnRealmData realmData = new WebAuthnRealmData(testRealm().toRepresentation(), isPasswordless());
            assertThat(realmData.getSignatureAlgorithms(), is(algorithms));
        }
        registerDefaultUser(shouldSuccess);
        assertThat(webAuthnErrorPage.isCurrent(), is(!shouldSuccess));
        if (!shouldSuccess) {
            final String expectedMessage = getExpectedMessageByDriver("NotSupportedError: Operation is not supported", "The operation either timed out or was not allowed");
            assertThat(webAuthnErrorPage.getError(), containsString(expectedMessage));
            return;
        }
        final String credentialType = getCredentialType();
        getTestingClient().server(TEST_REALM_NAME).run(session -> {
            final WebAuthnDataWrapper dataWrapper = new WebAuthnDataWrapper(session, USERNAME, credentialType);
            assertThat(dataWrapper, notNullValue());
            final WebAuthnCredentialData data = dataWrapper.getWebAuthnData();
            assertThat(data, notNullValue());
            final COSEKey pubKey = dataWrapper.getKey();
            assertThat(pubKey, notNullValue());
            assertThat(pubKey.getAlgorithm(), notNullValue());
            assertThat(pubKey.getAlgorithm().getValue(), is(selectedAlgorithm.getValue()));
            assertThat(pubKey.hasPublicKey(), is(true));
        });
    } catch (IOException e) {
        throw new RuntimeException(e.getCause());
    }
}
Also used : WebAuthnDataWrapper(org.keycloak.testsuite.webauthn.utils.WebAuthnDataWrapper) WebAuthnCredentialData(org.keycloak.models.credential.dto.WebAuthnCredentialData) COSEKey(com.webauthn4j.data.attestation.authenticator.COSEKey) Closeable(java.io.Closeable) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IOException(java.io.IOException) WebAuthnRealmData(org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData)

Aggregations

WebAuthnCredentialData (org.keycloak.models.credential.dto.WebAuthnCredentialData)8 IOException (java.io.IOException)5 WebAuthnDataWrapper (org.keycloak.testsuite.webauthn.utils.WebAuthnDataWrapper)4 COSEKey (com.webauthn4j.data.attestation.authenticator.COSEKey)3 WebAuthnRealmData (org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Test (org.junit.Test)2 WebAuthnSecretData (org.keycloak.models.credential.dto.WebAuthnSecretData)2 AbstractWebAuthnVirtualTest (org.keycloak.testsuite.webauthn.AbstractWebAuthnVirtualTest)2 AAGUID (com.webauthn4j.data.attestation.authenticator.AAGUID)1 AttestedCredentialData (com.webauthn4j.data.attestation.authenticator.AttestedCredentialData)1 Closeable (java.io.Closeable)1 WebAuthnCredentialModel (org.keycloak.models.credential.WebAuthnCredentialModel)1 CredentialRepresentation (org.keycloak.representations.idm.CredentialRepresentation)1 AbstractWebAuthnRealmUpdater (org.keycloak.testsuite.webauthn.updaters.AbstractWebAuthnRealmUpdater)1 Credential (org.openqa.selenium.virtualauthenticator.Credential)1