use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo 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);
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo in project open-ecard by ecsec.
the class CardStateMap method getMatchingEntries.
private synchronized Set<CardStateEntry> getMatchingEntries(CardApplicationPathType cHandle, byte[] slotHandle, RecognitionInfo recInfo, boolean filterAppId) {
// extract values from map
ChannelHandleType channel = cHandle.getChannelHandle();
String session = (channel != null) ? channel.getSessionIdentifier() : null;
byte[] ctx = cHandle.getContextHandle();
String ifdname = cHandle.getIFDName();
BigInteger slotIdx = cHandle.getSlotIndex();
byte[] cardApplication = cHandle.getCardApplication();
// when nothing has been specified, return all elements
Set<CardStateEntry> mergedSets;
if (session == null && ctx == null && slotHandle == null) {
mergedSets = new TreeSet<>(allEntries);
} else {
// fetch applicable lists from maps
Set<CardStateEntry> sessionEntries = setFromMap(sessionMap, session);
Set<CardStateEntry> ctxEntries = setFromMap(contextMap, ctx);
Set<CardStateEntry> slothandleEntries = setFromMap(slothandleMap, slotHandle);
// merge entries
ArrayList<Set<CardStateEntry>> setsToMerge = new ArrayList<>(3);
if (session != null) {
setsToMerge.add(sessionEntries);
}
if (ctx != null) {
setsToMerge.add(ctxEntries);
}
if (slotHandle != null) {
setsToMerge.add(slothandleEntries);
}
mergedSets = mergeSets(setsToMerge);
}
// filter maps for slotIndex if any is given
if (slotIdx != null) {
filterIdx(mergedSets, slotIdx);
}
if (ifdname != null) {
filterIfdname(mergedSets, ifdname);
}
if (filterAppId && cardApplication != null) {
filterCardApplication(mergedSets, cardApplication);
} else {
// [TR-03112-4] If no card application is specified, paths to all
// available cards (alpha-card applications) and unused card
// terminal slots are returned.
}
if (recInfo != null && recInfo.getCardType() != null) {
filterCardType(mergedSets, recInfo.getCardType());
}
return mergedSets;
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo 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);
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo in project open-ecard by ecsec.
the class AndroidMarshallerTest method testConversionOfStartPAOS.
@Test
public void testConversionOfStartPAOS() throws Exception {
WSMarshaller m = new AndroidMarshaller();
StartPAOS startP = new StartPAOS();
startP.setSessionIdentifier("5ec5ebb1dd254f392e6ca33cf5bf");
ConnectionHandleType connectionHandleType = new ConnectionHandleType();
connectionHandleType.setContextHandle(new BigInteger("94D7439CE657561E7AE3D491FD71AC21F8BCBB5608BA61F5A0EA52269BC01250", 16).toByteArray());
connectionHandleType.setSlotHandle(new BigInteger("EEB49368C1152BEC379DA59356D59039CA7757AC3EAF9430285F2CBB3DD6EDDD", 16).toByteArray());
connectionHandleType.setIFDName("Name of IFD");
connectionHandleType.setSlotIndex(new BigInteger("0"));
connectionHandleType.setCardApplication(new byte[] { 0x0, 0x0, 0x0 });
ChannelHandleType channelHandle = new ChannelHandleType();
channelHandle.setSessionIdentifier("sessionID");
connectionHandleType.setChannelHandle(channelHandle);
RecognitionInfo recognitionInfo = new RecognitionInfo();
recognitionInfo.setCardType("nPA_1-0-0.xml");
connectionHandleType.setRecognitionInfo(recognitionInfo);
startP.getConnectionHandle().add(connectionHandleType);
Document d = m.marshal(startP);
assertEquals(m.doc2str(d), START_PAOS);
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo in project open-ecard by ecsec.
the class CardRecognitionImpl method recognizeCard.
/**
* Recognizes the card in the defined reader.
*
* @param ctx Context handle of the IFD.
* @param ifdName Name of the card reader.
* @param slot Index of the slot in the reader.
* @return RecognitionInfo structure containing the card type of the detected card or {@code null} if no card could
* be detected.
* @throws RecognitionException Thrown in case there was an error in the recognition.
*/
@Nullable
@Override
public RecognitionInfo recognizeCard(byte[] ctx, String ifdName, BigInteger slot) throws RecognitionException {
// connect card
byte[] slotHandle = connect(ctx, ifdName, slot);
// recognise card
String type = treeCalls(slotHandle, getTree().getCardCall());
// disconnect and return
disconnect(slotHandle);
// build result or throw exception if it is null or unsupported
if (type == null || !isSupportedCard(type)) {
return null;
}
RecognitionInfo info = new RecognitionInfo();
info.setCardType(type);
return info;
}
Aggregations