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

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

Issue 2044523003: Revert of 👔 Reland of Move side-loaded test data /sdcard -> /sdcard/gtestdata (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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"
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"
14 #include "crypto/sha2.h" 12 #include "crypto/sha2.h"
15 #include "jni/MockCertVerifier_jni.h" 13 #include "jni/MockCertVerifier_jni.h"
16 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
17 #include "net/base/test_data_directory.h" 15 #include "net/base/test_data_directory.h"
18 #include "net/cert/asn1_util.h" 16 #include "net/cert/asn1_util.h"
19 #include "net/cert/cert_verifier.h" 17 #include "net/cert/cert_verifier.h"
20 #include "net/cert/cert_verify_result.h" 18 #include "net/cert/cert_verify_result.h"
21 #include "net/cert/mock_cert_verifier.h" 19 #include "net/cert/mock_cert_verifier.h"
22 #include "net/test/cert_test_util.h" 20 #include "net/test/cert_test_util.h"
23 21
(...skipping 20 matching lines...) Expand all
44 } 42 }
45 // Calculate SHA256 hash of public key bytes. 43 // Calculate SHA256 hash of public key bytes.
46 out_hash_value->tag = net::HASH_VALUE_SHA256; 44 out_hash_value->tag = net::HASH_VALUE_SHA256;
47 crypto::SHA256HashString(spki_bytes, out_hash_value->data(), 45 crypto::SHA256HashString(spki_bytes, out_hash_value->data(),
48 crypto::kSHA256Length); 46 crypto::kSHA256Length);
49 return true; 47 return true;
50 } 48 }
51 49
52 } // namespace 50 } // namespace
53 51
54 static jlong CreateMockCertVerifier( 52 static jlong CreateMockCertVerifier(JNIEnv* env,
55 JNIEnv* env, 53 const JavaParamRef<jclass>& jcaller,
56 const JavaParamRef<jclass>& jcaller, 54 const JavaParamRef<jobjectArray>& jcerts) {
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
63 std::vector<std::string> certs; 55 std::vector<std::string> certs;
64 base::android::AppendJavaStringArrayToStringVector(env, jcerts, &certs); 56 base::android::AppendJavaStringArrayToStringVector(env, jcerts, &certs);
65 net::MockCertVerifier* mock_cert_verifier = new net::MockCertVerifier(); 57 net::MockCertVerifier* mock_cert_verifier = new net::MockCertVerifier();
66 for (auto cert : certs) { 58 for (auto cert : certs) {
67 net::CertVerifyResult verify_result; 59 net::CertVerifyResult verify_result;
68 verify_result.verified_cert = 60 verify_result.verified_cert =
69 net::ImportCertFromFile(net::GetTestCertsDirectory(), cert); 61 net::ImportCertFromFile(net::GetTestCertsDirectory(), cert);
70 62
71 // Let the cert be treated as a known root cert. 63 // Let the cert be treated as a known root cert.
72 // This will enable HPKP verification. 64 // This will enable HPKP verification.
(...skipping 10 matching lines...) Expand all
83 } 75 }
84 76
85 return reinterpret_cast<jlong>(mock_cert_verifier); 77 return reinterpret_cast<jlong>(mock_cert_verifier);
86 } 78 }
87 79
88 bool RegisterMockCertVerifier(JNIEnv* env) { 80 bool RegisterMockCertVerifier(JNIEnv* env) {
89 return RegisterNativesImpl(env); 81 return RegisterNativesImpl(env);
90 } 82 }
91 83
92 } // namespace cronet 84 } // namespace cronet
OLDNEW
« no previous file with comments | « components/cronet/android/BUILD.gn ('k') | components/cronet/android/test/native_test_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698