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;
}
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();
}
}
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);
}
}
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);
}
}
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) {
}
}
Aggregations