Search in sources :

Example 11 with DynamicContext

use of org.openecard.common.DynamicContext in project open-ecard by ecsec.

the class CVCStepAction method perform.

@Override
public StepActionResult perform(Map<String, ExecutionResults> oldResults, StepResult result) {
    if (result.isBack()) {
        // no going back to the initialization step
        return new StepActionResult(StepActionResultStatus.REPEAT);
    }
    DynamicContext ctx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
    EACData eacData = (EACData) ctx.get(EACProtocol.EAC_DATA);
    CHATStep chatStep = new CHATStep(eacData);
    chatStep.setBackgroundTask(bTask);
    StepAction chatAction = new CHATStepAction(eacData, chatStep);
    chatStep.setAction(chatAction);
    return new StepActionResult(StepActionResultStatus.NEXT, chatStep);
}
Also used : StepAction(org.openecard.gui.executor.StepAction) EACData(org.openecard.sal.protocol.eac.EACData) StepActionResult(org.openecard.gui.executor.StepActionResult) DynamicContext(org.openecard.common.DynamicContext)

Example 12 with DynamicContext

use of org.openecard.common.DynamicContext 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 13 with DynamicContext

use of org.openecard.common.DynamicContext in project open-ecard by ecsec.

the class EACProtocol method init.

@Override
public void init(Context ctx) throws ActionInitializationException {
    DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
    dynCtx.putPromise(SCHEMA_VALIDATOR, new FuturePromise<>(new Callable<ObjectSchemaValidator>() {

        @Override
        public ObjectSchemaValidator call() throws Exception {
            boolean noValid = Boolean.valueOf(OpenecardProperties.getProperty("legacy.ignore_ns"));
            ObjectSchemaValidator v;
            if (!noValid) {
                v = JAXBSchemaValidator.load(DIDAuthenticate.class, "ISO24727-Protocols.xsd");
            } else {
                // always valid
                v = new ObjectSchemaValidator() {

                    @Override
                    public boolean validateObject(Object obj) throws ObjectValidatorException {
                        return true;
                    }
                };
            }
            return v;
        }
    }));
    addOrderStep(new PACEStep(ctx.getDispatcher(), ctx.getUserConsent(), ctx.getEventDispatcher()));
    addOrderStep(new TerminalAuthenticationStep(ctx.getDispatcher()));
    addOrderStep(new ChipAuthenticationStep(ctx.getDispatcher()));
}
Also used : DIDAuthenticate(iso.std.iso_iec._24727.tech.schema.DIDAuthenticate) ObjectValidatorException(org.openecard.common.interfaces.ObjectValidatorException) ObjectSchemaValidator(org.openecard.common.interfaces.ObjectSchemaValidator) Callable(java.util.concurrent.Callable) DynamicContext(org.openecard.common.DynamicContext)

Example 14 with DynamicContext

use of org.openecard.common.DynamicContext in project open-ecard by ecsec.

the class CHATStepAction method perform.

