Search in sources :

Example 66 with X509CertSelector

use of java.security.cert.X509CertSelector in project robovm by robovm.

the class X509CertSelectorTest method testMatchIpv4SubjectAlternativeName.

public void testMatchIpv4SubjectAlternativeName() throws Exception {
    X509CertSelector certSelector = new X509CertSelector();
    certSelector.addSubjectAlternativeName(GeneralName.iPAddress, "127.0.0.1");
    byte[] match = { 127, 0, 0, 1 };
    assertTrue(certSelector.match(newCertWithSubjectAltNameIpAddress(match)));
    byte[] noMatch = { 127, 0, 0, 2 };
    assertFalse(certSelector.match(newCertWithSubjectAltNameIpAddress(noMatch)));
}
Also used : X509CertSelector(java.security.cert.X509CertSelector)

Example 67 with X509CertSelector

use of java.security.cert.X509CertSelector in project robovm by robovm.

the class X509CertSelectorTest method testMatchIpv4MappedSubjectAlternativeName.

public void testMatchIpv4MappedSubjectAlternativeName() throws Exception {
    X509CertSelector certSelector = new X509CertSelector();
    certSelector.addSubjectAlternativeName(GeneralName.iPAddress, "::ffff:127.0.0.1");
    byte[] match = { 127, 0, 0, 1 };
    assertTrue(certSelector.match(newCertWithSubjectAltNameIpAddress(match)));
    byte[] noMatch = { 127, 0, 0, 2 };
    assertFalse(certSelector.match(newCertWithSubjectAltNameIpAddress(noMatch)));
}
Also used : X509CertSelector(java.security.cert.X509CertSelector)

Example 68 with X509CertSelector

use of java.security.cert.X509CertSelector in project robovm by robovm.

the class X509CertSelectorTest method testMatchMalformedSubjectAlternativeName.

public void testMatchMalformedSubjectAlternativeName() throws Exception {
    X509CertSelector certSelector = new X509CertSelector();
    try {
        certSelector.addSubjectAlternativeName(GeneralName.iPAddress, "1::x");
        fail();
    } catch (IOException expected) {
    }
    try {
        certSelector.addSubjectAlternativeName(GeneralName.iPAddress, "127.0.0.x");
        fail();
    } catch (IOException expected) {
    }
}
Also used : X509CertSelector(java.security.cert.X509CertSelector) IOException(java.io.IOException)

Example 69 with X509CertSelector

use of java.security.cert.X509CertSelector in project robovm by robovm.

the class PKIXBuilderParametersTest method testPKIXBuilderParametersKeyStoreCertSelector01.

/**
     * Test #1 for <code>PKIXBuilderParameters(KeyStore, CertSelector)</code>
     * constructor<br>
     * Assertion: <code>NullPointerException</code> - if the
     * <code>keystore</code> is <code>null</code>
     */
public final void testPKIXBuilderParametersKeyStoreCertSelector01() throws Exception {
    try {
        new PKIXBuilderParameters((KeyStore) null, new X509CertSelector());
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : PKIXBuilderParameters(java.security.cert.PKIXBuilderParameters) X509CertSelector(java.security.cert.X509CertSelector)

Example 70 with X509CertSelector

use of java.security.cert.X509CertSelector in project robovm by robovm.

the class PKIXBuilderParametersTest method testSetMaxPathLength.

/**
     * Test for <code>setMaxPathLength()</code>
     */
public final void testSetMaxPathLength() throws Exception {
    KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
    keyTest.load(null, null);
    ByteArrayInputStream certArray = new ByteArrayInputStream(certificate.getBytes());
    ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2.getBytes());
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    X509Certificate[] cert = new X509Certificate[2];
    cert[0] = (X509Certificate) cf.generateCertificate(certArray);
    cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
    keyTest.setCertificateEntry("alias1", cert[0]);
    keyTest.setCertificateEntry("alias2", cert[0]);
    keyTest.setCertificateEntry("alias3", cert[1]);
    PKIXBuilderParameters p = new PKIXBuilderParameters(keyTest, new X509CertSelector());
    assertEquals(5, p.getMaxPathLength());
    p.setMaxPathLength(10);
    assertEquals(10, p.getMaxPathLength());
    p.setMaxPathLength(0);
    assertEquals(0, p.getMaxPathLength());
    p.setMaxPathLength(-1);
    assertEquals(-1, p.getMaxPathLength());
    int[] maxPathLength = { -2, -10, Integer.MIN_VALUE };
    for (int i = 0; i < maxPathLength.length; i++) {
        try {
            p.setMaxPathLength(maxPathLength[i]);
            fail("InvalidParameterException expected ");
        } catch (InvalidParameterException e) {
        // expected
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) ByteArrayInputStream(java.io.ByteArrayInputStream) PKIXBuilderParameters(java.security.cert.PKIXBuilderParameters) X509CertSelector(java.security.cert.X509CertSelector) KeyStore(java.security.KeyStore) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate)

Aggregations

X509CertSelector (java.security.cert.X509CertSelector)116 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)29 X509Certificate (java.security.cert.X509Certificate)23 IOException (java.io.IOException)18 CollectionCertStoreParameters (java.security.cert.CollectionCertStoreParameters)17 X500Principal (javax.security.auth.x500.X500Principal)16 ArrayList (java.util.ArrayList)14 TrustAnchor (java.security.cert.TrustAnchor)13 CertificateFactory (java.security.cert.CertificateFactory)11 HashSet (java.util.HashSet)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 KeyStore (java.security.KeyStore)10 CertPathBuilder (java.security.cert.CertPathBuilder)10 CertStore (java.security.cert.CertStore)10 PublicKey (java.security.PublicKey)9 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)8 CertificateException (java.security.cert.CertificateException)8 ASN1OctetString (org.apache.harmony.security.asn1.ASN1OctetString)8 BigInteger (java.math.BigInteger)7 Date (java.util.Date)7