Merge "Expose findByIssuerAndSignature"
am: b27d820920
* commit 'b27d8209206e0aad76a257636417341c6f69fbb5':
Expose findByIssuerAndSignature
This commit is contained in:
@@ -23,4 +23,5 @@ import java.security.cert.X509Certificate;
|
|||||||
public interface CertificateSource {
|
public interface CertificateSource {
|
||||||
Set<X509Certificate> getCertificates();
|
Set<X509Certificate> getCertificates();
|
||||||
X509Certificate findBySubjectAndPublicKey(X509Certificate cert);
|
X509Certificate findBySubjectAndPublicKey(X509Certificate cert);
|
||||||
|
X509Certificate findByIssuerAndSignature(X509Certificate cert);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,4 +51,13 @@ public final class CertificatesEntryRef {
|
|||||||
|
|
||||||
return new TrustAnchor(foundCert, mOverridesPins);
|
return new TrustAnchor(foundCert, mOverridesPins);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TrustAnchor findByIssuerAndSignature(X509Certificate cert) {
|
||||||
|
X509Certificate foundCert = mSource.findByIssuerAndSignature(cert);
|
||||||
|
if (foundCert == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TrustAnchor(foundCert, mOverridesPins);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,6 +94,21 @@ abstract class DirectoryCertificateSource implements CertificateSource {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public X509Certificate findByIssuerAndSignature(final X509Certificate cert) {
|
||||||
|
return findCert(cert.getIssuerX500Principal(), new CertSelector() {
|
||||||
|
@Override
|
||||||
|
public boolean match(X509Certificate ca) {
|
||||||
|
try {
|
||||||
|
cert.verify(ca.getPublicKey());
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private static interface CertSelector {
|
private static interface CertSelector {
|
||||||
boolean match(X509Certificate cert);
|
boolean match(X509Certificate cert);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,4 +80,14 @@ class KeyStoreCertificateSource implements CertificateSource {
|
|||||||
}
|
}
|
||||||
return anchor.getTrustedCert();
|
return anchor.getTrustedCert();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public X509Certificate findByIssuerAndSignature(X509Certificate cert) {
|
||||||
|
ensureInitialized();
|
||||||
|
java.security.cert.TrustAnchor anchor = mIndex.findByIssuerAndSignature(cert);
|
||||||
|
if (anchor == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return anchor.getTrustedCert();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,6 +134,17 @@ public final class NetworkSecurityConfig {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
|
public TrustAnchor findTrustAnchorByIssuerAndSignature(X509Certificate cert) {
|
||||||
|
for (CertificatesEntryRef ref : mCertificatesEntryRefs) {
|
||||||
|
TrustAnchor anchor = ref.findByIssuerAndSignature(cert);
|
||||||
|
if (anchor != null) {
|
||||||
|
return anchor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a {@link Builder} for the default {@code NetworkSecurityConfig}.
|
* Return a {@link Builder} for the default {@code NetworkSecurityConfig}.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -90,4 +90,14 @@ public class ResourceCertificateSource implements CertificateSource {
|
|||||||
}
|
}
|
||||||
return anchor.getTrustedCert();
|
return anchor.getTrustedCert();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public X509Certificate findByIssuerAndSignature(X509Certificate cert) {
|
||||||
|
ensureInitialized();
|
||||||
|
java.security.cert.TrustAnchor anchor = mIndex.findByIssuerAndSignature(cert);
|
||||||
|
if (anchor == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return anchor.getTrustedCert();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,4 +44,12 @@ public class TestCertificateSource implements CertificateSource {
|
|||||||
}
|
}
|
||||||
return anchor.getTrustedCert();
|
return anchor.getTrustedCert();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public X509Certificate findByIssuerAndSignature(X509Certificate cert) {
|
||||||
|
java.security.cert.TrustAnchor anchor = mIndex.findByIssuerAndSignature(cert);
|
||||||
|
if (anchor == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return anchor.getTrustedCert();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user