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 "chrome/browser/net/certificate_error_reporter.h" | 5 #include "chrome/browser/net/certificate_error_reporter.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
19 #include "chrome/browser/net/cert_logger.pb.h" | 19 #include "chrome/browser/net/cert_logger.pb.h" |
20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "crypto/curve25519.h" |
22 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
23 #include "net/base/network_delegate_impl.h" | 24 #include "net/base/network_delegate_impl.h" |
24 #include "net/base/test_data_directory.h" | 25 #include "net/base/test_data_directory.h" |
25 #include "net/base/upload_bytes_element_reader.h" | 26 #include "net/base/upload_bytes_element_reader.h" |
26 #include "net/base/upload_data_stream.h" | 27 #include "net/base/upload_data_stream.h" |
27 #include "net/base/upload_element_reader.h" | 28 #include "net/base/upload_element_reader.h" |
28 #include "net/test/cert_test_util.h" | 29 #include "net/test/cert_test_util.h" |
29 #include "net/test/url_request/url_request_failed_job.h" | 30 #include "net/test/url_request/url_request_failed_job.h" |
30 #include "net/test/url_request/url_request_mock_data_job.h" | 31 #include "net/test/url_request/url_request_mock_data_job.h" |
31 #include "net/test/url_request/url_request_mock_http_job.h" | 32 #include "net/test/url_request/url_request_mock_http_job.h" |
32 #include "net/url_request/url_request_filter.h" | 33 #include "net/url_request/url_request_filter.h" |
33 #include "net/url_request/url_request_test_util.h" | 34 #include "net/url_request/url_request_test_util.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
35 | 36 |
36 using chrome_browser_net::CertificateErrorReporter; | 37 using chrome_browser_net::CertificateErrorReporter; |
37 using content::BrowserThread; | 38 using content::BrowserThread; |
38 using net::CompletionCallback; | 39 using net::CompletionCallback; |
39 using net::SSLInfo; | 40 using net::SSLInfo; |
40 using net::NetworkDelegateImpl; | 41 using net::NetworkDelegateImpl; |
41 using net::TestURLRequestContext; | 42 using net::TestURLRequestContext; |
42 using net::URLRequest; | 43 using net::URLRequest; |
43 | 44 |
44 namespace { | 45 namespace { |
45 | 46 |
46 const char kHostname[] = "test.mail.google.com"; | 47 const char kHostname[] = "test.mail.google.com"; |
47 const char kSecondRequestHostname[] = "test2.mail.google.com"; | 48 const char kSecondRequestHostname[] = "test2.mail.google.com"; |
48 const char kDummyFailureLog[] = "dummy failure log"; | 49 const char kDummyFailureLog[] = "dummy failure log"; |
49 const char kTestCertFilename[] = "test_mail_google_com.pem"; | 50 const char kTestCertFilename[] = "test_mail_google_com.pem"; |
| 51 const uint32 kServerPublicKeyVersion = 1; |
50 | 52 |
51 SSLInfo GetTestSSLInfo() { | 53 SSLInfo GetTestSSLInfo() { |
52 SSLInfo info; | 54 SSLInfo info; |
53 info.cert = | 55 info.cert = |
54 net::ImportCertFromFile(net::GetTestCertsDirectory(), kTestCertFilename); | 56 net::ImportCertFromFile(net::GetTestCertsDirectory(), kTestCertFilename); |
55 info.is_issued_by_known_root = true; | 57 info.is_issued_by_known_root = true; |
56 info.pinning_failure_log = kDummyFailureLog; | 58 info.pinning_failure_log = kDummyFailureLog; |
57 return info; | 59 return info; |
58 } | 60 } |
59 | 61 |
(...skipping 16 matching lines...) Expand all Loading... |
76 net::URLRequestMockHTTPJob::AddUrlHandlers(root_http, | 78 net::URLRequestMockHTTPJob::AddUrlHandlers(root_http, |
77 BrowserThread::GetBlockingPool()); | 79 BrowserThread::GetBlockingPool()); |
78 net::URLRequestMockDataJob::AddUrlHandler(); | 80 net::URLRequestMockDataJob::AddUrlHandler(); |
79 } | 81 } |
80 | 82 |
81 // Check that data uploaded in the request matches the test data (an SSL | 83 // Check that data uploaded in the request matches the test data (an SSL |
82 // report for one of the given hostnames, with the info returned by | 84 // report for one of the given hostnames, with the info returned by |
83 // |GetTestSSLInfo()|). The hostname sent in the report will be erased | 85 // |GetTestSSLInfo()|). The hostname sent in the report will be erased |
84 // from |expect_hostnames|. | 86 // from |expect_hostnames|. |
85 void CheckUploadData(URLRequest* request, | 87 void CheckUploadData(URLRequest* request, |
86 std::set<std::string>* expect_hostnames) { | 88 std::set<std::string>* expect_hostnames, |
| 89 bool encrypted, |
| 90 const uint8* server_private_key) { |
87 const net::UploadDataStream* upload = request->get_upload(); | 91 const net::UploadDataStream* upload = request->get_upload(); |
88 ASSERT_TRUE(upload); | 92 ASSERT_TRUE(upload); |
89 ASSERT_TRUE(upload->GetElementReaders()); | 93 ASSERT_TRUE(upload->GetElementReaders()); |
90 EXPECT_EQ(1u, upload->GetElementReaders()->size()); | 94 EXPECT_EQ(1u, upload->GetElementReaders()->size()); |
91 | 95 |
92 const net::UploadBytesElementReader* reader = | 96 const net::UploadBytesElementReader* reader = |
93 (*upload->GetElementReaders())[0]->AsBytesReader(); | 97 (*upload->GetElementReaders())[0]->AsBytesReader(); |
94 ASSERT_TRUE(reader); | 98 ASSERT_TRUE(reader); |
95 std::string upload_data(reader->bytes(), reader->length()); | 99 std::string upload_data(reader->bytes(), reader->length()); |
| 100 |
96 chrome_browser_net::CertLoggerRequest uploaded_request; | 101 chrome_browser_net::CertLoggerRequest uploaded_request; |
97 | 102 if (encrypted) { |
98 uploaded_request.ParseFromString(upload_data); | 103 chrome_browser_net::EncryptedCertLoggerRequest encrypted_request; |
| 104 encrypted_request.ParseFromString(upload_data); |
| 105 EXPECT_EQ(kServerPublicKeyVersion, |
| 106 encrypted_request.server_public_key_version()); |
| 107 EXPECT_EQ(chrome_browser_net::EncryptedCertLoggerRequest:: |
| 108 AEAD_ECDH_AES_128_CTR_HMAC_SHA256, |
| 109 encrypted_request.algorithm()); |
| 110 ASSERT_TRUE(chrome_browser_net::DecryptCertificateErrorReport( |
| 111 server_private_key, encrypted_request, &uploaded_request)); |
| 112 } else { |
| 113 uploaded_request.ParseFromString(upload_data); |
| 114 } |
99 | 115 |
100 EXPECT_EQ(1u, expect_hostnames->count(uploaded_request.hostname())); | 116 EXPECT_EQ(1u, expect_hostnames->count(uploaded_request.hostname())); |
101 expect_hostnames->erase(uploaded_request.hostname()); | 117 expect_hostnames->erase(uploaded_request.hostname()); |
102 | 118 |
103 EXPECT_EQ(GetPEMEncodedChain(), uploaded_request.cert_chain()); | 119 EXPECT_EQ(GetPEMEncodedChain(), uploaded_request.cert_chain()); |
104 EXPECT_EQ(1, uploaded_request.pin().size()); | 120 EXPECT_EQ(1, uploaded_request.pin().size()); |
105 EXPECT_EQ(kDummyFailureLog, uploaded_request.pin().Get(0)); | 121 EXPECT_EQ(kDummyFailureLog, uploaded_request.pin().Get(0)); |
106 } | 122 } |
107 | 123 |
108 // A network delegate that lets tests check that a certificate error | 124 // A network delegate that lets tests check that a certificate error |
109 // report was sent. It counts the number of requests and lets tests | 125 // report was sent. It counts the number of requests and lets tests |
110 // register a callback to run when the request is destroyed. It also | 126 // register a callback to run when the request is destroyed. It also |
111 // checks that the uploaded data is as expected (a report for | 127 // checks that the uploaded data is as expected (a report for |
112 // |kHostname| and |GetTestSSLInfo()|). | 128 // |kHostname| and |GetTestSSLInfo()|). |
113 class TestCertificateErrorReporterNetworkDelegate : public NetworkDelegateImpl { | 129 class TestCertificateErrorReporterNetworkDelegate : public NetworkDelegateImpl { |
114 public: | 130 public: |
115 TestCertificateErrorReporterNetworkDelegate() | 131 TestCertificateErrorReporterNetworkDelegate() |
116 : url_request_destroyed_callback_(base::Bind(&base::DoNothing)), | 132 : url_request_destroyed_callback_(base::Bind(&base::DoNothing)), |
117 all_url_requests_destroyed_callback_(base::Bind(&base::DoNothing)), | 133 all_url_requests_destroyed_callback_(base::Bind(&base::DoNothing)), |
118 num_requests_(0), | 134 num_requests_(0), |
119 expect_cookies_(false) {} | 135 expect_cookies_(false), |
| 136 expect_request_encrypted_(false) { |
| 137 memset(server_private_key_, 1, sizeof(server_private_key_)); |
| 138 crypto::curve25519::ScalarBaseMult(server_private_key_, server_public_key_); |
| 139 } |
120 | 140 |
121 ~TestCertificateErrorReporterNetworkDelegate() override {} | 141 ~TestCertificateErrorReporterNetworkDelegate() override {} |
122 | 142 |
123 void ExpectHostname(const std::string& hostname) { | 143 void ExpectHostname(const std::string& hostname) { |
124 expect_hostnames_.insert(hostname); | 144 expect_hostnames_.insert(hostname); |
125 } | 145 } |
126 | 146 |
127 void set_all_url_requests_destroyed_callback( | 147 void set_all_url_requests_destroyed_callback( |
128 const base::Closure& all_url_requests_destroyed_callback) { | 148 const base::Closure& all_url_requests_destroyed_callback) { |
129 all_url_requests_destroyed_callback_ = all_url_requests_destroyed_callback; | 149 all_url_requests_destroyed_callback_ = all_url_requests_destroyed_callback; |
130 } | 150 } |
131 | 151 |
132 void set_url_request_destroyed_callback( | 152 void set_url_request_destroyed_callback( |
133 const base::Closure& url_request_destroyed_callback) { | 153 const base::Closure& url_request_destroyed_callback) { |
134 url_request_destroyed_callback_ = url_request_destroyed_callback; | 154 url_request_destroyed_callback_ = url_request_destroyed_callback; |
135 } | 155 } |
136 | 156 |
137 void set_expect_url(const GURL& expect_url) { expect_url_ = expect_url; } | 157 void set_expect_url(const GURL& expect_url) { expect_url_ = expect_url; } |
138 | 158 |
139 int num_requests() const { return num_requests_; } | 159 int num_requests() const { return num_requests_; } |
140 | 160 |
141 // Sets whether cookies are expected to be sent on requests. If set to | 161 // Sets whether cookies are expected to be sent on requests. If set to |
142 // true, then |OnHeadersReceived| will expect a cookie | 162 // true, then |OnHeadersReceived| will expect a cookie |
143 // "cookie_name=cookie_value". | 163 // "cookie_name=cookie_value". |
144 void set_expect_cookies(bool expect_cookies) { | 164 void set_expect_cookies(bool expect_cookies) { |
145 expect_cookies_ = expect_cookies; | 165 expect_cookies_ = expect_cookies; |
146 } | 166 } |
147 | 167 |
| 168 void set_expect_request_encrypted(bool expect_request_encrypted) { |
| 169 expect_request_encrypted_ = expect_request_encrypted; |
| 170 } |
| 171 |
148 // NetworkDelegateImpl implementation | 172 // NetworkDelegateImpl implementation |
149 int OnBeforeURLRequest(URLRequest* request, | 173 int OnBeforeURLRequest(URLRequest* request, |
150 const CompletionCallback& callback, | 174 const CompletionCallback& callback, |
151 GURL* new_url) override { | 175 GURL* new_url) override { |
152 num_requests_++; | 176 num_requests_++; |
153 EXPECT_EQ(expect_url_, request->url()); | 177 EXPECT_EQ(expect_url_, request->url()); |
154 EXPECT_EQ("POST", request->method()); | 178 EXPECT_EQ("POST", request->method()); |
155 | 179 |
156 if (expect_cookies_) { | 180 if (expect_cookies_) { |
157 EXPECT_FALSE(request->load_flags() & net::LOAD_DO_NOT_SEND_COOKIES); | 181 EXPECT_FALSE(request->load_flags() & net::LOAD_DO_NOT_SEND_COOKIES); |
158 EXPECT_FALSE(request->load_flags() & net::LOAD_DO_NOT_SAVE_COOKIES); | 182 EXPECT_FALSE(request->load_flags() & net::LOAD_DO_NOT_SAVE_COOKIES); |
159 } else { | 183 } else { |
160 EXPECT_TRUE(request->load_flags() & net::LOAD_DO_NOT_SEND_COOKIES); | 184 EXPECT_TRUE(request->load_flags() & net::LOAD_DO_NOT_SEND_COOKIES); |
161 EXPECT_TRUE(request->load_flags() & net::LOAD_DO_NOT_SAVE_COOKIES); | 185 EXPECT_TRUE(request->load_flags() & net::LOAD_DO_NOT_SAVE_COOKIES); |
162 } | 186 } |
163 | 187 |
164 std::string uploaded_request_hostname; | 188 std::string uploaded_request_hostname; |
165 CheckUploadData(request, &expect_hostnames_); | 189 CheckUploadData(request, &expect_hostnames_, expect_request_encrypted_, |
| 190 server_private_key_); |
166 expect_hostnames_.erase(uploaded_request_hostname); | 191 expect_hostnames_.erase(uploaded_request_hostname); |
167 return net::OK; | 192 return net::OK; |
168 } | 193 } |
169 | 194 |
170 void OnURLRequestDestroyed(URLRequest* request) override { | 195 void OnURLRequestDestroyed(URLRequest* request) override { |
171 url_request_destroyed_callback_.Run(); | 196 url_request_destroyed_callback_.Run(); |
172 if (expect_hostnames_.empty()) | 197 if (expect_hostnames_.empty()) |
173 all_url_requests_destroyed_callback_.Run(); | 198 all_url_requests_destroyed_callback_.Run(); |
174 } | 199 } |
175 | 200 |
| 201 const uint8* server_public_key() { return server_public_key_; } |
| 202 |
176 private: | 203 private: |
177 base::Closure url_request_destroyed_callback_; | 204 base::Closure url_request_destroyed_callback_; |
178 base::Closure all_url_requests_destroyed_callback_; | 205 base::Closure all_url_requests_destroyed_callback_; |
179 int num_requests_; | 206 int num_requests_; |
180 GURL expect_url_; | 207 GURL expect_url_; |
181 std::set<std::string> expect_hostnames_; | 208 std::set<std::string> expect_hostnames_; |
182 bool expect_cookies_; | 209 bool expect_cookies_; |
| 210 bool expect_request_encrypted_; |
| 211 |
| 212 uint8 server_public_key_[32]; |
| 213 uint8 server_private_key_[32]; |
183 | 214 |
184 DISALLOW_COPY_AND_ASSIGN(TestCertificateErrorReporterNetworkDelegate); | 215 DISALLOW_COPY_AND_ASSIGN(TestCertificateErrorReporterNetworkDelegate); |
185 }; | 216 }; |
186 | 217 |
187 class CertificateErrorReporterTest : public ::testing::Test { | 218 class CertificateErrorReporterTest : public ::testing::Test { |
188 public: | 219 public: |
189 CertificateErrorReporterTest() : context_(true) { | 220 CertificateErrorReporterTest() : context_(true) { |
190 EnableUrlRequestMocks(true); | 221 EnableUrlRequestMocks(true); |
191 context_.set_network_delegate(&network_delegate_); | 222 context_.set_network_delegate(&network_delegate_); |
192 context_.Init(); | 223 context_.Init(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 // for the endpoint and sends the expected data. | 261 // for the endpoint and sends the expected data. |
231 TEST_F(CertificateErrorReporterTest, PinningViolationSendReportSendsRequest) { | 262 TEST_F(CertificateErrorReporterTest, PinningViolationSendReportSendsRequest) { |
232 GURL url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); | 263 GURL url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); |
233 CertificateErrorReporter reporter( | 264 CertificateErrorReporter reporter( |
234 context(), url, CertificateErrorReporter::DO_NOT_SEND_COOKIES); | 265 context(), url, CertificateErrorReporter::DO_NOT_SEND_COOKIES); |
235 SendReport(&reporter, network_delegate(), kHostname, url, 0, | 266 SendReport(&reporter, network_delegate(), kHostname, url, 0, |
236 CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION); | 267 CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION); |
237 } | 268 } |
238 | 269 |
239 TEST_F(CertificateErrorReporterTest, ExtendedReportingSendReportSendsRequest) { | 270 TEST_F(CertificateErrorReporterTest, ExtendedReportingSendReportSendsRequest) { |
240 GURL url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); | 271 // Data should be encrypted when sent to an HTTP URL. |
241 CertificateErrorReporter reporter( | 272 GURL http_url = net::URLRequestMockDataJob::GetMockHttpUrl("dummy data", 1); |
242 context(), url, CertificateErrorReporter::DO_NOT_SEND_COOKIES); | 273 CertificateErrorReporter http_reporter( |
243 SendReport(&reporter, network_delegate(), kHostname, url, 0, | 274 context(), http_url, CertificateErrorReporter::DO_NOT_SEND_COOKIES, |
| 275 network_delegate()->server_public_key(), kServerPublicKeyVersion); |
| 276 network_delegate()->set_expect_request_encrypted(true); |
| 277 SendReport(&http_reporter, network_delegate(), kHostname, http_url, 0, |
| 278 CertificateErrorReporter::REPORT_TYPE_EXTENDED_REPORTING); |
| 279 |
| 280 // Data should not be encrypted when sent to an HTTPS URL. |
| 281 GURL https_url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); |
| 282 CertificateErrorReporter https_reporter( |
| 283 context(), https_url, CertificateErrorReporter::DO_NOT_SEND_COOKIES); |
| 284 network_delegate()->set_expect_request_encrypted(false); |
| 285 SendReport(&https_reporter, network_delegate(), kHostname, https_url, 1, |
244 CertificateErrorReporter::REPORT_TYPE_EXTENDED_REPORTING); | 286 CertificateErrorReporter::REPORT_TYPE_EXTENDED_REPORTING); |
245 } | 287 } |
246 | 288 |
247 TEST_F(CertificateErrorReporterTest, SendMultipleReportsSequentially) { | 289 TEST_F(CertificateErrorReporterTest, SendMultipleReportsSequentially) { |
248 GURL url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); | 290 GURL url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); |
249 CertificateErrorReporter reporter( | 291 CertificateErrorReporter reporter( |
250 context(), url, CertificateErrorReporter::DO_NOT_SEND_COOKIES); | 292 context(), url, CertificateErrorReporter::DO_NOT_SEND_COOKIES); |
251 SendReport(&reporter, network_delegate(), kHostname, url, 0, | 293 SendReport(&reporter, network_delegate(), kHostname, url, 0, |
252 CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION); | 294 CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION); |
253 SendReport(&reporter, network_delegate(), kSecondRequestHostname, url, 1, | 295 SendReport(&reporter, network_delegate(), kSecondRequestHostname, url, 1, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 TEST_F(CertificateErrorReporterTest, DoNotSendCookiesPreference) { | 372 TEST_F(CertificateErrorReporterTest, DoNotSendCookiesPreference) { |
331 GURL url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); | 373 GURL url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); |
332 CertificateErrorReporter reporter( | 374 CertificateErrorReporter reporter( |
333 context(), url, CertificateErrorReporter::DO_NOT_SEND_COOKIES); | 375 context(), url, CertificateErrorReporter::DO_NOT_SEND_COOKIES); |
334 | 376 |
335 network_delegate()->set_expect_cookies(false); | 377 network_delegate()->set_expect_cookies(false); |
336 SendReport(&reporter, network_delegate(), kHostname, url, 0, | 378 SendReport(&reporter, network_delegate(), kHostname, url, 0, |
337 CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION); | 379 CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION); |
338 } | 380 } |
339 | 381 |
| 382 // Test vectors for the AES-CTR-128-HMAC-SHA256 AEAD. (AD not |
| 383 // implemented so only test vectors with empty AD are included here.) |
| 384 |
| 385 const char* keys[] = { |
| 386 "23189bf23bc4b734410d1c7ae321c42e144a25347a8029bb925e3d8ac1b92f4eb97227c1de" |
| 387 "ce86ae9dea7d127eb33f9b", |
| 388 "1ad577d3b47e3fff8528e336a43a7ffef72f811e05b5c69ccfe777b10f29061e289178e394" |
| 389 "a1c87ba483c7f98ea5431d", |
| 390 "84172547d8608bd9e788a7bb60df2982963716e45f8e63f0c5033327d85c920c5e3776e314" |
| 391 "246b1694b739c39abfa29f", |
| 392 "3d9b651e65e9239c9e33aafb091b348161ab797901fd0468aedd014e4d5683c8f3f54f20ea" |
| 393 "6bb07bb25dd258df7bcd5e", |
| 394 "353c3e9f87b40fc0281869c68d9d9bee5c95771dd79998c059bc5ceda71f139fe447cfdf34" |
| 395 "0e9eac57f232b9d230e45d", |
| 396 "1ccec52c77239bdf6ca50e5b702943b23015d08cb1d9bac592b3dec4c96be904110713e52e" |
| 397 "114a8bc294df26530a758a", |
| 398 "0d9322713cd132c339c38ec7a75862860de304c70486b89b0f587095c66bfd1abe56f0b34f" |
| 399 "9ca0dac577fd4262616600", |
| 400 }; |
| 401 |
| 402 const char* nonces[] = { |
| 403 "30681944cd5d78f46d36ed8a", |
| 404 "1fcaa4757a9e48ed2cb3be62", |
| 405 "a3f1643bb504b7ce9e5b43c2", |
| 406 "32bcf856a14437114e7814cc", |
| 407 "cc7a4b46b02f4e7f96fd34e3", |
| 408 "38554b7c40027afe9721e14a", |
| 409 "3298d02dd4eb85a98cb935e3", |
| 410 }; |
| 411 |
| 412 const char* plaintexts[] = { |
| 413 "59", |
| 414 "46d30dac550103006c292a9ac05d31", |
| 415 "7e76323eb13e64da9b240a57c95c855b", |
| 416 "08a667c2923f87a7db6502478d32280bdc", |
| 417 "44bcb61332930f606276268ddbf3287bcaedb5b25704489cbee63ec839d7a69533dbfb6e95" |
| 418 "fe5b4694eb485beb1437f0777774868ecf45c8a5b3edafa1d62a", |
| 419 "dac91fcdb3768df8d5ae9ddba1fe5917c084a5d9e6b14eee9a609cab2da34ec9f95cf2d10f" |
| 420 "ff77108477e694c76f362e29b9a9287d8b190a748ed0a929967ff8", |
| 421 "5dfedb1d168fe262d35f78d797560b2634f71d40f438c21cdcb8e73cf9884c11570554f55a" |
| 422 "6abd23d0e7775a9ab385ae6c9bbd67f08d1aec57347a8fad5a4b8c7b042b03c25facbffc76" |
| 423 "f0b1ce2e6c07d427eaebe71255d661ac8e8bfe8867e2d947d496ce2318a601d0beed024263" |
| 424 "11ca678d036deb3b4c65b1f89bd644a410", |
| 425 }; |
| 426 |
| 427 const char* expected_ciphertexts[] = { |
| 428 "92986aa8438da3cf4a98f478f90d24908c6a4e848f299873e649b256f5499d89d9", |
| 429 "37616eba30c55595fa0ad5d50f91ca5c3ac4010f75adf90f81e775b07ab939e7551a9b8e04" |
| 430 "86ba33766728ed498245", |
| 431 "966487c18f025d67b42a04c30d3ff4c38bb03d893f0ce8ea4a6a47245bc7f20c72acf8caa4" |
| 432 "66edd01365d0f74c929463", |
| 433 "5e8e02cc91c732356bb9f1fc599426a3795449e878d558beff4bc7dfbb5f0195444705cfb2" |
| 434 "59773b4faec524fbaca37ea0", |
| 435 "d038d67b8b690519fafa7467c9fb94135f9bf0bcd8247cd2c30da62ddf37a6d9a3a9bdcf8e" |
| 436 "c081fb4469c0fc2798e2e30afede7cda384438fd01e5d672dcb8db2c685a59cdf304c1fb57" |
| 437 "b66966a5ca1cc3536fe21eb1113c25868428640c7d", |
| 438 "e6bcb38b3bfd0b428a14bb3aca01a4a9e54b0853f10bd7750f5bb58d0e7dd18006f8929d7d" |
| 439 "862e5d6601ef63be8442334b4d51a99219cfedaa31f7ab19028459c4f05d9415840c2325da" |
| 440 "bbcd12dbeda31e47637437514c606dedfb8ce622edd0", |
| 441 "ff09fe27f12a87d5208bf246378ee0740e848262442b8b9c7670c8a73fe6732192cde43c1a" |
| 442 "1246743ed49e15ec63c87dc06eb3e0c92c1f286108b2c7e0754dcf1b9c3fc87efe3683289d" |
| 443 "aabf2db71d8742061f93098788c3c6f26328b86e358507a03af296d2c29009562cad376339" |
| 444 "9e0e2b89ed440f756c16214c8ab7ddfb845076c80fc76c67d6e4f9b9d470cc184db62ea7da" |
| 445 "49cae44cb3ce9e46c2f2ca9e", |
| 446 }; |
| 447 |
| 448 void ParseHex(const char* in, std::string* out) { |
| 449 size_t l = strlen(in); |
| 450 for (size_t i = 0; i < l / 2; ++i) { |
| 451 int value; |
| 452 sscanf(in + 2 * i, "%02x", &value); |
| 453 *out += (char)value; |
| 454 } |
| 455 } |
| 456 |
| 457 TEST_F(CertificateErrorReporterTest, Seal) { |
| 458 size_t num_test_vectors = sizeof(keys) / sizeof(char*); |
| 459 for (size_t i = 0; i < num_test_vectors; i++) { |
| 460 std::string key; |
| 461 std::string nonce; |
| 462 std::string plaintext; |
| 463 std::string expected_ciphertext; |
| 464 std::string ciphertext; |
| 465 ParseHex(keys[i], &key); |
| 466 ParseHex(nonces[i], &nonce); |
| 467 ParseHex(plaintexts[i], &plaintext); |
| 468 ParseHex(expected_ciphertexts[i], &expected_ciphertext); |
| 469 ASSERT_TRUE(chrome_browser_net::Seal(key, nonce, plaintext, &ciphertext)); |
| 470 EXPECT_EQ(expected_ciphertext, ciphertext); |
| 471 } |
| 472 } |
| 473 |
340 } // namespace | 474 } // namespace |
OLD | NEW |