Search in sources :

Example 1 with DeviceData

use of org.xdi.oxauth.model.fido.u2f.protocol.DeviceData in project oxAuth by GluuFederation.

the class RegistrationService method finishRegistration.

public DeviceRegistrationResult finishRegistration(RegisterRequestMessage requestMessage, RegisterResponse response, String userInum, Set<String> facets) throws BadInputException {
    RegisterRequest request = requestMessage.getRegisterRequest();
    String appId = request.getAppId();
    ClientData clientData = response.getClientData();
    clientDataValidationService.checkContent(clientData, RawRegistrationService.SUPPORTED_REGISTER_TYPES, request.getChallenge(), facets);
    RawRegisterResponse rawRegisterResponse = rawRegistrationService.parseRawRegisterResponse(response.getRegistrationData());
    rawRegistrationService.checkSignature(appId, clientData, rawRegisterResponse);
    Date now = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTime();
    DeviceRegistration deviceRegistration = rawRegistrationService.createDevice(rawRegisterResponse);
    deviceRegistration.setStatus(DeviceRegistrationStatus.ACTIVE);
    deviceRegistration.setApplication(appId);
    deviceRegistration.setCreationDate(now);
    int keyHandleHashCode = deviceRegistrationService.getKeyHandleHashCode(rawRegisterResponse.getKeyHandle());
    deviceRegistration.setKeyHandleHashCode(keyHandleHashCode);
    final String deviceRegistrationId = String.valueOf(System.currentTimeMillis());
    deviceRegistration.setId(deviceRegistrationId);
    String responseDeviceData = response.getDeviceData();
    if (StringHelper.isNotEmpty(responseDeviceData)) {
        try {
            String responseDeviceDataDecoded = new String(Base64Util.base64urldecode(responseDeviceData));
            DeviceData deviceData = ServerUtil.jsonMapperWithWrapRoot().readValue(responseDeviceDataDecoded, DeviceData.class);
            deviceRegistration.setDeviceData(deviceData);
        } catch (Exception ex) {
            throw new BadInputException(String.format("Device data is invalid: %s", responseDeviceData), ex);
        }
    }
    boolean approved = StringHelper.equals(RawRegistrationService.REGISTER_FINISH_TYPE, response.getClientData().getTyp());
    if (!approved) {
        log.debug("Registratio request with keyHandle '{}' was canceled", rawRegisterResponse.getKeyHandle());
        return new DeviceRegistrationResult(deviceRegistration, DeviceRegistrationResult.Status.CANCELED);
    }
    boolean twoStep = StringHelper.isNotEmpty(userInum);
    if (twoStep) {
        deviceRegistration.setDn(deviceRegistrationService.getDnForU2fDevice(userInum, deviceRegistrationId));
        // Check if there is device registration with keyHandle in LDAP already
        List<DeviceRegistration> foundDeviceRegistrations = deviceRegistrationService.findDeviceRegistrationsByKeyHandle(appId, deviceRegistration.getKeyHandle(), "oxId");
        if (foundDeviceRegistrations.size() != 0) {
            throw new BadInputException(String.format("KeyHandle %s was compromised", deviceRegistration.getKeyHandle()));
        }
        deviceRegistrationService.addUserDeviceRegistration(userInum, deviceRegistration);
    } else {
        deviceRegistration.setDn(deviceRegistrationService.getDnForOneStepU2fDevice(deviceRegistrationId));
        deviceRegistrationService.addOneStepDeviceRegistration(deviceRegistration);
    }
    return new DeviceRegistrationResult(deviceRegistration, DeviceRegistrationResult.Status.APPROVED);
}
Also used : RegisterRequest(org.xdi.oxauth.model.fido.u2f.protocol.RegisterRequest) GregorianCalendar(java.util.GregorianCalendar) RawRegisterResponse(org.xdi.oxauth.model.fido.u2f.message.RawRegisterResponse) DeviceRegistration(org.xdi.oxauth.model.fido.u2f.DeviceRegistration) Date(java.util.Date) DeviceCompromisedException(org.xdi.oxauth.exception.fido.u2f.DeviceCompromisedException) BadInputException(org.xdi.oxauth.model.fido.u2f.exception.BadInputException) BadInputException(org.xdi.oxauth.model.fido.u2f.exception.BadInputException) ClientData(org.xdi.oxauth.model.fido.u2f.protocol.ClientData) DeviceData(org.xdi.oxauth.model.fido.u2f.protocol.DeviceData) DeviceRegistrationResult(org.xdi.oxauth.model.fido.u2f.DeviceRegistrationResult)

Example 2 with DeviceData

use of org.xdi.oxauth.model.fido.u2f.protocol.DeviceData in project oxTrust by GluuFederation.

the class UpdatePersonAction method getDeviceata.

