Search in sources :

Example 16 with CardInfoType

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

the class TinySALTest method setUp.

@BeforeMethod()
public void setUp() throws Exception {
    env = new ClientEnv();
    Dispatcher dispatcher = new MessageDispatcher(env);
    env.setDispatcher(dispatcher);
    IFD ifd = new IFD();
    ifd.setEnvironment(env);
    env.setIFD(ifd);
    states = new CardStateMap();
    EstablishContextResponse ecr = env.getIFD().establishContext(new EstablishContext());
    final CardRecognitionImpl cr = new CardRecognitionImpl(env);
    ListIFDs listIFDs = new ListIFDs();
    contextHandle = ecr.getContextHandle();
    listIFDs.setContextHandle(ecr.getContextHandle());
    ListIFDsResponse listIFDsResponse = ifd.listIFDs(listIFDs);
    RecognitionInfo recognitionInfo = cr.recognizeCard(contextHandle, listIFDsResponse.getIFDName().get(0), BigInteger.ZERO);
    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 null;
        }
    };
    env.setCIFProvider(cp);
    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);
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) SALStateCallback(org.openecard.common.sal.state.SALStateCallback) 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) 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) 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) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 17 with CardInfoType

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

the class MiddlewareConfig method getCardInfoByCardSpec.

/**
 * Stores the CardType-Spec in a freshly allocated CardInfo Template.
 * The filled CardInfo Template will be returned.
 *
 * @param cardSpec specification of the card.
 * @return {@code CardInfoType} or {@code null} if there is no available CardInfo Template.
 */
public CardInfoType getCardInfoByCardSpec(CardSpecType cardSpec) {
    CardInfoType cardInfo = getCardInfoTemplate();
    cardInfo.setCardType(mapCardSpecToCardType(cardSpec));
    return cardInfo;
}
Also used : CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType)

Example 18 with CardInfoType

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

the class MiddlewareConfig method getCardInfoTemplate.

/**
 * Returns the CardInfo-Template as CardInfoType.
 *
 * @return CardInfo-Template or {@code null} if template can not be parsed.
 */
@Nonnull
private synchronized CardInfoType getCardInfoTemplate() {
    CardInfoType cardInfo;
    try {
        WSMarshaller m = MARSHALLER.deref();
        assert (m != null);
        Document doc = CIF_DOC.deref();
        cardInfo = m.unmarshal(doc, CardInfoType.class).getValue();
        return cardInfo;
    } catch (WSMarshallerException ex) {
        String msg = "Can not parse CardInfo-Document.";
        LOG.error(msg, ex);
        throw new RuntimeException(CARD_IMAGE_PATH, ex);
    } catch (InterruptedException ex) {
        String msg = "Shutdown requested while retrieving CIF template.";
        LOG.debug(msg);
        throw new RuntimeException(msg);
    } catch (NullPointerException ex) {
        String msg = "Marshaller and/ or CIF Template could not be loaded correctly.";
        LOG.error(msg, ex);
        throw new RuntimeException(msg);
    }
}
Also used : CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType) WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) WSMarshaller(org.openecard.ws.marshal.WSMarshaller) Document(org.w3c.dom.Document) Nonnull(javax.annotation.Nonnull)

Example 19 with CardInfoType

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

the class MiddlewareSAL method augmentCardInfo.

private CardInfoType augmentCardInfo(@Nonnull ConnectionHandleType handle, @Nonnull CardInfoType template, @Nonnull CardSpecType cardSpec) {
    boolean needsConnect = handle.getSlotHandle() == null;
    try {
        // connect card, so that we have a session
        MwSession session;
        if (needsConnect) {
            MwSlot slot = getMatchingSlot(handle.getIFDName(), handle.getSlotIndex());
            if (slot != null) {
                session = slot.openSession();
            } else {
                throw new TokenException("No card available in this slot.", CryptokiLibrary.CKR_TOKEN_NOT_PRESENT);
            }
        } else {
            session = managedSessions.get(handle.getSlotHandle());
        }
        if (session != null) {
            CIFCreator cc = new CIFCreator(session, template, cardSpec);
            CardInfoType cif = cc.addTokenInfo();
            LOG.info("Finished augmenting CardInfo file.");
            return cif;
        } else {
            LOG.warn("Card not available for object info retrieval anymore.");
            return null;
        }
    } catch (WSMarshallerException ex) {
        throw new RuntimeException("Failed to marshal CIF file.", ex);
    } catch (CryptokiException ex) {
        throw new RuntimeException("Error in PKCS#11 module while requesting CIF data.", ex);
    }
}
Also used : CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType) WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) CryptokiException(org.openecard.mdlw.sal.exceptions.CryptokiException) TokenException(org.openecard.mdlw.sal.exceptions.TokenException)

Example 20 with CardInfoType

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

the class CardRecognitionImpl method getAllTypesFromRepo.

private List<String> getAllTypesFromRepo(org.openecard.ws.GetCardInfoOrACD repo) throws WSHelper.WSException {
    // read list of all cifs from the repo
    GetCardInfoOrACD req = new GetCardInfoOrACD();
    req.setAction(ECardConstants.CIF.GET_OTHER);
    GetCardInfoOrACDResponse res = repo.getCardInfoOrACD(req);
    WSHelper.checkResult(res);
    ArrayList<String> oids = new ArrayList<>();
    for (Object cif : res.getCardInfoOrCapabilityInfo()) {
        if (cif instanceof CardInfoType) {
            String type = ((CardInfoType) cif).getCardType().getObjectIdentifier();
            oids.add(type);
        }
    }
    return oids;
}
Also used : 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)

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