use of network.oxalis.as4.lang.OxalisAs4Exception in project Oxalis-AS4 by OxalisCommunity.
the class SOAPHeaderParser method getAttachmentDigest.
public static byte[] getAttachmentDigest(String refId, SOAPHeader header) throws OxalisAs4Exception {
NodeList sigInfoNode = header.getElementsByTagNameNS(NS_ALL, SIG_INFO);
if (sigInfoNode.getLength() != 1) {
throw new OxalisAs4Exception(String.format("Expected one Signature elements in header, but found %d", sigInfoNode.getLength()));
}
Element sigInfoElement = (Element) sigInfoNode.item(0);
NodeList refNodes = sigInfoElement.getElementsByTagNameNS(NS_ALL, REF);
for (int i = 0; i < refNodes.getLength(); i++) {
Element refElement = (Element) refNodes.item(i);
if (refId.equals(refElement.getAttribute("URI"))) {
NodeList digestValueNode = refElement.getElementsByTagNameNS(NS_ALL, DIGEST_VAL);
return digestValueNode.item(0).getTextContent().getBytes(StandardCharsets.UTF_8);
}
}
return null;
}
use of network.oxalis.as4.lang.OxalisAs4Exception in project Oxalis-AS4 by OxalisCommunity.
the class SOAPHeaderParser method getSenderCertificate.
public static X509Certificate getSenderCertificate(SOAPHeader header) throws OxalisAs4Exception {
NodeList sigNode = header.getElementsByTagNameNS(NS_ALL, SIG);
if (sigNode.getLength() != 1) {
throw new OxalisAs4Exception(String.format("Expected one Signature element in header, but found %d", sigNode.getLength()));
}
Element sigElement = (Element) sigNode.item(0);
NodeList keyInfoNode = sigElement.getElementsByTagNameNS(NS_ALL, KEY_INFO);
if (keyInfoNode.getLength() != 1) {
throw new OxalisAs4Exception(String.format("Expected one KeyInfo child of Signature, but found %d", keyInfoNode.getLength()));
}
Element keyInfoElement = (Element) keyInfoNode.item(0);
NodeList refNode = keyInfoElement.getElementsByTagNameNS(NS_ALL, REF);
if (refNode == null || refNode.getLength() != 1) {
throw new OxalisAs4Exception(("Zero or multiple Reference nodes under Signature->KeyInfo"));
}
String refUri = ((Element) refNode.item(0)).getAttribute("URI").replace("#", "");
NodeList bstNodes = header.getElementsByTagNameNS(NS_ALL, BST);
if (bstNodes != null) {
for (int i = 0; i < bstNodes.getLength(); i++) {
Element bstElem = (Element) bstNodes.item(i);
if (bstElem.getAttributeNS("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Id").equals(refUri)) {
try {
String pem = bstElem.getTextContent().replaceAll("[\r\n]+", "");
byte[] buf = Base64.getDecoder().decode(pem);
return (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(buf));
} catch (CertificateException e) {
throw new OxalisAs4Exception("Could not create certificate from BinarySecurityToken", e);
}
}
}
}
return null;
}
use of network.oxalis.as4.lang.OxalisAs4Exception in project Oxalis-AS4 by OxalisCommunity.
the class SOAPHeaderParser method getSignature.
public static byte[] getSignature(SOAPHeader header) throws OxalisAs4Exception {
NodeList sigNode = header.getElementsByTagNameNS(NS_ALL, SIG);
if (sigNode.getLength() != 1) {
throw new OxalisAs4Exception(String.format("Expected one Signature element in header, but found %d", sigNode.getLength()));
}
Element sigElement = (Element) sigNode.item(0);
NodeList sigValNode = sigElement.getElementsByTagNameNS(NS_ALL, SIG_VAL);
if (sigValNode == null || sigValNode.getLength() != 1) {
throw new OxalisAs4Exception("Zero or multiple SignatureValue elements in header");
}
return sigValNode.item(0).getTextContent().replace("\r\n", "").getBytes(StandardCharsets.UTF_8);
}
use of network.oxalis.as4.lang.OxalisAs4Exception in project Oxalis-AS4 by OxalisCommunity.
the class SOAPHeaderParser method refListFromElement.
private static List<ReferenceType> refListFromElement(Element element) throws OxalisAs4Exception {
NodeList refNodes = element.getElementsByTagNameNS(NS_ALL, REF);
List<ReferenceType> referenceList = Lists.newArrayList();
if (refNodes == null) {
return Collections.emptyList();
}
try {
Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller();
for (int i = 0; i < refNodes.getLength(); i++) {
referenceList.add(unmarshaller.unmarshal(refNodes.item(i), ReferenceType.class).getValue());
}
} catch (JAXBException e) {
throw new OxalisAs4Exception("Could not unmarshal reference node", e);
}
return referenceList;
}
use of network.oxalis.as4.lang.OxalisAs4Exception in project Oxalis-AS4 by OxalisCommunity.
the class As4MessageFactory method createReceiptMessage.
public SOAPMessage createReceiptMessage(UserMessage inUserMessage, ProsessingContext prosessingContext) throws OxalisAs4Exception {
XMLGregorianCalendar xmlGc = XMLUtil.dateToXMLGeorgianCalendar(prosessingContext.getReceiptTimestamp().getDate());
MessageInfo messageInfo = MessageInfo.builder().withTimestamp(xmlGc).withMessageId(messageIdGenerator.generate()).withRefToMessageId(inUserMessage.getMessageInfo().getMessageId()).build();
List<MessagePartNRInformation> mpList = prosessingContext.getReferenceList().stream().map(reference -> MessagePartNRInformation.builder().withReference(reference).build()).collect(Collectors.toList());
NonRepudiationInformation nri = NonRepudiationInformation.builder().addMessagePartNRInformation(mpList).build();
SignalMessage signalMessage = SignalMessage.builder().withMessageInfo(messageInfo).withReceipt(Receipt.builder().withAny(nri).build()).build();
return marshalSignalMessage(signalMessage);
}
Aggregations