Search in sources :

Example 6 with CertificateChainCleaner

use of okhttp3.internal.tls.CertificateChainCleaner in project okhttp by square.

the class CertificateChainCleanerTest method unrelatedCertificatesAreOmitted.

@Test
public void unrelatedCertificatesAreOmitted() throws Exception {
    HeldCertificate root = new HeldCertificate.Builder().serialNumber("1").build();
    HeldCertificate certA = new HeldCertificate.Builder().serialNumber("2").issuedBy(root).build();
    HeldCertificate certB = new HeldCertificate.Builder().serialNumber("3").issuedBy(certA).build();
    HeldCertificate certUnnecessary = new HeldCertificate.Builder().serialNumber("4").build();
    CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate);
    assertEquals(list(certB, certA, root), cleaner.clean(list(certB, certUnnecessary, certA, root), "hostname"));
}
Also used : HeldCertificate(okhttp3.internal.tls.HeldCertificate) CertificateChainCleaner(okhttp3.internal.tls.CertificateChainCleaner) Test(org.junit.Test)

Example 7 with CertificateChainCleaner

use of okhttp3.internal.tls.CertificateChainCleaner in project okhttp by square.

the class CertificateChainCleanerTest method chainMaxLength.

@Test
public void chainMaxLength() throws Exception {
    List<HeldCertificate> heldCertificates = chainOfLength(10);
    List<Certificate> certificates = new ArrayList<>();
    for (HeldCertificate heldCertificate : heldCertificates) {
        certificates.add(heldCertificate.certificate);
    }
    X509Certificate root = heldCertificates.get(heldCertificates.size() - 1).certificate;
    CertificateChainCleaner cleaner = CertificateChainCleaner.get(root);
    assertEquals(certificates, cleaner.clean(certificates, "hostname"));
    assertEquals(certificates, cleaner.clean(certificates.subList(0, 9), "hostname"));
}
Also used : HeldCertificate(okhttp3.internal.tls.HeldCertificate) ArrayList(java.util.ArrayList) X509Certificate(java.security.cert.X509Certificate) CertificateChainCleaner(okhttp3.internal.tls.CertificateChainCleaner) X509Certificate(java.security.cert.X509Certificate) HeldCertificate(okhttp3.internal.tls.HeldCertificate) Certificate(java.security.cert.Certificate) Test(org.junit.Test)

Example 8 with CertificateChainCleaner

use of okhttp3.internal.tls.CertificateChainCleaner in project okhttp by square.

the class CertificateChainCleanerTest method orderedChainOfCertificatesWithoutRoot.

@Test
public void orderedChainOfCertificatesWithoutRoot() throws Exception {
    HeldCertificate root = new HeldCertificate.Builder().serialNumber("1").build();
    HeldCertificate certA = new HeldCertificate.Builder().serialNumber("2").issuedBy(root).build();
    HeldCertificate certB = new HeldCertificate.Builder().serialNumber("3").issuedBy(certA).build();
    CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate);
    assertEquals(list(certB, certA, root), // Root is added!
    cleaner.clean(list(certB, certA), "hostname"));
}
Also used : HeldCertificate(okhttp3.internal.tls.HeldCertificate) CertificateChainCleaner(okhttp3.internal.tls.CertificateChainCleaner) Test(org.junit.Test)

Example 9 with CertificateChainCleaner

use of okhttp3.internal.tls.CertificateChainCleaner in project okhttp by square.

the class CertificateChainCleanerTest method unorderedChainOfCertificatesWithRoot.

@Test
public void unorderedChainOfCertificatesWithRoot() throws Exception {
    HeldCertificate root = new HeldCertificate.Builder().serialNumber("1").build();
    HeldCertificate certA = new HeldCertificate.Builder().serialNumber("2").issuedBy(root).build();
    HeldCertificate certB = new HeldCertificate.Builder().serialNumber("3").issuedBy(certA).build();
    HeldCertificate certC = new HeldCertificate.Builder().serialNumber("4").issuedBy(certB).build();
    CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate);
    assertEquals(list(certC, certB, certA, root), cleaner.clean(list(certC, certA, root, certB), "hostname"));
}
Also used : HeldCertificate(okhttp3.internal.tls.HeldCertificate) CertificateChainCleaner(okhttp3.internal.tls.CertificateChainCleaner) Test(org.junit.Test)

Example 10 with CertificateChainCleaner

use of okhttp3.internal.tls.CertificateChainCleaner in project okhttp by square.

the class CertificateChainCleanerTest method trustedRootNotSelfSigned.

@Test
public void trustedRootNotSelfSigned() throws Exception {
    HeldCertificate unknownSigner = new HeldCertificate.Builder().serialNumber("1").build();
    HeldCertificate trusted = new HeldCertificate.Builder().issuedBy(unknownSigner).serialNumber("2").build();
    HeldCertificate intermediateCa = new HeldCertificate.Builder().issuedBy(trusted).serialNumber("3").build();
    HeldCertificate certificate = new HeldCertificate.Builder().issuedBy(intermediateCa).serialNumber("4").build();
    CertificateChainCleaner cleaner = CertificateChainCleaner.get(trusted.certificate);
    assertEquals(list(certificate, intermediateCa, trusted), cleaner.clean(list(certificate, intermediateCa), "hostname"));
    assertEquals(list(certificate, intermediateCa, trusted), cleaner.clean(list(certificate, intermediateCa, trusted), "hostname"));
}
Also used : HeldCertificate(okhttp3.internal.tls.HeldCertificate) CertificateChainCleaner(okhttp3.internal.tls.CertificateChainCleaner) Test(org.junit.Test)

Aggregations

CertificateChainCleaner (okhttp3.internal.tls.CertificateChainCleaner)11 HeldCertificate (okhttp3.internal.tls.HeldCertificate)11 Test (org.junit.Test)11 Certificate (java.security.cert.Certificate)2 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)2