Search in sources :

Example 1 with RawAuthenticateResponse

use of org.xdi.oxauth.model.fido.u2f.message.RawAuthenticateResponse in project oxAuth by GluuFederation.

the class RawAuthenticationServiceTest method testSecureClickRawAuthenticationResponse.

@Test
public void testSecureClickRawAuthenticationResponse() {
    String secureClickResponseHex = "01010000 001a3044 0220652a 4248527f 805a6203 a903e820 20d9d871 3966614b f41b93c9 02c83a9f c56f0220 230283f9 8305f889 d379278b 5fde2e2f d3e68182 08dfff75 3e218b74 a6e56306";
    byte[] secureClickResponseBytes = Hex.decode(secureClickResponseHex);
    // Base64 URL encode to allow consume by API
    String u2fResponseBase64 = Base64Util.base64urlencode(secureClickResponseBytes);
    RawAuthenticateResponse rawAuthenticateResponse = rawAuthenticationService.parseRawAuthenticateResponse(u2fResponseBase64);
    assertNotNull(rawAuthenticateResponse);
}
Also used : RawAuthenticateResponse(org.xdi.oxauth.model.fido.u2f.message.RawAuthenticateResponse) BaseComponentTest(org.xdi.oxauth.BaseComponentTest) Test(org.testng.annotations.Test)

Example 2 with RawAuthenticateResponse

use of org.xdi.oxauth.model.fido.u2f.message.RawAuthenticateResponse in project oxAuth by GluuFederation.

the class AuthenticationService method finishAuthentication.

public DeviceRegistrationResult finishAuthentication(AuthenticateRequestMessage requestMessage, AuthenticateResponse response, String userInum, Set<String> facets) throws BadInputException, DeviceCompromisedException {
    List<DeviceRegistration> deviceRegistrations = deviceRegistrationService.findUserDeviceRegistrations(userInum, requestMessage.getAppId());
    final AuthenticateRequest request = getAuthenticateRequest(requestMessage, response);
    DeviceRegistration usedDeviceRegistration = null;
    for (DeviceRegistration deviceRegistration : deviceRegistrations) {
        if (StringHelper.equals(request.getKeyHandle(), deviceRegistration.getKeyHandle())) {
            usedDeviceRegistration = deviceRegistration;
            break;
        }
    }
    if (usedDeviceRegistration == null) {
        throw new BadInputException("Failed to find DeviceRegistration for the given AuthenticateRequest");
    }
    if (usedDeviceRegistration.isCompromised()) {
        throw new DeviceCompromisedException(usedDeviceRegistration, "The device is marked as possibly compromised, and cannot be authenticated");
    }
    ClientData clientData = response.getClientData();
    clientDataValidationService.checkContent(clientData, RawAuthenticationService.SUPPORTED_AUTHENTICATE_TYPES, request.getChallenge(), facets);
    RawAuthenticateResponse rawAuthenticateResponse = rawAuthenticationService.parseRawAuthenticateResponse(response.getSignatureData());
    rawAuthenticationService.checkSignature(request.getAppId(), clientData, rawAuthenticateResponse, Base64Util.base64urldecode(usedDeviceRegistration.getDeviceRegistrationConfiguration().getPublicKey()));
    rawAuthenticateResponse.checkUserPresence();
    usedDeviceRegistration.checkAndUpdateCounter(rawAuthenticateResponse.getCounter());
    usedDeviceRegistration.setLastAccessTime(new Date());
    deviceRegistrationService.updateDeviceRegistration(userInum, usedDeviceRegistration);
    DeviceRegistrationResult.Status status = DeviceRegistrationResult.Status.APPROVED;
    boolean approved = StringHelper.equals(RawAuthenticationService.AUTHENTICATE_GET_TYPE, clientData.getTyp());
    if (!approved) {
        status = DeviceRegistrationResult.Status.CANCELED;
        log.debug("Authentication request with keyHandle '{}' was canceled", response.getKeyHandle());
    }
    return new DeviceRegistrationResult(usedDeviceRegistration, status);
}
Also used : AuthenticateRequest(org.xdi.oxauth.model.fido.u2f.protocol.AuthenticateRequest) BadInputException(org.xdi.oxauth.model.fido.u2f.exception.BadInputException) ClientData(org.xdi.oxauth.model.fido.u2f.protocol.ClientData) DeviceRegistration(org.xdi.oxauth.model.fido.u2f.DeviceRegistration) DeviceCompromisedException(org.xdi.oxauth.exception.fido.u2f.DeviceCompromisedException) DeviceRegistrationResult(org.xdi.oxauth.model.fido.u2f.DeviceRegistrationResult) RawAuthenticateResponse(org.xdi.oxauth.model.fido.u2f.message.RawAuthenticateResponse) Date(java.util.Date)

Aggregations

RawAuthenticateResponse (org.xdi.oxauth.model.fido.u2f.message.RawAuthenticateResponse)2 Date (java.util.Date)1 Test (org.testng.annotations.Test)1 BaseComponentTest (org.xdi.oxauth.BaseComponentTest)1 DeviceCompromisedException (org.xdi.oxauth.exception.fido.u2f.DeviceCompromisedException)1 DeviceRegistration (org.xdi.oxauth.model.fido.u2f.DeviceRegistration)1 DeviceRegistrationResult (org.xdi.oxauth.model.fido.u2f.DeviceRegistrationResult)1 BadInputException (org.xdi.oxauth.model.fido.u2f.exception.BadInputException)1 AuthenticateRequest (org.xdi.oxauth.model.fido.u2f.protocol.AuthenticateRequest)1 ClientData (org.xdi.oxauth.model.fido.u2f.protocol.ClientData)1