<?xml version="1.0"?>
-<!--
+<!--
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
Bruno Girin brunogirin@gmail.com
This build was tested with ant 1.6.2 although it will probably work with
- other versions. The following jar files should be available on the
+ other versions. The following jar files should be available on the
classpath when running ant:
LIBRARY LOCATION
To build the documentation you will need to install forrest and set
the FORREST_HOME environment variable. Forrest 0.5.1 required.
- Since POI 3.5 you will need JDK 1.5 or newer to build POI.
+ Since POI 3.5 you will need JDK 1.5 or newer to build POI.
Some people may find the tests hang when run through Ant. If this
happens to you, try giving Ant some more memory when you run it, eg:
<property name="ooxml.output.test.dir" location="build/ooxml-test-classes"/>
<property name="ooxml.testokfile" location="build/ooxml-testokfile.txt"/>
- <!-- The following jars are downloaded by the fetch-ooxml-jars task -->
+ <!-- The following jars are downloaded by the fetch-ooxml-jars task -->
<property name="ooxml.dom4j.jar" location="${ooxml.lib}/dom4j-1.6.1.jar"/>
<property name="ooxml.dom4j.url" value="${repository.m2}/maven2/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar"/>
<property name="ooxml.xmlbeans.jar" location="${ooxml.lib}/xmlbeans-2.3.0.jar"/>
<property name="ooxml.xalan.url" value="${repository.m2}/maven2/xalan/xalan/2.7.1/xalan-2.7.1.jar"/>
<property name="ooxml.xalan-serializer.jar" location="${ooxml.lib}/serializer-2.7.1.jar"/>
<property name="ooxml.xalan-serializer.url" value="${repository.m2}/maven2/xalan/serializer/2.7.1/serializer-2.7.1.jar"/>
- <property name="ooxml.joda-time.jar" location="${ooxml.lib}/joda-time-1.6.jar"/>
- <property name="ooxml.joda-time.url" value="${repository.m2}/maven2/joda-time/joda-time/1.6/joda-time-1.6.jar"/>
<!-- BouncyCastle is used only for OOXML Digital Signature tests -->
<property name="ooxml.bcprov.jar" location="${ooxml.lib}/bcprov-jdk15-140.jar"/>
<property name="ooxml.bcprov.url" value="${repository.m2}/maven2/bouncycastle/bcprov-jdk15/140/bcprov-jdk15-140.jar"/>
<property name="maven.ooxml.xsds.version.id" value="1.0"/>
<property name="maven.ooxml.xsds.jar" value="ooxml-schemas-${maven.ooxml.xsds.version.id}.jar"/>
-
+
<property name="build.site" location="build/tmp/site/build/site"/>
<property name="build.site.src" location="build/tmp/site"/>
<property name="junit.report.dir" location="${build.site}/junit"/>
<property name="jdk.version.source" value="1.5"
description="JDK version of source code"/>
<property name="jdk.version.class" value="1.5"
- description="JDK version of generated class files"/>
+ description="JDK version of generated class files"/>
<path id="main.classpath">
- <fileset dir="${main.lib}">
- <include name="*.jar"/>
- </fileset>
+ <fileset dir="${main.lib}">
+ <include name="*.jar"/>
+ </fileset>
<pathelement location="${main.resource1.dir}"/>
</path>
<pathelement location="${ooxml.output.dir}"/>
<pathelement location="${ooxml.output.test.dir}"/>
<pathelement location="${main.output.test.dir}"/> <!-- ooxml tests use some utilities from main tests -->
- <pathelement location="${scratchpad.output.test.dir}"/>
+ <pathelement location="${scratchpad.output.test.dir}"/>
<pathelement location="${junit.jar1.dir}"/>
<pathelement location="${ooxml.src.test}"/>
</path>
<available resource="clovertasks" property="clover.present"/>
<antcall target="with.clover"/>
-
+
<mkdir dir="build"/>
<mkdir dir="build/non-ant-classes"/>
<mkdir dir="${main.output.dir}"/>
<available file="${ooxml.xmlsec.jar}"/>
<available file="${ooxml.xalan.jar}"/>
<available file="${ooxml.xalan-serializer.jar}"/>
- <available file="${ooxml.joda-time.jar}"/>
<available file="${ooxml.bcprov.jar}"/>
</and>
<isset property="disconnected"/>
<param name="sourcefile" value="${ooxml.xalan-serializer.url}"/>
<param name="destfile" value="${ooxml.xalan-serializer.jar}"/>
</antcall>
- <antcall target="downloadfile">
- <param name="sourcefile" value="${ooxml.joda-time.url}"/>
- <param name="destfile" value="${ooxml.joda-time.jar}"/>
- </antcall>
<antcall target="downloadfile">
<param name="sourcefile" value="${ooxml.bcprov.url}"/>
<param name="destfile" value="${ooxml.bcprov.jar}"/>
</xmlbean>
</target>
- <target name="compile" depends="init, compile-main,
+ <target name="compile" depends="init, compile-main,
compile-scratchpad, compile-contrib, compile-examples, compile-scratchpad-examples"
description="Compiles the POI main classes, scratchpad, contrib, examples, and scratchpad examples"/>
<!-- Generate the .java file -->
<property name="version.java" value="${main.output.dir}/org/apache/poi/Version.java" />
<delete file="${version.java}" />
- <copy
+ <copy
file="src/resources/version/Version.java.template"
tofile="${version.java}">
<filterset>
<junit fork="yes" forkmode="once" printsummary="yes" haltonfailure="${halt.on.test.failure}"
failureproperty="main.test.failed" showoutput="true">
<classpath refid="test.classpath"/>
- <sysproperty key="user.language" value="en"/>
- <sysproperty key="user.country" value="US"/>
- <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
+ <sysproperty key="user.language" value="en"/>
+ <sysproperty key="user.country" value="US"/>
+ <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain"/>
<formatter type="xml"/>
<pathelement location="${scratchpad.output.test.dir}"/>
<pathelement location="${junit.jar1.dir}"/>
</classpath>
- <sysproperty key="user.language" value="en"/>
- <sysproperty key="user.country" value="US"/>
- <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
+ <sysproperty key="user.language" value="en"/>
+ <sysproperty key="user.country" value="US"/>
+ <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain" usefile="no"/>
<batchtest todir="${main.reports.test}">
</fileset>
</batchtest>
</junit>
- </target>
+ </target>
<pathelement location="${scratchpad.output.test.dir}"/>
<pathelement location="${junit.jar1.dir}"/>
</classpath>
- <sysproperty key="user.language" value="en"/>
- <sysproperty key="user.country" value="US"/>
- <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
+ <sysproperty key="user.language" value="en"/>
+ <sysproperty key="user.country" value="US"/>
+ <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain" usefile="no"/>
<formatter type="xml"/>
<pathelement location="${scratchpad.output.test.dir}"/>
<pathelement location="${junit.jar1.dir}"/>
</classpath>
- <sysproperty key="user.language" value="en"/>
- <sysproperty key="user.country" value="US"/>
- <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
+ <sysproperty key="user.language" value="en"/>
+ <sysproperty key="user.country" value="US"/>
+ <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain"/>
<formatter type="xml"/>
<pathelement location="${scratchpad.output.test.dir}"/>
<pathelement location="${junit.jar1.dir}"/>
</classpath>
- <sysproperty key="user.language" value="en"/>
- <sysproperty key="user.country" value="US"/>
- <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
+ <sysproperty key="user.language" value="en"/>
+ <sysproperty key="user.country" value="US"/>
+ <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="java.awt.headless" value="true"/>
<sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain" usefile="no"/>
<test name="${testcase}"/>
</junit>
</target>
-
+
<target name="-test-contrib-check">
<uptodate property="contrib.test.notRequired" targetfile="${contrib.testokfile}">
<srcfiles dir="${contrib.src}"/>
<pathelement location="${contrib.output.test.dir}"/>
<pathelement location="${junit.jar1.dir}"/>
</classpath>
- <sysproperty key="user.language" value="en"/>
- <sysproperty key="user.country" value="US"/>
+ <sysproperty key="user.language" value="en"/>
+ <sysproperty key="user.country" value="US"/>
<sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain"/>
<formatter type="xml"/>
<target name="test-ooxml" depends="compile-main,compile-ooxml,-test-ooxml-check" unless="ooxml.test.notRequired">
<junit printsummary="yes" fork="yes" forkmode="once" haltonfailure="${halt.on.test.failure}" failureproperty="ooxml.test.failed">
<classpath refid="test.ooxml.classpath" />
- <sysproperty key="user.language" value="en"/>
- <sysproperty key="user.country" value="US"/>
- <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
+ <sysproperty key="user.language" value="en"/>
+ <sysproperty key="user.country" value="US"/>
+ <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain"/>
<formatter type="xml"/>
<target name="single-test-ooxml" depends="-test-property-check,compile-main,compile-ooxml" description="Runs a single ooxml test case specified with -Dtestcase=classname">
<junit printsummary="yes" showoutput="true" filtertrace="no" haltonfailure="false" >
<classpath refid="test.ooxml.classpath" />
- <sysproperty key="user.language" value="en"/>
- <sysproperty key="user.country" value="US"/>
- <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
+ <sysproperty key="user.language" value="en"/>
+ <sysproperty key="user.country" value="US"/>
+ <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain" usefile="no"/>
<formatter type="xml"/>
<attribute name="Implementation-Title" value="Apache POI"/>
<attribute name="Implementation-Version" value="${version.id}-${DSTAMP}"/>
<attribute name="Implementation-Vendor" value="Apache"/>
- </manifest>
+ </manifest>
</jar>
<jar destfile="${dist.dir}/${jar.name}-contrib-${version.id}-${DSTAMP}.jar">
<fileset dir="${contrib.output.dir}" />
<attribute name="Implementation-Title" value="Apache POI"/>
<attribute name="Implementation-Version" value="${version.id}-${DSTAMP}"/>
<attribute name="Implementation-Vendor" value="Apache"/>
- </manifest>
+ </manifest>
</jar>
<jar destfile="${dist.dir}/${jar.name}-scratchpad-${version.id}-${DSTAMP}.jar">
<fileset dir="${scratchpad.output.dir}" />
<attribute name="Implementation-Title" value="Apache POI"/>
<attribute name="Implementation-Version" value="${version.id}-${DSTAMP}"/>
<attribute name="Implementation-Vendor" value="Apache"/>
- </manifest>
+ </manifest>
</jar>
<jar destfile="${dist.dir}/${jar.name}-ooxml-${version.id}-${DSTAMP}.jar">
<fileset dir="${ooxml.output.dir}" />
<attribute name="Implementation-Title" value="Apache POI"/>
<attribute name="Implementation-Version" value="${version.id}-${DSTAMP}"/>
<attribute name="Implementation-Vendor" value="Apache"/>
- </manifest>
+ </manifest>
</jar>
</target>
<target name="jar-examples" depends="compile, compile-version" description="Creates a jar file of the examples, in case people want to use them as-is">
<attribute name="Implementation-Title" value="Apache POI"/>
<attribute name="Implementation-Version" value="${version.id}-${DSTAMP}"/>
<attribute name="Implementation-Vendor" value="Apache"/>
- </manifest>
+ </manifest>
</jar>
</target>
JDepend is not available. You must download JDepend from
<http://www.clarkware.com/software/JDepend.html> and include the
JAR file in your classpath.
- </echo>
+ </echo>
<fail message="JDepend is not available."/>
</target>
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
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;
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;
/**
* 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<Reference> references, List<XMLObject> objects)
private void addManifestObject(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<Reference> references,
List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
- Manifest manifest = constructManifest(signatureFactory, document);
+ Manifest manifest = constructManifest(signatureFactory);
String objectId = "idPackageObject"; // really has to be this value.
List<XMLStructure> objectContent = new LinkedList<XMLStructure>();
objectContent.add(manifest);
references.add(reference);
}
- private Manifest constructManifest(XMLSignatureFactory signatureFactory, Document document) throws NoSuchAlgorithmException,
+ private Manifest constructManifest(XMLSignatureFactory signatureFactory) throws NoSuchAlgorithmException,
InvalidAlgorithmParameterException {
List<Reference> manifestReferences = new LinkedList<Reference>();
try {
- addRelationshipsReferences(signatureFactory, document, manifestReferences);
+ addRelationshipsReferences(signatureFactory, manifestReferences);
} catch (Exception e) {
throw new RuntimeException("error: " + e.getMessage(), e);
}
return manifest;
}
- private void addSignatureTime(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<XMLStructure> objectContent) {
+ private static void addSignatureTime(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<XMLStructure> objectContent) {
/*
* SignatureTime
*/
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);
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<Reference> references,
List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
List<XMLStructure> objectContent = new LinkedList<XMLStructure>();
references.add(reference);
}
- private void addRelationshipsReferences(XMLSignatureFactory signatureFactory, Document document, List<Reference> manifestReferences) throws IOException,
- ParserConfigurationException, SAXException, TransformerException, NoSuchAlgorithmException,
+ private void addRelationshipsReferences(XMLSignatureFactory signatureFactory, List<Reference> 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;
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<Reference> manifestReferences) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
LOG.debug("relationships: " + zipEntryName);
RelationshipTransformParameterSpec parameterSpec = new RelationshipTransformParameterSpec();
InvalidAlgorithmParameterException {
List<String> documentResourceNames;
try {
- documentResourceNames = getResourceNames(this.signatureService.getOfficeOpenXMLDocumentURL(), contentType);
+ documentResourceNames = getResourceNames(_signatureService.getOfficeOpenXMLDocumentURL(), contentType);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
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;
--- /dev/null
+/* ====================================================================
+ 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;
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
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;
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;
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 {
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());
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();
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
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;
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;
}
}
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
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;
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));
/*
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));
/*
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));
/*
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));
/*
--- /dev/null
+/* ====================================================================
+ 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();
+ }
+}