private DeviceData getDeviceata(String data) {
    ObjectMapper mapper = new ObjectMapper();
    // JSON from file to Object
    DeviceData obj = null;
    try {
        obj = mapper.readValue(data, DeviceData.class);
    } catch (JsonParseException e) {
        // TODO Auto-generated catch block
        log.error("Failed to convert device string to object JsonParseException", e);
    } catch (JsonMappingException e) {
        // TODO Auto-generated catch block
        log.error("Failed to convert device string to object JsonMappingException", e);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        log.error("Failed to convert device string to object IOException", e);
    }
    return obj;
}
Also used : JsonMappingException(org.codehaus.jackson.map.JsonMappingException) DeviceData(org.xdi.oxauth.model.fido.u2f.protocol.DeviceData) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 3 with DeviceData

use of org.xdi.oxauth.model.fido.u2f.protocol.DeviceData in project oxTrust by GluuFederation.

the class UpdatePersonAction method update.

/**
 * Initializes attributes for updating person
 *
 * @return String describing success of the operation
 * @throws Exception
 */
public String update() {
    if (this.person != null) {
        return OxTrustConstants.RESULT_SUCCESS;
    }
    this.update = true;
    try {
        this.person = personService.getPersonByInum(inum);
    } catch (BaseMappingException ex) {
        log.error("Failed to find person {}", inum, ex);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to find person");
        conversationService.endConversation();
        return OxTrustConstants.RESULT_FAILURE;
    }
    initAttributes(false);
    try {
        this.gluuStatus = this.person.getStatus();
        List<String> oxexternal = this.person.getOxExternalUid();
        externalAuthCustomAttributes = new ArrayList<String>();
        if (oxexternal != null && oxexternal.size() > 0) {
            for (String oxexternalStr : oxexternal) {
                String[] args = oxexternalStr.split(":");
                externalAuthCustomAttributes.add(args[0]);
            }
        }
        List<GluuCustomFidoDevice> gluuCustomFidoDevices = fidoDeviceService.searchFidoDevices(this.person.getInum(), null);
        deviceDataMap = new ArrayList<GluuDeviceDataBean>();
        if (gluuCustomFidoDevices != null) {
            for (GluuCustomFidoDevice gluuCustomFidoDevice : gluuCustomFidoDevices) {
                GluuDeviceDataBean gluuDeviceDataBean = new GluuDeviceDataBean();
                gluuDeviceDataBean.setCreationDate(ldapEntryManager.decodeGeneralizedTime(gluuCustomFidoDevice.getCreationDate()).toGMTString());
                gluuDeviceDataBean.setId(gluuCustomFidoDevice.getId());
                String devicedata = gluuCustomFidoDevice.getDeviceData();
                String modality = "";
                String nickName = "";
                if (devicedata != null) {
                    DeviceData deviceData = getDeviceata(devicedata);
                    // nickName = deviceData.getName();
                    nickName = gluuCustomFidoDevice.getNickname();
                    modality = "Super-Gluu Device";
                } else {
                    // nickName = "U2F";
                    nickName = gluuCustomFidoDevice.getNickname();
                    modality = "U2F device";
                }
                gluuDeviceDataBean.setNickName(nickName);
                gluuDeviceDataBean.setModality(modality);
                deviceDataMap.add(gluuDeviceDataBean);
            }
        }
        if (oxexternal != null && oxexternal.size() > 0) {
            for (String oxexternalStr : oxexternal) {
                String[] args = oxexternalStr.split(":");
                GluuDeviceDataBean gluuDeviceDataBean = new GluuDeviceDataBean();
                gluuDeviceDataBean.setNickName(args[0]);
                gluuDeviceDataBean.setModality(args[0]);
                gluuDeviceDataBean.setId(oxexternalStr);
                deviceDataMap.add(gluuDeviceDataBean);
            }
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    userPasswordAction.setPerson(this.person);
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) GluuDeviceDataBean(org.gluu.oxtrust.model.fido.GluuDeviceDataBean) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) DeviceData(org.xdi.oxauth.model.fido.u2f.protocol.DeviceData) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException)

Aggregations

DeviceData (org.xdi.oxauth.model.fido.u2f.protocol.DeviceData)3 IOException (java.io.IOException)2 JsonParseException (org.codehaus.jackson.JsonParseException)2 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)2 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 GluuCustomFidoDevice (org.gluu.oxtrust.model.fido.GluuCustomFidoDevice)1 GluuDeviceDataBean (org.gluu.oxtrust.model.fido.GluuDeviceDataBean)1 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)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 RawRegisterResponse (org.xdi.oxauth.model.fido.u2f.message.RawRegisterResponse)1 ClientData (org.xdi.oxauth.model.fido.u2f.protocol.ClientData)1 RegisterRequest (org.xdi.oxauth.model.fido.u2f.protocol.RegisterRequest)1