Search in sources :

Example 61 with ConnectionHandleType

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

the class ListTokens method getUnknownCards.

private List<TokenInfoType> getUnknownCards(List<ConnectionHandleType> knownHandles) {
    ArrayList<TokenInfoType> result = new ArrayList<>();
    List<byte[]> ifdCtxs = ctx.getIfdCtx();
    for (byte[] ifdCtx : ifdCtxs) {
        try {
            // get all IFD names
            GetStatus gs = new GetStatus();
            gs.setContextHandle(ifdCtx);
            GetStatusResponse gsr = (GetStatusResponse) dispatcher.safeDeliver(gs);
            WSHelper.checkResult(gsr);
            for (IFDStatusType istatus : gsr.getIFDStatus()) {
                for (SlotStatusType sstatus : istatus.getSlotStatus()) // check if name is already in the list of known cards
                if (sstatus.isCardAvailable() && !isInHandleList(istatus.getIFDName(), knownHandles)) {
                    TokenInfoType ti = new TokenInfoType();
                    org.openecard.ws.chipgateway.ConnectionHandleType conHandle;
                    conHandle = new org.openecard.ws.chipgateway.ConnectionHandleType();
                    conHandle.setCardType(ECardConstants.UNKNOWN_CARD);
                    ti.setConnectionHandle(conHandle);
                    // add to handle list
                    result.add(ti);
                }
            }
        } catch (WSHelper.WSException ex) {
            LOG.warn("Failed to retrieve status info from IFD. Skipping unknown card entries.");
        }
    }
    return result;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) WSHelper(org.openecard.common.WSHelper) GetStatusResponse(iso.std.iso_iec._24727.tech.schema.GetStatusResponse) ArrayList(java.util.ArrayList) TokenInfoType(org.openecard.ws.chipgateway.TokenInfoType) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType) GetStatus(iso.std.iso_iec._24727.tech.schema.GetStatus)

Example 62 with ConnectionHandleType

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

the class GenericCryptographyProtocolTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    env = new ClientEnv();
    Dispatcher d = new MessageDispatcher(env);
    env.setDispatcher(d);
    ifd = new IFD();
    ifd.setGUI(new SwingUserConsent(new SwingDialogWrapper()));
    env.setIFD(ifd);
    states = new CardStateMap();
    EstablishContextResponse ecr = env.getIFD().establishContext(new EstablishContext());
    final CardRecognitionImpl cr = new CardRecognitionImpl(env);
    ListIFDs listIFDs = new ListIFDs();
    CIFProvider cp = new CIFProvider() {

        @Override
        public CardInfoType getCardInfo(ConnectionHandleType type, String cardType) {
            return cr.getCardInfo(cardType);
        }

        @Override
        public boolean needsRecognition(byte[] atr) {
            return true;
        }

        @Override
        public CardInfoType getCardInfo(String cardType) throws RuntimeException {
            return cr.getCardInfo(cardType);
        }

        @Override
        public InputStream getCardImage(String cardType) {
            return cr.getCardImage(cardType);
        }
    };
    env.setCIFProvider(cp);
    listIFDs.setContextHandle(ecr.getContextHandle());
    ListIFDsResponse listIFDsResponse = ifd.listIFDs(listIFDs);
    RecognitionInfo recognitionInfo = cr.recognizeCard(ecr.getContextHandle(), listIFDsResponse.getIFDName().get(0), BigInteger.ZERO);
    SALStateCallback salCallback = new SALStateCallback(env, states);
    ConnectionHandleType connectionHandleType = new ConnectionHandleType();
    connectionHandleType.setContextHandle(ecr.getContextHandle());
    connectionHandleType.setRecognitionInfo(recognitionInfo);
    connectionHandleType.setIFDName(listIFDsResponse.getIFDName().get(0));
    connectionHandleType.setSlotIndex(new BigInteger("0"));
    salCallback.signalEvent(EventType.CARD_RECOGNIZED, new IfdEventObject(connectionHandleType));
    instance = new TinySAL(env, states);
    env.setSAL(instance);
    // init AddonManager
    UserConsent uc = new SwingUserConsent(new SwingDialogWrapper());
    AddonManager manager = new AddonManager(env, uc, states, null);
    instance.setAddonManager(manager);
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) SALStateCallback(org.openecard.common.sal.state.SALStateCallback) TinySAL(org.openecard.sal.TinySAL) ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) ListIFDsResponse(iso.std.iso_iec._24727.tech.schema.ListIFDsResponse) IFD(org.openecard.ifd.scio.IFD) CardRecognitionImpl(org.openecard.recognition.CardRecognitionImpl) Dispatcher(org.openecard.common.interfaces.Dispatcher) MessageDispatcher(org.openecard.transport.dispatcher.MessageDispatcher) EstablishContextResponse(iso.std.iso_iec._24727.tech.schema.EstablishContextResponse) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) UserConsent(org.openecard.gui.UserConsent) ClientEnv(org.openecard.common.ClientEnv) CIFProvider(org.openecard.common.interfaces.CIFProvider) MessageDispatcher(org.openecard.transport.dispatcher.MessageDispatcher) SwingDialogWrapper(org.openecard.gui.swing.SwingDialogWrapper) RecognitionInfo(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) BigInteger(java.math.BigInteger) CardStateMap(org.openecard.common.sal.state.CardStateMap) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) IfdEventObject(org.openecard.common.event.IfdEventObject) AddonManager(org.openecard.addon.AddonManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 63 with ConnectionHandleType

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

the class AbstractPINAction method connectToRootApplication.

/**
 * Connect to the root application of the card specified with a connection handle using a empty CardApplicationPath
 * and afterwards a CardApplicationConnect.
 *
 * @param cHandle
 *            The connection handle for the card to connect to root application.
 * @return The updated connection handle (now including a SlotHandle) or null if connecting went wrong.
 */
protected ConnectionHandleType connectToRootApplication(ConnectionHandleType cHandle) {
    // Perform a CardApplicationPath and CardApplicationConnect to connect to the card application
    CardApplicationPath cardApplicationPath = new CardApplicationPath();
    cardApplicationPath.setCardAppPathRequest(cHandle);
    CardApplicationPathResponse cardApplicationPathResponse = (CardApplicationPathResponse) dispatcher.safeDeliver(cardApplicationPath);
    // Check CardApplicationPathResponse
    try {
        WSHelper.checkResult(cardApplicationPathResponse);
    } catch (WSException ex) {
        LOG.error("CardApplicationPath failed.", ex);
        return null;
    }
    CardApplicationConnect cardApplicationConnect = new CardApplicationConnect();
    cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
    CardApplicationConnectResponse cardApplicationConnectResponse = (CardApplicationConnectResponse) dispatcher.safeDeliver(cardApplicationConnect);
    // Check CardApplicationConnectResponse
    try {
        WSHelper.checkResult(cardApplicationConnectResponse);
    } catch (WSException ex) {
        LOG.error("CardApplicationConnect failed.", ex);
        return null;
    }
    // Update ConnectionHandle. It now includes a SlotHandle.
    cHandle = cardApplicationConnectResponse.getConnectionHandle();
    return cHandle;
}
Also used : CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) WSException(org.openecard.common.WSHelper.WSException) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)

Example 64 with ConnectionHandleType

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

the class AbstractPINAction method recognizeState.

/**
 * Recognize the PIN state of the card given through the connection handle.
 *
 * @param cHandle The connection handle for the card for which the pin state should be recognized.
 * @return The recognized State (may be {@code RecognizedState.UNKNOWN}).
 */
protected RecognizedState recognizeState(ConnectionHandleType cHandle) {
    Transmit t = new Transmit();
    t.setSlotHandle(cHandle.getSlotHandle());
    InputAPDUInfoType inputAPDU = new InputAPDUInfoType();
    inputAPDU.setInputAPDU(RECOGNIZE_APDU);
    t.getInputAPDUInfo().add(inputAPDU);
    TransmitResponse response = (TransmitResponse) dispatcher.safeDeliver(t);
    byte[] responseAPDU = response.getOutputAPDU().get(0);
    RecognizedState state;
    if (ByteUtils.compare(RESPONSE_RC3, responseAPDU)) {
        state = RecognizedState.PIN_activated_RC3;
    } else if (ByteUtils.compare(RESPONSE_DEACTIVATED, responseAPDU)) {
        state = RecognizedState.PIN_deactivated;
    } else if (ByteUtils.compare(RESPONSE_RC2, responseAPDU)) {
        state = RecognizedState.PIN_activated_RC2;
    } else if (ByteUtils.compare(RESPONSE_SUSPENDED, responseAPDU)) {
        state = RecognizedState.PIN_suspended;
    } else if (ByteUtils.compare(RESPONSE_BLOCKED, responseAPDU)) {
        state = RecognizedState.PIN_blocked;
    } else {
        LOG.error("Unhandled response to the PIN state recognition APDU: {}\n");
        state = RecognizedState.UNKNOWN;
    }
    LOG.info("State of the PIN: {}.", state);
    return state;
}
Also used : Transmit(iso.std.iso_iec._24727.tech.schema.Transmit) InputAPDUInfoType(iso.std.iso_iec._24727.tech.schema.InputAPDUInfoType) TransmitResponse(iso.std.iso_iec._24727.tech.schema.TransmitResponse)

