Bug 58326 - Forbidden APIs patches - first set of changes for locale and timezone settings

commit single files because of svn failures ...

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1701684 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2015-09-07 20:14:33 +00:00
parent 062cf73c07
commit f2e8549612
1 changed files with 14 additions and 14 deletions

View File

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