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"));
}
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"));
}
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"));
}
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"));
}
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"));
}
Aggregations