Search in sources :

Example 6 with CardInfoType

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

the class CardRecognitionImpl method getCardInfos.

@Override
public List<CardInfoType> getCardInfos() {
    // TODO: add caching
    GetCardInfoOrACD req = new GetCardInfoOrACD();
    req.setAction(ECardConstants.CIF.GET_OTHER);
    GetCardInfoOrACDResponse res = getCifRepo().getCardInfoOrACD(req);
    // checkout response if it contains our cardinfo
    List<Serializable> cifs = res.getCardInfoOrCapabilityInfo();
    ArrayList<CardInfoType> result = new ArrayList<>();
    for (Serializable next : cifs) {
        if (next instanceof CardInfoType) {
            result.add((CardInfoType) next);
        }
    }
    return result;
}
Also used : Serializable(java.io.Serializable) CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType) GetCardInfoOrACD(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACD) ArrayList(java.util.ArrayList) GetCardInfoOrACDResponse(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse)

Example 7 with CardInfoType

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

the class LocalCifRepo method getCardInfoOrACD.

@Override
public GetCardInfoOrACDResponse getCardInfoOrACD(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACD parameters) {
    List<String> cardTypes = parameters.getCardTypeIdentifier();
    ArrayList<CardInfoType> cifsResult = new ArrayList<>(cardTypes.size());
    Result result = WSHelper.makeResultOK();
    try {
        if (ECardConstants.CIF.GET_SPECIFIED.equals(parameters.getAction())) {
            ArrayList<String> missingTypes = new ArrayList<>();
            for (String cardType : cardTypes) {
                Document cif = cifs.get(cardType);
                if (cif == null) {
                    missingTypes.add(cardType);
                } else {
                    // marshal here to receive a copy of the CIF
                    cifsResult.add((CardInfoType) m.unmarshal(cif));
                }
            }
            if (!missingTypes.isEmpty()) {
                StringBuilder error = new StringBuilder("The following card types could not be found:");
                for (String type : missingTypes) {
                    error.append("\n  ").append(type);
                }
                result = WSHelper.makeResultError(ECardConstants.Minor.SAL.UNKNOWN_CARDTYPE, error.toString());
            }
        } else if (ECardConstants.CIF.GET_OTHER.equals(parameters.getAction())) {
            HashMap<String, Document> cifsTmp = new HashMap<>();
            cifsTmp.putAll(cifs);
            for (String cardType : cardTypes) {
                cifsTmp.remove(cardType);
            }
            for (Map.Entry<String, Document> e : cifsTmp.entrySet()) {
                Document next = e.getValue();
                cifsResult.add((CardInfoType) m.unmarshal(next));
            }
        } else {
            result = WSHelper.makeResultError(ECardConstants.Minor.App.INT_ERROR, "Given action is unsupported.");
        }
        GetCardInfoOrACDResponse res = WSHelper.makeResponse(GetCardInfoOrACDResponse.class, result);
        res.getCardInfoOrCapabilityInfo().addAll(cifsResult);
        return res;
    } catch (WSMarshallerException ex) {
        String msg = "Failed to unmarshal a CIF document.";
        logger.error(msg, ex);
        result = WSHelper.makeResultError(ECardConstants.Minor.App.INT_ERROR, msg);
        GetCardInfoOrACDResponse res = WSHelper.makeResponse(GetCardInfoOrACDResponse.class, result);
        return res;
    }
}
Also used : WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) Result(oasis.names.tc.dss._1_0.core.schema.Result) CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType) GetCardInfoOrACDResponse(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse)

Example 8 with CardInfoType

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

