]> source.dussan.org Git - poi.git/commitdiff
Bug 58326 - Forbidden APIs patches - first set of changes for locale and timezone...
authorAndreas Beeker <kiwiwings@apache.org>
Mon, 7 Sep 2015 20:14:33 +0000 (20:14 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Mon, 7 Sep 2015 20:14:33 +0000 (20:14 +0000)
commit single files because of svn failures ...

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1701684 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java

index 0835c566b810a31165cf4abdc339454c4c374c69..79edd32fbd998821601ffaee338fd1c70a3e3eb5 100644 (file)
@@ -52,7 +52,6 @@ import java.util.Collections;
 import java.util.Date;\r
 import java.util.Iterator;\r
 import java.util.List;\r
-import java.util.TimeZone;\r
 \r
 import org.apache.poi.POIDataSamples;\r
 import org.apache.poi.openxml4j.opc.OPCPackage;\r
@@ -71,6 +70,7 @@ import org.apache.poi.poifs.crypt.dsig.services.TimeStampService;
 import org.apache.poi.poifs.crypt.dsig.services.TimeStampServiceValidator;\r
 import org.apache.poi.util.DocumentHelper;\r
 import org.apache.poi.util.IOUtils;\r
+import org.apache.poi.util.LocaleUtil;\r
 import org.apache.poi.util.POILogFactory;\r
 import org.apache.poi.util.POILogger;\r
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;\r
@@ -99,10 +99,9 @@ public class TestSignatureInfo {
         CryptoFunctions.registerBouncyCastle();\r
 \r
         /*** TODO : set cal to now ... only set to fixed date for debugging ... */ \r
-        cal = Calendar.getInstance();\r
-        cal.clear();\r
-        cal.setTimeZone(TimeZone.getTimeZone("UTC"));\r
-        cal.set(2014, 7, 6, 21, 42, 12);\r
+        cal = LocaleUtil.getLocaleCalendar(LocaleUtil.TIMEZONE_UTC);\r
+//        cal.set(2014, 7, 6, 21, 42, 12);\r
+//        cal.clear(Calendar.MILLISECOND);\r
 \r
         // don't run this test when we are using older Xerces as it triggers an XML Parser backwards compatibility issue \r
         // in the xmlsec jar file\r
@@ -241,6 +240,7 @@ public class TestSignatureInfo {
     public void testManipulation() throws Exception {\r
         // sign & validate\r
         String testFile = "hello-world-unsigned.xlsx";\r
+        @SuppressWarnings("resource")\r
         OPCPackage pkg = OPCPackage.open(copy(testdata.getFile(testFile)), PackageAccess.READ_WRITE);\r
         sign(pkg, "Test", "CN=Test", 1);\r
         \r
@@ -289,6 +289,7 @@ public class TestSignatureInfo {
         pkg.close();\r
     }\r
 \r
+    @SuppressWarnings("resource")\r
     @Test\r
     public void testSignEnvelopingDocument() throws Exception {\r
         String testFile = "hello-world-unsigned.xlsx";\r
@@ -350,9 +351,9 @@ public class TestSignatureInfo {
         } else {\r
             TimeStampServiceValidator tspValidator = new TimeStampServiceValidator() {\r
                 @Override\r
-                public void validate(List<X509Certificate> certificateChain,\r
+                public void validate(List<X509Certificate> validateChain,\r
                 RevocationData revocationData) throws Exception {\r
-                    for (X509Certificate certificate : certificateChain) {\r
+                    for (X509Certificate certificate : validateChain) {\r
                         LOG.log(POILogger.DEBUG, "certificate: " + certificate.getSubjectX500Principal());\r
                         LOG.log(POILogger.DEBUG, "validity: " + certificate.getNotBefore() + " - " + certificate.getNotAfter());\r
                     }\r
@@ -370,7 +371,7 @@ public class TestSignatureInfo {
 \r
         RevocationDataService revocationDataService = new RevocationDataService(){\r
             @Override\r
-            public RevocationData getRevocationData(List<X509Certificate> certificateChain) {\r
+            public RevocationData getRevocationData(List<X509Certificate> revocationChain) {\r
                 return revocationData;\r
             }\r
         };\r
@@ -498,9 +499,8 @@ public class TestSignatureInfo {
         SignatureConfig signatureConfig = new SignatureConfig();\r
         signatureConfig.setKey(keyPair.getPrivate());\r
         signatureConfig.setSigningCertificateChain(certChain);\r
-        Calendar cal = Calendar.getInstance();\r
-        cal.set(2007, 7, 1);\r
-        signatureConfig.setExecutionTime(cal.getTime());\r
+        Calendar oldCal = LocaleUtil.getLocaleCalendar(2007, 7, 1);\r
+        signatureConfig.setExecutionTime(oldCal.getTime());\r
         signatureConfig.setDigestAlgo(HashAlgorithm.sha1);\r
         signatureConfig.setOpcPackage(pkg);\r
         \r
@@ -615,10 +615,10 @@ public class TestSignatureInfo {
             keyPair = new KeyPair(x509.getPublicKey(), (PrivateKey)key);\r
         } else {\r
             keyPair = PkiTestUtils.generateKeyPair();\r
-            Calendar cal = Calendar.getInstance();\r
             Date notBefore = cal.getTime();\r
-            cal.add(Calendar.YEAR, 1);\r
-            Date notAfter = cal.getTime();\r
+            Calendar cal2 = (Calendar)cal.clone();\r
+            cal2.add(Calendar.YEAR, 1);\r
+            Date notAfter = cal2.getTime();\r
             KeyUsage keyUsage = new KeyUsage(KeyUsage.digitalSignature);\r
             \r
             x509 = PkiTestUtils.generateCertificate(keyPair.getPublic(), subjectDN\r