Search in sources :

Example 36 with Connect

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

the class TerminalTest method testFeatures.

@Test(enabled = false)
public void testFeatures() {
    init();
    ifd.setGUI(new SwingUserConsent(new SwingDialogWrapper()));
    Connect con = new Connect();
    con.setContextHandle(ctxHandle);
    con.setIFDName(ifdName);
    con.setSlot(BigInteger.ZERO);
    con.setExclusive(Boolean.FALSE);
    slotHandle = ifd.connect(con).getSlotHandle();
    GetIFDCapabilities cap = new GetIFDCapabilities();
    cap.setContextHandle(ctxHandle);
    cap.setIFDName(ifdName);
    GetIFDCapabilitiesResponse capR = ifd.getIFDCapabilities(cap);
}
Also used : GetIFDCapabilities(iso.std.iso_iec._24727.tech.schema.GetIFDCapabilities) SwingDialogWrapper(org.openecard.gui.swing.SwingDialogWrapper) Connect(iso.std.iso_iec._24727.tech.schema.Connect) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) GetIFDCapabilitiesResponse(iso.std.iso_iec._24727.tech.schema.GetIFDCapabilitiesResponse) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 37 with Connect

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

the class TerminalTest method testTransmit.

@Test(enabled = false)
public void testTransmit() {
    init();
    Connect con = new Connect();
    con.setContextHandle(ctxHandle);
    con.setIFDName(ifdName);
    con.setSlot(BigInteger.ZERO);
    con.setExclusive(Boolean.FALSE);
    slotHandle = ifd.connect(con).getSlotHandle();
    Transmit t = new Transmit();
    InputAPDUInfoType apdu = new InputAPDUInfoType();
    apdu.getAcceptableStatusCode().add(new byte[] { (byte) 0x90, (byte) 0x00 });
    apdu.setInputAPDU(new byte[] { (byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x0C });
    t.getInputAPDUInfo().add(apdu);
    t.setSlotHandle(slotHandle);
    TransmitResponse res = ifd.transmit(t);
    assertEquals(ECardConstants.Major.OK, res.getResult().getResultMajor());
}
Also used : Transmit(iso.std.iso_iec._24727.tech.schema.Transmit) Connect(iso.std.iso_iec._24727.tech.schema.Connect) InputAPDUInfoType(iso.std.iso_iec._24727.tech.schema.InputAPDUInfoType) TransmitResponse(iso.std.iso_iec._24727.tech.schema.TransmitResponse) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 38 with Connect

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

the class PAOS method sendStartPAOS.

/**
 * Sends start PAOS and answers all successor messages to the server associated with this instance.
 * Messages are exchanged until the server replies with a {@code StartPAOSResponse} message.
 *
 * @param message The StartPAOS message which is sent in the first message.
 * @return The {@code StartPAOSResponse} message from the server.
 * @throws DispatcherException In case there errors with the message conversion or the dispatcher.
 * @throws PAOSException In case there were errors in the transport layer.
 * @throws PAOSConnectionException
 */
public StartPAOSResponse sendStartPAOS(StartPAOS message) throws DispatcherException, PAOSException, PAOSConnectionException {
    Object msg = message;
    StreamHttpClientConnection conn = null;
    HttpContext ctx = new BasicHttpContext();
    HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
    DefaultConnectionReuseStrategy reuse = new DefaultConnectionReuseStrategy();
    boolean connectionDropped = false;
    ResponseBaseType lastResponse = null;
    try {
        // loop and send makes a computer happy
        while (true) {
            // set up connection to PAOS endpoint
            // if this one fails we may not continue
            conn = openHttpStream();
            boolean isReusable;
            // send as long as connection is valid
            try {
                do {
                    // save the last message we sent to the eID-Server.
                    if (msg instanceof ResponseBaseType) {
                        lastResponse = (ResponseBaseType) msg;
                    }
                    // prepare request
                    String resource = tlsHandler.getResource();
                    BasicHttpEntityEnclosingRequest req = new BasicHttpEntityEnclosingRequest("POST", resource);
                    HttpRequestHelper.setDefaultHeader(req, tlsHandler.getServerAddress());
                    req.setHeader(HEADER_KEY_PAOS, headerValuePaos);
                    req.setHeader("Accept", "text/xml, application/xml, application/vnd.paos+xml");
                    ContentType reqContentType = ContentType.create("application/vnd.paos+xml", "UTF-8");
                    HttpUtils.dumpHttpRequest(LOG, "before adding content", req);
                    String reqMsgStr = createPAOSResponse(msg);
                    StringEntity reqMsg = new StringEntity(reqMsgStr, reqContentType);
                    req.setEntity(reqMsg);
                    req.setHeader(reqMsg.getContentType());
                    req.setHeader("Content-Length", Long.toString(reqMsg.getContentLength()));
                    // send request and receive response
                    LOG.debug("Sending HTTP request.");
                    HttpResponse response = httpexecutor.execute(req, conn, ctx);
                    LOG.debug("HTTP response received.");
                    int statusCode = response.getStatusLine().getStatusCode();
                    try {
                        checkHTTPStatusCode(statusCode);
                    } catch (PAOSConnectionException ex) {
                        // response with error. So check the status of our last response to the eID-Server
                        if (lastResponse != null) {
                            WSHelper.checkResult(lastResponse);
                        }
                        throw ex;
                    }
                    conn.receiveResponseEntity(response);
                    HttpEntity entity = response.getEntity();
                    byte[] entityData = FileUtils.toByteArray(entity.getContent());
                    HttpUtils.dumpHttpResponse(LOG, response, entityData);
                    // consume entity
                    Object requestObj = processPAOSRequest(new ByteArrayInputStream(entityData));
                    // break when message is startpaosresponse
                    if (requestObj instanceof StartPAOSResponse) {
                        StartPAOSResponse startPAOSResponse = (StartPAOSResponse) requestObj;
                        // an ok.
                        if (lastResponse != null) {
                            WSHelper.checkResult(lastResponse);
                        }
                        WSHelper.checkResult(startPAOSResponse);
                        return startPAOSResponse;
                    }
                    // send via dispatcher
                    msg = dispatcher.deliver(requestObj);
                    // check if connection can be used one more time
                    isReusable = reuse.keepAlive(response, ctx);
                    connectionDropped = false;
                } while (isReusable);
            } catch (IOException ex) {
                if (!connectionDropped) {
                    connectionDropped = true;
                    LOG.warn("PAOS server closed the connection. Trying to connect again.");
                } else {
                    String errMsg = "Error in the link to the PAOS server.";
                    LOG.error(errMsg);
                    throw new PAOSException(DELIVERY_FAILED, ex);
                }
            }
        }
    } catch (HttpException ex) {
        throw new PAOSException(DELIVERY_FAILED, ex);
    } catch (SOAPException ex) {
        throw new PAOSException(SOAP_MESSAGE_FAILURE, ex);
    } catch (MarshallingTypeException ex) {
        throw new PAOSDispatcherException(MARSHALLING_ERROR, ex);
    } catch (InvocationTargetException ex) {
        throw new PAOSDispatcherException(DISPATCHER_ERROR, ex);
    } catch (TransformerException ex) {
        throw new DispatcherException(ex);
    } catch (WSException ex) {
        throw new PAOSException(ex);
    } finally {
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (IOException ex) {
        // throw new PAOSException(ex);
        }
    }
}
Also used : MarshallingTypeException(org.openecard.ws.marshal.MarshallingTypeException) HttpRequestExecutor(org.openecard.apache.http.protocol.HttpRequestExecutor) ContentType(org.openecard.apache.http.entity.ContentType) HttpEntity(org.openecard.apache.http.HttpEntity) BasicHttpContext(org.openecard.apache.http.protocol.BasicHttpContext) DefaultConnectionReuseStrategy(org.openecard.apache.http.impl.DefaultConnectionReuseStrategy) StartPAOSResponse(iso.std.iso_iec._24727.tech.schema.StartPAOSResponse) StreamHttpClientConnection(org.openecard.transport.httpcore.StreamHttpClientConnection) StringEntity(org.openecard.apache.http.entity.StringEntity) SOAPException(org.openecard.ws.soap.SOAPException) WSException(org.openecard.common.WSHelper.WSException) HttpException(org.openecard.apache.http.HttpException) TransformerException(javax.xml.transform.TransformerException) BasicHttpEntityEnclosingRequest(org.openecard.apache.http.message.BasicHttpEntityEnclosingRequest) BasicHttpContext(org.openecard.apache.http.protocol.BasicHttpContext) HttpContext(org.openecard.apache.http.protocol.HttpContext) HttpResponse(org.openecard.apache.http.HttpResponse) DispatcherException(org.openecard.common.interfaces.DispatcherException) ResponseBaseType(oasis.names.tc.dss._1_0.core.schema.ResponseBaseType) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 39 with Connect

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

the class ListTokens method connectCards.

private ArrayList<ConnectionHandleType> connectCards() throws WSHelper.WSException {
    // get all cards in the system
    CardApplicationPath pathReq = new CardApplicationPath();
    CardApplicationPathType pathType = new CardApplicationPathType();
    pathReq.setCardAppPathRequest(pathType);
    CardApplicationPathResponse pathRes = (CardApplicationPathResponse) dispatcher.safeDeliver(pathReq);
    WSHelper.checkResult(pathRes);
    // remove duplicates
    TreeSet<CardApplicationPathType> paths = new TreeSet<>(new Comparator<CardApplicationPathType>() {

        @Override
        public int compare(CardApplicationPathType o1, CardApplicationPathType o2) {
            int cmp1 = o1.getIFDName().compareTo(o2.getIFDName());
            if (cmp1 == 0) {
                return o1.getSlotIndex().compareTo(o2.getSlotIndex());
            } else {
                return cmp1;
            }
        }
    });
    paths.addAll(pathRes.getCardAppPathResultSet().getCardApplicationPathResult());
    // connect every card in the set
    ArrayList<ConnectionHandleType> connectedCards = new ArrayList<>();
    for (CardApplicationPathType path : paths) {
        try {
            CardApplicationConnect conReq = new CardApplicationConnect();
            conReq.setCardApplicationPath(path);
            conReq.setExclusiveUse(false);
            CardApplicationConnectResponse conRes = (CardApplicationConnectResponse) dispatcher.safeDeliver(conReq);
            WSHelper.checkResult(conRes);
            connectedCards.add(conRes.getConnectionHandle());
        } catch (WSHelper.WSException ex) {
            LOG.error("Failed to connect card, skipping this entry.", ex);
        }
    }
    return connectedCards;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) WSHelper(org.openecard.common.WSHelper) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) ArrayList(java.util.ArrayList) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) TreeSet(java.util.TreeSet)

