Search in sources :

Example 11 with Disconnect

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

the class CardRecognitionImpl method disconnect.

private void disconnect(byte[] slotHandle) throws RecognitionException {
    // end exclusive card access
    EndTransaction end = new EndTransaction();
    end.setSlotHandle(slotHandle);
    EndTransactionResponse endTransactionResponse = (EndTransactionResponse) env.getDispatcher().safeDeliver(end);
    checkResult(endTransactionResponse.getResult());
    Disconnect d = new Disconnect();
    d.setSlotHandle(slotHandle);
    DisconnectResponse r = (DisconnectResponse) env.getDispatcher().safeDeliver(d);
    checkResult(r.getResult());
}
Also used : EndTransaction(iso.std.iso_iec._24727.tech.schema.EndTransaction) Disconnect(iso.std.iso_iec._24727.tech.schema.Disconnect) DisconnectResponse(iso.std.iso_iec._24727.tech.schema.DisconnectResponse) EndTransactionResponse(iso.std.iso_iec._24727.tech.schema.EndTransactionResponse)

Example 12 with Disconnect

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

the class ChipGateway method sendHello.

public TerminateType sendHello() throws VersionTooOld, ChipGatewayDataError, ConnectionError, InvalidRedirectUrlException, AuthServerException {
    try {
        byte[] challenge = ValueGenerators.generateRandom(32);
        helloReq = new HelloRequestType();
        helloReq.setSessionIdentifier(sessionId);
        helloReq.setVersion(String.format("%s.%s.%s", AppVersion.getMajor(), AppVersion.getMinor(), AppVersion.getPatch()));
        helloReq.setChallenge(challenge);
        // send Hello
        String helloReqMsg = mapper.writeValueAsString(helloReq);
        HelloResponseType helloResp = sendMessageInterruptable(getResource(helloUrl), helloReqMsg, HelloResponseType.class);
        processHelloResponse(helloResp);
        // send GetCommand
        GetCommandType cmdReq = createGetCommandRequest();
        String cmdReqMsg = mapper.writeValueAsString(cmdReq);
        CommandType cmdResp;
        try {
            cmdResp = sendMessageInterruptable(getResource(getCommandUrl), cmdReqMsg, CommandType.class);
        } catch (ThreadTerminateException ex) {
            performProcessCancelled();
            throw ex;
        }
        // send messages to the server as long as there is no termination response
        while (cmdResp.getTerminate() == null) {
            ListTokensRequestType tokensReq = cmdResp.getListTokensRequest();
            ListCertificatesRequestType certReq = cmdResp.getListCertificatesRequest();
            SignRequestType signReq = cmdResp.getSignRequest();
            if (tokensReq != null) {
                cmdResp = processTokensRequest(tokensReq);
            } else if (certReq != null) {
                cmdResp = processCertificatesRequest(certReq);
            } else if (signReq != null) {
                cmdResp = processSignRequest(signReq);
            } else {
                throw new ChipGatewayDataError(token.finalizeErrorAddress(ResultMinor.SERVER_ERROR), INVALID_CHIPGATEWAY_MSG);
            }
        }
        // return the last message (terminate type)
        return cmdResp.getTerminate();
    } catch (JsonProcessingException ex) {
        throw new ChipGatewayDataError(token.finalizeErrorAddress(ResultMinor.CLIENT_ERROR), INVALID_CHIPGATEWAY_MSG, ex);
    } finally {
        // clear token cache and delete all pins in it
        tokenCache.clearPins();
        // display GUI if needed
        if (showDialogThread != null) {
            showDialogThread.start();
        }
        try {
            // in case we are interrupted, terminate is sent in the background, so don't close just yet
            if (conn != null && !isInterrupted) {
                conn.close();
            }
        } catch (IOException ex) {
            LOG.error("Failed to close connection to server.", ex);
        }
        // disconnect all slots which have been connected in the process
        for (byte[] nextSlot : connectedSlots) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Disconnecting card with slotHandle={}.", ByteUtils.toHexString(nextSlot));
            }
            CardApplicationDisconnect req = new CardApplicationDisconnect();
            // req.setAction(ActionType.RESET);
            ConnectionHandleType handle = HandlerBuilder.create().setSlotHandle(nextSlot).buildConnectionHandle();
            req.setConnectionHandle(handle);
            dispatcher.safeDeliver(req);
        }
    }
}
Also used : ListTokensRequestType(org.openecard.ws.chipgateway.ListTokensRequestType) ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) CardApplicationDisconnect(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect) ChipGatewayDataError(org.openecard.addons.cg.ex.ChipGatewayDataError) GetCommandType(org.openecard.ws.chipgateway.GetCommandType) IOException(java.io.IOException) SignRequestType(org.openecard.ws.chipgateway.SignRequestType) HelloResponseType(org.openecard.ws.chipgateway.HelloResponseType) CommandType(org.openecard.ws.chipgateway.CommandType) GetCommandType(org.openecard.ws.chipgateway.GetCommandType) ListCertificatesRequestType(org.openecard.ws.chipgateway.ListCertificatesRequestType) HelloRequestType(org.openecard.ws.chipgateway.HelloRequestType) ThreadTerminateException(org.openecard.common.ThreadTerminateException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 13 with Disconnect

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

the class GenericPINAction method performUnblockPIN.

private StepActionResult performUnblockPIN(Map<String, ExecutionResults> oldResults) {
    try {
        EstablishChannelResponse pukResponse = performPACEWithPUK(oldResults);
        if (pukResponse == null) {
            gPINStep.setWrongPUKFormat(true);
            gPINStep.setFailedPUKVerify(false);
            // to reset the text fields
            gPINStep.updateState(state);
            return new StepActionResult(StepActionResultStatus.REPEAT);
        }
        if (pukResponse.getResult().getResultMajor().equals(ECardConstants.Major.ERROR)) {
            if (pukResponse.getResult().getResultMinor().equals(ECardConstants.Minor.IFD.AUTHENTICATION_FAILED)) {
                // i think we should not display the counter
                // gPINStep.decreasePUKCounter();
                gPINStep.setWrongPUKFormat(false);
                gPINStep.setFailedPUKVerify(true);
                // to reset the text fields
                gPINStep.updateState(state);
                return new StepActionResult(StepActionResultStatus.REPEAT);
            } else {
                WSHelper.checkResult(pukResponse);
            }
        }
        // Here no exception is thrown so sent the ResetRetryCounter command
        ResetRetryCounter resetRetryCounter = new ResetRetryCounter((byte) 0x03);
        List<byte[]> responses = new ArrayList<>();
        responses.add(new byte[] { (byte) 0x90, (byte) 0x00 });
        responses.add(new byte[] { (byte) 0x69, (byte) 0x84 });
        CardResponseAPDU resetCounterResponse = resetRetryCounter.transmit(dispatcher, slotHandle, responses);
        if (Arrays.equals(resetCounterResponse.getTrailer(), new byte[] { (byte) 0x69, (byte) 0x84 })) {
            gPINStep.updateState(RecognizedState.PUK_blocked);
            return new StepActionResult(StepActionResultStatus.REPEAT);
        } else if (Arrays.equals(resetCounterResponse.getTrailer(), new byte[] { (byte) 0x90, (byte) 0x00 })) {
            gPINStep.updateState(RecognizedState.PIN_activated_RC3);
            return new StepActionResult(StepActionResultStatus.REPEAT, generateSuccessStep(lang.translationForKey(PUK_SUCCESS)));
        } else {
            gPINStep.updateState(RecognizedState.UNKNOWN);
            return new StepActionResult(StepActionResultStatus.REPEAT);
        }
    } catch (APDUException | ParserConfigurationException ex) {
        LOG.error("An internal error occurred while trying to unblock the PIN.", ex);
        return new StepActionResult(StepActionResultStatus.REPEAT, generateErrorStep(lang.translationForKey(ERROR_INTERNAL)));
    } catch (WSHelper.WSException ex) {
        // This is for PIN Pad Readers in case the user pressed the cancel button on the reader.
        if (ex.getResultMinor().equals(ECardConstants.Minor.IFD.CANCELLATION_BY_USER)) {
            LOG.error("User canceled the authentication manually or removed the card.", ex);
            return new StepActionResult(StepActionResultStatus.REPEAT, generateErrorStep(lang.translationForKey(ERROR_USER_CANCELLATION_OR_CARD_REMOVED)));
        }
        // for users which forgot to type in something
        if (ex.getResultMinor().equals(ECardConstants.Minor.IFD.TIMEOUT_ERROR)) {
            LOG.error("The terminal timed out no password was entered.", ex);
            return new StepActionResult(StepActionResultStatus.REPEAT, generateErrorStep(lang.translationForKey(ERROR_TIMEOUT)));
        }
        // for people which think they have to remove the card in the process
        if (ex.getResultMinor().equals(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE)) {
            LOG.error("The SlotHandle was invalid so probably the user removed the card or an reset occurred.", ex);
            return new StepActionResult(StepActionResultStatus.REPEAT, generateErrorStep(lang.translationForKey(ERROR_CARD_REMOVED)));
        }
        // We don't know what happend so just show an general error message
        LOG.error("An unknown error occurred while trying to verify the PUK.", ex);
        return new StepActionResult(StepActionResultStatus.REPEAT, generateErrorStep(lang.translationForKey(ERROR_UNKNOWN)));
    } finally {
        // destroy the pace channel
        DestroyChannel destChannel = new DestroyChannel();
        destChannel.setSlotHandle(slotHandle);
        dispatcher.safeDeliver(destChannel);
        // For readers which do not support DestroyChannel but have generic pace support
        Disconnect disconnect = new Disconnect();
        disconnect.setSlotHandle(slotHandle);
        disconnect.setAction(ActionType.RESET);
        dispatcher.safeDeliver(disconnect);
    }
}
Also used : WSHelper(org.openecard.common.WSHelper) APDUException(org.openecard.common.apdu.exception.APDUException) ResetRetryCounter(org.openecard.common.apdu.ResetRetryCounter) EstablishChannelResponse(iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse) ArrayList(java.util.ArrayList) StepActionResult(org.openecard.gui.executor.StepActionResult) Disconnect(iso.std.iso_iec._24727.tech.schema.Disconnect) CardApplicationDisconnect(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect) DestroyChannel(iso.std.iso_iec._24727.tech.schema.DestroyChannel) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) CardResponseAPDU(org.openecard.common.apdu.common.CardResponseAPDU)

