1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.security.net.config; 18 19 import java.io.File; 20 import java.security.cert.Certificate; 21 import java.security.cert.X509Certificate; 22 import java.util.Date; 23 import java.util.Set; 24 25 import com.android.org.conscrypt.TrustedCertificateStore; 26 27 /** @hide */ 28 public class TrustedCertificateStoreAdapter extends TrustedCertificateStore { 29 private final NetworkSecurityConfig mConfig; 30 TrustedCertificateStoreAdapter(NetworkSecurityConfig config)31 public TrustedCertificateStoreAdapter(NetworkSecurityConfig config) { 32 mConfig = config; 33 } 34 35 @Override findIssuer(X509Certificate cert)36 public X509Certificate findIssuer(X509Certificate cert) { 37 TrustAnchor anchor = mConfig.findTrustAnchorByIssuerAndSignature(cert); 38 if (anchor == null) { 39 return null; 40 } 41 return anchor.certificate; 42 } 43 44 @Override findAllIssuers(X509Certificate cert)45 public Set<X509Certificate> findAllIssuers(X509Certificate cert) { 46 return mConfig.findAllCertificatesByIssuerAndSignature(cert); 47 } 48 49 @Override getTrustAnchor(X509Certificate cert)50 public X509Certificate getTrustAnchor(X509Certificate cert) { 51 TrustAnchor anchor = mConfig.findTrustAnchorBySubjectAndPublicKey(cert); 52 if (anchor == null) { 53 return null; 54 } 55 return anchor.certificate; 56 } 57 58 @Override isUserAddedCertificate(X509Certificate cert)59 public boolean isUserAddedCertificate(X509Certificate cert) { 60 // isUserAddedCertificate is used only for pinning overrides, so use overridesPins here. 61 TrustAnchor anchor = mConfig.findTrustAnchorBySubjectAndPublicKey(cert); 62 if (anchor == null) { 63 return false; 64 } 65 return anchor.overridesPins; 66 } 67 68 @Override getCertificateFile(File dir, X509Certificate x)69 public File getCertificateFile(File dir, X509Certificate x) { 70 // getCertificateFile is only used for tests, do not support it here. 71 throw new UnsupportedOperationException(); 72 } 73 74 // The methods below are exposed in TrustedCertificateStore but not used by conscrypt, do not 75 // support them. 76 77 @Override getCertificate(String alias)78 public Certificate getCertificate(String alias) { 79 throw new UnsupportedOperationException(); 80 } 81 82 @Override getCertificate(String alias, boolean includeDeletedSystem)83 public Certificate getCertificate(String alias, boolean includeDeletedSystem) { 84 throw new UnsupportedOperationException(); 85 } 86 87 @Override getCreationDate(String alias)88 public Date getCreationDate(String alias) { 89 throw new UnsupportedOperationException(); 90 } 91 92 @Override aliases()93 public Set<String> aliases() { 94 throw new UnsupportedOperationException(); 95 } 96 97 @Override userAliases()98 public Set<String> userAliases() { 99 throw new UnsupportedOperationException(); 100 } 101 102 @Override allSystemAliases()103 public Set<String> allSystemAliases() { 104 throw new UnsupportedOperationException(); 105 } 106 107 @Override containsAlias(String alias)108 public boolean containsAlias(String alias) { 109 throw new UnsupportedOperationException(); 110 } 111 112 @Override getCertificateAlias(Certificate c)113 public String getCertificateAlias(Certificate c) { 114 throw new UnsupportedOperationException(); 115 } 116 117 @Override getCertificateAlias(Certificate c, boolean includeDeletedSystem)118 public String getCertificateAlias(Certificate c, boolean includeDeletedSystem) { 119 throw new UnsupportedOperationException(); 120 } 121 } 122