use of com.webauthn4j.validator.exception.ValidationException in project webauthn4j by webauthn4j.
the class WebAuthnManagerSample method registrationValidationSample.
public void registrationValidationSample() {
// Client properties
byte[] attestationObject = null;
byte[] clientDataJSON = null;
String clientExtensionJSON = null;
/* set clientExtensionJSON */
Set<String> transports = null;
// Server properties
Origin origin = null;
String rpId = null;
Challenge challenge = null;
byte[] tokenBindingId = null;
ServerProperty serverProperty = new ServerProperty(origin, rpId, challenge, tokenBindingId);
// expectations
List<PublicKeyCredentialParameters> pubKeyCredParams = null;
boolean userVerificationRequired = false;
boolean userPresenceRequired = true;
RegistrationRequest registrationRequest = new RegistrationRequest(attestationObject, clientDataJSON, clientExtensionJSON, transports);
RegistrationParameters registrationParameters = new RegistrationParameters(serverProperty, pubKeyCredParams, userVerificationRequired, userPresenceRequired);
RegistrationData registrationData;
try {
registrationData = webAuthnManager.parse(registrationRequest);
} catch (DataConversionException e) {
// If you would like to handle WebAuthn data structure parse error, please catch DataConversionException
throw e;
}
try {
webAuthnManager.validate(registrationData, registrationParameters);
} catch (ValidationException e) {
// If you would like to handle WebAuthn data validation error, please catch ValidationException
throw e;
}
// please persist Authenticator object, which will be used in the authentication process.
Authenticator authenticator = new // You may create your own Authenticator implementation to save friendly authenticator name
AuthenticatorImpl(registrationData.getAttestationObject().getAuthenticatorData().getAttestedCredentialData(), registrationData.getAttestationObject().getAttestationStatement(), registrationData.getAttestationObject().getAuthenticatorData().getSignCount());
// please persist authenticator in your manner
save(authenticator);
}
use of com.webauthn4j.validator.exception.ValidationException in project webauthn4j by webauthn4j.
the class DeviceCheckManagerSample method authenticationValidationSample.
public void authenticationValidationSample() {
// Client properties
byte[] keyId = null;
byte[] assertion = null;
byte[] clientDataHash = null;
// Server properties
String teamIdentifier = null;
String cfBundleIdentifier = null;
byte[] challenge = null;
DCServerProperty dcServerProperty = new DCServerProperty(teamIdentifier, cfBundleIdentifier, new DefaultChallenge(challenge));
// please load authenticator object persisted in the attestation process in your manner
DCAppleDevice dcAppleDevice = load(keyId);
DCAssertionRequest dcAssertionRequest = new DCAssertionRequest(keyId, assertion, clientDataHash);
DCAssertionParameters dcAssertionParameters = new DCAssertionParameters(dcServerProperty, dcAppleDevice);
DCAssertionData dcAssertionData;
try {
dcAssertionData = deviceCheckManager.parse(dcAssertionRequest);
} catch (DataConversionException e) {
// If you would like to handle Apple App Attest data structure parse error, please catch DataConversionException
throw e;
}
try {
deviceCheckManager.validate(dcAssertionData, dcAssertionParameters);
} catch (ValidationException e) {
// If you would like to handle Apple App Attest data validation error, please catch ValidationException
throw e;
}
// please update the counter of the authenticator record
updateCounter(dcAssertionData.getCredentialId(), dcAssertionData.getAuthenticatorData().getSignCount());
}
Aggregations