Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: components/cronet/android/test/mock_cert_verifier.cc

Issue 2117763004: Revert of Enable public key pinning of local trust anchors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 crypto::kSHA256Length); 48 crypto::kSHA256Length);
49 return true; 49 return true;
50 } 50 }
51 51
52 } // namespace 52 } // namespace
53 53
54 static jlong CreateMockCertVerifier( 54 static jlong CreateMockCertVerifier(
55 JNIEnv* env, 55 JNIEnv* env,
56 const JavaParamRef<jclass>& jcaller, 56 const JavaParamRef<jclass>& jcaller,
57 const JavaParamRef<jobjectArray>& jcerts, 57 const JavaParamRef<jobjectArray>& jcerts,
58 const jboolean jknown_root,
59 const JavaParamRef<jstring>& jtest_data_dir) { 58 const JavaParamRef<jstring>& jtest_data_dir) {
60 base::FilePath test_data_dir( 59 base::FilePath test_data_dir(
61 base::android::ConvertJavaStringToUTF8(env, jtest_data_dir)); 60 base::android::ConvertJavaStringToUTF8(env, jtest_data_dir));
62 base::InitAndroidTestPaths(test_data_dir); 61 base::InitAndroidTestPaths(test_data_dir);
63 62
64 std::vector<std::string> certs; 63 std::vector<std::string> certs;
65 base::android::AppendJavaStringArrayToStringVector(env, jcerts, &certs); 64 base::android::AppendJavaStringArrayToStringVector(env, jcerts, &certs);
66 net::MockCertVerifier* mock_cert_verifier = new net::MockCertVerifier(); 65 net::MockCertVerifier* mock_cert_verifier = new net::MockCertVerifier();
67 for (const auto& cert : certs) { 66 for (auto cert : certs) {
68 net::CertVerifyResult verify_result; 67 net::CertVerifyResult verify_result;
69 verify_result.verified_cert = 68 verify_result.verified_cert =
70 net::ImportCertFromFile(net::GetTestCertsDirectory(), cert); 69 net::ImportCertFromFile(net::GetTestCertsDirectory(), cert);
71 70
72 // By default, HPKP verification is enabled for known trust roots only. 71 // Let the cert be treated as a known root cert.
73 verify_result.is_issued_by_known_root = jknown_root; 72 // This will enable HPKP verification.
73 verify_result.is_issued_by_known_root = true;
74 74
75 // Calculate the public key hash and add it to the verify_result. 75 // Calculate the public key hash and add it to the verify_result.
76 net::HashValue hashValue; 76 net::HashValue hashValue;
77 CHECK(CalculatePublicKeySha256(*verify_result.verified_cert.get(), 77 CHECK(CalculatePublicKeySha256(*verify_result.verified_cert.get(),
78 &hashValue)); 78 &hashValue));
79 verify_result.public_key_hashes.push_back(hashValue); 79 verify_result.public_key_hashes.push_back(hashValue);
80 80
81 mock_cert_verifier->AddResultForCert(verify_result.verified_cert.get(), 81 mock_cert_verifier->AddResultForCert(verify_result.verified_cert.get(),
82 verify_result, net::OK); 82 verify_result, net::OK);
83 } 83 }
84 84
85 return reinterpret_cast<jlong>(mock_cert_verifier); 85 return reinterpret_cast<jlong>(mock_cert_verifier);
86 } 86 }
87 87
88 bool RegisterMockCertVerifier(JNIEnv* env) { 88 bool RegisterMockCertVerifier(JNIEnv* env) {
89 return RegisterNativesImpl(env); 89 return RegisterNativesImpl(env);
90 } 90 }
91 91
92 } // namespace cronet 92 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698