Search in sources :

Example 1 with SignatureProperties

use of javax.xml.crypto.dsig.SignatureProperties in project camel by apache.

the class TimestampProperty method get.

@Override
public Output get(Input input) throws Exception {
    Transform transform = input.getSignatureFactory().newTransform(CanonicalizationMethod.INCLUSIVE, (TransformParameterSpec) null);
    Reference ref = input.getSignatureFactory().newReference("#propertiesObject", input.getSignatureFactory().newDigestMethod(input.getContentDigestAlgorithm(), null), Collections.singletonList(transform), null, null);
    String doc2 = "<ts:timestamp xmlns:ts=\"http:/timestamp\">" + System.currentTimeMillis() + "</ts:timestamp>";
    InputStream is = new ByteArrayInputStream(doc2.getBytes("UTF-8"));
    Document doc = XmlSignatureHelper.newDocumentBuilder(Boolean.TRUE).parse(is);
    DOMStructure structure = new DOMStructure(doc.getDocumentElement());
    SignatureProperty prop = input.getSignatureFactory().newSignatureProperty(Collections.singletonList(structure), input.getSignatureId(), "property");
    SignatureProperties properties = input.getSignatureFactory().newSignatureProperties(Collections.singletonList(prop), "properties");
    XMLObject propertiesObject = input.getSignatureFactory().newXMLObject(Collections.singletonList(properties), "propertiesObject", null, null);
    XmlSignatureProperties.Output result = new Output();
    result.setReferences(Collections.singletonList(ref));
    result.setObjects(Collections.singletonList(propertiesObject));
    return result;
}
Also used : Reference(javax.xml.crypto.dsig.Reference) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XmlSignatureProperties(org.apache.camel.component.xmlsecurity.api.XmlSignatureProperties) XMLObject(javax.xml.crypto.dsig.XMLObject) Document(org.w3c.dom.Document) SignatureProperty(javax.xml.crypto.dsig.SignatureProperty) ByteArrayInputStream(java.io.ByteArrayInputStream) DOMStructure(javax.xml.crypto.dom.DOMStructure) XmlSignatureProperties(org.apache.camel.component.xmlsecurity.api.XmlSignatureProperties) SignatureProperties(javax.xml.crypto.dsig.SignatureProperties) Transform(javax.xml.crypto.dsig.Transform)

Example 2 with SignatureProperties

use of javax.xml.crypto.dsig.SignatureProperties in project poi by apache.

the class OOXMLSignatureFacet method addSignatureTime.

protected void addSignatureTime(Document document, List<XMLStructure> objectContent) {
    /*
         * SignatureTime
         */
    DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT);
    fmt.setTimeZone(LocaleUtil.TIMEZONE_UTC);
    String nowStr = fmt.format(signatureConfig.getExecutionTime());
    LOG.log(POILogger.DEBUG, "now: " + nowStr);
    SignatureTimeDocument sigTime = SignatureTimeDocument.Factory.newInstance();
    CTSignatureTime ctTime = sigTime.addNewSignatureTime();
    ctTime.setFormat("YYYY-MM-DDThh:mm:ssTZD");
    ctTime.setValue(nowStr);
    Element n = (Element) document.importNode(ctTime.getDomNode(), true);
    List<XMLStructure> signatureTimeContent = new ArrayList<XMLStructure>();
    signatureTimeContent.add(new DOMStructure(n));
    SignatureProperty signatureTimeSignatureProperty = getSignatureFactory().newSignatureProperty(signatureTimeContent, "#" + signatureConfig.getPackageSignatureId(), "idSignatureTime");
    List<SignatureProperty> signaturePropertyContent = new ArrayList<SignatureProperty>();
    signaturePropertyContent.add(signatureTimeSignatureProperty);
    SignatureProperties signatureProperties = getSignatureFactory().newSignatureProperties(signaturePropertyContent, "id-signature-time-" + signatureConfig.getExecutionTime());
    objectContent.add(signatureProperties);
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) XMLStructure(javax.xml.crypto.XMLStructure) SignatureProperty(javax.xml.crypto.dsig.SignatureProperty) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) CTSignatureTime(org.openxmlformats.schemas.xpackage.x2006.digitalSignature.CTSignatureTime) DOMStructure(javax.xml.crypto.dom.DOMStructure) SignatureProperties(javax.xml.crypto.dsig.SignatureProperties) SignatureTimeDocument(org.openxmlformats.schemas.xpackage.x2006.digitalSignature.SignatureTimeDocument) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with SignatureProperties

