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

Side by Side Diff: chrome/browser/net/chrome_fraudulent_certificate_reporter_unittest.cc

Issue 949633002: Include both certificate chains in invalid cert reporting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a comment to cert logger pb Created 5 years, 10 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 (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 #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" 5 #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "chrome/browser/net/cert_logger.pb.h"
15 #include "content/public/test/test_browser_thread.h" 16 #include "content/public/test/test_browser_thread.h"
16 #include "net/base/request_priority.h" 17 #include "net/base/request_priority.h"
17 #include "net/base/test_data_directory.h" 18 #include "net/base/test_data_directory.h"
18 #include "net/cert/x509_certificate.h" 19 #include "net/cert/x509_certificate.h"
19 #include "net/http/transport_security_state.h" 20 #include "net/http/transport_security_state.h"
20 #include "net/ssl/ssl_info.h" 21 #include "net/ssl/ssl_info.h"
21 #include "net/test/cert_test_util.h" 22 #include "net/test/cert_test_util.h"
22 #include "net/url_request/fraudulent_certificate_reporter.h" 23 #include "net/url_request/fraudulent_certificate_reporter.h"
23 #include "net/url_request/url_request.h" 24 #include "net/url_request/url_request.h"
24 #include "net/url_request/url_request_context.h" 25 #include "net/url_request/url_request_context.h"
(...skipping 30 matching lines...) Expand all
55 static SSLInfo GetGoodSSLInfo() { 56 static SSLInfo GetGoodSSLInfo() {
56 SSLInfo info; 57 SSLInfo info;
57 58
58 info.cert = net::ImportCertFromFile(net::GetTestCertsDirectory(), 59 info.cert = net::ImportCertFromFile(net::GetTestCertsDirectory(),
59 "test_mail_google_com.pem"); 60 "test_mail_google_com.pem");
60 info.is_issued_by_known_root = true; 61 info.is_issued_by_known_root = true;
61 62
62 return info; 63 return info;
63 } 64 }
64 65
66 static SSLInfo GetExtendedReportingSSLInfo() {
67 SSLInfo info;
68 // Use different cert chains for the verified chain and the chain as
69 // sent by the server, and make sure that they are both included in
70 // the report.
71 info.cert = net::ImportCertFromFile(net::GetTestCertsDirectory(),
72 "test_mail_google_com.pem");
73 info.is_issued_by_known_root = true;
74 info.unverified_server_cert =
75 net::ImportCertFromFile(net::GetTestCertsDirectory(), "expired_cert.pem");
76 return info;
77 }
78
65 // Checks that |info| is good as required by the SSL checks performed in 79 // Checks that |info| is good as required by the SSL checks performed in
66 // URLRequestHttpJob::OnStartCompleted, which are enough to trigger pin 80 // URLRequestHttpJob::OnStartCompleted, which are enough to trigger pin
67 // checking but not sufficient to pass 81 // checking but not sufficient to pass
68 // DomainState::IsChainOfPublicKeysPermitted. 82 // DomainState::IsChainOfPublicKeysPermitted.
69 static bool IsGoodSSLInfo(const SSLInfo& info) { 83 static bool IsGoodSSLInfo(const SSLInfo& info) {
70 return info.is_valid() && info.is_issued_by_known_root; 84 return info.is_valid() && info.is_issued_by_known_root;
71 } 85 }
72 86
73 class TestReporter : public ChromeFraudulentCertificateReporter { 87 class TestReporter : public ChromeFraudulentCertificateReporter {
74 public: 88 public:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 146 }
133 147
134 void SendReport(ReportType type, 148 void SendReport(ReportType type,
135 const std::string& hostname, 149 const std::string& hostname,
136 const net::SSLInfo& ssl_info) override { 150 const net::SSLInfo& ssl_info) override {
137 DCHECK(!hostname.empty()); 151 DCHECK(!hostname.empty());
138 DCHECK(ssl_info.is_valid()); 152 DCHECK(ssl_info.is_valid());
139 ChromeFraudulentCertificateReporter::SendReport(REPORT_TYPE_PIN_VIOLATION, 153 ChromeFraudulentCertificateReporter::SendReport(REPORT_TYPE_PIN_VIOLATION,
140 hostname, ssl_info); 154 hostname, ssl_info);
141 } 155 }
156
157 static std::string BuildReportPublic(ReportType type,
158 const std::string& hostname,
159 const net::SSLInfo& ssl_info) {
160 return BuildReport(type, hostname, ssl_info);
161 }
142 }; 162 };
143 163
144 static void DoReportIsSent() { 164 static void DoReportIsSent() {
145 net::TestURLRequestContext context; 165 net::TestURLRequestContext context;
146 SendingTestReporter reporter(&context); 166 SendingTestReporter reporter(&context);
147 SSLInfo info = GetGoodSSLInfo(); 167 SSLInfo info = GetGoodSSLInfo();
148 reporter.SendReport(FraudulentCertificateReporter::REPORT_TYPE_PIN_VIOLATION, 168 reporter.SendReport(FraudulentCertificateReporter::REPORT_TYPE_PIN_VIOLATION,
149 "mail.google.com", info); 169 "mail.google.com", info);
150 } 170 }
151 171
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 loop.RunUntilIdle(); 207 loop.RunUntilIdle();
188 } 208 }
189 209
190 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { 210 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) {
191 base::MessageLoopForIO loop; 211 base::MessageLoopForIO loop;
192 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); 212 content::TestBrowserThread io_thread(BrowserThread::IO, &loop);
193 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); 213 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent));
194 loop.RunUntilIdle(); 214 loop.RunUntilIdle();
195 } 215 }
196 216
217 // Test that a report for a google.com pinning violation contains the
218 // right data.
219 TEST(ChromeFraudulentCertificateReporterTest, BuildReportForPinningViolation) {
220 SSLInfo info = GetGoodSSLInfo();
221 std::string report = MockReporter::BuildReportPublic(
222 ChromeFraudulentCertificateReporter::REPORT_TYPE_EXTENDED_REPORTING,
223 "mail.google.com", info);
224 CertLoggerRequest request;
225 request.ParseFromString(report);
226
227 std::vector<std::string> cert_chain;
228 info.cert->GetPEMEncodedChain(&cert_chain);
229
230 std::string expected_cert_chain;
231 for (size_t i = 0; i < cert_chain.size(); ++i) {
232 expected_cert_chain += cert_chain[i];
233 }
234
235 EXPECT_EQ(request.hostname(), "mail.google.com");
236 EXPECT_EQ(request.cert_chain(), expected_cert_chain);
237 }
238
239 // Test that an extended reporting report (used for invalid certificate
240 // chains) contains the right data, including the chain as received by
241 // the client and as verified by the client (which could be different
242 // chains).
243 TEST(ChromeFraudulentCertificateReporterTest, BuildReportForInvalidCertChain) {
244 SSLInfo info = GetExtendedReportingSSLInfo();
245 std::string report = MockReporter::BuildReportPublic(
246 ChromeFraudulentCertificateReporter::REPORT_TYPE_EXTENDED_REPORTING,
247 "mail.google.com", info);
248 CertLoggerRequest request;
249 request.ParseFromString(report);
250
251 std::vector<std::string> cert_chain;
252 info.cert->GetPEMEncodedChain(&cert_chain);
253 std::vector<std::string> unverified_server_cert_chain;
254 info.unverified_server_cert->GetPEMEncodedChain(
255 &unverified_server_cert_chain);
256
257 std::string expected_cert;
258 std::string expected_unverified_server_cert;
259 for (size_t i = 0; i < cert_chain.size(); ++i) {
260 expected_cert += cert_chain[i];
261 }
262 for (size_t i = 0; i < cert_chain.size(); ++i) {
263 expected_unverified_server_cert += unverified_server_cert_chain[i];
264 }
265
266 EXPECT_EQ(request.hostname(), "mail.google.com");
267 EXPECT_EQ(request.cert_chain(), expected_cert);
268 EXPECT_EQ(request.unverified_server_cert_chain(),
269 expected_unverified_server_cert);
270 }
271
197 } // namespace chrome_browser_net 272 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698