Search in sources :

Example 1 with EACAdditionalInputType

use of iso.std.iso_iec._24727.tech.schema.EACAdditionalInputType in project open-ecard by ecsec.

the class ChipAuthenticationStep method perform.

@Override
public DIDAuthenticateResponse perform(DIDAuthenticate didAuthenticate, Map<String, Object> internalData) {
    DIDAuthenticateResponse response = new DIDAuthenticateResponse();
    byte[] slotHandle = didAuthenticate.getConnectionHandle().getSlotHandle();
    DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
    try {
        ObjectSchemaValidator valid = (ObjectSchemaValidator) dynCtx.getPromise(EACProtocol.SCHEMA_VALIDATOR).deref();
        boolean messageValid = valid.validateObject(didAuthenticate);
        if (!messageValid) {
            String msg = "Validation of the EACAdditionalInputType message failed.";
            logger.error(msg);
            dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
            response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INCORRECT_PARM, msg));
            return response;
        }
    } catch (ObjectValidatorException ex) {
        String msg = "Validation of the EACAdditionalInputType message failed due to invalid input data.";
        logger.error(msg, ex);
        dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
        response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INT_ERROR, msg));
        return response;
    } catch (InterruptedException ex) {
        String msg = "Thread interrupted while waiting for schema validator instance.";
        logger.error(msg, ex);
        dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
        response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INT_ERROR, msg));
        return response;
    }
    try {
        EACAdditionalInputType eacAdditionalInput = new EACAdditionalInputType(didAuthenticate.getAuthenticationProtocolData());
        EAC2OutputType eac2Output = eacAdditionalInput.getOutputType();
        TerminalAuthentication ta = new TerminalAuthentication(dispatcher, slotHandle);
        ChipAuthentication ca = new ChipAuthentication(dispatcher, slotHandle);
        // save signature, it is needed in the authentication step
        byte[] signature = eacAdditionalInput.getSignature();
        internalData.put(EACConstants.IDATA_SIGNATURE, signature);
        // perform TA and CA authentication
        AuthenticationHelper auth = new AuthenticationHelper(ta, ca);
        eac2Output = auth.performAuth(eac2Output, internalData);
        response.setResult(WSHelper.makeResultOK());
        response.setAuthenticationProtocolData(eac2Output.getAuthDataType());
    } catch (ParserConfigurationException | ProtocolException | TLVException e) {
        logger.error(e.getMessage(), e);
        response.setResult(WSHelper.makeResultUnknownError(e.getMessage()));
        dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
    }
    Promise<Object> p = (Promise<Object>) dynCtx.getPromise(TR03112Keys.PROCESSING_CANCELLATION);
    if (p.derefNonblocking() == null) {
        // authentication finished, notify GUI
        dynCtx.put(EACProtocol.AUTHENTICATION_DONE, true);
        return response;
    } else {
        // authentication finished, notify GUI
        dynCtx.put(EACProtocol.AUTHENTICATION_DONE, false);
        response = new DIDAuthenticateResponse();
        String msg = "Authentication canceled by the user.";
        response.setResult(WSHelper.makeResultError(ECardConstants.Minor.SAL.CANCELLATION_BY_USER, msg));
        return response;
    }
}
Also used : ProtocolException(org.openecard.common.sal.protocol.exception.ProtocolException) TLVException(org.openecard.common.tlv.TLVException) EACAdditionalInputType(org.openecard.sal.protocol.eac.anytype.EACAdditionalInputType) Promise(org.openecard.common.util.Promise) DIDAuthenticateResponse(iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse) ObjectValidatorException(org.openecard.common.interfaces.ObjectValidatorException) ObjectSchemaValidator(org.openecard.common.interfaces.ObjectSchemaValidator) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DynamicContext(org.openecard.common.DynamicContext) EAC2OutputType(org.openecard.sal.protocol.eac.anytype.EAC2OutputType)

Example 2 with EACAdditionalInputType

use of iso.std.iso_iec._24727.tech.schema.EACAdditionalInputType in project open-ecard by ecsec.

the class AndroidMarshaller method parseDIDAuthenticationDataType.

private DIDAuthenticationDataType parseDIDAuthenticationDataType(XmlPullParser parser) throws XmlPullParserException, IOException {
    Document document = documentBuilder.newDocument();
    DIDAuthenticationDataType didAuthenticationDataType;
    String attrValue = parser.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance", "type");
    if (attrValue != null && attrValue.contains("EAC1InputType")) {
        didAuthenticationDataType = new EAC1InputType();
    } else if (attrValue != null && attrValue.contains("EAC2InputType")) {
        didAuthenticationDataType = new EAC2InputType();
    } else if (attrValue != null && attrValue.contains("EACAdditionalInputType")) {
        didAuthenticationDataType = new EACAdditionalInputType();
    } else {
        didAuthenticationDataType = new DIDAuthenticationDataType();
    }
    if (parser.getAttributeValue(null, "Protocol") != null && !parser.getAttributeValue(null, "Protocol").isEmpty()) {
        didAuthenticationDataType.setProtocol(parser.getAttributeValue(null, "Protocol"));
    }
    int eventType;
    do {
        parser.next();
        eventType = parser.getEventType();
        if (eventType == XmlPullParser.START_TAG) {
            Element em = createElementIso(document, parser.getName());
            em.setTextContent(parser.nextText());
            didAuthenticationDataType.getAny().add(em);
        }
    } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("AuthenticationProtocolData")));
    return didAuthenticationDataType;
}
Also used : EACAdditionalInputType(iso.std.iso_iec._24727.tech.schema.EACAdditionalInputType) EAC2InputType(iso.std.iso_iec._24727.tech.schema.EAC2InputType) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) DIDAuthenticationDataType(iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType) LocalizedString(org.openecard.addon.manifest.LocalizedString) Document(org.w3c.dom.Document) EAC1InputType(iso.std.iso_iec._24727.tech.schema.EAC1InputType)

Aggregations

DIDAuthenticateResponse (iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse)1 DIDAuthenticationDataType (iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType)1 EAC1InputType (iso.std.iso_iec._24727.tech.schema.EAC1InputType)1 EAC2InputType (iso.std.iso_iec._24727.tech.schema.EAC2InputType)1 EACAdditionalInputType (iso.std.iso_iec._24727.tech.schema.EACAdditionalInputType)1 JAXBElement (javax.xml.bind.JAXBElement)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 LocalizedString (org.openecard.addon.manifest.LocalizedString)1 DynamicContext (org.openecard.common.DynamicContext)1 ObjectSchemaValidator (org.openecard.common.interfaces.ObjectSchemaValidator)1 ObjectValidatorException (org.openecard.common.interfaces.ObjectValidatorException)1 ProtocolException (org.openecard.common.sal.protocol.exception.ProtocolException)1 TLVException (org.openecard.common.tlv.TLVException)1 Promise (org.openecard.common.util.Promise)1 EAC2OutputType (org.openecard.sal.protocol.eac.anytype.EAC2OutputType)1 EACAdditionalInputType (org.openecard.sal.protocol.eac.anytype.EACAdditionalInputType)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1