Search in sources :

Example 86 with X509CertSelector

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

the class X509CertSelectorTest method test_addSubjectAlternativeNameLintLjava_lang_String2.

/**
     * java.security.cert.X509CertSelector#addSubjectAlternativeName(int, String)
     */
public void test_addSubjectAlternativeNameLintLjava_lang_String2() throws Exception {
    GeneralName san6 = new GeneralName(6, "http://uniform.Resource.Id");
    GeneralName san2 = new GeneralName(2, "dNSName");
    GeneralNames sans1 = new GeneralNames();
    sans1.addName(san6);
    sans1.addName(san2);
    X509CertSelector selector = new X509CertSelector();
    selector.addSubjectAlternativeName(6, "http://uniform.Resource.Id");
    selector.addSubjectAlternativeName(2, "dNSName");
    GeneralNames sans2 = new GeneralNames();
    sans2.addName(san2);
    TestCert cert1 = new TestCert(sans1);
    TestCert cert2 = new TestCert(sans2);
    assertTrue(selector.match(cert1));
    assertFalse(selector.match(cert2));
    selector.setSubjectAlternativeNames(null);
    GeneralName name = new GeneralName(new Name("O=Android"));
    try {
        selector.addSubjectAlternativeName(0, (name.toString()));
    } catch (IOException e) {
    // ok
    }
}
Also used : GeneralNames(org.apache.harmony.security.x509.GeneralNames) X509CertSelector(java.security.cert.X509CertSelector) GeneralName(org.apache.harmony.security.x509.GeneralName) IOException(java.io.IOException) GeneralName(org.apache.harmony.security.x509.GeneralName) OtherName(org.apache.harmony.security.x509.OtherName) Name(org.apache.harmony.security.x501.Name)

Example 87 with X509CertSelector

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

the class X509CertSelectorTest method test_setPathToNamesLjava_util_Collection.

/**
     * java.security.cert.X509CertSelector#setPathToNames(Collection<List<?>>)
     */
public void test_setPathToNamesLjava_util_Collection() throws Exception {
    GeneralName san0 = new GeneralName(new OtherName("1.2.3.4.5", new byte[] { 1, 2, 0, 1 }));
    GeneralName san1 = new GeneralName(1, "rfc@822.Name");
    GeneralName san2 = new GeneralName(2, "dNSName");
    GeneralName san3 = new GeneralName(new ORAddress());
    GeneralName san4 = new GeneralName(new Name("O=Organization"));
    GeneralName san6 = new GeneralName(6, "http://uniform.Resource.Id");
    GeneralName san7 = new GeneralName(7, "1.1.1.1");
    GeneralName san8 = new GeneralName(8, "1.2.3.4444.55555");
    GeneralNames sans1 = new GeneralNames();
    sans1.addName(san0);
    sans1.addName(san1);
    sans1.addName(san2);
    sans1.addName(san3);
    sans1.addName(san4);
    sans1.addName(san6);
    sans1.addName(san7);
    sans1.addName(san8);
    GeneralNames sans2 = new GeneralNames();
    sans2.addName(san0);
    TestCert cert1 = new TestCert(sans1);
    TestCert cert2 = new TestCert(sans2);
    X509CertSelector selector = new X509CertSelector();
    selector.setMatchAllSubjectAltNames(true);
    selector.setPathToNames(null);
    assertTrue("Any certificate should match in the case of null " + "subjectAlternativeNames criteria.", selector.match(cert1) && selector.match(cert2));
    Collection<List<?>> sans = sans1.getPairsList();
    selector.setPathToNames(sans);
    selector.getPathToNames();
}
Also used : GeneralNames(org.apache.harmony.security.x509.GeneralNames) OtherName(org.apache.harmony.security.x509.OtherName) X509CertSelector(java.security.cert.X509CertSelector) List(java.util.List) ArrayList(java.util.ArrayList) GeneralName(org.apache.harmony.security.x509.GeneralName) ORAddress(org.apache.harmony.security.x509.ORAddress) GeneralName(org.apache.harmony.security.x509.GeneralName) OtherName(org.apache.harmony.security.x509.OtherName) Name(org.apache.harmony.security.x501.Name)

Example 88 with X509CertSelector

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

the class X509CertSelectorTest method test_setSerialNumberLjava_math_BigInteger.

/**
     * java.security.cert.X509CertSelector#setSerialNumber(java.math.BigInteger)
     */
public void test_setSerialNumberLjava_math_BigInteger() throws Exception {
    BigInteger ser1 = new BigInteger("10000");
    BigInteger ser2 = new BigInteger("10001");
    TestCert cert1 = new TestCert(ser1);
    TestCert cert2 = new TestCert(ser2);
    X509CertSelector selector = new X509CertSelector();
    selector.setSerialNumber(null);
    assertTrue("Any certificate should match in the case of null " + "serialNumber criteria.", selector.match(cert1) && selector.match(cert2));
    selector.setSerialNumber(ser1);
    assertTrue("The certificate should match the selection criteria.", selector.match(cert1));
    assertFalse("The certificate should not match the selection criteria.", selector.match(cert2));
    selector.setSerialNumber(ser2);
    assertTrue("The certificate should match the selection criteria.", selector.match(cert2));
}
Also used : BigInteger(java.math.BigInteger) X509CertSelector(java.security.cert.X509CertSelector)

Example 89 with X509CertSelector

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

the class X509CertSelectorTest method test_getIssuer.

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

Example 90 with X509CertSelector

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

the class X509CertSelectorTest method test_matchLjava_security_cert_Certificate.

/**
     * java.security.cert.X509CertSelector#match(java.security.cert.Certificate)
     */
public void test_matchLjava_security_cert_Certificate() throws Exception {
    X509CertSelector selector = new X509CertSelector();
    assertFalse(selector.match(null));
    CertificateFactory certFact = CertificateFactory.getInstance("X509");
    X509Certificate cert1 = (X509Certificate) certFact.generateCertificate(new ByteArrayInputStream(TestUtils.getX509Certificate_v3()));
    X509Certificate cert2 = (X509Certificate) certFact.generateCertificate(new ByteArrayInputStream(TestUtils.getX509Certificate_v1()));
    selector.setCertificate(cert1);
    assertTrue(selector.match(cert1));
    assertFalse(selector.match(cert2));
    selector.setCertificate(cert2);
    assertFalse(selector.match(cert1));
    assertTrue(selector.match(cert2));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) X509CertSelector(java.security.cert.X509CertSelector) 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