Search in sources :

Example 6 with CardApplicationDisconnect

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

the class ChangePinInSALAction method execute.

@Override
public void execute() {
    List<ConnectionHandleType> connectedCards = null;
    try {
        connectedCards = connectCards();
        if (connectedCards.isEmpty()) {
        // TODO: show no card inserted dialog
        }
        for (ConnectionHandleType nextCard : connectedCards) {
            // pick first card, find pin DID and call didupdate
            String didName = null;
            try {
                didName = getPinDid(nextCard);
            } catch (WSException ex) {
                LOG.info("Skipping card, because it has no PIN DID.");
                continue;
            }
            DIDUpdate updateReq = new DIDUpdate();
            updateReq.setConnectionHandle(nextCard);
            updateReq.setDIDName(didName);
            DIDUpdateDataType updateData = new PinCompareDIDUpdateDataType();
            updateData.setProtocol("urn:oid:1.3.162.15480.3.0.9");
            updateReq.setDIDUpdateData(updateData);
            dispatcher.safeDeliver(updateReq);
        }
    } catch (WSException ex) {
    } finally {
        if (connectedCards != null) {
            for (ConnectionHandleType nextHandle : connectedCards) {
                CardApplicationDisconnect dr = new CardApplicationDisconnect();
                dr.setConnectionHandle(nextHandle);
                dr.setAction(ActionType.RESET);
                dispatcher.safeDeliver(dr);
            }
        }
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) CardApplicationDisconnect(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect) DIDUpdate(iso.std.iso_iec._24727.tech.schema.DIDUpdate) WSException(org.openecard.common.WSHelper.WSException) PinCompareDIDUpdateDataType(iso.std.iso_iec._24727.tech.schema.PinCompareDIDUpdateDataType) PinCompareDIDUpdateDataType(iso.std.iso_iec._24727.tech.schema.PinCompareDIDUpdateDataType) DIDUpdateDataType(iso.std.iso_iec._24727.tech.schema.DIDUpdateDataType)

Example 7 with CardApplicationDisconnect

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

the class TinySALTest method testCardApplicationDisconnect.

/**
 * Test of cardApplicationDisconnect method, of class TinySAL.
 */
@Test(enabled = TESTS_ENABLED)
public void testCardApplicationDisconnect() {
    System.out.println("cardApplicationDisconnect");
    // test normal case
    // get esign path
    CardApplicationPath cardApplicationPath = new CardApplicationPath();
    CardApplicationPathType cardApplicationPathType = new CardApplicationPathType();
    cardApplicationPathType.setCardApplication(appIdentifier_ESIGN);
    cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
    CardApplicationPathResponse cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
    // connect to esign
    CardApplicationConnect cardApplicationConnect = new CardApplicationConnect();
    cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
    CardApplicationConnectResponse result = instance.cardApplicationConnect(cardApplicationConnect);
    assertEquals(appIdentifier_ESIGN, result.getConnectionHandle().getCardApplication());
    assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
    // disconnect
    CardApplicationDisconnect cardApplicationDisconnect = new CardApplicationDisconnect();
    cardApplicationDisconnect.setConnectionHandle(result.getConnectionHandle());
    instance.cardApplicationDisconnect(cardApplicationDisconnect);
    assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
    // test invalid connectionhandle
    // connect to esign
    cardApplicationConnect = new CardApplicationConnect();
    cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
    result = instance.cardApplicationConnect(cardApplicationConnect);
    assertEquals(appIdentifier_ESIGN, result.getConnectionHandle().getCardApplication());
    assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
    // disconnect
    cardApplicationDisconnect = new CardApplicationDisconnect();
    cardApplicationDisconnect.setConnectionHandle(result.getConnectionHandle());
    cardApplicationDisconnect.getConnectionHandle().setSlotHandle(new byte[] { 0x0, 0x0, 0x0 });
    CardApplicationDisconnectResponse cardApplicationDisconnectResponse = instance.cardApplicationDisconnect(cardApplicationDisconnect);
    assertEquals(ECardConstants.Major.ERROR, cardApplicationDisconnectResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, cardApplicationDisconnectResponse.getResult().getResultMinor());
    // test nullpointer
    // connect to esign
    cardApplicationConnect = new CardApplicationConnect();
    cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
    result = instance.cardApplicationConnect(cardApplicationConnect);
    assertEquals(appIdentifier_ESIGN, result.getConnectionHandle().getCardApplication());
    assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
    // disconnect
    cardApplicationDisconnect = new CardApplicationDisconnect();
    cardApplicationDisconnect.setConnectionHandle(null);
    cardApplicationDisconnectResponse = instance.cardApplicationDisconnect(cardApplicationDisconnect);
    assertEquals(ECardConstants.Major.ERROR, cardApplicationDisconnectResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, cardApplicationDisconnectResponse.getResult().getResultMinor());
}
Also used : CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) 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) CardApplicationDisconnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnectResponse) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) Test(org.testng.annotations.Test)

Example 8 with CardApplicationDisconnect

use of iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect 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 9 with CardApplicationDisconnect

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

the class CardStateMap method removeSlotHandleEntry.

/**
 * Remove the entry reference in slotHandle index. <br>
 * This function is needed to update the index in CardApplicationDisconnect.
 *
 * @param slotHandle SlotHandle for which the entry reference should be deleted.
 */
public synchronized void removeSlotHandleEntry(byte[] slotHandle) {
    ConnectionHandleType handle = new ConnectionHandleType();
    handle.setSlotHandle(slotHandle);
    Set<CardStateEntry> entries = getMatchingEntries(handle);
    Iterator<CardStateEntry> it = entries.iterator();
    if (it.hasNext()) {
        CardStateEntry entry = it.next();
        removeMapEntry(handle.getSlotHandle(), slothandleMap, entry);
        clearProtocolsForEntry(entry);
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)

Example 10 with CardApplicationDisconnect

use of iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect 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)

Aggregations

CardApplicationDisconnect (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect)9 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)8 CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)5 CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)5 CardApplicationDisconnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnectResponse)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 Disconnect (iso.std.iso_iec._24727.tech.schema.Disconnect)3 DisconnectResponse (iso.std.iso_iec._24727.tech.schema.DisconnectResponse)3 IOException (java.io.IOException)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 Connect (iso.std.iso_iec._24727.tech.schema.Connect)2 ConnectResponse (iso.std.iso_iec._24727.tech.schema.ConnectResponse)2 DIDAuthenticate (iso.std.iso_iec._24727.tech.schema.DIDAuthenticate)2 DIDAuthenticateResponse (iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse)2 DestroyChannel (iso.std.iso_iec._24727.tech.schema.DestroyChannel)2