Search in sources :

Example 1 with CertificateChainCleaner

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

the class CertificateChainCleanerTest method normalizeUnknownSelfSignedCertificate.

@Test
public void normalizeUnknownSelfSignedCertificate() throws Exception {
    HeldCertificate root = new HeldCertificate.Builder().serialNumber("1").build();
    CertificateChainCleaner cleaner = CertificateChainCleaner.get();
    try {
        cleaner.clean(list(root), "hostname");
        fail();
    } catch (SSLPeerUnverifiedException expected) {
    }
}
Also used : SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) HeldCertificate(okhttp3.internal.tls.HeldCertificate) CertificateChainCleaner(okhttp3.internal.tls.CertificateChainCleaner) Test(org.junit.Test)

Example 2 with CertificateChainCleaner

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

the class CertificateChainCleanerTest method normalizeSingleSelfSignedCertificate.

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

Example 3 with CertificateChainCleaner

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

the class CertificateChainCleanerTest method orderedChainOfCertificatesWithRoot.

@Test
public void orderedChainOfCertificatesWithRoot() 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), cleaner.clean(list(certB, certA, root), "hostname"));
}
Also used : HeldCertificate(okhttp3.internal.tls.HeldCertificate) CertificateChainCleaner(okhttp3.internal.tls.CertificateChainCleaner) Test(org.junit.Test)

Example 4 with CertificateChainCleaner

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

the class CertificateChainCleanerTest method chainTooLong.

@Test
public void chainTooLong() throws Exception {
    List<HeldCertificate> heldCertificates = chainOfLength(11);
    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);
    try {
        cleaner.clean(certificates, "hostname");
        fail();
    } catch (SSLPeerUnverifiedException expected) {
    }
}
Also used : SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) 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 5 with CertificateChainCleaner

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

the class CertificateChainCleanerTest method chainGoesAllTheWayToSelfSignedRoot.

@Test
public void chainGoesAllTheWayToSelfSignedRoot() throws Exception {
    HeldCertificate selfSigned = new HeldCertificate.Builder().serialNumber("1").build();
    HeldCertificate trusted = new HeldCertificate.Builder().serialNumber("2").issuedBy(selfSigned).build();
    HeldCertificate certA = new HeldCertificate.Builder().serialNumber("3").issuedBy(trusted).build();
    HeldCertificate certB = new HeldCertificate.Builder().serialNumber("4").issuedBy(certA).build();
    CertificateChainCleaner cleaner = CertificateChainCleaner.get(selfSigned.certificate, trusted.certificate);
    assertEquals(list(certB, certA, trusted, selfSigned), cleaner.clean(list(certB, certA), "hostname"));
    assertEquals(list(certB, certA, trusted, selfSigned), cleaner.clean(list(certB, certA, trusted), "hostname"));
    assertEquals(list(certB, certA, trusted, selfSigned), cleaner.clean(list(certB, certA, trusted, selfSigned), "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