Fix deprecate warnings on X509 api calls

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895034 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2021-11-14 13:15:14 +00:00
parent 474576677b
commit 007a6f6160
3 changed files with 8 additions and 11 deletions

View File

@ -214,7 +214,7 @@ public class XAdESXLSignatureFacet implements SignatureFacet {
} }
CRLIdentifierType crlIdentifier = crlRef.addNewCRLIdentifier(); CRLIdentifierType crlIdentifier = crlRef.addNewCRLIdentifier();
String issuerName = crl.getIssuerDN().getName().replace(",", ", "); String issuerName = crl.getIssuerX500Principal().getName().replace(",", ", ");
crlIdentifier.setIssuer(issuerName); crlIdentifier.setIssuer(issuerName);
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Z"), Locale.ROOT); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Z"), Locale.ROOT);
cal.setTime(crl.getThisUpdate()); cal.setTime(crl.getThisUpdate());

View File

@ -172,7 +172,7 @@ public class DummyKeystore {
throw new IOException("Please add private key and certificate in the PEM file."); throw new IOException("Please add private key and certificate in the PEM file.");
} }
String alias = x509.getSubjectDN().getName(); String alias = x509.getSubjectX500Principal().getName();
keystore.setKeyEntry(alias, key, keyPass.toCharArray(), new Certificate[]{x509}); keystore.setKeyEntry(alias, key, keyPass.toCharArray(), new Certificate[]{x509});
return new KeyCertPair(key, new Certificate[]{x509}); return new KeyCertPair(key, new Certificate[]{x509});

View File

@ -23,6 +23,7 @@
================================================================= */ ================================================================= */
package org.apache.poi.poifs.crypt.dsig; package org.apache.poi.poifs.crypt.dsig;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -52,6 +53,7 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Supplier; import java.util.function.Supplier;
import javax.security.auth.x500.X500Principal;
import javax.xml.crypto.MarshalException; import javax.xml.crypto.MarshalException;
import javax.xml.crypto.dsig.CanonicalizationMethod; import javax.xml.crypto.dsig.CanonicalizationMethod;
import javax.xml.crypto.dsig.XMLSignatureException; import javax.xml.crypto.dsig.XMLSignatureException;
@ -807,14 +809,9 @@ class TestSignatureInfo {
assertNotNull(result); assertNotNull(result);
if (multi) { String[] act = result.stream().map(X509Certificate::getSubjectX500Principal).map(X500Principal::getName).toArray(String[]::new);
assertEquals(2, result.size()); String[] exp = multi ? new String[]{ "CN=Muj Klic", "CN=My Second key" } : new String[]{ "CN=My Second key" };
assertEquals("CN=Muj Klic", result.get(0).getSubjectDN().toString()); assertArrayEquals(exp, act);
assertEquals("CN=My Second key", result.get(1).getSubjectDN().toString());
} else {
assertEquals(1, result.size());
assertEquals("CN=My Second key", result.get(0).getSubjectDN().toString());
}
assertTrue(si.verifySignature()); assertTrue(si.verifySignature());
pkg.revert(); pkg.revert();
@ -859,7 +856,7 @@ class TestSignatureInfo {
final List<X509Certificate> certs = sic.getSigningCertificateChain(); final List<X509Certificate> certs = sic.getSigningCertificateChain();
assertEquals(1, certs.size()); assertEquals(1, certs.size());
assertEquals("CN=Test", certs.get(0).getSubjectDN().getName()); assertEquals("CN=Test", certs.get(0).getSubjectX500Principal().getName());
assertEquals("SuperDuper-Reviewer", sic.getXadesRole()); assertEquals("SuperDuper-Reviewer", sic.getXadesRole());
assertEquals("Purpose for signing", sic.getSignatureDescription()); assertEquals("Purpose for signing", sic.getSignatureDescription());
assertEquals("2018-06-10T09:00:54Z", sic.formatExecutionTime()); assertEquals("2018-06-10T09:00:54Z", sic.formatExecutionTime());