Search in sources :

Example 36 with X509CertSelector

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

the class X509CertSelectorTest method test_getSubjectKeyIdentifier.

/**
     * java.security.cert.X509CertSelector#getSubjectKeyIdentifier()
     */
public void test_getSubjectKeyIdentifier() {
    // random value
    byte[] skid1 = new byte[] { 1, 2, 3, 4, 5 };
    // random value
    byte[] skid2 = new byte[] { 4, 5, 5, 4, 3, 2, 1 };
    X509CertSelector selector = new X509CertSelector();
    assertNull("Selector should return null", selector.getSubjectKeyIdentifier());
    selector.setSubjectKeyIdentifier(skid1);
    assertTrue("The returned keyID should be equal to specified", Arrays.equals(skid1, selector.getSubjectKeyIdentifier()));
    selector.getSubjectKeyIdentifier()[0]++;
    assertTrue("The returned keyID should be equal to specified", Arrays.equals(skid1, selector.getSubjectKeyIdentifier()));
    assertFalse("The returned keyID should differ", Arrays.equals(skid2, selector.getSubjectKeyIdentifier()));
}
Also used : X509CertSelector(java.security.cert.X509CertSelector)

Example 37 with X509CertSelector

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

the class X509CertSelectorTest method test_getSubjectPublicKeyAlgID.

/**
     * java.security.cert.X509CertSelector#getSubjectPublicKeyAlgID()
     */
public void test_getSubjectPublicKeyAlgID() throws Exception {
    X509CertSelector selector = new X509CertSelector();
    String[] validOIDs = { "0.0.20", "1.25.0", "2.0.39", "0.2.10", "1.35.15", "2.17.89" };
    assertNull("Selector should return null", selector.getSubjectPublicKeyAlgID());
    for (int i = 0; i < validOIDs.length; i++) {
        try {
            selector.setSubjectPublicKeyAlgID(validOIDs[i]);
            assertEquals(validOIDs[i], selector.getSubjectPublicKeyAlgID());
        } catch (IOException e) {
            System.out.println("t = " + e.getMessage());
        //fail("Unexpected exception " + e.getMessage());
        }
    }
    // RSA encryption
    String pkaid1 = "1.2.840.113549.1.1.1";
    // MD5 with RSA encryption
    String pkaid2 = "1.2.840.113549.1.1.4";
    selector.setSubjectPublicKeyAlgID(pkaid1);
    assertTrue("The returned oid should be equal to specified", pkaid1.equals(selector.getSubjectPublicKeyAlgID()));
    assertFalse("The returned oid should differ", pkaid2.equals(selector.getSubjectPublicKeyAlgID()));
}
Also used : X509CertSelector(java.security.cert.X509CertSelector) ASN1OctetString(org.apache.harmony.security.asn1.ASN1OctetString) IOException(java.io.IOException)

Example 38 with X509CertSelector

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

the class X509CertSelectorTest method test_setSubjectPublicKeyLB$.

/**
     * java.security.cert.X509CertSelector#setSubjectPublicKey(byte[])
     */
public void test_setSubjectPublicKeyLB$() throws Exception {
    //SubjectPublicKeyInfo  ::=  SEQUENCE  {
    //    algorithm            AlgorithmIdentifier,
    //    subjectPublicKey     BIT STRING  }
    byte[] enc = { // SEQUENCE
    0x30, // SEQUENCE
    0x0E, // SEQUENCE
    0x30, // SEQUENCE
    0x07, //OID
    0x06, //OID
    0x02, //OID
    0x03, //OID
    0x05, //ANY
    0x01, //ANY
    0x01, //ANY
    0x07, // subjectPublicKey
    0x03, // subjectPublicKey
    0x03, // subjectPublicKey
    0x01, // subjectPublicKey
    0x01, // subjectPublicKey
    0x06 };
    X509CertSelector selector = new X509CertSelector();
    selector.setSubjectPublicKey(enc);
    PublicKey key = selector.getSubjectPublicKey();
    assertEquals("0.3.5", key.getAlgorithm());
    assertEquals("X.509", key.getFormat());
    assertTrue(Arrays.equals(enc, key.getEncoded()));
    assertNotNull(key.toString());
}
Also used : PublicKey(java.security.PublicKey) X509CertSelector(java.security.cert.X509CertSelector)

Example 39 with X509CertSelector

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

the class X509CertSelectorTest method test_setExtendedKeyUsageLjava_util_Set.

/**
     * java.security.cert.X509CertSelector#setExtendedKeyUsage(Set<String>)
     */
