Chromium Code Reviews| 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/ssl/chrome_security_state_model_client.h" | 5 #include "chrome/browser/ssl/chrome_security_state_model_client.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "content/public/browser/security_style_explanation.h" | 31 #include "content/public/browser/security_style_explanation.h" |
| 32 #include "content/public/browser/security_style_explanations.h" | 32 #include "content/public/browser/security_style_explanations.h" |
| 33 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 34 #include "content/public/common/referrer.h" | 34 #include "content/public/common/referrer.h" |
| 35 #include "content/public/common/ssl_status.h" | 35 #include "content/public/common/ssl_status.h" |
| 36 #include "content/public/test/browser_test_utils.h" | 36 #include "content/public/test/browser_test_utils.h" |
| 37 #include "net/base/net_errors.h" | 37 #include "net/base/net_errors.h" |
| 38 #include "net/cert/cert_status_flags.h" | 38 #include "net/cert/cert_status_flags.h" |
| 39 #include "net/cert/cert_verify_result.h" | 39 #include "net/cert/cert_verify_result.h" |
| 40 #include "net/cert/mock_cert_verifier.h" | 40 #include "net/cert/mock_cert_verifier.h" |
| 41 #include "net/cert/sct_status_flags.h" | |
| 42 #include "net/cert/signed_certificate_timestamp.h" | |
| 41 #include "net/cert/x509_certificate.h" | 43 #include "net/cert/x509_certificate.h" |
| 42 #include "net/dns/mock_host_resolver.h" | 44 #include "net/dns/mock_host_resolver.h" |
| 45 #include "net/ssl/signed_certificate_timestamp_and_status.h" | |
| 43 #include "net/ssl/ssl_cipher_suite_names.h" | 46 #include "net/ssl/ssl_cipher_suite_names.h" |
| 44 #include "net/ssl/ssl_connection_status_flags.h" | 47 #include "net/ssl/ssl_connection_status_flags.h" |
| 45 #include "net/test/cert_test_util.h" | 48 #include "net/test/cert_test_util.h" |
| 46 #include "net/test/embedded_test_server/embedded_test_server.h" | 49 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 47 #include "net/test/embedded_test_server/request_handler_util.h" | 50 #include "net/test/embedded_test_server/request_handler_util.h" |
| 48 #include "net/test/test_data_directory.h" | 51 #include "net/test/test_data_directory.h" |
| 49 #include "net/test/url_request/url_request_failed_job.h" | 52 #include "net/test/url_request/url_request_failed_job.h" |
| 50 #include "net/test/url_request/url_request_mock_http_job.h" | 53 #include "net/test/url_request/url_request_mock_http_job.h" |
| 51 #include "net/url_request/url_request_filter.h" | 54 #include "net/url_request/url_request_filter.h" |
| 52 #include "net/url_request/url_request_test_util.h" | 55 #include "net/url_request/url_request_test_util.h" |
| (...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1106 | 1109 |
| 1107 // The messages explaining the security style do, however, get | 1110 // The messages explaining the security style do, however, get |
| 1108 // downgraded: SECURE_PROTOCOL_AND_CIPHERSUITE should not show up when | 1111 // downgraded: SECURE_PROTOCOL_AND_CIPHERSUITE should not show up when |
| 1109 // the TLS settings are obsolete. | 1112 // the TLS settings are obsolete. |
| 1110 for (const auto& explanation : | 1113 for (const auto& explanation : |
| 1111 observer.latest_explanations().secure_explanations) { | 1114 observer.latest_explanations().secure_explanations) { |
| 1112 EXPECT_NE(l10n_util::GetStringUTF8(IDS_SECURE_PROTOCOL_AND_CIPHERSUITE), | 1115 EXPECT_NE(l10n_util::GetStringUTF8(IDS_SECURE_PROTOCOL_AND_CIPHERSUITE), |
| 1113 explanation.summary); | 1116 explanation.summary); |
| 1114 } | 1117 } |
| 1115 } | 1118 } |
| 1116 | 1119 |
|
estark
2016/08/03 23:48:24
Unfortunately a lot of the code from here down is
| |
| 1120 // After AddSCTUrlHandler() is called, requests to this hostname | |
| 1121 // will be served with Signed Certificate Timestamps. | |
| 1122 const char kMockHostnameWithSCTs[] = "example-scts.test"; | |
| 1123 | |
| 1124 // URLRequestJobWithSCTs mocks a connection that includes a set of dummy | |
| 1125 // SCTs with these statuses. | |
| 1126 const std::vector<net::ct::SCTVerifyStatus> kTestSCTStatuses{ | |
| 1127 net::ct::SCT_STATUS_OK, net::ct::SCT_STATUS_LOG_UNKNOWN, | |
| 1128 net::ct::SCT_STATUS_OK}; | |
| 1129 | |
| 1130 // A URLRequestMockHTTPJob that mocks a TLS connection with SCTs | |
| 1131 // attached to it. The SCTs will have verification statuses | |
| 1132 // |kTestSCTStatuses|. | |
| 1133 class URLRequestJobWithSCTs : public net::URLRequestMockHTTPJob { | |
| 1134 public: | |
| 1135 URLRequestJobWithSCTs(net::URLRequest* request, | |
| 1136 net::NetworkDelegate* network_delegate, | |
| 1137 const base::FilePath& file_path, | |
| 1138 scoped_refptr<net::X509Certificate> cert, | |
| 1139 scoped_refptr<base::TaskRunner> task_runner) | |
| 1140 : net::URLRequestMockHTTPJob(request, | |
| 1141 network_delegate, | |
| 1142 file_path, | |
| 1143 task_runner), | |
| 1144 cert_(std::move(cert)) {} | |
| 1145 | |
| 1146 void GetResponseInfo(net::HttpResponseInfo* info) override { | |
| 1147 net::URLRequestMockHTTPJob::GetResponseInfo(info); | |
| 1148 for (const auto& status : kTestSCTStatuses) { | |
| 1149 scoped_refptr<net::ct::SignedCertificateTimestamp> dummy_sct = | |
| 1150 new net::ct::SignedCertificateTimestamp(); | |
| 1151 info->ssl_info.signed_certificate_timestamps.push_back( | |
| 1152 net::SignedCertificateTimestampAndStatus(dummy_sct, status)); | |
| 1153 } | |
| 1154 info->ssl_info.cert = cert_; | |
| 1155 } | |
| 1156 | |
| 1157 protected: | |
| 1158 ~URLRequestJobWithSCTs() override {} | |
| 1159 | |
| 1160 private: | |
| 1161 const scoped_refptr<net::X509Certificate> cert_; | |
| 1162 | |
| 1163 DISALLOW_COPY_AND_ASSIGN(URLRequestJobWithSCTs); | |
| 1164 }; | |
| 1165 | |
| 1166 // A URLRequestInterceptor that handles requests with | |
| 1167 // URLRequestJobWithSCTs jobs. | |
| 1168 class URLRequestWithSCTsInterceptor : public net::URLRequestInterceptor { | |
| 1169 public: | |
| 1170 URLRequestWithSCTsInterceptor( | |
| 1171 const base::FilePath& base_path, | |
| 1172 scoped_refptr<base::SequencedWorkerPool> worker_pool, | |
| 1173 scoped_refptr<net::X509Certificate> cert) | |
| 1174 : base_path_(base_path), | |
| 1175 worker_pool_(std::move(worker_pool)), | |
| 1176 cert_(std::move(cert)) {} | |
| 1177 | |
| 1178 ~URLRequestWithSCTsInterceptor() override {} | |
| 1179 | |
| 1180 // net::URLRequestInterceptor: | |
| 1181 net::URLRequestJob* MaybeInterceptRequest( | |
| 1182 net::URLRequest* request, | |
| 1183 net::NetworkDelegate* network_delegate) const override { | |
| 1184 return new URLRequestJobWithSCTs( | |
| 1185 request, network_delegate, base_path_, cert_, | |
| 1186 worker_pool_->GetTaskRunnerWithShutdownBehavior( | |
| 1187 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | |
| 1188 } | |
| 1189 | |
| 1190 private: | |
| 1191 const base::FilePath base_path_; | |
| 1192 const scoped_refptr<base::SequencedWorkerPool> worker_pool_; | |
| 1193 const scoped_refptr<net::X509Certificate> cert_; | |
| 1194 | |
| 1195 DISALLOW_COPY_AND_ASSIGN(URLRequestWithSCTsInterceptor); | |
| 1196 }; | |
| 1197 | |
| 1198 // Installs a handler to serve HTTPS requests to |kMockHostnameWithSCTs| | |
| 1199 // with connections that have SCTs. | |
| 1200 void AddSCTUrlHandler(const base::FilePath& base_path, | |
| 1201 scoped_refptr<net::X509Certificate> cert, | |
| 1202 scoped_refptr<base::SequencedWorkerPool> worker_pool) { | |
| 1203 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); | |
| 1204 filter->AddHostnameInterceptor( | |
| 1205 "https", kMockHostnameWithSCTs, | |
| 1206 std::unique_ptr<net::URLRequestInterceptor>( | |
| 1207 new URLRequestWithSCTsInterceptor(base_path, worker_pool, cert))); | |
| 1208 } | |
| 1209 | |
| 1210 class BrowserTestURLRequestWithSCTs : public InProcessBrowserTest { | |
| 1211 public: | |
| 1212 BrowserTestURLRequestWithSCTs() : InProcessBrowserTest(), cert_(nullptr) {} | |
| 1213 | |
| 1214 void SetUpInProcessBrowserTestFixture() override { | |
| 1215 cert_ = | |
| 1216 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
| 1217 ASSERT_TRUE(cert_); | |
| 1218 } | |
| 1219 | |
| 1220 void SetUpOnMainThread() override { | |
| 1221 base::FilePath serve_file; | |
| 1222 PathService::Get(chrome::DIR_TEST_DATA, &serve_file); | |
| 1223 serve_file = serve_file.Append(FILE_PATH_LITERAL("title1.html")); | |
| 1224 content::BrowserThread::PostTask( | |
| 1225 content::BrowserThread::IO, FROM_HERE, | |
| 1226 base::Bind( | |
| 1227 &AddSCTUrlHandler, serve_file, cert_, | |
| 1228 make_scoped_refptr(content::BrowserThread::GetBlockingPool()))); | |
| 1229 } | |
| 1230 | |
| 1231 private: | |
| 1232 scoped_refptr<net::X509Certificate> cert_; | |
| 1233 | |
| 1234 DISALLOW_COPY_AND_ASSIGN(BrowserTestURLRequestWithSCTs); | |
| 1235 }; | |
| 1236 | |
| 1237 // Tests that, when Signed Certificate Timestamps (SCTs) are served on a | |
| 1238 // connection, the SCTs verification statuses are exposed on the | |
| 1239 // SecurityInfo. | |
| 1240 IN_PROC_BROWSER_TEST_F(BrowserTestURLRequestWithSCTs, | |
| 1241 SecurityInfoWithSCTsAttached) { | |
| 1242 ui_test_utils::NavigateToURL( | |
| 1243 browser(), GURL(std::string("https://") + kMockHostnameWithSCTs)); | |
| 1244 | |
| 1245 content::WebContents* web_contents = | |
| 1246 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 1247 ASSERT_TRUE(web_contents); | |
| 1248 ChromeSecurityStateModelClient* model_client = | |
| 1249 ChromeSecurityStateModelClient::FromWebContents(web_contents); | |
| 1250 ASSERT_TRUE(model_client); | |
| 1251 const SecurityStateModel::SecurityInfo& security_info = | |
| 1252 model_client->GetSecurityInfo(); | |
| 1253 EXPECT_EQ(SecurityStateModel::SECURE, security_info.security_level); | |
| 1254 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses); | |
| 1255 } | |
| 1256 | |
| 1117 } // namespace | 1257 } // namespace |
| OLD | NEW |