Search in sources :

Example 31 with X509CertSelector

use of java.security.cert.X509CertSelector 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 32 with X509CertSelector

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

the class X509CertSelectorTest method test_getPrivateKeyValid.

/**
     * java.security.cert.X509CertSelector#getPrivateKeyValid()
     */
public void test_getPrivateKeyValid() {
    Date date1 = new Date(100);
    Date date2 = new Date(200);
    X509CertSelector selector = new X509CertSelector();
    assertNull("Selector should return null", selector.getPrivateKeyValid());
    selector.setPrivateKeyValid(date1);
    assertTrue("The returned date should be equal to specified", date1.equals(selector.getPrivateKeyValid()));
    selector.getPrivateKeyValid().setTime(200);
    assertTrue("The returned date should be equal to specified", date1.equals(selector.getPrivateKeyValid()));
    assertFalse("The returned date should differ", date2.equals(selector.getPrivateKeyValid()));
}
Also used : X509CertSelector(java.security.cert.X509CertSelector) Date(java.util.Date)

Example 33 with X509CertSelector

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

the class X509CertSelectorTest method test_getBasicConstraints.

/**
     * java.security.cert.X509CertSelector#getBasicConstraints()
     */
public void test_getBasicConstraints() {
    X509CertSelector selector = new X509CertSelector();
    int[] validValues = { 2, 1, 0, 1, 2, 3, 10, 20 };
    for (int i = 0; i < validValues.length; i++) {
        selector.setBasicConstraints(validValues[i]);
        assertEquals(validValues[i], selector.getBasicConstraints());
    }
}
Also used : X509CertSelector(java.security.cert.X509CertSelector)

Example 34 with X509CertSelector

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

the class X509CertSelectorTest method test_getSubjectPublicKey.

/**
     * java.security.cert.X509CertSelector#getSubjectPublicKey()
     */
public void test_getSubjectPublicKey() 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());
    key = new MyPublicKey();
    selector.setSubjectPublicKey(key);
    PublicKey keyActual = selector.getSubjectPublicKey();
    assertEquals(key, keyActual);
    assertEquals(key.getAlgorithm(), keyActual.getAlgorithm());
}
Also used : PublicKey(java.security.PublicKey) X509CertSelector(java.security.cert.X509CertSelector)

Example 35 with X509CertSelector

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

the class X509CertSelectorTest method test_setCertificateLjava_security_cert_X509Certificate.

/**
     * java.security.cert.X509CertSelector#setCertificate(java.security.cert.Certificate)
     */
public void test_setCertificateLjava_security_cert_X509Certificate() throws Exception {
    TestCert cert1 = new TestCert("same certificate");
    TestCert cert2 = new TestCert("other certificate");
    X509CertSelector selector = new X509CertSelector();
    selector.setCertificate(null);
    assertTrue("Any certificates should match in the case of null " + "certificateEquals criteria.", selector.match(cert1) && selector.match(cert2));
    selector.setCertificate(cert1);
    assertTrue("The certificate should match the selection criteria.", selector.match(cert1));
    assertFalse("The certificate should not match the selection criteria.", selector.match(cert2));
    selector.setCertificate(cert2);
    assertTrue("The certificate should match the selection criteria.", selector.match(cert2));
    selector.setCertificate(null);
    assertNull(selector.getCertificate());
}
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