Example 14 with Disconnect

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

the class GenericPINAction method updateConnectionHandle.

/**
 * Update the connection handle.
 * This is necessary after every step because we Disconnect the card with a reset if we have success or not.
 */
private void updateConnectionHandle() {
    CardApplicationPath cPath = new CardApplicationPath();
    CardApplicationPathType cPathType = new CardApplicationPathType();
    cPath.setCardAppPathRequest(cPathType);
    CardApplicationPathResponse cPathResp = (CardApplicationPathResponse) dispatcher.safeDeliver(cPath);
    List<CardApplicationPathType> cRes = cPathResp.getCardAppPathResultSet().getCardApplicationPathResult();
    for (CardApplicationPathType capt : cRes) {
        CardApplicationConnect cConn = new CardApplicationConnect();
        cConn.setCardApplicationPath(capt);
        CardApplicationConnectResponse conRes = (CardApplicationConnectResponse) dispatcher.safeDeliver(cConn);
        String cardType = conRes.getConnectionHandle().getRecognitionInfo().getCardType();
        ConnectionHandleType cHandleNew = conRes.getConnectionHandle();
        if (cardType.equals("http://bsi.bund.de/cif/npa.xml")) {
            // ensure same terminal and get the new slothandle
            if (cHandleNew.getIFDName().equals(cHandle.getIFDName()) && !Arrays.equals(cHandleNew.getSlotHandle(), slotHandle)) {
                cHandle = cHandleNew;
                slotHandle = cHandle.getSlotHandle();
                break;
            // also end if the connection handle found as before than it is still valid
            } else if (cHandleNew.getIFDName().equals(cHandle.getIFDName()) && Arrays.equals(cHandleNew.getSlotHandle(), slotHandle)) {
                break;
            }
        } else {
            CardApplicationDisconnect disconnect = new CardApplicationDisconnect();
            disconnect.setConnectionHandle(conRes.getConnectionHandle());
            disconnect.setAction(ActionType.RESET);
            dispatcher.safeDeliver(disconnect);
        }
    }
}
Also used : CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) CardApplicationDisconnect(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)

