use of iso.std.iso_iec._24727.tech.schema.EstablishContext in project open-ecard by ecsec.
the class IFD method establishContext.
@Override
public synchronized EstablishContextResponse establishContext(EstablishContext parameters) {
EstablishContextResponse response;
try {
// on first call, create a new unique handle
if (ctxHandle == null) {
// scwrapper = new SCWrapper();
cm = new ChannelManager();
ctxHandle = ChannelManager.createCtxHandle();
env.addIFDCtx(ctxHandle);
numClients = new AtomicInteger(1);
// TODO: add custom ThreadFactory to control the thread name
threadPool = Executors.newCachedThreadPool(new ThreadFactory() {
private final AtomicInteger num = new AtomicInteger(0);
private final ThreadGroup group = new ThreadGroup("IFD Wait");
@Override
public Thread newThread(Runnable r) {
String name = String.format("SCIO Watcher %d", num.getAndIncrement());
Thread t = new Thread(group, r, name);
t.setDaemon(false);
return t;
}
});
asyncWaitThreads = new ConcurrentSkipListMap<>();
evManager = new IfdEventManager(env, cm, ctxHandle);
evManager.initialize();
} else {
// on second or further calls, increment usage counter
numClients.incrementAndGet();
}
// prepare response
response = WSHelper.makeResponse(EstablishContextResponse.class, WSHelper.makeResultOK());
response.setContextHandle(ctxHandle);
return response;
} catch (IFDException ex) {
LOG.warn(ex.getMessage(), ex);
return WSHelper.makeResponse(EstablishContextResponse.class, ex.getResult());
}
}
use of iso.std.iso_iec._24727.tech.schema.EstablishContext in project open-ecard by ecsec.
the class ManagerTest method runManager.
@Test(enabled = false)
public void runManager() throws InterruptedException, IFDException {
IFD ifd = new IFD();
EstablishContext ctx = new EstablishContext();
EstablishContextResponse ctxR = ifd.establishContext(ctx);
Environment env = new ClientEnv();
env.setIFD(ifd);
IfdEventManager evt = new IfdEventManager(env, new ChannelManager(), ctxR.getContextHandle());
evt.initialize();
Thread.sleep(1000);
// evt.terminate();
Thread.sleep(1000000);
}
use of iso.std.iso_iec._24727.tech.schema.EstablishContext in project open-ecard by ecsec.
the class PINTest method testModifyPin.
@Test(enabled = false)
public void testModifyPin() throws IFDException, WSMarshallerException, SAXException {
IFD ifd = new IFD();
ifd.setGUI(new SwingUserConsent(new SwingDialogWrapper()));
EstablishContext eCtx = new EstablishContext();
byte[] ctxHandle = ifd.establishContext(eCtx).getContextHandle();
ListIFDs listIFDs = new ListIFDs();
listIFDs.setContextHandle(ctxHandle);
String ifdName = ifd.listIFDs(listIFDs).getIFDName().get(0);
Connect connect = new Connect();
connect.setContextHandle(ctxHandle);
connect.setIFDName(ifdName);
connect.setSlot(BigInteger.ZERO);
byte[] slotHandle = ifd.connect(connect).getSlotHandle();
// prepare pace call
String xmlCall = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<iso:EstablishChannel xmlns:iso=\"urn:iso:std:iso-iec:24727:tech:schema\">\n" + " <iso:SlotHandle>" + ByteUtils.toHexString(slotHandle) + "</iso:SlotHandle>\n" + " <iso:AuthenticationProtocolData Protocol=\"urn:oid:0.4.0.127.0.7.2.2.4\">\n" + " <iso:PinID>03</iso:PinID>\n" + " </iso:AuthenticationProtocolData>\n" + "</iso:EstablishChannel>";
WSMarshaller m = WSMarshallerFactory.createInstance();
EstablishChannel eCh = (EstablishChannel) m.unmarshal(m.str2doc(xmlCall));
// send pace call
EstablishChannelResponse eChR = ifd.establishChannel(eCh);
assertEquals(eChR.getResult().getResultMajor(), ECardConstants.Major.OK);
PasswordAttributesType pwdAttr = create(true, ASCII_NUMERIC, 6, 6, 6);
pwdAttr.setPadChar(new byte[] { (byte) 0x3F });
PCSCPinModify ctrlStruct = new PCSCPinModify(pwdAttr, StringUtils.toByteArray("002C0203"));
byte[] structData = ctrlStruct.toBytes();
String pinStr = "00 2C 02 03 06 3F3F3F3F3F3F";
String ctrlStr = "15 05 82 06 00 00 00 0606 01 02 02 0407 00 01 02 000000 0B000000";
// This is the command the 'AusweisApp' sends
// String ausweisApp = "150582080000000606010202090400010200000005000000002C020300";
byte[] referenceData = StringUtils.toByteArray(ctrlStr + pinStr, true);
assertEquals(referenceData, structData);
ControlIFD controlIFD = new ControlIFD();
controlIFD.setCommand(ByteUtils.concatenate((byte) PCSCFeatures.MODIFY_PIN_DIRECT, structData));
controlIFD.setSlotHandle(slotHandle);
ControlIFDResponse response = ifd.controlIFD(controlIFD);
}
use of iso.std.iso_iec._24727.tech.schema.EstablishContext in project open-ecard by ecsec.
the class PINTest method executePACE_PIN.
@Test(enabled = false)
public void executePACE_PIN() throws UnsupportedDataTypeException, JAXBException, SAXException, WSMarshallerException {
IFD ifd = new IFD();
ifd.setGUI(new SwingUserConsent(new SwingDialogWrapper()));
EstablishContext eCtx = new EstablishContext();
byte[] ctxHandle = ifd.establishContext(eCtx).getContextHandle();
ListIFDs listIFDs = new ListIFDs();
listIFDs.setContextHandle(ctxHandle);
String ifdName = ifd.listIFDs(listIFDs).getIFDName().get(0);
Connect connect = new Connect();
connect.setContextHandle(ctxHandle);
connect.setIFDName(ifdName);
connect.setSlot(BigInteger.ZERO);
byte[] slotHandle = ifd.connect(connect).getSlotHandle();
// prepare pace call
String xmlCall = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<iso:EstablishChannel xmlns:iso=\"urn:iso:std:iso-iec:24727:tech:schema\">\n" + " <iso:SlotHandle>" + ByteUtils.toHexString(slotHandle) + "</iso:SlotHandle>\n" + " <iso:AuthenticationProtocolData Protocol=\"urn:oid:0.4.0.127.0.7.2.2.4\">\n" + " <iso:PinID>03</iso:PinID>\n" + " </iso:AuthenticationProtocolData>\n" + "</iso:EstablishChannel>";
WSMarshaller m = WSMarshallerFactory.createInstance();
EstablishChannel eCh = (EstablishChannel) m.unmarshal(m.str2doc(xmlCall));
// send pace call
EstablishChannelResponse eChR = ifd.establishChannel(eCh);
}
use of iso.std.iso_iec._24727.tech.schema.EstablishContext in project open-ecard by ecsec.
the class TestTransactions method testExecute.
/**
* Manual test to ensure the card recognition with transactions is working as expected. This test starts two
* Threads. The first one blocks the card for 15 seconds. The second one attempts to recognize the card. This will
* obviously fail within the 15 seconds and a MessageDialog will be displayed. After the 15 seconds the recognition
* will succeed.
*
* @throws Exception
*/
// a reader with an inserted card is needed
@Test(enabled = false)
public void testExecute() throws Exception {
// set up ifd and establish context
Environment env = new ClientEnv();
final IFD ifd = new org.openecard.ifd.scio.IFD();
env.setIFD(ifd);
EstablishContext eCtx = new EstablishContext();
EstablishContextResponse eCtxR = ifd.establishContext(eCtx);
final byte[] ctx = eCtxR.getContextHandle();
// Set up GUI and card recognition
SwingUserConsent gui = new SwingUserConsent(new SwingDialogWrapper());
final CardRecognitionImpl recog = new CardRecognitionImpl(env);
recog.setGUI(gui);
// get the first reader
ListIFDs listIFDs = new ListIFDs();
listIFDs.setContextHandle(ctx);
ListIFDsResponse listIFDsResponse = ifd.listIFDs(listIFDs);
final String ifdName = listIFDsResponse.getIFDName().get(0);
Thread t1 = new Thread(new BlockingRunnable(ctx, ifdName, ifd));
t1.start();
Thread t2 = new Thread(new RecognizeRunnable(ctx, ifdName, recog));
t2.start();
t2.join();
}
Aggregations