Example 40 with Connect

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

the class TCTokenHandler method prepareHandle.

private ConnectionHandleType prepareHandle(ConnectionHandleType connectionHandle) throws WSException {
    // Perform a CardApplicationPath and CardApplicationConnect to connect to the card application
    CardApplicationPath appPath = new CardApplicationPath();
    appPath.setCardAppPathRequest(connectionHandle);
    CardApplicationPathResponse appPathRes = (CardApplicationPathResponse) dispatcher.safeDeliver(appPath);
    // Check CardApplicationPathResponse
    WSHelper.checkResult(appPathRes);
    CardApplicationConnect appConnect = new CardApplicationConnect();
    List<CardApplicationPathType> pathRes;
    pathRes = appPathRes.getCardAppPathResultSet().getCardApplicationPathResult();
    appConnect.setCardApplicationPath(pathRes.get(0));
    CardApplicationConnectResponse appConnectRes;
    appConnectRes = (CardApplicationConnectResponse) dispatcher.safeDeliver(appConnect);
    // Update ConnectionHandle. It now includes a SlotHandle.
    connectionHandle = appConnectRes.getConnectionHandle();
    // Check CardApplicationConnectResponse
    WSHelper.checkResult(appConnectRes);
    return connectionHandle;
}
Also used : CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)

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