diff options
author | Thomas <> | 2023-06-23 08:55:21 +0200 |
---|---|---|
committer | Thomas <> | 2023-06-23 08:55:21 +0200 |
commit | ad42c0d94412597de4b28e1dad292b49482e0f33 (patch) | |
tree | 0fe2ca23a1a43d09c92e25491787e7622168c4ac /moaSig/moa-sig-lib/src/test | |
parent | 317c64d0d9bb2a5eb84d769d3bcc802a645aaa6d (diff) | |
download | moa-sig-ad42c0d94412597de4b28e1dad292b49482e0f33.tar.gz moa-sig-ad42c0d94412597de4b28e1dad292b49482e0f33.tar.bz2 moa-sig-ad42c0d94412597de4b28e1dad292b49482e0f33.zip |
test(core): add test for X500 name normalization
Diffstat (limited to 'moaSig/moa-sig-lib/src/test')
-rw-r--r-- | moaSig/moa-sig-lib/src/test/java/test/at/gv/egovernment/moa/spss/server/config/X500NormalisationTest.java | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/moaSig/moa-sig-lib/src/test/java/test/at/gv/egovernment/moa/spss/server/config/X500NormalisationTest.java b/moaSig/moa-sig-lib/src/test/java/test/at/gv/egovernment/moa/spss/server/config/X500NormalisationTest.java new file mode 100644 index 0000000..e580d56 --- /dev/null +++ b/moaSig/moa-sig-lib/src/test/java/test/at/gv/egovernment/moa/spss/server/config/X500NormalisationTest.java @@ -0,0 +1,135 @@ +package test.at.gv.egovernment.moa.spss.server.config; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.security.cert.CertificateException; + +import org.junit.runners.MethodSorters; +import org.junit.FixMethodOrder; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.BlockJUnit4ClassRunner; + +import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; +import iaik.asn1.ObjectID; +import iaik.asn1.structures.Name; +import iaik.utils.RFC2253NameParser; +import iaik.utils.RFC2253NameParserException; +import iaik.x509.X509Certificate; + +@RunWith(BlockJUnit4ClassRunner.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class X500NormalisationTest { + + private static final String RESULT = + "C=AT,O=Swisscom IT Services Finance S.E.,organizationIdentifier=VATAT-U64741248,OU=Digital Certificate Services,CN=Swisscom Diamant EU CA 4.1"; + + @Test + public void aaa_withCertificate() throws CertificateException, IOException, RFC2253NameParserException { + + X509Certificate eeCert = new X509Certificate( + X500NormalisationTest.class.getResourceAsStream("/data/ee.crt")); + + String normalizedName = ConfigurationProvider.normalizeX500Names(((Name)eeCert.getIssuerDN()).getRFC2253String()); + + assertEquals(RESULT, normalizedName); + + } + + @Test + public void aaa_withString() throws CertificateException, IOException, RFC2253NameParserException { + String normalizedName = ConfigurationProvider.normalizeX500Names(RESULT); + + assertEquals(RESULT, normalizedName); + + } + + @Ignore + @Test + public void aaa_withStringSecond() throws CertificateException, IOException, RFC2253NameParserException { + String normalizedName = ConfigurationProvider.normalizeX500Names( + "organizationIdentifier=VATAT-U64741248,OU=Digital Certificate Services,CN=Swisscom Diamant EU CA 4.1,O=Swisscom IT Services Finance S.E.,C=AT"); + + assertEquals(RESULT, normalizedName); + + } + + @Test + public void bbb_withCertificateDetailedImpl() throws CertificateException, IOException, RFC2253NameParserException { + + X509Certificate eeCert = new X509Certificate( + X500NormalisationTest.class.getResourceAsStream("/data/ee.crt")); + + RFC2253NameParser.register( + "organizationIdentifier", + new ObjectID("2.5.4.97", "organizationIdentifier", (String) null, false)); + + final RFC2253NameParser parser = new RFC2253NameParser(((Name)eeCert.getIssuerDN()).getRFC2253String()); + final Name name = parser.parse(); + String normalizedName = name.getRFC2253String(); + + assertEquals(RESULT, normalizedName); + + } + + @Test + public void bbb_withString() throws CertificateException, IOException, RFC2253NameParserException { + RFC2253NameParser.register( + "organizationIdentifier", + new ObjectID("2.5.4.97", "organizationIdentifier", (String) null, false)); + + final RFC2253NameParser parser = new RFC2253NameParser(RESULT); + final Name name = parser.parse(); + String normalizedName = name.getRFC2253String(); + + assertEquals(RESULT, normalizedName); + + name.getRFC2253String(true); + name.getRFC2253String(false); + + } + + @Test + public void bbb_withStringSecond() throws CertificateException, IOException, RFC2253NameParserException { + RFC2253NameParser.register( + "organizationIdentifier", + new ObjectID("2.5.4.97", "organizationIdentifier", (String) null, false)); + + final RFC2253NameParser parser = new RFC2253NameParser( + "C=AT,O=Swisscom IT Services Finance S.E.,organizationIdentifier=VATAT-U64741248,OU=Digital Certificate Services,CN=Swisscom Diamant EU CA 4.1"); + final Name name = parser.parse(); + String normalizedName = name.getRFC2253String(); + + + + assertEquals(RESULT, normalizedName); + + } + + /* + * Ignored, because 'ORG_ID' from original Cert is not valid. + * Reason: underline '_' is not an allowed attributeType (see Section 3 https://www.rfc-editor.org/rfc/rfc2253.html) + * - attributeType = (ALPHA 1*keychar) / oid + * - keychar = ALPHA / DIGIT / "-" + */ + @Ignore + @Test + public void ccc_withStringSecond() throws CertificateException, IOException, RFC2253NameParserException { + RFC2253NameParser.register( + "ORG-ID", + new ObjectID("2.5.4.97", "organizationIdentifier", (String) null, false)); + + final RFC2253NameParser parser = new RFC2253NameParser( + "ORG-ID=VATAT-U64741248,OU=Digital Certificate Services,CN=Swisscom Diamant EU CA 4.1,O=Swisscom IT Services Finance S.E.,C=AT"); + final Name name = parser.parse(); + String normalizedName = name.getRFC2253String(); + + + + assertEquals(RESULT, normalizedName); + + } + +} |