Search in sources :

Example 41 with X500Principal

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

the class X509CertSelectorTest method test_setIssuerLjavax_security_auth_x500_X500Principal.

/**
     * java.security.cert.X509CertSelector#setIssuer(javax.security.auth.x500.X500Principal)
     */
public void test_setIssuerLjavax_security_auth_x500_X500Principal() throws Exception {
    X500Principal iss1 = new X500Principal("O=First Org.");
    X500Principal iss2 = new X500Principal("O=Second Org.");
    TestCert cert1 = new TestCert(iss1);
    TestCert cert2 = new TestCert(iss2);
    X509CertSelector selector = new X509CertSelector();
    selector.setIssuer((X500Principal) null);
    assertTrue("Any certificates should match " + "in the case of null issuer criteria.", selector.match(cert1) && selector.match(cert2));
    selector.setIssuer(iss1);
    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(iss2);
    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 42 with X500Principal

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

the class X509CertSelectorTest method test_setSubjectLjavax_security_auth_x500_X500Principal.

/**
     * java.security.cert.X509CertSelector#setSubject(javax.security.auth.x500.X500Principal)
     */
public void test_setSubjectLjavax_security_auth_x500_X500Principal() throws Exception {
    X500Principal sub1 = new X500Principal("O=First Org.");
    X500Principal sub2 = new X500Principal("O=Second Org.");
    TestCert cert1 = new TestCert(sub1);
    TestCert cert2 = new TestCert(sub2);
    X509CertSelector selector = new X509CertSelector();
    selector.setSubject((X500Principal) null);
    assertTrue("Any certificates should match " + "in the case of null subjcet criteria.", selector.match(cert1) && selector.match(cert2));
    selector.setSubject(sub1);
    assertTrue("The certificate should match the selection criteria.", selector.match(cert1));
    assertFalse("The certificate should not match the selection criteria.", selector.match(cert2));
    selector.setSubject(sub2);
    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 43 with X500Principal

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

the class X509CertSelectorTest method test_getIssuerAsString.

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

Example 44 with X500Principal

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

the class X509CRLSelector method addIssuer.

/**
     * Adds an issuer to the criterion for the issuer distinguished names.
     * <p>
     * The CRL issuer must match at least one of the specified distinguished
     * names.
     *
     * @param issuer
     *            the issuer to add to the criterion
     */
public void addIssuer(X500Principal issuer) {
    if (issuer == null) {
        throw new NullPointerException("issuer == null");
    }
    if (issuerNames == null) {
        issuerNames = new ArrayList<String>();
    }
    String name = issuer.getName(X500Principal.CANONICAL);
    if (!issuerNames.contains(name)) {
        issuerNames.add(name);
    }
    if (issuerPrincipals == null) {
        issuerPrincipals = new ArrayList<X500Principal>(issuerNames.size());
    }
    // extend the list of issuer Principals
    int size = issuerNames.size() - 1;
    for (int i = issuerPrincipals.size(); i < size; i++) {
        issuerPrincipals.add(new X500Principal(issuerNames.get(i)));
    }
    issuerPrincipals.add(issuer);
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) ASN1OctetString(org.apache.harmony.security.asn1.ASN1OctetString)

Example 45 with X500Principal

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

the class X509CertSelector method setIssuer.

/**
     * Sets the issuer that a certificate must match.
     *
     * @param issuerDN
     *            the distinguished issuer name in ASN.1 DER encoded format, or
     *            {@code null} to not check the issuer.
     * @throws IOException
     *             if decoding the issuer fail.
     */
public void setIssuer(byte[] issuerDN) throws IOException {
    if (issuerDN == null) {
        issuer = null;
        return;
    }
    try {
        issuer = new X500Principal(issuerDN);
        this.issuerName = null;
        this.issuerBytes = new byte[issuerDN.length];
        System.arraycopy(issuerDN, 0, this.issuerBytes, 0, issuerDN.length);
    } catch (IllegalArgumentException e) {
        throw new IOException(e.getMessage());
    }
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) IOException(java.io.IOException)

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