Search in sources :

Example 31 with Connect

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());
}
Also used : CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) DSIListResponse(iso.std.iso_iec._24727.tech.schema.DSIListResponse) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) DataSetListResponse(iso.std.iso_iec._24727.tech.schema.DataSetListResponse) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) DSIList(iso.std.iso_iec._24727.tech.schema.DSIList) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) DataSetList(iso.std.iso_iec._24727.tech.schema.DataSetList) Test(org.testng.annotations.Test)

Example 32 with Connect

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);
    }
}
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 33 with Connect

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;
}
Also used : RecognitionInfo(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo) Nullable(javax.annotation.Nullable)

Example 34 with Connect

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) {
    }
}
Also used : ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) IFD(org.openecard.ifd.scio.IFD) Connect(iso.std.iso_iec._24727.tech.schema.Connect) EstablishChannelResponse(iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse) WSMarshaller(org.openecard.ws.marshal.WSMarshaller) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) UnsupportedDataTypeException(javax.activation.UnsupportedDataTypeException) WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) ClientEnv(org.openecard.common.ClientEnv) MessageDispatcher(org.openecard.transport.dispatcher.MessageDispatcher) SwingDialogWrapper(org.openecard.gui.swing.SwingDialogWrapper) EstablishChannel(iso.std.iso_iec._24727.tech.schema.EstablishChannel) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) Test(org.testng.annotations.Test)

Example 35 with Connect

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();
}
Also used : SwingDialogWrapper(org.openecard.gui.swing.SwingDialogWrapper) ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) InputUnitType(iso.std.iso_iec._24727.tech.schema.InputUnitType) ControlIFD(iso.std.iso_iec._24727.tech.schema.ControlIFD) VerifyUserResponse(iso.std.iso_iec._24727.tech.schema.VerifyUserResponse) Connect(iso.std.iso_iec._24727.tech.schema.Connect) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) VerifyUser(iso.std.iso_iec._24727.tech.schema.VerifyUser) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) PinInputType(iso.std.iso_iec._24727.tech.schema.PinInputType) Test(org.testng.annotations.Test)

Aggregations

CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)27 CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)27 CardApplicationPathType (iso.std.iso_iec._24727.tech.schema.CardApplicationPathType)25 CardApplicationPath (iso.std.iso_iec._24727.tech.schema.CardApplicationPath)24 CardApplicationPathResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse)24 Test (org.testng.annotations.Test)23 Connect (iso.std.iso_iec._24727.tech.schema.Connect)11 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)10 DataSetList (iso.std.iso_iec._24727.tech.schema.DataSetList)7 DataSetListResponse (iso.std.iso_iec._24727.tech.schema.DataSetListResponse)7 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)7 ListIFDs (iso.std.iso_iec._24727.tech.schema.ListIFDs)7 ConnectResponse (iso.std.iso_iec._24727.tech.schema.ConnectResponse)6 CardApplicationList (iso.std.iso_iec._24727.tech.schema.CardApplicationList)5 CardApplicationListResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationListResponse)5 CardApplicationDisconnect (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect)4 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)4 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)4 BeginTransaction (iso.std.iso_iec._24727.tech.schema.BeginTransaction)3 BeginTransactionResponse (iso.std.iso_iec._24727.tech.schema.BeginTransactionResponse)3