the class PINCompareProtocolTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    env = new ClientEnv();
    Dispatcher d = new MessageDispatcher(env);
    env.setDispatcher(d);
    IFD ifd = new IFD();
    ifd.setGUI(uc);
    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);
    Connect c = new Connect();
    c.setContextHandle(ecr.getContextHandle());
    c.setIFDName(listIFDsResponse.getIFDName().get(0));
    c.setSlot(BigInteger.ZERO);
    ConnectResponse connectResponse = env.getIFD().connect(c);
    ConnectionHandleType connectionHandleType = new ConnectionHandleType();
    connectionHandleType.setContextHandle(ecr.getContextHandle());
    connectionHandleType.setRecognitionInfo(recognitionInfo);
    connectionHandleType.setIFDName(listIFDsResponse.getIFDName().get(0));
    connectionHandleType.setSlotIndex(BigInteger.ZERO);
    connectionHandleType.setSlotHandle(connectResponse.getSlotHandle());
    salCallback.signalEvent(EventType.CARD_RECOGNIZED, new IfdEventObject(connectionHandleType));
    instance = new TinySAL(env, states);
    // init AddonManager
    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) ConnectResponse(iso.std.iso_iec._24727.tech.schema.ConnectResponse) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) IFD(org.openecard.ifd.scio.IFD) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) Connect(iso.std.iso_iec._24727.tech.schema.Connect) 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) ClientEnv(org.openecard.common.ClientEnv) CIFProvider(org.openecard.common.interfaces.CIFProvider) MessageDispatcher(org.openecard.transport.dispatcher.MessageDispatcher) RecognitionInfo(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo) 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 9 with CardInfoType

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

the class StatusHandler method getSupportedCards.

@Nonnull
private static List<StatusType.SupportedCards> getSupportedCards(List<String> protocols, List<CardInfoType> cifs) {
    List<StatusType.SupportedCards> result = new ArrayList<>();
    for (CardInfoType cif : cifs) {
        StatusType.SupportedCards supportedCard = new StatusType.SupportedCards();
        result.add(supportedCard);
        String name = cif.getCardType().getObjectIdentifier();
        supportedCard.setCardType(name);
        for (CardApplicationType app : cif.getApplicationCapabilities().getCardApplication()) {
            for (DIDInfoType did : app.getDIDInfo()) {
                String proto = did.getDifferentialIdentity().getDIDProtocol();
                // add protocol to list only if it is supported by the application and not yet added
                if (protocols.contains(proto) && !supportedCard.getDIDProtocols().contains(proto)) {
                    supportedCard.getDIDProtocols().add(proto);
                }
            }
        }
    }
    return result;
}
Also used : CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType) CardApplicationType(iso.std.iso_iec._24727.tech.schema.CardApplicationType) DIDInfoType(iso.std.iso_iec._24727.tech.schema.DIDInfoType) StatusType(org.openecard.ws.schema.StatusType) ArrayList(java.util.ArrayList) Nonnull(javax.annotation.Nonnull)

Example 10 with CardInfoType

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

Aggregations

CardInfoType (iso.std.iso_iec._24727.tech.schema.CardInfoType)19 ClientEnv (org.openecard.common.ClientEnv)8 CardRecognitionImpl (org.openecard.recognition.CardRecognitionImpl)8 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)6 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)4 EstablishContextResponse (iso.std.iso_iec._24727.tech.schema.EstablishContextResponse)4 GetCardInfoOrACDResponse (iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse)4 ArrayList (java.util.ArrayList)4 Expectations (mockit.Expectations)4 IfdEventObject (org.openecard.common.event.IfdEventObject)4 CIFProvider (org.openecard.common.interfaces.CIFProvider)4 Environment (org.openecard.common.interfaces.Environment)4 CardStateMap (org.openecard.common.sal.state.CardStateMap)4 SALStateCallback (org.openecard.common.sal.state.SALStateCallback)4 IFD (org.openecard.ifd.scio.IFD)4 MessageDispatcher (org.openecard.transport.dispatcher.MessageDispatcher)4 Test (org.testng.annotations.Test)4 RecognitionInfo (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo)3 GetCardInfoOrACD (iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACD)3 ListIFDs (iso.std.iso_iec._24727.tech.schema.ListIFDs)3