| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.net; | 5 package org.chromium.net; |
| 6 | 6 |
| 7 import android.content.ActivityNotFoundException; | 7 import android.content.ActivityNotFoundException; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.security.KeyChain; | 10 import android.security.KeyChain; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 196 } |
| 197 | 197 |
| 198 /** | 198 /** |
| 199 * Validate the server's certificate chain is trusted. | 199 * Validate the server's certificate chain is trusted. |
| 200 * | 200 * |
| 201 * @param certChain The ASN.1 DER encoded bytes for certificates. | 201 * @param certChain The ASN.1 DER encoded bytes for certificates. |
| 202 * @param authType The key exchange algorithm name (e.g. RSA) | 202 * @param authType The key exchange algorithm name (e.g. RSA) |
| 203 * @return Android certificate verification result code. | 203 * @return Android certificate verification result code. |
| 204 */ | 204 */ |
| 205 @CalledByNative | 205 @CalledByNative |
| 206 public static int verifyServerCertificates(byte[][] certChain, String authTy
pe) { | 206 public static int verifyServerCertificates(Context context, byte[][] certCha
in, |
| 207 String authType) { |
| 207 try { | 208 try { |
| 208 return X509Util.verifyServerCertificates(certChain, authType); | 209 return X509Util.verifyServerCertificates(context, certChain, authTyp
e); |
| 209 } catch (KeyStoreException e) { | 210 } catch (KeyStoreException e) { |
| 210 return CertVerifyResultAndroid.VERIFY_FAILED; | 211 return CertVerifyResultAndroid.VERIFY_FAILED; |
| 211 } catch (NoSuchAlgorithmException e) { | 212 } catch (NoSuchAlgorithmException e) { |
| 212 return CertVerifyResultAndroid.VERIFY_FAILED; | 213 return CertVerifyResultAndroid.VERIFY_FAILED; |
| 213 } | 214 } |
| 214 } | 215 } |
| 215 | 216 |
| 216 /** | 217 /** |
| 217 * Adds a test root certificate to the local trust store. | 218 * Adds a test root certificate to the local trust store. |
| 218 * @param rootCert DER encoded bytes of the certificate. | 219 * @param rootCert DER encoded bytes of the certificate. |
| 219 */ | 220 */ |
| 220 @CalledByNativeUnchecked | 221 @CalledByNativeUnchecked |
| 221 public static void addTestRootCertificate(byte[] rootCert) throws Certificat
eException, | 222 public static void addTestRootCertificate(Context context, byte[] rootCert) |
| 222 KeyStoreException, NoSuchAlgorithmException { | 223 throws CertificateException, KeyStoreException, NoSuchAlgorithmExcep
tion { |
| 223 X509Util.addTestRootCertificate(rootCert); | 224 X509Util.addTestRootCertificate(context, rootCert); |
| 224 } | 225 } |
| 225 | 226 |
| 226 /** | 227 /** |
| 227 * Removes all test root certificates added by |addTestRootCertificate| call
s from the local | 228 * Removes all test root certificates added by |addTestRootCertificate| call
s from the local |
| 228 * trust store. | 229 * trust store. |
| 229 */ | 230 */ |
| 230 @CalledByNativeUnchecked | 231 @CalledByNativeUnchecked |
| 231 public static void clearTestRootCertificates() throws NoSuchAlgorithmExcepti
on, | 232 public static void clearTestRootCertificates(Context context) throws NoSuchA
lgorithmException, |
| 232 CertificateException, KeyStoreException { | 233 CertificateException, KeyStoreException { |
| 233 X509Util.clearTestRootCertificates(); | 234 X509Util.clearTestRootCertificates(context); |
| 234 } | 235 } |
| 235 } | 236 } |
| OLD | NEW |