Search in sources :

Example 31 with X500Principal

use of javax.security.auth.x500.X500Principal in project robovm by robovm.

the class TrustAnchorTest method testGetCAPublicKey01.

/**
     * Test #1 for <code>getCAPublicKey()</code> method<br>
     *
     * Assertion: returns most trusted CA public key</code><br>
     * Test preconditions: valid name passed to the constructor<br>
     * Expected: the same name must be returned by the method<br>
     *
     */
public final void testGetCAPublicKey01() throws Exception {
    PublicKey pk = new TestKeyPair(keyAlg).getPublic();
    // sub testcase 1
    TrustAnchor ta = new TrustAnchor(validCaNameRfc2253, pk, null);
    assertEquals("equals1", pk, ta.getCAPublicKey());
    // sub testcase 2
    X500Principal x500p = new X500Principal(validCaNameRfc2253);
    ta = new TrustAnchor(x500p, pk, null);
    assertEquals("equals2", pk, ta.getCAPublicKey());
}
Also used : TestKeyPair(org.apache.harmony.security.tests.support.TestKeyPair) PublicKey(java.security.PublicKey) X500Principal(javax.security.auth.x500.X500Principal) TrustAnchor(java.security.cert.TrustAnchor)

Example 32 with X500Principal

use of javax.security.auth.x500.X500Principal in project robovm by robovm.

the class TrustAnchorTest method testTrustAnchorX500PrincipalPublicKeybyteArray04.

/**
     * Test #4 for <code>TrustAnchor(X500Principal, PublicKey, byte[])</code> constructor<br>
     * Assertion: <code>NullPointerException</code> if <code>caPrincipal</code>
     * or <code>caPublicKey</code> parameter is <code>null</code><br>
     * Test preconditions: pass <code>null</code> as mentioned parameter<br>
     * Expected: NullPointerException
     * @throws InvalidKeySpecException
     */
public final void testTrustAnchorX500PrincipalPublicKeybyteArray04() throws Exception {
    PublicKey pk = new TestKeyPair(keyAlg).getPublic();
    X500Principal x500p = new X500Principal(validCaNameRfc2253);
    // sub testcase 1
    try {
        new TrustAnchor((X500Principal) null, pk, getEncodingPSOnly());
        fail("NullPointerException has not been thrown");
    } catch (NullPointerException ok) {
    }
    // sub testcase 2
    try {
        new TrustAnchor(x500p, null, getEncodingPSOnly());
        fail("NullPointerException has not been thrown");
    } catch (NullPointerException ok) {
    }
    // sub testcase 3
    try {
        new TrustAnchor((X500Principal) null, null, getEncodingPSOnly());
        fail("NullPointerException has not been thrown");
    } catch (NullPointerException ok) {
    }
}
Also used : TestKeyPair(org.apache.harmony.security.tests.support.TestKeyPair) PublicKey(java.security.PublicKey) X500Principal(javax.security.auth.x500.X500Principal) TrustAnchor(java.security.cert.TrustAnchor)

Example 33 with X500Principal

use of javax.security.auth.x500.X500Principal in project robovm by robovm.

the class X509CertSelectorTest method test_setIssuerLjava_lang_String.

/**
     * java.security.cert.X509CertSelector#setIssuer(java.lang.String)
     */
public void test_setIssuerLjava_lang_String() throws Exception {
    String name1 = "O=First Org.";
    String name2 = "O=Second Org.";
    X500Principal iss1 = new X500Principal(name1);
    X500Principal iss2 = new X500Principal(name2);
    TestCert cert1 = new TestCert(iss1);
    TestCert cert2 = new TestCert(iss2);
    X509CertSelector selector = new X509CertSelector();
    selector.setIssuer((String) null);
    assertTrue("Any certificates should match " + "in the case of null issuer criteria.", selector.match(cert1) && selector.match(cert2));
    selector.setIssuer(name1);
    assertTrue("The certificate should match the selection criteria.", selector.match(cert1));
    assertFalse("The certificate should not match the selection criteria.", selector.match(cert2));
    selector.setIssuer(name2);
    assertTrue("The certificate should match the selection criteria.", selector.match(cert2));
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) X509CertSelector(java.security.cert.X509CertSelector) ASN1OctetString(org.apache.harmony.security.asn1.ASN1OctetString)

