Search in sources :

Example 76 with X509CertSelector

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

the class X509CertSelectorTest method test_setSubjectKeyIdentifierLB$.

/**
     * java.security.cert.X509CertSelector#setSubjectKeyIdentifier(byte[])
     */
public void test_setSubjectKeyIdentifierLB$() throws Exception {
    // random value
    byte[] skid1 = new byte[] { 1, 2, 3, 4, 5 };
    // random value
    byte[] skid2 = new byte[] { 5, 4, 3, 2, 1 };
    TestCert cert1 = new TestCert(skid1);
    TestCert cert2 = new TestCert(skid2);
    X509CertSelector selector = new X509CertSelector();
    selector.setSubjectKeyIdentifier(null);
    assertTrue("Any certificate should match in the case of null " + "serialNumber criteria.", selector.match(cert1) && selector.match(cert2));
    selector.setSubjectKeyIdentifier(skid1);
    assertTrue("The certificate should match the selection criteria.", selector.match(cert1));
    assertFalse("The certificate should not match the selection criteria.", selector.match(cert2));
    selector.setSubjectKeyIdentifier(skid2);
    skid2[0]++;
    assertTrue("The certificate should match the selection criteria.", selector.match(cert2));
}
Also used : X509CertSelector(java.security.cert.X509CertSelector)

Example 77 with X509CertSelector

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

the class X509CertSelectorTest method test_addPathToNameLintLbyte_array.

/**
     * java.security.cert.X509CertSelector#addPathToName(int, byte[])
     */
public void test_addPathToNameLintLbyte_array() throws IOException {
    // Regression for HARMONY-2487
    int[] types = { GeneralName.OTHER_NAME, GeneralName.RFC822_NAME, GeneralName.DNS_NAME, GeneralName.X400_ADDR, GeneralName.DIR_NAME, GeneralName.EDIP_NAME, GeneralName.UR_ID, GeneralName.IP_ADDR, GeneralName.REG_ID };
    for (int i = 0; i < types.length; i++) {
        try {
            new X509CertSelector().addPathToName(types[i], (byte[]) null);
            fail("No expected NullPointerException for type: " + types[i]);
        } catch (NullPointerException expected) {
        }
    }
}
Also used : X509CertSelector(java.security.cert.X509CertSelector)

Example 78 with X509CertSelector

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

the class X509CertSelectorTest method test_setPrivateKeyValidLjava_util_Date.

/**
     * java.security.cert.X509CertSelector#setPrivateKeyValid(java.util.Date)
     */
public void test_setPrivateKeyValidLjava_util_Date() throws Exception {
    Date date1 = new Date(100000000);
    Date date2 = new Date(200000000);
    Date date3 = new Date(300000000);
    Date date4 = new Date(150000000);
    Date date5 = new Date(250000000);
    TestCert cert1 = new TestCert(date1, date2);
    TestCert cert2 = new TestCert(date2, date3);
    X509CertSelector selector = new X509CertSelector();
    selector.setPrivateKeyValid(null);
    assertTrue("Any certificate should match in the case of null " + "privateKeyValid criteria.", selector.match(cert1) && selector.match(cert2));
    selector.setPrivateKeyValid(date4);
    assertTrue("The certificate should match the selection criteria.", selector.match(cert1));
    assertFalse("The certificate should not match the selection criteria.", selector.match(cert2));
    selector.setPrivateKeyValid(date5);
    date5.setTime(date4.getTime());
    assertTrue("The certificate should match the selection criteria.", selector.match(cert2));
}
Also used : X509CertSelector(java.security.cert.X509CertSelector) Date(java.util.Date)

Example 79 with X509CertSelector

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

the class X509CertSelectorTest method test_setKeyUsageZ.

/**
     * java.security.cert.X509CertSelector#setKeyUsage(boolean)
     */
public void test_setKeyUsageZ() throws Exception {
    boolean[] ku1 = new boolean[] { true, true, true, true, true, true, true, true, true };
    // decipherOnly is disallowed
    boolean[] ku2 = new boolean[] { true, true, true, true, true, true, true, true, false };
    TestCert cert1 = new TestCert(ku1);
    TestCert cert2 = new TestCert(ku2);
    TestCert cert3 = new TestCert((boolean[]) null);
    X509CertSelector selector = new X509CertSelector();
    selector.setKeyUsage(null);
    assertTrue("Any certificate should match in the case of null keyUsage criteria.", selector.match(cert1) && selector.match(cert2));
    selector.setKeyUsage(ku1);
    assertTrue("The certificate should match the selection criteria.", selector.match(cert1));
    assertFalse("The certificate should not match the selection criteria.", selector.match(cert2));
    assertTrue("The certificate which does not have a keyUsage extension " + "implicitly allows all keyUsage values.", selector.match(cert3));
    selector.setKeyUsage(ku2);
    ku2[0] = !ku2[0];
    assertTrue("The certificate should match the selection criteria.", selector.match(cert2));
}
Also used : X509CertSelector(java.security.cert.X509CertSelector)

Example 80 with X509CertSelector

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

the class X509CertSelectorTest method test_addSubjectAlternativeNameLintLjava_lang_String.

/**
     * java.security.cert.X509CertSelector#addSubjectAlternativeName(int, String)
     */
public void test_addSubjectAlternativeNameLintLjava_lang_String() {
    // Regression for HARMONY-727
    int[] types = { GeneralName.OTHER_NAME, // GeneralName.RFC822_NAME,
    GeneralName.DNS_NAME, GeneralName.X400_ADDR, GeneralName.DIR_NAME, GeneralName.EDIP_NAME, GeneralName.UR_ID, GeneralName.IP_ADDR, GeneralName.REG_ID };
    for (int i = 0; i < types.length; i++) {
        try {
            new X509CertSelector().addSubjectAlternativeName(types[i], "-0xDFRF");
            fail("IOException expected for type: " + types[i]);
        } catch (IOException expected) {
        }
    }
}
Also used : X509CertSelector(java.security.cert.X509CertSelector) IOException(java.io.IOException)

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