use of iso.std.iso_iec._24727.tech.schema.Connect in project open-ecard by ecsec.
the class TinySALTest method testDsiList.
/**
* Test of dsiList method, of class TinySAL.
*/
@Test(enabled = TESTS_ENABLED)
public void testDsiList() {
System.out.println("dsiList");
// get path to esign
CardApplicationPath cardApplicationPath = new CardApplicationPath();
CardApplicationPathType cardApplicationPathType = new CardApplicationPathType();
cardApplicationPathType.setCardApplication(appIdentifier_ESIGN);
cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
CardApplicationPathResponse cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
// connect to esign
CardApplicationConnect cardApplicationConnect = new CardApplicationConnect();
cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
CardApplicationConnectResponse result = instance.cardApplicationConnect(cardApplicationConnect);
assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
// list datasets of esign
DataSetList dataSetList = new DataSetList();
dataSetList.setConnectionHandle(result.getConnectionHandle());
DataSetListResponse dataSetListResponse = instance.dataSetList(dataSetList);
Assert.assertTrue(dataSetListResponse.getDataSetNameList().getDataSetName().size() > 0);
assertEquals(ECardConstants.Major.OK, dataSetListResponse.getResult().getResultMajor());
String dataSetName = dataSetListResponse.getDataSetNameList().getDataSetName().get(0);
DSIList parameters = new DSIList();
parameters.setConnectionHandle(result.getConnectionHandle());
DSIListResponse resultDSIList = instance.dsiList(parameters);
assertEquals(ECardConstants.Major.OK, resultDSIList.getResult().getResultMajor());
assertTrue(resultDSIList.getDSINameList().getDSIName().isEmpty());
}
use of iso.std.iso_iec._24727.tech.schema.Connect 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);
}
}
use of iso.std.iso_iec._24727.tech.schema.Connect 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;
}
use of iso.std.iso_iec._24727.tech.schema.Connect in project open-ecard by ecsec.
the class PACETest method executePACE_PIN.
@Test(enabled = false)
public void executePACE_PIN() throws UnsupportedDataTypeException, JAXBException, SAXException, WSMarshallerException {
ClientEnv env = new ClientEnv();
MessageDispatcher dispatcher = new MessageDispatcher(env);
IFD ifd = new IFD();
SwingUserConsent gui = new SwingUserConsent(new SwingDialogWrapper());
ifd.setGUI(gui);
env.setIFD(ifd);
env.setDispatcher(dispatcher);
ifd.addProtocol(ECardConstants.Protocol.PACE, new PACEProtocolFactory());
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();
// PinID: 02 = CAN, 03 = PIN
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>02</iso:PinID>\n" + " <iso:CHAT>7f4c12060904007f0007030102025305300301ffb7</iso:CHAT>\n" + // Remove PIN element to active the GUI
" <iso:PIN>142390</iso:PIN>\n" + // + " <iso:PIN>123456</iso:PIN>\n"
" </iso:AuthenticationProtocolData>\n" + "</iso:EstablishChannel>";
WSMarshaller m = WSMarshallerFactory.createInstance();
EstablishChannel eCh = (EstablishChannel) m.unmarshal(m.str2doc(xmlCall));
EstablishChannelResponse eChR = ifd.establishChannel(eCh);
LOG.info("PACE result: {}", eChR.getResult().getResultMajor());
try {
LOG.info("{}", eChR.getResult().getResultMinor());
LOG.info("{}", eChR.getResult().getResultMessage().getValue());
} catch (Exception ignore) {
}
}
use of iso.std.iso_iec._24727.tech.schema.Connect in project open-ecard by ecsec.
the class PINTest method verifyeGK.
@Test(enabled = false)
public void verifyeGK() {
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();
VerifyUser verify = new VerifyUser();
verify.setSlotHandle(slotHandle);
InputUnitType inputUnit = new InputUnitType();
verify.setInputUnit(inputUnit);
PinInputType pinInput = new PinInputType();
inputUnit.setPinInput(pinInput);
pinInput.setIndex(BigInteger.ZERO);
pinInput.setPasswordAttributes(create(true, ISO_9564_1, 6, 8, 8));
verify.setTemplate(StringUtils.toByteArray("00 20 00 01", true));
VerifyUserResponse verifyR = ifd.verifyUser(verify);
byte[] responseCode = verifyR.getResponse();
}
Aggregations