Search in sources :

Example 1 with ListIFDs

use of iso.std.iso_iec._24727.tech.schema.ListIFDs in project open-ecard by ecsec.

the class IfdEventRunner method ifdStatus.

@Nonnull
private List<IFDStatusType> ifdStatus() throws WSException {
    LOG.debug("Requesting terminal names.");
    ListIFDs listReq = new ListIFDs();
    listReq.setContextHandle(ctxHandle);
    ListIFDsResponse ifds = env.getIFD().listIFDs(listReq);
    WSHelper.checkResult(ifds);
    LOG.debug("Requesting status for all terminals found.");
    ArrayList<IFDStatusType> result = new ArrayList<>();
    for (String ifd : ifds.getIFDName()) {
        GetStatus status = new GetStatus();
        status.setContextHandle(ctxHandle);
        status.setIFDName(ifd);
        GetStatusResponse statusResponse = env.getIFD().getStatus(status);
        try {
            WSHelper.checkResult(statusResponse);
            result.addAll(statusResponse.getIFDStatus());
        } catch (WSException ex) {
            String msg = "Failed to request status from terminal, assuming no card present.";
            LOG.error(msg, ex);
            IFDStatusType is = new IFDStatusType();
            is.setIFDName(ifd);
            result.add(is);
        }
    }
    return result;
}
Also used : ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) ListIFDsResponse(iso.std.iso_iec._24727.tech.schema.ListIFDsResponse) GetStatusResponse(iso.std.iso_iec._24727.tech.schema.GetStatusResponse) ArrayList(java.util.ArrayList) WSException(org.openecard.common.WSHelper.WSException) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) GetStatus(iso.std.iso_iec._24727.tech.schema.GetStatus) Nonnull(javax.annotation.Nonnull)

Example 2 with ListIFDs

use of iso.std.iso_iec._24727.tech.schema.ListIFDs in project open-ecard by ecsec.

the class IFD method listIFDs.

@Override
public ListIFDsResponse listIFDs(ListIFDs parameters) {
    ListIFDsResponse response;
    if (!ByteUtils.compare(ctxHandle, parameters.getContextHandle())) {
        String msg = "Invalid context handle specified.";
        Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_CONTEXT_HANDLE, msg);
        response = WSHelper.makeResponse(ListIFDsResponse.class, r);
        return response;
    } else {
        try {
            List<SCIOTerminal> terminals = cm.getTerminals().list();
            ArrayList<String> ifds = new ArrayList<>(terminals.size());
            for (SCIOTerminal next : terminals) {
                ifds.add(next.getName());
            }
            response = WSHelper.makeResponse(ListIFDsResponse.class, WSHelper.makeResultOK());
            response.getIFDName().addAll(ifds);
            return response;
        } catch (SCIOException ex) {
            LOG.warn(ex.getMessage(), ex);
            Result r = WSHelper.makeResultUnknownError(ex.getMessage());
            response = WSHelper.makeResponse(ListIFDsResponse.class, r);
            return response;
        }
    }
}
Also used : ListIFDsResponse(iso.std.iso_iec._24727.tech.schema.ListIFDsResponse) SCIOException(org.openecard.common.ifd.scio.SCIOException) SCIOTerminal(org.openecard.common.ifd.scio.SCIOTerminal) ArrayList(java.util.ArrayList) Result(oasis.names.tc.dss._1_0.core.schema.Result)

Example 3 with ListIFDs

use of iso.std.iso_iec._24727.tech.schema.ListIFDs 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);
}
Also used : ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) PasswordAttributesType(iso.std.iso_iec._24727.tech.schema.PasswordAttributesType) ControlIFD(iso.std.iso_iec._24727.tech.schema.ControlIFD) ControlIFD(iso.std.iso_iec._24727.tech.schema.ControlIFD) PCSCPinModify(org.openecard.ifd.scio.reader.PCSCPinModify) Connect(iso.std.iso_iec._24727.tech.schema.Connect) EstablishChannelResponse(iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse) WSMarshaller(org.openecard.ws.marshal.WSMarshaller) SwingDialogWrapper(org.openecard.gui.swing.SwingDialogWrapper) EstablishChannel(iso.std.iso_iec._24727.tech.schema.EstablishChannel) ControlIFDResponse(iso.std.iso_iec._24727.tech.schema.ControlIFDResponse) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) Test(org.testng.annotations.Test)

Example 4 with ListIFDs

use of iso.std.iso_iec._24727.tech.schema.ListIFDs 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);
}
Also used : SwingDialogWrapper(org.openecard.gui.swing.SwingDialogWrapper) ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) EstablishChannel(iso.std.iso_iec._24727.tech.schema.EstablishChannel) ControlIFD(iso.std.iso_iec._24727.tech.schema.ControlIFD) Connect(iso.std.iso_iec._24727.tech.schema.Connect) EstablishChannelResponse(iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) WSMarshaller(org.openecard.ws.marshal.WSMarshaller) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) Test(org.testng.annotations.Test)

Example 5 with ListIFDs

use of iso.std.iso_iec._24727.tech.schema.ListIFDs 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();
}
Also used : ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) ListIFDsResponse(iso.std.iso_iec._24727.tech.schema.ListIFDsResponse) IFD(org.openecard.ws.IFD) EstablishContextResponse(iso.std.iso_iec._24727.tech.schema.EstablishContextResponse) ClientEnv(org.openecard.common.ClientEnv) SwingDialogWrapper(org.openecard.gui.swing.SwingDialogWrapper) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) Environment(org.openecard.common.interfaces.Environment) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) Test(org.testng.annotations.Test)

Aggregations

ListIFDs (iso.std.iso_iec._24727.tech.schema.ListIFDs)12 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)11 ListIFDsResponse (iso.std.iso_iec._24727.tech.schema.ListIFDsResponse)8 Connect (iso.std.iso_iec._24727.tech.schema.Connect)7 EstablishContextResponse (iso.std.iso_iec._24727.tech.schema.EstablishContextResponse)6 SwingDialogWrapper (org.openecard.gui.swing.SwingDialogWrapper)6 SwingUserConsent (org.openecard.gui.swing.SwingUserConsent)6 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)5 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)5 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)5 ClientEnv (org.openecard.common.ClientEnv)5 Test (org.testng.annotations.Test)5 RecognitionInfo (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo)4 CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)3 CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)3 ConnectResponse (iso.std.iso_iec._24727.tech.schema.ConnectResponse)3 ControlIFD (iso.std.iso_iec._24727.tech.schema.ControlIFD)3 BeginTransaction (iso.std.iso_iec._24727.tech.schema.BeginTransaction)2 BeginTransactionResponse (iso.std.iso_iec._24727.tech.schema.BeginTransactionResponse)2 CardApplicationDisconnect (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect)2