use of org.openecard.common.event.IfdEventObject 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 org.openecard.common.event.IfdEventObject 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 org.openecard.common.event.IfdEventObject in project open-ecard by ecsec.
the class SALStateCallback method signalEvent.
@Override
public void signalEvent(EventType eventType, EventObject eventData) {
if (eventData instanceof IfdEventObject) {
IfdEventObject ifdEvtData = (IfdEventObject) eventData;
ConnectionHandleType handle = ifdEvtData.getHandle();
switch(eventType) {
// only add cards with a cardinfo file
case CARD_RECOGNIZED:
LOG.info("Add ConnectionHandle to SAL:\n{}", HandlePrinter.printHandle(handle));
String cardType = handle.getRecognitionInfo().getCardType();
CardInfoType cif = env.getCIFProvider().getCardInfo(handle, cardType);
if (cif != null) {
manager.addCredential(handle, ifdEvtData.getIfaceProtocol(), cif);
} else {
LOG.info("Not adding card to SAL, because it has no CardInfo file.");
}
break;
case CARD_REMOVED:
LOG.info("Remove ConnectionHandle from SAL.\n{}", HandlePrinter.printHandle(handle));
manager.removeCredential(handle);
break;
default:
// not a relevant event
break;
}
}
}
Aggregations