Search in sources :

Example 26 with X500Principal

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

the class X509CertSelectorTest method test_getSubjectAsBytes.

/**
     * java.security.cert.X509CertSelector#getSubjectAsBytes()
     */
public void test_getSubjectAsBytes() 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 sub1 = new X500Principal(name1);
    X500Principal sub2 = new X500Principal(name2);
    X509CertSelector selector = new X509CertSelector();
    assertNull("Selector should return null", selector.getSubjectAsBytes());
    selector.setSubject(sub1);
    assertTrue("The returned issuer should be equal to specified", Arrays.equals(name1, selector.getSubjectAsBytes()));
    assertFalse("The returned issuer should differ", name2.equals(selector.getSubjectAsBytes()));
    selector.setSubject(sub2);
    assertTrue("The returned issuer should be equal to specified", Arrays.equals(name2, selector.getSubjectAsBytes()));
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) X509CertSelector(java.security.cert.X509CertSelector)

Example 27 with X500Principal

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

the class X509Certificate2Test method testGetIssuerX500Principal.

public void testGetIssuerX500Principal() {
    // return valid encoding
    MyX509Certificate cert = new MyX509Certificate() {

        private static final long serialVersionUID = 638659908323741165L;

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

Example 28 with X500Principal

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

the class X509Certificate2Test method testGetSubjectX500Principal.

public void testGetSubjectX500Principal() {
    // return valid encoding
    MyX509Certificate cert = new MyX509Certificate() {

        private static final long serialVersionUID = -3625913637413840694L;

        public byte[] getEncoded() {
            return TestUtils.getX509Certificate_v1();
        }
    };
    assertEquals(new X500Principal("CN=Y"), cert.getSubjectX500Principal());
}
Also used : X500Principal(javax.security.auth.x500.X500Principal)

Example 29 with X500Principal

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

the class TrustAnchorTest method testGetTrustedCer02.

/**
     * Test #2 for <code>getCAName()</code> method<br>
     *
     * Assertion: returns ... <code>null</code> if <code>TrustAnchor</code>
     * was not specified as trusted certificate<br>
     * Test preconditions: test object is not specified as trusted certificate<br>
     * Expected: <code>null</code> as return value<br>
     * @throws InvalidKeySpecException
     */
public final void testGetTrustedCer02() throws Exception {
    PublicKey pk = new TestKeyPair(keyAlg).getPublic();
    // sub testcase 1
    TrustAnchor ta = new TrustAnchor(validCaNameRfc2253, pk, null);
    assertNull("null1", ta.getTrustedCert());
    // sub testcase 2
    X500Principal x500p = new X500Principal(validCaNameRfc2253);
    ta = new TrustAnchor(x500p, pk, null);
    assertNull("null2", ta.getTrustedCert());
    X509Certificate cert = new TestCertUtils.TestX509Certificate(x500p, x500p);
    TrustAnchor ta2 = new TrustAnchor(cert, null);
    assertSame(cert, ta2.getTrustedCert());
}
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) X509Certificate(java.security.cert.X509Certificate)

Example 30 with X500Principal

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

the class TrustAnchorTest method testToString.

/**
     * Test #1 for <code>toString()</code> method<br>
     *
     * Assertion: returns a formatted string describing the TrustAnchor<br>
     * Test preconditions: valid parameters are passed to the constructors<br>
     * Expected: not null string<br>
     */
public final void testToString() throws Exception {
    PublicKey pk = new TestKeyPair(keyAlg).getPublic();
    TrustAnchor ta1 = new TrustAnchor(validCaNameRfc2253, pk, getFullEncoding());
    assertNotNull(ta1.toString());
    X500Principal x500p = new X500Principal(validCaNameRfc2253);
    TrustAnchor ta2 = new TrustAnchor(x500p, pk, getEncodingNoMinMax());
    assertNotNull(ta2.toString());
    CertificateFactory certFact = CertificateFactory.getInstance("X509");
    X509Certificate pemCert = (X509Certificate) certFact.generateCertificate(new ByteArrayInputStream(TestUtils.getX509Certificate_v3()));
    TrustAnchor ta3 = new TrustAnchor(pemCert, getEncodingPSOnly());
    assertNotNull(ta3.toString());
}
Also used : TestKeyPair(org.apache.harmony.security.tests.support.TestKeyPair) ByteArrayInputStream(java.io.ByteArrayInputStream) PublicKey(java.security.PublicKey) X500Principal(javax.security.auth.x500.X500Principal) TrustAnchor(java.security.cert.TrustAnchor) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate)

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