From: Josh Micich Date: Wed, 14 Oct 2009 21:32:06 +0000 (+0000) Subject: removed new dependency on joda X-Git-Tag: REL_3_6~107 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bef0cdf35ce50f46409946132faf7e59ed605822;p=poi.git removed new dependency on joda git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@825294 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/build.xml b/build.xml index 8b9b3550d1..c5f90d9b83 100644 --- a/build.xml +++ b/build.xml @@ -1,5 +1,5 @@ - + @@ -142,8 +142,6 @@ under the License. - - @@ -157,7 +155,7 @@ under the License. - + @@ -175,12 +173,12 @@ under the License. + description="JDK version of generated class files"/> - - - + + + @@ -224,7 +222,7 @@ under the License. - + @@ -290,7 +288,7 @@ under the License. - + @@ -375,7 +373,6 @@ under the License. - @@ -419,10 +416,6 @@ under the License. - - - - @@ -482,7 +475,7 @@ under the License. - @@ -605,7 +598,7 @@ under the License. - @@ -638,9 +631,9 @@ under the License. - - - + + + @@ -669,9 +662,9 @@ under the License. - - - + + + @@ -681,7 +674,7 @@ under the License. - + @@ -695,9 +688,9 @@ under the License. - - - + + + @@ -731,9 +724,9 @@ under the License. - - - + + + @@ -762,9 +755,9 @@ under the License. - - - + + + @@ -772,7 +765,7 @@ under the License. - + @@ -789,8 +782,8 @@ under the License. - - + + @@ -819,9 +812,9 @@ under the License. - - - + + + @@ -843,9 +836,9 @@ under the License. - - - + + + @@ -1094,7 +1087,7 @@ FORREST_HOME environment variable! - + @@ -1107,7 +1100,7 @@ FORREST_HOME environment variable! - + @@ -1120,7 +1113,7 @@ FORREST_HOME environment variable! - + @@ -1133,7 +1126,7 @@ FORREST_HOME environment variable! - + @@ -1148,7 +1141,7 @@ FORREST_HOME environment variable! - + @@ -1251,7 +1244,7 @@ FORREST_HOME environment variable! JDepend is not available. You must download JDepend from <http://www.clarkware.com/software/JDepend.html> and include the JAR file in your classpath. - + diff --git a/src/ooxml/java/org/apache/poi/ooxml/signature/service/signer/ooxml/OOXMLSignatureAspect.java b/src/ooxml/java/org/apache/poi/ooxml/signature/service/signer/ooxml/OOXMLSignatureAspect.java index df6956664f..067dfece83 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/signature/service/signer/ooxml/OOXMLSignatureAspect.java +++ b/src/ooxml/java/org/apache/poi/ooxml/signature/service/signer/ooxml/OOXMLSignatureAspect.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -29,8 +28,10 @@ import java.io.InputStream; import java.net.URL; import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; +import java.util.Calendar; import java.util.LinkedList; import java.util.List; +import java.util.TimeZone; import java.util.UUID; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -57,10 +58,6 @@ import org.apache.poi.ooxml.signature.service.signer.NoCloseInputStream; import org.apache.poi.ooxml.signature.service.signer.SignatureAspect; import org.apache.xml.security.utils.Constants; import org.apache.xpath.XPathAPI; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.ISODateTimeFormat; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -73,19 +70,14 @@ import org.xml.sax.SAXException; /** * Office OpenXML Signature Aspect implementation. */ -public class OOXMLSignatureAspect implements SignatureAspect { +final class OOXMLSignatureAspect implements SignatureAspect { private static final Log LOG = LogFactory.getLog(OOXMLSignatureAspect.class); - private final AbstractOOXMLSignatureService signatureService; + private final AbstractOOXMLSignatureService _signatureService; - /** - * Main constructor. - * - * @param ooxmlUrl - */ public OOXMLSignatureAspect(AbstractOOXMLSignatureService signatureService) { - this.signatureService = signatureService; + _signatureService = signatureService; } public void preSign(XMLSignatureFactory signatureFactory, Document document, String signatureId, List references, List objects) @@ -98,7 +90,7 @@ public class OOXMLSignatureAspect implements SignatureAspect { private void addManifestObject(XMLSignatureFactory signatureFactory, Document document, String signatureId, List references, List objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { - Manifest manifest = constructManifest(signatureFactory, document); + Manifest manifest = constructManifest(signatureFactory); String objectId = "idPackageObject"; // really has to be this value. List objectContent = new LinkedList(); objectContent.add(manifest); @@ -112,12 +104,12 @@ public class OOXMLSignatureAspect implements SignatureAspect { references.add(reference); } - private Manifest constructManifest(XMLSignatureFactory signatureFactory, Document document) throws NoSuchAlgorithmException, + private Manifest constructManifest(XMLSignatureFactory signatureFactory) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { List manifestReferences = new LinkedList(); try { - addRelationshipsReferences(signatureFactory, document, manifestReferences); + addRelationshipsReferences(signatureFactory, manifestReferences); } catch (Exception e) { throw new RuntimeException("error: " + e.getMessage(), e); } @@ -145,7 +137,7 @@ public class OOXMLSignatureAspect implements SignatureAspect { return manifest; } - private void addSignatureTime(XMLSignatureFactory signatureFactory, Document document, String signatureId, List objectContent) { + private static void addSignatureTime(XMLSignatureFactory signatureFactory, Document document, String signatureId, List objectContent) { /* * SignatureTime */ @@ -155,9 +147,7 @@ public class OOXMLSignatureAspect implements SignatureAspect { formatElement.setTextContent("YYYY-MM-DDThh:mm:ssTZD"); signatureTimeElement.appendChild(formatElement); Element valueElement = document.createElementNS("http://schemas.openxmlformats.org/package/2006/digital-signature", "mdssi:Value"); - DateTime dateTime = new DateTime(DateTimeZone.UTC); - DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis(); - String now = fmt.print(dateTime); + String now = formatTimestampAsISO8601(System.currentTimeMillis()); LOG.debug("now: " + now); valueElement.setTextContent(now); signatureTimeElement.appendChild(valueElement); @@ -172,6 +162,34 @@ public class OOXMLSignatureAspect implements SignatureAspect { objectContent.add(signatureProperties); } + /** + * @return text formatted "YYYY-MM-DDThh:mm:ssTZD" + */ + static String formatTimestampAsISO8601(long ts) { + Calendar c = Calendar.getInstance(); + c.setTimeInMillis(ts); + c.setTimeZone(TimeZone.getTimeZone("UTC")); + char[] buf = "yyyy-mm-ddThh:mm:ssZ".toCharArray(); + itoa(buf, 0, 4, c.get(Calendar.YEAR)); + itoa(buf, 5, 2, c.get(Calendar.MONTH)+1); + itoa(buf, 8, 2, c.get(Calendar.DAY_OF_MONTH)); + itoa(buf, 11, 2, c.get(Calendar.HOUR_OF_DAY)); + itoa(buf, 14, 2, c.get(Calendar.MINUTE)); + itoa(buf, 17, 2, c.get(Calendar.SECOND)); + return new String(buf); + } + + private static void itoa(char[] buf, int start, int len, int value) { + int acc = value; + int i=start+len-1; + while (i>=start) { + int d = acc % 10; + acc /= 10; + buf[i] = (char) ('0' + d); + i--; + } + } + private void addSignatureInfo(XMLSignatureFactory signatureFactory, Document document, String signatureId, List references, List objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { List objectContent = new LinkedList(); @@ -200,10 +218,10 @@ public class OOXMLSignatureAspect implements SignatureAspect { references.add(reference); } - private void addRelationshipsReferences(XMLSignatureFactory signatureFactory, Document document, List manifestReferences) throws IOException, - ParserConfigurationException, SAXException, TransformerException, NoSuchAlgorithmException, + private void addRelationshipsReferences(XMLSignatureFactory signatureFactory, List manifestReferences) throws IOException, + ParserConfigurationException, SAXException, NoSuchAlgorithmException, InvalidAlgorithmParameterException { - URL ooxmlUrl = this.signatureService.getOfficeOpenXMLDocumentURL(); + URL ooxmlUrl = _signatureService.getOfficeOpenXMLDocumentURL(); InputStream inputStream = ooxmlUrl.openStream(); ZipInputStream zipInputStream = new ZipInputStream(inputStream); ZipEntry zipEntry; @@ -212,11 +230,11 @@ public class OOXMLSignatureAspect implements SignatureAspect { continue; } Document relsDocument = loadDocumentNoClose(zipInputStream); - addRelationshipsReference(signatureFactory, document, zipEntry.getName(), relsDocument, manifestReferences); + addRelationshipsReference(signatureFactory, zipEntry.getName(), relsDocument, manifestReferences); } } - private void addRelationshipsReference(XMLSignatureFactory signatureFactory, Document document, String zipEntryName, Document relsDocument, + private void addRelationshipsReference(XMLSignatureFactory signatureFactory, String zipEntryName, Document relsDocument, List manifestReferences) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { LOG.debug("relationships: " + zipEntryName); RelationshipTransformParameterSpec parameterSpec = new RelationshipTransformParameterSpec(); @@ -267,7 +285,7 @@ public class OOXMLSignatureAspect implements SignatureAspect { InvalidAlgorithmParameterException { List documentResourceNames; try { - documentResourceNames = getResourceNames(this.signatureService.getOfficeOpenXMLDocumentURL(), contentType); + documentResourceNames = getResourceNames(_signatureService.getOfficeOpenXMLDocumentURL(), contentType); } catch (Exception e) { throw new RuntimeException(e); } @@ -318,7 +336,7 @@ public class OOXMLSignatureAspect implements SignatureAspect { } protected Document findDocument(String zipEntryName) throws IOException, ParserConfigurationException, SAXException { - URL ooxmlUrl = this.signatureService.getOfficeOpenXMLDocumentURL(); + URL ooxmlUrl = _signatureService.getOfficeOpenXMLDocumentURL(); InputStream inputStream = ooxmlUrl.openStream(); ZipInputStream zipInputStream = new ZipInputStream(inputStream); ZipEntry zipEntry; diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/AllOOXMLSignatureTests.java b/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/AllOOXMLSignatureTests.java new file mode 100644 index 0000000000..8fd20148c2 --- /dev/null +++ b/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/AllOOXMLSignatureTests.java @@ -0,0 +1,36 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.ooxml.signature.service.signer; + +import org.apache.poi.ooxml.signature.service.signer.ooxml.TestOOXMLSignatureAspect; + +import junit.framework.Test; +import junit.framework.TestSuite; + + +public final class AllOOXMLSignatureTests { + + public static Test suite() { + TestSuite result = new TestSuite(AllOOXMLSignatureTests.class.getName()); + result.addTestSuite(TestAbstractOOXMLSignatureService.class); + result.addTestSuite(TestAbstractXmlSignatureService.class); + result.addTestSuite(TestOOXMLSignatureAspect.class); + result.addTestSuite(TestOOXMLSignatureVerifier.class); + return result; + } +} diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/PkiTestUtils.java b/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/PkiTestUtils.java index a307ee0906..40a8875dcb 100644 --- a/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/PkiTestUtils.java +++ b/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/PkiTestUtils.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -40,6 +39,8 @@ import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.security.spec.RSAKeyGenParameterSpec; +import java.util.Calendar; +import java.util.Date; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -53,6 +54,7 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.apache.poi.util.HexRead; import org.bouncycastle.asn1.ASN1InputStream; import org.bouncycastle.asn1.ASN1Sequence; import org.bouncycastle.asn1.DERIA5String; @@ -71,18 +73,18 @@ import org.bouncycastle.asn1.x509.X509Extensions; import org.bouncycastle.asn1.x509.X509ObjectIdentifiers; import org.bouncycastle.jce.X509Principal; import org.bouncycastle.x509.X509V3CertificateGenerator; -import org.joda.time.DateTime; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.xml.sax.InputSource; import org.xml.sax.SAXException; -public class PkiTestUtils { +final class PkiTestUtils { - public static final byte[] SHA1_DIGEST_INFO_PREFIX = new byte[] { 0x30, 0x1f, 0x30, 0x07, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x04, 0x14 }; + public static final byte[] SHA1_DIGEST_INFO_PREFIX = + HexRead.readFromString( "30 1f 30 07 06 05 2b 0e 03 02 1a 04 14"); private PkiTestUtils() { - super(); + // no instances of this class } static KeyPair generateKeyPair() throws Exception { @@ -107,17 +109,21 @@ public class PkiTestUtils { return new AuthorityKeyIdentifier(info); } - static X509Certificate generateCertificate(PublicKey subjectPublicKey, String subjectDn, DateTime notBefore, DateTime notAfter, + public static X509Certificate generateCertificate(PublicKey subjectPublicKey, String subjectDn, X509Certificate issuerCertificate, PrivateKey issuerPrivateKey, boolean caFlag, int pathLength, String crlUri, String ocspUri, KeyUsage keyUsage) throws IOException, InvalidKeyException, IllegalStateException, NoSuchAlgorithmException, SignatureException, CertificateException { + + Date notBefore = makeDate(2010, 1, 1); + Date notAfter = makeDate(2011, 1, 1); + String signatureAlgorithm = "SHA1withRSA"; X509V3CertificateGenerator certificateGenerator = new X509V3CertificateGenerator(); certificateGenerator.reset(); certificateGenerator.setPublicKey(subjectPublicKey); certificateGenerator.setSignatureAlgorithm(signatureAlgorithm); - certificateGenerator.setNotBefore(notBefore.toDate()); - certificateGenerator.setNotAfter(notAfter.toDate()); + certificateGenerator.setNotBefore(notBefore); + certificateGenerator.setNotAfter(notAfter); X509Principal issuerDN; if (null != issuerCertificate) { issuerDN = new X509Principal(issuerCertificate.getSubjectX500Principal().toString()); @@ -173,6 +179,13 @@ public class PkiTestUtils { return certificate; } + private static Date makeDate(int year, int month, int day) { + Calendar c = Calendar.getInstance(); + c.set(year, month, day, 0, 0, 0); + c.set(Calendar.MILLISECOND, 0); + return c.getTime(); + } + static Document loadDocument(InputStream documentInputStream) throws ParserConfigurationException, SAXException, IOException { InputSource inputSource = new InputSource(documentInputStream); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/TestAbstractOOXMLSignatureService.java b/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/TestAbstractOOXMLSignatureService.java index d6cc51c65a..5aa8b0b5ca 100644 --- a/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/TestAbstractOOXMLSignatureService.java +++ b/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/TestAbstractOOXMLSignatureService.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -42,13 +41,11 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.poi.ooxml.signature.service.signer.TemporaryDataStorage; import org.apache.poi.ooxml.signature.service.signer.ooxml.AbstractOOXMLSignatureService; import org.apache.poi.ooxml.signature.service.signer.ooxml.OOXMLProvider; import org.apache.poi.ooxml.signature.service.signer.ooxml.OOXMLSignatureVerifier; import org.apache.poi.ooxml.signature.service.spi.DigestInfo; import org.bouncycastle.asn1.x509.KeyUsage; -import org.joda.time.DateTime; @@ -62,35 +59,35 @@ public class TestAbstractOOXMLSignatureService extends TestCase { private static class OOXMLTestSignatureService extends AbstractOOXMLSignatureService { - private final URL ooxmlUrl; + private final URL _ooxmlUrl; - private final TemporaryTestDataStorage temporaryDataStorage; + private final TemporaryTestDataStorage _temporaryDataStorage; - private final ByteArrayOutputStream signedOOXMLOutputStream; + private final ByteArrayOutputStream _signedOOXMLOutputStream; public OOXMLTestSignatureService(URL ooxmlUrl) { - this.temporaryDataStorage = new TemporaryTestDataStorage(); - this.signedOOXMLOutputStream = new ByteArrayOutputStream(); - this.ooxmlUrl = ooxmlUrl; + _temporaryDataStorage = new TemporaryTestDataStorage(); + _signedOOXMLOutputStream = new ByteArrayOutputStream(); + _ooxmlUrl = ooxmlUrl; } @Override protected URL getOfficeOpenXMLDocumentURL() { - return this.ooxmlUrl; + return _ooxmlUrl; } @Override protected OutputStream getSignedOfficeOpenXMLDocumentOutputStream() { - return this.signedOOXMLOutputStream; + return _signedOOXMLOutputStream; } public byte[] getSignedOfficeOpenXMLDocumentData() { - return this.signedOOXMLOutputStream.toByteArray(); + return _signedOOXMLOutputStream.toByteArray(); } @Override protected TemporaryDataStorage getTemporaryDataStorage() { - return this.temporaryDataStorage; + return _temporaryDataStorage; } } @@ -189,9 +186,7 @@ public class TestAbstractOOXMLSignatureService extends TestCase { byte[] digestInfoValue = ArrayUtils.addAll(PkiTestUtils.SHA1_DIGEST_INFO_PREFIX, digestInfo.digestValue); byte[] signatureValue = cipher.doFinal(digestInfoValue); - DateTime notBefore = new DateTime(); - DateTime notAfter = notBefore.plusYears(1); - X509Certificate certificate = PkiTestUtils.generateCertificate(keyPair.getPublic(), signerDn, notBefore, notAfter, null, keyPair.getPrivate(), true, 0, + X509Certificate certificate = PkiTestUtils.generateCertificate(keyPair.getPublic(), signerDn, null, keyPair.getPrivate(), true, 0, null, null, new KeyUsage(KeyUsage.nonRepudiation)); // operate: postSign diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/TestAbstractXmlSignatureService.java b/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/TestAbstractXmlSignatureService.java index 538c96d0be..352cc3e354 100644 --- a/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/TestAbstractXmlSignatureService.java +++ b/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/TestAbstractXmlSignatureService.java @@ -69,7 +69,6 @@ import org.apache.xpath.XPathAPI; import org.bouncycastle.asn1.x509.KeyUsage; import org.jcp.xml.dsig.internal.dom.DOMReference; import org.jcp.xml.dsig.internal.dom.DOMXMLSignature; -import org.joda.time.DateTime; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -215,9 +214,7 @@ public final class TestAbstractXmlSignatureService extends TestCase { byte[] digestInfoValue = ArrayUtils.addAll(PkiTestUtils.SHA1_DIGEST_INFO_PREFIX, digestInfo.digestValue); byte[] signatureValue = cipher.doFinal(digestInfoValue); - DateTime notBefore = new DateTime(); - DateTime notAfter = notBefore.plusYears(1); - X509Certificate certificate = PkiTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test", notBefore, notAfter, null, keyPair.getPrivate(), true, + X509Certificate certificate = PkiTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test", null, keyPair.getPrivate(), true, 0, null, null, new KeyUsage(KeyUsage.nonRepudiation)); /* @@ -313,9 +310,7 @@ public final class TestAbstractXmlSignatureService extends TestCase { byte[] digestInfoValue = ArrayUtils.addAll(PkiTestUtils.SHA1_DIGEST_INFO_PREFIX, digestInfo.digestValue); byte[] signatureValue = cipher.doFinal(digestInfoValue); - DateTime notBefore = new DateTime(); - DateTime notAfter = notBefore.plusYears(1); - X509Certificate certificate = PkiTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test", notBefore, notAfter, null, keyPair.getPrivate(), true, + X509Certificate certificate = PkiTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test", null, keyPair.getPrivate(), true, 0, null, null, new KeyUsage(KeyUsage.nonRepudiation)); /* @@ -395,9 +390,7 @@ public final class TestAbstractXmlSignatureService extends TestCase { byte[] digestInfoValue = ArrayUtils.addAll(PkiTestUtils.SHA1_DIGEST_INFO_PREFIX, digestInfo.digestValue); byte[] signatureValue = cipher.doFinal(digestInfoValue); - DateTime notBefore = new DateTime(); - DateTime notAfter = notBefore.plusYears(1); - X509Certificate certificate = PkiTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test", notBefore, notAfter, null, keyPair.getPrivate(), true, + X509Certificate certificate = PkiTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test", null, keyPair.getPrivate(), true, 0, null, null, new KeyUsage(KeyUsage.nonRepudiation)); /* @@ -475,9 +468,7 @@ public final class TestAbstractXmlSignatureService extends TestCase { byte[] digestInfoValue = ArrayUtils.addAll(PkiTestUtils.SHA1_DIGEST_INFO_PREFIX, digestInfo.digestValue); byte[] signatureValue = cipher.doFinal(digestInfoValue); - DateTime notBefore = new DateTime(); - DateTime notAfter = notBefore.plusYears(1); - X509Certificate certificate = PkiTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test", notBefore, notAfter, null, keyPair.getPrivate(), true, + X509Certificate certificate = PkiTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test", null, keyPair.getPrivate(), true, 0, null, null, new KeyUsage(KeyUsage.nonRepudiation)); /* diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/ooxml/TestOOXMLSignatureAspect.java b/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/ooxml/TestOOXMLSignatureAspect.java new file mode 100644 index 0000000000..aeee8f0d98 --- /dev/null +++ b/src/ooxml/testcases/org/apache/poi/ooxml/signature/service/signer/ooxml/TestOOXMLSignatureAspect.java @@ -0,0 +1,40 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.ooxml.signature.service.signer.ooxml; + +import java.util.Calendar; +import java.util.TimeZone; + +import junit.framework.TestCase; + +public final class TestOOXMLSignatureAspect extends TestCase { + + private static final TimeZone TIME_ZONE_UTC = TimeZone.getTimeZone("UTC"); + + public void testFormatTimestampAsISO8601() { + assertEquals("2010-06-05T04:03:02Z", OOXMLSignatureAspect.formatTimestampAsISO8601(makeTimestamp(2010, 6, 5, 4, 3, 2))); + } + + private static long makeTimestamp(int year, int month, int day, int hour, int minute, int second) { + Calendar c = Calendar.getInstance(); + c.setTimeZone(TIME_ZONE_UTC); + c.set(year, month-1, day, hour, minute, second); + c.set(Calendar.MILLISECOND, 0); + return c.getTimeInMillis(); + } +}