Search in sources :

Example 36 with X500Principal

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

the class TrustAnchorTest method testGetCA01.

/**
     * Test #1 for <code>getCA()</code> method<br>
     *
     * Assertion: returns most trusted CA<br>
     * Test preconditions: valid CA or CA name passed to the constructor<br>
     * Expected: the same CA ot the CA with the same name must be returned
     * by the method<br>
     * @throws InvalidKeySpecException
     */
public final void testGetCA01() throws Exception {
    PublicKey pk = new TestKeyPair(keyAlg).getPublic();
    // sub testcase 1
    TrustAnchor ta = new TrustAnchor(validCaNameRfc2253, pk, null);
    X500Principal ca = ta.getCA();
    assertEquals("equals1", validCaNameRfc2253, ca.getName());
    // sub testcase 2
    X500Principal x500p = new X500Principal(validCaNameRfc2253);
    ta = new TrustAnchor(x500p, pk, null);
    assertEquals("equals2", x500p, ta.getCA());
}
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 37 with X500Principal

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

the class X509CRLSelector2Test method testAddIssuerNameLjava_lang_String03.

/**
     * addIssuerName(String name) method testing. Tests if CRLs with specified
     * issuers match the selector, and if not specified issuer does not match
     * the selector.
     */
public void testAddIssuerNameLjava_lang_String03() {
    X509CRLSelector selector = new X509CRLSelector();
    String iss1 = "O=First Org.";
    String iss2 = "O=Second Org.";
    TestCRL crl1 = new TestCRL(new X500Principal(iss1));
    TestCRL crl2 = new TestCRL(new X500Principal(iss2));
    try {
        selector.addIssuerName(iss1);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected IOException was thrown.");
    }
    assertTrue("The CRL should match the selection criteria.", selector.match(crl1));
    assertFalse("The CRL should not match the selection criteria.", selector.match(crl2));
    try {
        selector.addIssuerName(iss2);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected IOException was thrown.");
    }
    assertTrue("The CRL should match the selection criteria.", selector.match(crl2));
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) ASN1OctetString(org.apache.harmony.security.asn1.ASN1OctetString) IOException(java.io.IOException) X509CRLSelector(java.security.cert.X509CRLSelector)

Example 38 with X500Principal

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

the class X509CRLSelector2Test method testAddIssuerName$B.

/**
     * addIssuerName(byte[] name) method testing. Tests if CRLs with specified
     * issuers match the selector, and if not specified issuer does not match
     * the selector.
     */
public void testAddIssuerName$B() {
    X509CRLSelector selector = new X509CRLSelector();
    byte[] iss1 = 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[] iss2 = 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 };
    TestCRL crl1 = new TestCRL(new X500Principal(iss1));
    TestCRL crl2 = new TestCRL(new X500Principal(iss2));
    try {
        selector.addIssuerName(iss1);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected IOException was thrown.");
    }
    assertTrue("The CRL should match the selection criteria.", selector.match(crl1));
    assertFalse("The CRL should not match the selection criteria.", selector.match(crl2));
    try {
        selector.addIssuerName(iss2);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected IOException was thrown.");
    }
    assertTrue("The CRL should match the selection criteria.", selector.match(crl2));
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) IOException(java.io.IOException) X509CRLSelector(java.security.cert.X509CRLSelector)

Example 39 with X500Principal

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

the class X509CRLSelector2Test method testClone.

/**
     * clone() method testing. Tests if the selector is cloned correctly: the
     * crl which matche to the initial selector should match to the clone and
     * the change of clone should not cause the change of initial selector.
     */
@AndroidOnly("Uses specific classes: " + "org.apache.harmony.security.asn1.ASN1OctetString, " + "org.apache.harmony.security.asn1.ASN1Integer.")
public void testClone() {
    X509CRLSelector selector = new X509CRLSelector();
    X500Principal iss1 = new X500Principal("O=First Org.");
    X500Principal iss2 = new X500Principal("O=Second Org.");
    X500Principal iss3 = new X500Principal("O=Third Org.");
    BigInteger minCRL = new BigInteger("10000");
    BigInteger maxCRL = new BigInteger("10000");
    Date date = new Date(200);
    selector.addIssuer(iss1);
    selector.addIssuer(iss2);
    selector.setMinCRLNumber(minCRL);
    selector.setMaxCRLNumber(maxCRL);
    selector.setDateAndTime(date);
    X509CRLSelector clone = (X509CRLSelector) selector.clone();
    TestCRL crl = new TestCRL(iss1);
    crl.setCrlNumber(minCRL);
    crl.setUpdateDates(new Date(200), new Date(200));
    assertTrue("The specified CRL should match the clone selector.", selector.match(crl));
    clone.addIssuer(iss3);
    assertFalse("The changes of the clone selector should not cause " + "the changes of initial object", selector.getIssuerNames().size() == 3);
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) BigInteger(java.math.BigInteger) X509CRLSelector(java.security.cert.X509CRLSelector) Date(java.util.Date) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 40 with X500Principal

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

the class X509CRLTest method testGetIssuerX500Principal.

/**
     * java.security.cert.X509CRL#getIssuerX500Principal()
     */
public void testGetIssuerX500Principal() {
    // return valid encoding
    TBTCRL crl = new TBTCRL() {

        public byte[] getEncoded() {
            return TestUtils.getX509CRL_v1();
        }
    };
    assertEquals(new X500Principal("CN=Z"), crl.getIssuerX500Principal());
}
Also used : X500Principal(javax.security.auth.x500.X500Principal)

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