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
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
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
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
pkg.close();\r
}\r
\r
+ @SuppressWarnings("resource")\r
@Test\r
public void testSignEnvelopingDocument() throws Exception {\r
String testFile = "hello-world-unsigned.xlsx";\r
} 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
\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
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
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