OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "mock_cert_verifier.h" | 5 #include "mock_cert_verifier.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
11 #include "base/android/jni_array.h" | 11 #include "base/android/jni_array.h" |
| 12 #include "base/android/jni_string.h" |
| 13 #include "base/test/test_support_android.h" |
12 #include "crypto/sha2.h" | 14 #include "crypto/sha2.h" |
13 #include "jni/MockCertVerifier_jni.h" | 15 #include "jni/MockCertVerifier_jni.h" |
14 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
15 #include "net/base/test_data_directory.h" | 17 #include "net/base/test_data_directory.h" |
16 #include "net/cert/asn1_util.h" | 18 #include "net/cert/asn1_util.h" |
17 #include "net/cert/cert_verifier.h" | 19 #include "net/cert/cert_verifier.h" |
18 #include "net/cert/cert_verify_result.h" | 20 #include "net/cert/cert_verify_result.h" |
19 #include "net/cert/mock_cert_verifier.h" | 21 #include "net/cert/mock_cert_verifier.h" |
20 #include "net/test/cert_test_util.h" | 22 #include "net/test/cert_test_util.h" |
21 | 23 |
(...skipping 20 matching lines...) Expand all Loading... |
42 } | 44 } |
43 // Calculate SHA256 hash of public key bytes. | 45 // Calculate SHA256 hash of public key bytes. |
44 out_hash_value->tag = net::HASH_VALUE_SHA256; | 46 out_hash_value->tag = net::HASH_VALUE_SHA256; |
45 crypto::SHA256HashString(spki_bytes, out_hash_value->data(), | 47 crypto::SHA256HashString(spki_bytes, out_hash_value->data(), |
46 crypto::kSHA256Length); | 48 crypto::kSHA256Length); |
47 return true; | 49 return true; |
48 } | 50 } |
49 | 51 |
50 } // namespace | 52 } // namespace |
51 | 53 |
52 static jlong CreateMockCertVerifier(JNIEnv* env, | 54 static jlong CreateMockCertVerifier( |
53 const JavaParamRef<jclass>& jcaller, | 55 JNIEnv* env, |
54 const JavaParamRef<jobjectArray>& jcerts) { | 56 const JavaParamRef<jclass>& jcaller, |
| 57 const JavaParamRef<jobjectArray>& jcerts, |
| 58 const JavaParamRef<jstring>& jtest_data_dir) { |
| 59 base::FilePath test_data_dir( |
| 60 base::android::ConvertJavaStringToUTF8(env, jtest_data_dir)); |
| 61 base::InitAndroidTestPaths(test_data_dir); |
| 62 |
55 std::vector<std::string> certs; | 63 std::vector<std::string> certs; |
56 base::android::AppendJavaStringArrayToStringVector(env, jcerts, &certs); | 64 base::android::AppendJavaStringArrayToStringVector(env, jcerts, &certs); |
57 net::MockCertVerifier* mock_cert_verifier = new net::MockCertVerifier(); | 65 net::MockCertVerifier* mock_cert_verifier = new net::MockCertVerifier(); |
58 for (auto cert : certs) { | 66 for (auto cert : certs) { |
59 net::CertVerifyResult verify_result; | 67 net::CertVerifyResult verify_result; |
60 verify_result.verified_cert = | 68 verify_result.verified_cert = |
61 net::ImportCertFromFile(net::GetTestCertsDirectory(), cert); | 69 net::ImportCertFromFile(net::GetTestCertsDirectory(), cert); |
62 | 70 |
63 // Let the cert be treated as a known root cert. | 71 // Let the cert be treated as a known root cert. |
64 // This will enable HPKP verification. | 72 // This will enable HPKP verification. |
(...skipping 10 matching lines...) Expand all Loading... |
75 } | 83 } |
76 | 84 |
77 return reinterpret_cast<jlong>(mock_cert_verifier); | 85 return reinterpret_cast<jlong>(mock_cert_verifier); |
78 } | 86 } |
79 | 87 |
80 bool RegisterMockCertVerifier(JNIEnv* env) { | 88 bool RegisterMockCertVerifier(JNIEnv* env) { |
81 return RegisterNativesImpl(env); | 89 return RegisterNativesImpl(env); |
82 } | 90 } |
83 | 91 |
84 } // namespace cronet | 92 } // namespace cronet |
OLD | NEW |