diff --git a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java index ad2e8c41b5..4130e2396c 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java +++ b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java @@ -214,7 +214,7 @@ public class XAdESXLSignatureFacet implements SignatureFacet { } CRLIdentifierType crlIdentifier = crlRef.addNewCRLIdentifier(); - String issuerName = crl.getIssuerDN().getName().replace(",", ", "); + String issuerName = crl.getIssuerX500Principal().getName().replace(",", ", "); crlIdentifier.setIssuer(issuerName); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Z"), Locale.ROOT); cal.setTime(crl.getThisUpdate()); diff --git a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/DummyKeystore.java b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/DummyKeystore.java index 7f19686fe0..a7fbcb6f1d 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/DummyKeystore.java +++ b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/DummyKeystore.java @@ -172,7 +172,7 @@ public class DummyKeystore { 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}); return new KeyCertPair(key, new Certificate[]{x509}); diff --git a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java index 754fc465ec..77cc1472e3 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java +++ b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java @@ -23,6 +23,7 @@ ================================================================= */ 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.assertFalse; 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.Supplier; +import javax.security.auth.x500.X500Principal; import javax.xml.crypto.MarshalException; import javax.xml.crypto.dsig.CanonicalizationMethod; import javax.xml.crypto.dsig.XMLSignatureException; @@ -807,14 +809,9 @@ class TestSignatureInfo { assertNotNull(result); - if (multi) { - assertEquals(2, result.size()); - assertEquals("CN=Muj Klic", result.get(0).getSubjectDN().toString()); - 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()); - } + String[] act = result.stream().map(X509Certificate::getSubjectX500Principal).map(X500Principal::getName).toArray(String[]::new); + String[] exp = multi ? new String[]{ "CN=Muj Klic", "CN=My Second key" } : new String[]{ "CN=My Second key" }; + assertArrayEquals(exp, act); assertTrue(si.verifySignature()); pkg.revert(); @@ -859,7 +856,7 @@ class TestSignatureInfo { final List certs = sic.getSigningCertificateChain(); 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("Purpose for signing", sic.getSignatureDescription()); assertEquals("2018-06-10T09:00:54Z", sic.formatExecutionTime());