]> source.dussan.org Git - poi.git/commitdiff
timestamping fixes
authorAndreas Beeker <kiwiwings@apache.org>
Wed, 27 Aug 2014 22:58:03 +0000 (22:58 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Wed, 27 Aug 2014 22:58:03 +0000 (22:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/xml_signature@1620990 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java
src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/TSPTimeStampService.java
src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/XmlSignatureService.java
src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java

index 9d1cf3a064b25057a186f32a7c134701eb8b473f..8d895bac17e08b930fad6fcc3e721c0d1b893a04 100644 (file)
@@ -83,6 +83,7 @@ import org.etsi.uri.x01903.v13.OCSPIdentifierType;
 import org.etsi.uri.x01903.v13.OCSPRefType;\r
 import org.etsi.uri.x01903.v13.OCSPRefsType;\r
 import org.etsi.uri.x01903.v13.OCSPValuesType;\r
+import org.etsi.uri.x01903.v13.QualifyingPropertiesDocument;\r
 import org.etsi.uri.x01903.v13.QualifyingPropertiesType;\r
 import org.etsi.uri.x01903.v13.ResponderIDType;\r
 import org.etsi.uri.x01903.v13.RevocationValuesType;\r
@@ -180,12 +181,14 @@ public class XAdESXLSignatureFacet implements SignatureFacet {
     ) throws XmlException {\r
         LOG.log(POILogger.DEBUG, "XAdES-X-L post sign phase");\r
 \r
+        QualifyingPropertiesDocument qualDoc = null;\r
         QualifyingPropertiesType qualProps = null;\r
 \r
         // check for XAdES-BES\r
         NodeList qualNl = document.getElementsByTagNameNS("http://uri.etsi.org/01903/v1.3.2#", "QualifyingProperties");\r
         if (qualNl.getLength() == 1) {\r
-            qualProps = QualifyingPropertiesType.Factory.parse(qualNl.item(0));\r
+            qualDoc = QualifyingPropertiesDocument.Factory.parse(qualNl.item(0));\r
+            qualProps = qualDoc.getQualifyingProperties();\r
         } else {\r
             throw new IllegalArgumentException("no XAdES-BES extension present");\r
         }\r
@@ -335,6 +338,7 @@ public class XAdESXLSignatureFacet implements SignatureFacet {
         }\r
 \r
         // marshal XAdES-X\r
+        unsignedSigProps.addNewSigAndRefsTimeStamp().set(timeStampXadesX1);\r
 \r
         // XAdES-X-L\r
         CertificateValuesType certificateValues = unsignedSigProps.addNewCertificateValues();\r
@@ -351,7 +355,7 @@ public class XAdESXLSignatureFacet implements SignatureFacet {
         createRevocationValues(revocationValues, revocationData);\r
 \r
         // marshal XAdES-X-L\r
-        Node n = document.importNode(qualProps.getDomNode().getFirstChild(), true);\r
+        Node n = document.importNode(qualProps.getDomNode(), true);\r
         qualNl.item(0).getParentNode().replaceChild(n, qualNl.item(0));\r
     }\r
 \r
index ff4beb41ce8ca3bb2a41de4aa3242be6a5f594b7..793a9e2252cd2be17ed4ebf5448569a0cc2c53f1 100644 (file)
@@ -43,7 +43,6 @@ import java.util.Map;
 \r
 import javax.xml.bind.DatatypeConverter;\r
 \r
-import org.apache.commons.codec.binary.Hex;\r
 import org.apache.poi.poifs.crypt.CryptoFunctions;\r
 import org.apache.poi.poifs.crypt.HashAlgorithm;\r
 import org.apache.poi.util.IOUtils;\r
@@ -315,18 +314,13 @@ public class TSPTimeStampService implements TimeStampService {
         JcaX509ExtensionUtils utils = new JcaX509ExtensionUtils();\r
         \r
         X509CertificateHolder signerCert = null;\r
-        Map<String, X509CertificateHolder> certificateMap = new HashMap<String, X509CertificateHolder>();\r
+        Map<X500Name, X509CertificateHolder> certificateMap = new HashMap<X500Name, X509CertificateHolder>();\r
         for (X509CertificateHolder certificate : certificates) {\r
             if (signerCertIssuer.equals(certificate.getIssuer())\r
                 && signerCertSerialNumber.equals(certificate.getSerialNumber())) {\r
                 signerCert = certificate;\r
             }\r
-            byte skiBytes[] = utils.createSubjectKeyIdentifier(certificate.getSubjectPublicKeyInfo()).getKeyIdentifier();\r
-            String ski = Hex.encodeHexString(skiBytes);\r
-            certificateMap.put(ski, certificate);\r
-            LOG.log(POILogger.DEBUG, "embedded certificate: "\r
-                    + certificate.getSubject() + "; SKI="\r
-                    + ski);\r
+            certificateMap.put(certificate.getSubject(), certificate);\r
         }\r
 \r
         // TSP signer cert path building\r
@@ -344,9 +338,7 @@ public class TSPTimeStampService implements TimeStampService {
             if (certificate.getSubject().equals(certificate.getIssuer())) {\r
                 break;\r
             }\r
-            byte akiBytes[] = utils.createAuthorityKeyIdentifier(certificate.getSubjectPublicKeyInfo()).getKeyIdentifier();\r
-            String aki = Hex.encodeHexString(akiBytes);\r
-            certificate = certificateMap.get(aki);\r
+            certificate = certificateMap.get(certificate.getIssuer());\r
         } while (null != certificate);\r
 \r
         // verify TSP signer signature\r
index 51b32a0c17d0ae0e9f614dd99d3890ac25afacd8..c034a5dca6871ec00c777b795c35e3bb81996f96 100644 (file)
@@ -282,6 +282,7 @@ public class XmlSignatureService implements SignatureService {
             signatureFacet.postSign(document, signingCertificateChain);\r
         }\r
 \r
+        registerIds(document);\r
         writeDocument(document);\r
     }\r
 \r
@@ -384,8 +385,6 @@ public class XmlSignatureService implements SignatureService {
         xmlSignature.sign(xmlSignContext);\r
 \r
         registerIds(document);\r
-        // document.getElementById("idPackageObject").setAttributeNS(XmlNS, "xmlns:mdssi", PackageNamespaces.DIGITAL_SIGNATURE);\r
-\r
         \r
         /*\r
          * Completion of undigested ds:References in the ds:Manifests.\r
index 43a6b549b778ed3cb319345d88594af5882345b3..34def89b8b138931298f710c0e8a360bd3bc06fc 100644 (file)
@@ -80,7 +80,6 @@ import org.bouncycastle.cert.ocsp.OCSPResp;
 import org.etsi.uri.x01903.v13.DigestAlgAndValueType;\r
 import org.etsi.uri.x01903.v13.QualifyingPropertiesType;\r
 import org.junit.BeforeClass;\r
-import org.junit.Ignore;\r
 import org.junit.Test;\r
 import org.w3.x2000.x09.xmldsig.SignatureDocument;\r
 import org.w3c.dom.Document;\r
@@ -204,7 +203,6 @@ public class TestSignatureInfo {
 \r
     @SuppressWarnings("unused")\r
     @Test\r
-    @Ignore\r
     public void testSignEnvelopingDocument() throws Exception {\r
         String testFile = "hello-world-unsigned.xlsx";\r
         OPCPackage pkg = OPCPackage.open(copy(testdata.getFile(testFile)), PackageAccess.READ_WRITE);\r