@Override
public StepActionResult perform(Map<String, ExecutionResults> oldResults, StepResult result) {
    if (result.isOK()) {
        processResult(oldResults);
        DynamicContext ctx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
        boolean nativePace = (boolean) ctx.get(EACProtocol.IS_NATIVE_PACE);
        PACEMarkerType paceMarker = (PACEMarkerType) ctx.get(EACProtocol.PACE_MARKER);
        EacPinStatus status = (EacPinStatus) ctx.get(EACProtocol.PIN_STATUS);
        byte[] slotHandle = (byte[]) ctx.get(EACProtocol.SLOT_HANDLE);
        Dispatcher dispatcher = (Dispatcher) ctx.get(EACProtocol.DISPATCHER);
        Step pinStep;
        assert (status != null);
        switch(status) {
            case BLOCKED:
                ctx.put(EACProtocol.PIN_BLOCKED_STATUS, status);
                pinStep = new ErrorStep(LANG.translationForKey("step_error_title_blocked", PIN), LANG.translationForKey("step_error_pin_blocked", PIN, PIN, PUK, PIN), WSHelper.createException(WSHelper.makeResultError(ECardConstants.Minor.IFD.PASSWORD_BLOCKED, "Password blocked.")));
                break;
            case DEACTIVATED:
                ctx.put(EACProtocol.PIN_BLOCKED_STATUS, status);
                pinStep = new ErrorStep(LANG.translationForKey("step_error_title_deactivated"), LANG.translationForKey("step_error_pin_deactivated"), WSHelper.createException(WSHelper.makeResultError(ECardConstants.Minor.IFD.PASSWORD_SUSPENDED, "Card deactivated.")));
                break;
            default:
                pinStep = new PINStep(eacData, !nativePace, paceMarker, status);
                pinStep.setBackgroundTask(bTask);
                StepAction pinAction = new PINStepAction(eacData, !nativePace, slotHandle, dispatcher, (PINStep) pinStep, status);
                pinStep.setAction(pinAction);
        }
        return new StepActionResult(StepActionResultStatus.NEXT, pinStep);
    } else {
        // cancel can not happen, so only back is left to be handled
        return new StepActionResult(StepActionResultStatus.BACK);
    }
}
Also used : PACEMarkerType(org.openecard.sal.protocol.eac.anytype.PACEMarkerType) StepAction(org.openecard.gui.executor.StepAction) Step(org.openecard.gui.definition.Step) Dispatcher(org.openecard.common.interfaces.Dispatcher) StepActionResult(org.openecard.gui.executor.StepActionResult) DynamicContext(org.openecard.common.DynamicContext)

Example 15 with DynamicContext

use of org.openecard.common.DynamicContext in project open-ecard by ecsec.

the class CardMonitor method call.

@Override
public StepActionResult call() throws Exception {
    try {
        logger.debug("Waiting for card to be removed.");
        cardRemoved.deref();
        logger.debug("Card has been removed.");
        String title = langPin.translationForKey(ERROR_TITLE);
        String desc = langPin.translationForKey(ERROR_CARD_REMOVED);
        ErrorStep replacement = new ErrorStep(title, desc);
        DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
        dynCtx.put(EACProtocol.PACE_EXCEPTION, WSHelper.createException(WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, "Card has been removed.")));
        return new StepActionResult(StepActionResultStatus.REPEAT, replacement);
    } catch (InterruptedException ex) {
        logger.debug("Card has not been removed.");
        // terminate the current thread
        throw ex;
    }
}
Also used : StepActionResult(org.openecard.gui.executor.StepActionResult) DynamicContext(org.openecard.common.DynamicContext)

Aggregations

DynamicContext (org.openecard.common.DynamicContext)22 URL (java.net.URL)5 MalformedURLException (java.net.MalformedURLException)4 ObjectSchemaValidator (org.openecard.common.interfaces.ObjectSchemaValidator)4 ObjectValidatorException (org.openecard.common.interfaces.ObjectValidatorException)4 Promise (org.openecard.common.util.Promise)4 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)3 DIDAuthenticateResponse (iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse)3 Pair (org.openecard.common.util.Pair)3 StepActionResult (org.openecard.gui.executor.StepActionResult)3 DIDAuthenticate (iso.std.iso_iec._24727.tech.schema.DIDAuthenticate)2 IOException (java.io.IOException)2 BigInteger (java.math.BigInteger)2 URISyntaxException (java.net.URISyntaxException)2 InvalidAddressException (org.openecard.binding.tctoken.ex.InvalidAddressException)2 UserCancellationException (org.openecard.binding.tctoken.ex.UserCancellationException)2 TlsServerCertificate (org.openecard.bouncycastle.tls.TlsServerCertificate)2 CardVerifiableCertificate (org.openecard.crypto.common.asn1.cvc.CardVerifiableCertificate)2 CardVerifiableCertificateChain (org.openecard.crypto.common.asn1.cvc.CardVerifiableCertificateChain)2 UserConsentNavigator (org.openecard.gui.UserConsentNavigator)2