Example 65 with ConnectionHandleType

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

the class AbstractPINAction method genericPACESupport.

/**
 * Check if the selected card reader supports PACE.
 * In that case, the reader is a standard or comfort reader.
 *
 * @param connectionHandle Handle describing the IFD and reader.
 * @return true when card reader supports genericPACE, false otherwise.
 * @throws WSException In case request for the terminal capabilities returned an error.
 */
protected boolean genericPACESupport(ConnectionHandleType connectionHandle) throws WSException {
    // Request terminal capabilities
    GetIFDCapabilities capabilitiesRequest = new GetIFDCapabilities();
    capabilitiesRequest.setContextHandle(connectionHandle.getContextHandle());
    capabilitiesRequest.setIFDName(connectionHandle.getIFDName());
    GetIFDCapabilitiesResponse capabilitiesResponse = (GetIFDCapabilitiesResponse) dispatcher.safeDeliver(capabilitiesRequest);
    WSHelper.checkResult(capabilitiesResponse);
    if (capabilitiesResponse.getIFDCapabilities() != null) {
        List<SlotCapabilityType> capabilities = capabilitiesResponse.getIFDCapabilities().getSlotCapability();
        // Check all capabilities for generic PACE
        final String genericPACE = PACECapabilities.PACECapability.GenericPACE.getProtocol();
        for (SlotCapabilityType capability : capabilities) {
            if (capability.getIndex().equals(connectionHandle.getSlotIndex())) {
                for (String protocol : capability.getProtocol()) {
                    if (protocol.equals(genericPACE)) {
                        return true;
                    }
                }
            }
        }
    }
    // No PACE capability found
    return false;
}
Also used : GetIFDCapabilities(iso.std.iso_iec._24727.tech.schema.GetIFDCapabilities) SlotCapabilityType(iso.std.iso_iec._24727.tech.schema.SlotCapabilityType) GetIFDCapabilitiesResponse(iso.std.iso_iec._24727.tech.schema.GetIFDCapabilitiesResponse)

Aggregations

ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)110 CardStateEntry (org.openecard.common.sal.state.CardStateEntry)47 ECardException (org.openecard.common.ECardException)43 IncorrectParameterException (org.openecard.common.sal.exception.IncorrectParameterException)37 ThreadTerminateException (org.openecard.common.ThreadTerminateException)36 NamedEntityNotFoundException (org.openecard.common.sal.exception.NamedEntityNotFoundException)34 UnknownProtocolException (org.openecard.common.sal.exception.UnknownProtocolException)34 TLVException (org.openecard.common.tlv.TLVException)29 AddonNotFoundException (org.openecard.addon.AddonNotFoundException)28 InappropriateProtocolForActionException (org.openecard.common.sal.exception.InappropriateProtocolForActionException)28 NameExistsException (org.openecard.common.sal.exception.NameExistsException)28 PrerequisitesNotSatisfiedException (org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException)28 SecurityConditionNotSatisfiedException (org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException)28 UnknownConnectionHandleException (org.openecard.common.sal.exception.UnknownConnectionHandleException)28 DIDStructureType (iso.std.iso_iec._24727.tech.schema.DIDStructureType)22 Publish (org.openecard.common.interfaces.Publish)17 CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)15 ArrayList (java.util.ArrayList)15 CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)14 CardApplicationPathType (iso.std.iso_iec._24727.tech.schema.CardApplicationPathType)14