Search in sources :

Example 6 with WSException

use of org.openecard.common.WSHelper.WSException in project open-ecard by ecsec.

the class AbstractPINAction method connectToRootApplication.

/**
 * Connect to the root application of the card specified with a connection handle using a empty CardApplicationPath
 * and afterwards a CardApplicationConnect.
 *
 * @param cHandle
 *            The connection handle for the card to connect to root application.
 * @return The updated connection handle (now including a SlotHandle) or null if connecting went wrong.
 */
protected ConnectionHandleType connectToRootApplication(ConnectionHandleType cHandle) {
    // Perform a CardApplicationPath and CardApplicationConnect to connect to the card application
    CardApplicationPath cardApplicationPath = new CardApplicationPath();
    cardApplicationPath.setCardAppPathRequest(cHandle);
    CardApplicationPathResponse cardApplicationPathResponse = (CardApplicationPathResponse) dispatcher.safeDeliver(cardApplicationPath);
    // Check CardApplicationPathResponse
    try {
        WSHelper.checkResult(cardApplicationPathResponse);
    } catch (WSException ex) {
        LOG.error("CardApplicationPath failed.", ex);
        return null;
    }
    CardApplicationConnect cardApplicationConnect = new CardApplicationConnect();
    cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
    CardApplicationConnectResponse cardApplicationConnectResponse = (CardApplicationConnectResponse) dispatcher.safeDeliver(cardApplicationConnect);
    // Check CardApplicationConnectResponse
    try {
        WSHelper.checkResult(cardApplicationConnectResponse);
    } catch (WSException ex) {
        LOG.error("CardApplicationConnect failed.", ex);
        return null;
    }
    // Update ConnectionHandle. It now includes a SlotHandle.
    cHandle = cardApplicationConnectResponse.getConnectionHandle();
    return cHandle;
}
Also used : 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) WSException(org.openecard.common.WSHelper.WSException) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)

Example 7 with WSException

use of org.openecard.common.WSHelper.WSException in project open-ecard by ecsec.

the class ChangePinInSALAction method execute.

@Override
public void execute() {
    List<ConnectionHandleType> connectedCards = null;
    try {
        connectedCards = connectCards();
        if (connectedCards.isEmpty()) {
        // TODO: show no card inserted dialog
        }
        for (ConnectionHandleType nextCard : connectedCards) {
            // pick first card, find pin DID and call didupdate
            String didName = null;
            try {
                didName = getPinDid(nextCard);
            } catch (WSException ex) {
                LOG.info("Skipping card, because it has no PIN DID.");
                continue;
            }
            DIDUpdate updateReq = new DIDUpdate();
            updateReq.setConnectionHandle(nextCard);
            updateReq.setDIDName(didName);
            DIDUpdateDataType updateData = new PinCompareDIDUpdateDataType();
            updateData.setProtocol("urn:oid:1.3.162.15480.3.0.9");
            updateReq.setDIDUpdateData(updateData);
            dispatcher.safeDeliver(updateReq);
        }
    } catch (WSException ex) {
    } finally {
        if (connectedCards != null) {
            for (ConnectionHandleType nextHandle : connectedCards) {
                CardApplicationDisconnect dr = new CardApplicationDisconnect();
                dr.setConnectionHandle(nextHandle);
                dr.setAction(ActionType.RESET);
                dispatcher.safeDeliver(dr);
            }
        }
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) CardApplicationDisconnect(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect) DIDUpdate(iso.std.iso_iec._24727.tech.schema.DIDUpdate) WSException(org.openecard.common.WSHelper.WSException) PinCompareDIDUpdateDataType(iso.std.iso_iec._24727.tech.schema.PinCompareDIDUpdateDataType) PinCompareDIDUpdateDataType(iso.std.iso_iec._24727.tech.schema.PinCompareDIDUpdateDataType) DIDUpdateDataType(iso.std.iso_iec._24727.tech.schema.DIDUpdateDataType)

Example 8 with WSException

use of org.openecard.common.WSHelper.WSException in project open-ecard by ecsec.

the class GetCardsAndPINStatusAction method execute.

@Override
public void execute() {
    // check if a german identity card is inserted, if not wait for it
    ConnectionHandleType cHandle = waitForCardType(GERMAN_IDENTITY_CARD);
    if (cHandle == null) {
        LOG.debug("User cancelled card insertion.");
        return;
    }
    cHandle = connectToRootApplication(cHandle);
    RecognizedState pinState = recognizeState(cHandle);
    boolean nativePace;
    try {
        nativePace = genericPACESupport(cHandle);
    } catch (WSException e) {
        LOG.error("Could not get capabilities from reader.");
        return;
    }
    PINDialog uc = new PINDialog(gui, dispatcher, cHandle, pinState, !nativePace);
    uc.show();
    Disconnect d = new Disconnect();
    d.setSlotHandle(cHandle.getSlotHandle());
    dispatcher.safeDeliver(d);
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) PINDialog(org.openecard.plugins.pinplugin.gui.PINDialog) Disconnect(iso.std.iso_iec._24727.tech.schema.Disconnect) WSException(org.openecard.common.WSHelper.WSException)

Example 9 with WSException

use of org.openecard.common.WSHelper.WSException in project open-ecard by ecsec.

the class TestLocalCif method testeGKCif.

@Test
public void testeGKCif() throws WSMarshallerException, IOException, SAXException {
    LocalCifRepo repo = new LocalCifRepo(new JAXBMarshaller());
    GetCardInfoOrACD req = new GetCardInfoOrACD();
    req.setAction(ECardConstants.CIF.GET_SPECIFIED);
    req.getCardTypeIdentifier().add("http://ws.gematik.de/egk/1.0.0");
    GetCardInfoOrACDResponse res = repo.getCardInfoOrACD(req);
    try {
        WSHelper.checkResult(res);
    } catch (WSException ex) {
        Assert.fail("Local repo returned with error\n" + ex.getMessage());
    }
    Assert.assertEquals(1, res.getCardInfoOrCapabilityInfo().size());
}
Also used : GetCardInfoOrACD(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACD) WSException(org.openecard.common.WSHelper.WSException) GetCardInfoOrACDResponse(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse) LocalCifRepo(org.openecard.recognition.staticrepo.LocalCifRepo) JAXBMarshaller(org.openecard.ws.jaxb.JAXBMarshaller) Test(org.testng.annotations.Test)

Example 10 with WSException

use of org.openecard.common.WSHelper.WSException 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)

Aggregations

WSException (org.openecard.common.WSHelper.WSException)16 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)5 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)4 StepActionResult (org.openecard.gui.executor.StepActionResult)4 DIDAuthenticationDataType (iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType)3 Disconnect (iso.std.iso_iec._24727.tech.schema.Disconnect)3 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 AuthDataMap (org.openecard.common.anytype.AuthDataMap)3 AuthDataResponse (org.openecard.common.anytype.AuthDataResponse)3 DispatcherException (org.openecard.common.interfaces.DispatcherException)3 ExecutionResults (org.openecard.gui.executor.ExecutionResults)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 TransformerException (javax.xml.transform.TransformerException)2 APDUException (org.openecard.common.apdu.exception.APDUException)2 Step (org.openecard.gui.definition.Step)2 CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)1 CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)1 CardApplicationDisconnect (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect)1