Example 15 with Disconnect

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

the class ChangePINAction method execute.

@Override
public void execute() {
    // check if a german identity card is inserted, if not wait for it
    ConnectionHandleType cHandle = waitForCardType(GERMAN_IDENTITY_CARD);
    if (cHandle == null) {
        LOG.debug("User cancelled card insertion.");
        return;
    }
    cHandle = connectToRootApplication(cHandle);
    RecognizedState pinState = recognizeState(cHandle);
    boolean nativePace;
    try {
        nativePace = genericPACESupport(cHandle);
    } catch (WSException e) {
        LOG.error("Could not get capabilities from reader.");
        return;
    }
    ChangePINDialog uc = new ChangePINDialog(gui, dispatcher, cHandle, pinState, !nativePace);
    uc.show();
    Disconnect d = new Disconnect();
    d.setSlotHandle(cHandle.getSlotHandle());
    dispatcher.safeDeliver(d);
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) ChangePINDialog(org.openecard.plugins.pinplugin.gui.ChangePINDialog) Disconnect(iso.std.iso_iec._24727.tech.schema.Disconnect) WSException(org.openecard.common.WSHelper.WSException)

Aggregations

CardApplicationDisconnect (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect)10 Disconnect (iso.std.iso_iec._24727.tech.schema.Disconnect)10 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)9 CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)5 CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)5 CardApplicationPath (iso.std.iso_iec._24727.tech.schema.CardApplicationPath)5 CardApplicationPathResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse)5 CardApplicationPathType (iso.std.iso_iec._24727.tech.schema.CardApplicationPathType)5 DisconnectResponse (iso.std.iso_iec._24727.tech.schema.DisconnectResponse)5 CardApplicationDisconnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnectResponse)4 DestroyChannel (iso.std.iso_iec._24727.tech.schema.DestroyChannel)4 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)4 IOException (java.io.IOException)4 EndTransaction (iso.std.iso_iec._24727.tech.schema.EndTransaction)3 EndTransactionResponse (iso.std.iso_iec._24727.tech.schema.EndTransactionResponse)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 ThreadTerminateException (org.openecard.common.ThreadTerminateException)3 BeginTransaction (iso.std.iso_iec._24727.tech.schema.BeginTransaction)2 BeginTransactionResponse (iso.std.iso_iec._24727.tech.schema.BeginTransactionResponse)2 ChannelHandleType (iso.std.iso_iec._24727.tech.schema.ChannelHandleType)2