use of javax.xml.crypto.dsig.SignatureProperties in project poi by apache.

the class OOXMLSignatureFacet method addSignatureInfo.

protected void addSignatureInfo(Document document, List<Reference> references, List<XMLObject> objects) throws XMLSignatureException {
    List<XMLStructure> objectContent = new ArrayList<XMLStructure>();
    SignatureInfoV1Document sigV1 = SignatureInfoV1Document.Factory.newInstance();
    CTSignatureInfoV1 ctSigV1 = sigV1.addNewSignatureInfoV1();
    ctSigV1.setManifestHashAlgorithm(signatureConfig.getDigestMethodUri());
    Element n = (Element) document.importNode(ctSigV1.getDomNode(), true);
    n.setAttributeNS(XML_NS, XMLConstants.XMLNS_ATTRIBUTE, MS_DIGSIG_NS);
    List<XMLStructure> signatureInfoContent = new ArrayList<XMLStructure>();
    signatureInfoContent.add(new DOMStructure(n));
    SignatureProperty signatureInfoSignatureProperty = getSignatureFactory().newSignatureProperty(signatureInfoContent, "#" + signatureConfig.getPackageSignatureId(), "idOfficeV1Details");
    List<SignatureProperty> signaturePropertyContent = new ArrayList<SignatureProperty>();
    signaturePropertyContent.add(signatureInfoSignatureProperty);
    SignatureProperties signatureProperties = getSignatureFactory().newSignatureProperties(signaturePropertyContent, null);
    objectContent.add(signatureProperties);
    String objectId = "idOfficeObject";
    objects.add(getSignatureFactory().newXMLObject(objectContent, objectId, null, null));
    Reference reference = newReference("#" + objectId, null, XML_DIGSIG_NS + "Object", null, null);
    references.add(reference);
}
Also used : SignatureInfoV1Document(com.microsoft.schemas.office.x2006.digsig.SignatureInfoV1Document) Reference(javax.xml.crypto.dsig.Reference) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) DOMStructure(javax.xml.crypto.dom.DOMStructure) SignatureProperties(javax.xml.crypto.dsig.SignatureProperties) CTSignatureInfoV1(com.microsoft.schemas.office.x2006.digsig.CTSignatureInfoV1) XMLStructure(javax.xml.crypto.XMLStructure) SignatureProperty(javax.xml.crypto.dsig.SignatureProperty)

Aggregations

DOMStructure (javax.xml.crypto.dom.DOMStructure)3 SignatureProperties (javax.xml.crypto.dsig.SignatureProperties)3 SignatureProperty (javax.xml.crypto.dsig.SignatureProperty)3 ArrayList (java.util.ArrayList)2 XMLStructure (javax.xml.crypto.XMLStructure)2 Reference (javax.xml.crypto.dsig.Reference)2 Element (org.w3c.dom.Element)2 CTSignatureInfoV1 (com.microsoft.schemas.office.x2006.digsig.CTSignatureInfoV1)1 SignatureInfoV1Document (com.microsoft.schemas.office.x2006.digsig.SignatureInfoV1Document)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Transform (javax.xml.crypto.dsig.Transform)1 XMLObject (javax.xml.crypto.dsig.XMLObject)1 XmlSignatureProperties (org.apache.camel.component.xmlsecurity.api.XmlSignatureProperties)1 CTSignatureTime (org.openxmlformats.schemas.xpackage.x2006.digitalSignature.CTSignatureTime)1 SignatureTimeDocument (org.openxmlformats.schemas.xpackage.x2006.digitalSignature.SignatureTimeDocument)1 Document (org.w3c.dom.Document)1