Search in sources :

Example 6 with WSMarshallerException

use of org.openecard.ws.marshal.WSMarshallerException in project open-ecard by ecsec.

the class ManifestExtractor method getAddonSpecificationFromFile.

/**
 * Get an AddonSpecification object from the jar file containing the addon.
 *
 * @param file jar file to get the AddonSpecification from.
 * @return The {@link AddonSpecification} of the addon, or {@code null} if it could not be extracted.
 */
public AddonSpecification getAddonSpecificationFromFile(File file) {
    String name = file.getName();
    JarFile jarFile;
    AddonSpecification abd;
    try {
        jarFile = new JarFile(file);
    } catch (IOException e) {
        logger.debug("File {} will not be registered as plugin because it's not a JarFile.", name);
        return null;
    }
    try {
        InputStream manifestStream = getPluginEntryClass(jarFile);
        if (manifestStream == null) {
            logger.debug("File {} will not be registered as plugin because it doesn't contain a addon.xml.", name);
            return null;
        } else {
            marshaller.addXmlTypeClass(AddonSpecification.class);
            Document manifestDoc = marshaller.str2doc(manifestStream);
            abd = (AddonSpecification) marshaller.unmarshal(manifestDoc);
        }
    } catch (IOException | SAXException | WSMarshallerException ex) {
        logger.error("Failed to process addon.xml entry for file " + name + ".", ex);
        return null;
    } finally {
        try {
            jarFile.close();
        } catch (IOException ex) {
            logger.error("Failed to close jar file.", ex);
        }
    }
    return abd;
}
Also used : WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) InputStream(java.io.InputStream) AddonSpecification(org.openecard.addon.manifest.AddonSpecification) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 7 with WSMarshallerException

use of org.openecard.ws.marshal.WSMarshallerException in project open-ecard by ecsec.

the class TCTokenHandler method handleNoCardActivate.

/**
 * Activates the client according to the received TCToken.
 *
 * @param token The activation TCToken.
 * @return The response containing the result of the activation process.
 */
public BindingResult handleNoCardActivate(TCToken token) {
    if (LOG.isDebugEnabled()) {
        try {
            WSMarshaller m = WSMarshallerFactory.createInstance();
            LOG.debug("TCToken:\n{}", m.doc2str(m.marshal(token)));
        } catch (TransformerException | WSMarshallerException ex) {
        // it's no use
        }
    }
    try {
        // process binding and follow redirect addresses afterwards
        ChipGatewayResponse response = processBinding(token);
        // fill in values, so it is usuable by the transport module
        response.finishResponse();
        return response;
    } catch (RedirectionBaseError ex) {
        LOG.error(ex.getMessage(), ex);
        return ex.getBindingResult();
    } catch (FatalActivationError ex) {
        LOG.error(ex.getMessage(), ex);
        return ex.getBindingResult();
    }
}
Also used : FatalActivationError(org.openecard.addons.cg.ex.FatalActivationError) WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) ChipGatewayResponse(org.openecard.addons.cg.impl.ChipGatewayResponse) WSMarshaller(org.openecard.ws.marshal.WSMarshaller) TransformerException(javax.xml.transform.TransformerException) RedirectionBaseError(org.openecard.addons.cg.ex.RedirectionBaseError)

Example 8 with WSMarshallerException

use of org.openecard.ws.marshal.WSMarshallerException in project open-ecard by ecsec.

the class MiddlewareConfig method getCardInfoTemplate.

/**
 * Returns the CardInfo-Template as CardInfoType.
 *
 * @return CardInfo-Template or {@code null} if template can not be parsed.
 */
@Nonnull
private synchronized CardInfoType getCardInfoTemplate() {
    CardInfoType cardInfo;
    try {
        WSMarshaller m = MARSHALLER.deref();
        assert (m != null);
        Document doc = CIF_DOC.deref();
        cardInfo = m.unmarshal(doc, CardInfoType.class).getValue();
        return cardInfo;
    } catch (WSMarshallerException ex) {
        String msg = "Can not parse CardInfo-Document.";
        LOG.error(msg, ex);
        throw new RuntimeException(CARD_IMAGE_PATH, ex);
    } catch (InterruptedException ex) {
        String msg = "Shutdown requested while retrieving CIF template.";
        LOG.debug(msg);
        throw new RuntimeException(msg);
    } catch (NullPointerException ex) {
        String msg = "Marshaller and/ or CIF Template could not be loaded correctly.";
        LOG.error(msg, ex);
        throw new RuntimeException(msg);
    }
}
Also used : CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType) WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) WSMarshaller(org.openecard.ws.marshal.WSMarshaller) Document(org.w3c.dom.Document) Nonnull(javax.annotation.Nonnull)

Example 9 with WSMarshallerException

use of org.openecard.ws.marshal.WSMarshallerException 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 10 with WSMarshallerException

use of org.openecard.ws.marshal.WSMarshallerException 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)

Aggregations

WSMarshallerException (org.openecard.ws.marshal.WSMarshallerException)12 Document (org.w3c.dom.Document)8 SAXException (org.xml.sax.SAXException)7 IOException (java.io.IOException)6 WSMarshaller (org.openecard.ws.marshal.WSMarshaller)6 TransformerException (javax.xml.transform.TransformerException)5 CardInfoType (iso.std.iso_iec._24727.tech.schema.CardInfoType)3 InputStream (java.io.InputStream)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 HTMLDocument (javax.swing.text.html.HTMLDocument)2 AddonPropertiesException (org.openecard.addon.AddonPropertiesException)2 MarshallingTypeException (org.openecard.ws.marshal.MarshallingTypeException)2 JoranException (ch.qos.logback.core.joran.spi.JoranException)1 Connect (iso.std.iso_iec._24727.tech.schema.Connect)1 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)1 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)1 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)1 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)1 GetCardInfoOrACDResponse (iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse)1