Example 34 with X500Principal

use of javax.security.auth.x500.X500Principal in project robovm by robovm.

the class X509CertSelectorTest method test_setIssuerLB$.

/**
     * java.security.cert.X509CertSelector#setIssuer(byte[])
     */
public void test_setIssuerLB$() throws Exception {
    byte[] name1 = new byte[] // manually obtained DER encoding of "O=First Org." issuer name;
    { 48, 21, 49, 19, 48, 17, 6, 3, 85, 4, 10, 19, 10, 70, 105, 114, 115, 116, 32, 79, 114, 103, 46 };
    byte[] name2 = new byte[] // manually obtained DER encoding of "O=Second Org." issuer name;
    { 48, 22, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 83, 101, 99, 111, 110, 100, 32, 79, 114, 103, 46 };
    X500Principal iss1 = new X500Principal(name1);
    X500Principal iss2 = new X500Principal(name2);
    TestCert cert1 = new TestCert(iss1);
    TestCert cert2 = new TestCert(iss2);
    X509CertSelector selector = new X509CertSelector();
    selector.setIssuer((byte[]) null);
    assertTrue("Any certificates should match " + "in the case of null issuer criteria.", selector.match(cert1) && selector.match(cert2));
    selector.setIssuer(name1);
    assertTrue("The certificate should match the selection criteria.", selector.match(cert1));
    assertFalse("The certificate should not match the selection criteria.", selector.match(cert2));
    selector.setIssuer(name2);
    assertTrue("The certificate should match the selection criteria.", selector.match(cert2));
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) X509CertSelector(java.security.cert.X509CertSelector)

Example 35 with X500Principal

use of javax.security.auth.x500.X500Principal in project robovm by robovm.

the class X509CertSelectorTest method test_getSubjectAsString.

/**
     * java.security.cert.X509CertSelector#getSubjectAsString()
     */
public void test_getSubjectAsString() {
    String name1 = "O=First Org.";
    String name2 = "O=Second Org.";
    X500Principal sub1 = new X500Principal(name1);
    X500Principal sub2 = new X500Principal(name2);
    X509CertSelector selector = new X509CertSelector();
    assertNull("Selector should return null", selector.getSubjectAsString());
    selector.setSubject(sub1);
    assertEquals("The returned subject should be equal to specified", name1, selector.getSubjectAsString());
    assertFalse("The returned subject should differ", name2.equals(selector.getSubjectAsString()));
    selector.setSubject(sub2);
    assertEquals("The returned subject should be equal to specified", name2, selector.getSubjectAsString());
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) X509CertSelector(java.security.cert.X509CertSelector) ASN1OctetString(org.apache.harmony.security.asn1.ASN1OctetString)

Aggregations

X500Principal (javax.security.auth.x500.X500Principal)246 X509Certificate (java.security.cert.X509Certificate)68 IOException (java.io.IOException)52 ArrayList (java.util.ArrayList)39 List (java.util.List)25 Principal (java.security.Principal)21 PublicKey (java.security.PublicKey)21 TrustAnchor (java.security.cert.TrustAnchor)21 Certificate (java.security.cert.Certificate)20 X509CertSelector (java.security.cert.X509CertSelector)16 HashMap (java.util.HashMap)16 BigInteger (java.math.BigInteger)15 KeyPair (java.security.KeyPair)15 HashSet (java.util.HashSet)14 Test (org.junit.Test)14 KeyPairGenerator (java.security.KeyPairGenerator)13 CertPathValidatorException (java.security.cert.CertPathValidatorException)13 CertificateException (java.security.cert.CertificateException)13 GeneralSecurityException (java.security.GeneralSecurityException)12 CertificateParsingException (java.security.cert.CertificateParsingException)12