From 90359aefff2b593f83377981b33ab6911079f072 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Sat, 18 Oct 2014 23:19:49 +0000 Subject: [PATCH] Removed some custom classloading code, which doesn't make sense anymore Tested a few other timestamp providers limited the use of the additional libraries to xml dsign classes while running the junit tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1632858 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 31 ++++++++++++-- .../dsig/services/TSPTimeStampService.java | 5 ++- .../poi/poifs/crypt/TestSignatureInfo.java | 42 ++++++++----------- 3 files changed, 50 insertions(+), 28 deletions(-) diff --git a/build.xml b/build.xml index 2b4c5ec0f5..cebb06aab6 100644 --- a/build.xml +++ b/build.xml @@ -36,7 +36,7 @@ under the License. LIBRARY LOCATION ======= ======== - junit(3.8+) http://www.junit.org + junit(4.11+) http://www.junit.org To build the documentation you will need to install forrest and set the FORREST_HOME environment variable. Forrest 0.5.1 required. @@ -259,7 +259,8 @@ under the License. - + + @@ -727,7 +728,10 @@ under the License. encoding="${java.source.encoding}" fork="yes" includeantruntime="false"> - + + + + + @@ -986,6 +991,26 @@ under the License. + + + + + + + + + + + + + + + + + + + diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/TSPTimeStampService.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/TSPTimeStampService.java index 0937b0f360..99a0e29982 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/TSPTimeStampService.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/TSPTimeStampService.java @@ -131,11 +131,14 @@ public class TSPTimeStampService implements TimeStampService { huc.setRequestProperty("Authorization", "Basic " + encoding); } + huc.setRequestMethod("POST"); + huc.setConnectTimeout(20000); + huc.setReadTimeout(20000); huc.setDoOutput(true); // also sets method to POST. huc.setRequestProperty("User-Agent", signatureConfig.getUserAgent()); huc.setRequestProperty("Content-Type", signatureConfig.isTspOldProtocol() ? "application/timestamp-request" - : "application/timestamp-query;charset=ISO-8859-1"); + : "application/timestamp-query"); // "; charset=ISO-8859-1"); OutputStream hucOut = huc.getOutputStream(); hucOut.write(encodedRequest); diff --git a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java index a9fa25f4e3..e7c58eed48 100644 --- a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java +++ b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java @@ -23,7 +23,10 @@ ================================================================= */ package org.apache.poi.poifs.crypt; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.File; import java.io.FileInputStream; @@ -32,8 +35,6 @@ import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Method; import java.net.ConnectException; -import java.net.URL; -import java.net.URLClassLoader; import java.security.Key; import java.security.KeyPair; import java.security.KeyStore; @@ -88,28 +89,17 @@ public class TestSignatureInfo { private KeyPair keyPair = null; private X509Certificate x509 = null; - - @BeforeClass public static void initBouncy() throws IOException { - File bcProvJar = new File("lib/bcprov-ext-jdk15on-1.51.jar"); - File bcPkixJar = new File("lib/bcpkix-jdk15on-151.jar"); - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URLClassLoader ucl = new URLClassLoader(new URL[]{bcProvJar.toURI().toURL(),bcPkixJar.toURI().toURL()}, cl); - try { - Thread.currentThread().setContextClassLoader(ucl); - CryptoFunctions.registerBouncyCastle(); - - /*** TODO : set cal to now ... only set to fixed date for debugging ... */ - cal = Calendar.getInstance(); - cal.clear(); - cal.setTimeZone(TimeZone.getTimeZone("UTC")); - cal.set(2014, 7, 6, 21, 42, 12); - } finally { - ucl.close(); - } - } + CryptoFunctions.registerBouncyCastle(); + /*** TODO : set cal to now ... only set to fixed date for debugging ... */ + cal = Calendar.getInstance(); + cal.clear(); + cal.setTimeZone(TimeZone.getTimeZone("UTC")); + cal.set(2014, 7, 6, 21, 42, 12); + } + @Test public void getSignerUnsigned() throws Exception { String testFiles[] = { @@ -303,8 +293,12 @@ public class TestSignatureInfo { boolean mockTsp = false; // http://timestamping.edelweb.fr/service/tsp // http://tsa.belgium.be/connect - signatureConfig.setTspUrl("http://timestamping.edelweb.fr/service/tsp"); - signatureConfig.setTspOldProtocol(true); + // http://timestamp.comodoca.com/authenticode + // http://timestamp.comodoca.com/rfc3161 + // http://services.globaltrustfinder.com/adss/tsa + signatureConfig.setTspUrl("http://timestamp.comodoca.com/rfc3161"); + signatureConfig.setTspRequestPolicy(null); // comodoca request fails, if default policy is set ... + signatureConfig.setTspOldProtocol(false); if (mockTsp) { TimeStampService tspService = new TimeStampService(){ -- 2.39.5