public void test_setExtendedKeyUsageLjava_util_Set() throws Exception {
    HashSet<String> ku1 = new HashSet<String>(Arrays.asList(new String[] { "1.3.6.1.5.5.7.3.1", "1.3.6.1.5.5.7.3.2", "1.3.6.1.5.5.7.3.3", "1.3.6.1.5.5.7.3.4", "1.3.6.1.5.5.7.3.8", "1.3.6.1.5.5.7.3.9", "1.3.6.1.5.5.7.3.5", "1.3.6.1.5.5.7.3.6", "1.3.6.1.5.5.7.3.7" }));
    HashSet<String> ku2 = new HashSet<String>(Arrays.asList(new String[] { "1.3.6.1.5.5.7.3.1", "1.3.6.1.5.5.7.3.2", "1.3.6.1.5.5.7.3.3", "1.3.6.1.5.5.7.3.4", "1.3.6.1.5.5.7.3.8", "1.3.6.1.5.5.7.3.9", "1.3.6.1.5.5.7.3.5", "1.3.6.1.5.5.7.3.6" }));
    TestCert cert1 = new TestCert(ku1);
    TestCert cert2 = new TestCert(ku2);
    X509CertSelector selector = new X509CertSelector();
    selector.setExtendedKeyUsage(null);
    assertTrue("Any certificate should match in the case of null " + "extendedKeyUsage criteria.", selector.match(cert1) && selector.match(cert2));
    selector.setExtendedKeyUsage(ku1);
    assertEquals(ku1, selector.getExtendedKeyUsage());
    selector.setExtendedKeyUsage(ku2);
    assertEquals(ku2, selector.getExtendedKeyUsage());
}
Also used : X509CertSelector(java.security.cert.X509CertSelector) ASN1OctetString(org.apache.harmony.security.asn1.ASN1OctetString) HashSet(java.util.HashSet)

Example 40 with X509CertSelector

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

the class X509CertSelectorTest method test_clone.

/**
     * java.security.cert.X509CertSelector#clone()
     */
public void test_clone() throws Exception {
    X509CertSelector selector = new X509CertSelector();
    X509CertSelector selector1 = (X509CertSelector) selector.clone();
    assertEquals(selector.getMatchAllSubjectAltNames(), selector1.getMatchAllSubjectAltNames());
    assertEquals(selector.getAuthorityKeyIdentifier(), selector1.getAuthorityKeyIdentifier());
    assertEquals(selector.getBasicConstraints(), selector1.getBasicConstraints());
    assertEquals(selector.getCertificate(), selector1.getCertificate());
    assertEquals(selector.getCertificateValid(), selector1.getCertificateValid());
    assertEquals(selector.getExtendedKeyUsage(), selector1.getExtendedKeyUsage());
    assertEquals(selector.getIssuer(), selector1.getIssuer());
    assertEquals(selector.getIssuerAsBytes(), selector1.getIssuerAsBytes());
    assertEquals(selector.getIssuerAsString(), selector1.getIssuerAsString());
    assertEquals(selector.getKeyUsage(), selector1.getKeyUsage());
    assertEquals(selector.getNameConstraints(), selector1.getNameConstraints());
    assertEquals(selector.getPathToNames(), selector1.getPathToNames());
    assertEquals(selector.getPolicy(), selector1.getPolicy());
    assertEquals(selector.getPrivateKeyValid(), selector1.getPrivateKeyValid());
    assertEquals(selector.getSerialNumber(), selector1.getSerialNumber());
    assertEquals(selector.getSubject(), selector1.getSubject());
    assertEquals(selector.getSubjectAlternativeNames(), selector1.getSubjectAlternativeNames());
    assertEquals(selector.getSubjectAsBytes(), selector1.getSubjectAsBytes());
    assertEquals(selector.getSubjectAsString(), selector1.getSubjectAsString());
    assertEquals(selector.getSubjectKeyIdentifier(), selector1.getSubjectKeyIdentifier());
    assertEquals(selector.getSubjectPublicKey(), selector1.getSubjectPublicKey());
    assertEquals(selector.getSubjectPublicKeyAlgID(), selector1.getSubjectPublicKeyAlgID());
    selector = null;
    try {
        selector.clone();
        fail();
    } catch (NullPointerException expected) {
    }
}
Also used : X509CertSelector(java.security.cert.X509CertSelector)

Aggregations

X509CertSelector (java.security.cert.X509CertSelector)151 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)54 X509Certificate (java.security.cert.X509Certificate)41 CollectionCertStoreParameters (java.security.cert.CollectionCertStoreParameters)33 IOException (java.io.IOException)23 CertPathBuilder (java.security.cert.CertPathBuilder)22 HashSet (java.util.HashSet)22 TrustAnchor (java.security.cert.TrustAnchor)20 X500Principal (javax.security.auth.x500.X500Principal)20 KeyStore (java.security.KeyStore)18 ArrayList (java.util.ArrayList)18 CertStore (java.security.cert.CertStore)17 CertPathTrustManagerParameters (javax.net.ssl.CertPathTrustManagerParameters)15 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)13 CertificateException (java.security.cert.CertificateException)11 CertificateFactory (java.security.cert.CertificateFactory)11 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 Date (java.util.Date)10