Search in sources :

Example 6 with ProtocolException

use of org.openecard.common.sal.protocol.exception.ProtocolException 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 7 with ProtocolException

use of org.openecard.common.sal.protocol.exception.ProtocolException in project open-ecard by ecsec.

the class TerminalAuthentication method externalAuthentication.

/**
 * Performs an External Authentication.
 * Sends an External Authentication APDU. (Protocol step 4)
 * See BSI-TR-03110, version 2.10, part 3, B.11.7.
 *
 * @param terminalSignature Terminal signature
 * @throws ProtocolException
 */
public void externalAuthentication(byte[] terminalSignature) throws ProtocolException {
    try {
        CardCommandAPDU externalAuthentication = new ExternalAuthentication(terminalSignature);
        externalAuthentication.transmit(dispatcher, slotHandle);
    } catch (APDUException e) {
        throw new ProtocolException(e.getResult());
    }
}
Also used : CardCommandAPDU(org.openecard.common.apdu.common.CardCommandAPDU) ProtocolException(org.openecard.common.sal.protocol.exception.ProtocolException) APDUException(org.openecard.common.apdu.exception.APDUException) ExternalAuthentication(org.openecard.common.apdu.ExternalAuthentication)

Example 8 with ProtocolException

use of org.openecard.common.sal.protocol.exception.ProtocolException in project open-ecard by ecsec.

the class TerminalAuthentication method getChallenge.

/**
 * Gets a challenge from the PICC.
 * Sends a Get Challenge APDU. (Protocol step 3)
 * See BSI-TR-03110, version 2.10, part 3, B.11.6.
 *
 * @return Challenge
 * @throws ProtocolException
 */
public byte[] getChallenge() throws ProtocolException {
    try {
        CardCommandAPDU getChallenge = new GetChallenge();
        CardResponseAPDU response = getChallenge.transmit(dispatcher, slotHandle);
        return response.getData();
    } catch (APDUException e) {
        throw new ProtocolException(e.getResult());
    }
}
Also used : CardCommandAPDU(org.openecard.common.apdu.common.CardCommandAPDU) ProtocolException(org.openecard.common.sal.protocol.exception.ProtocolException) APDUException(org.openecard.common.apdu.exception.APDUException) CardResponseAPDU(org.openecard.common.apdu.common.CardResponseAPDU) GetChallenge(org.openecard.common.apdu.GetChallenge)

Aggregations

ProtocolException (org.openecard.common.sal.protocol.exception.ProtocolException)8 APDUException (org.openecard.common.apdu.exception.APDUException)7 CardCommandAPDU (org.openecard.common.apdu.common.CardCommandAPDU)6 CardResponseAPDU (org.openecard.common.apdu.common.CardResponseAPDU)3 TLVException (org.openecard.common.tlv.TLVException)2 DIDAuthenticateResponse (iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 DynamicContext (org.openecard.common.DynamicContext)1 ExternalAuthentication (org.openecard.common.apdu.ExternalAuthentication)1 GeneralAuthenticate (org.openecard.common.apdu.GeneralAuthenticate)1 GetChallenge (org.openecard.common.apdu.GetChallenge)1 ObjectSchemaValidator (org.openecard.common.interfaces.ObjectSchemaValidator)1 ObjectValidatorException (org.openecard.common.interfaces.ObjectValidatorException)1 FCP (org.openecard.common.tlv.iso7816.FCP)1 Promise (org.openecard.common.util.Promise)1 CardVerifiableCertificate (org.openecard.crypto.common.asn1.cvc.CardVerifiableCertificate)1 EAC2OutputType (org.openecard.sal.protocol.eac.anytype.EAC2OutputType)1 EACAdditionalInputType (org.openecard.sal.protocol.eac.anytype.EACAdditionalInputType)1 MSESetATCA (org.openecard.sal.protocol.eac.apdu.MSESetATCA)1 MSESetATTA (org.openecard.sal.protocol.eac.apdu.MSESetATTA)1