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

Side by Side Diff: content/child/web_url_loader_impl.cc

Issue 1772603002: Addition of Certificate Transparency details to Security panel of DevTools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/child/web_url_loader_impl.h" 5 #include "content/child/web_url_loader_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <iomanip>
10 #include <iostream>
Eran Messeri 2016/03/09 20:58:47 Including iostream will introduce additional stati
dwaxweiler 2016/03/10 11:02:28 Acknowledged.
11 #include <sstream>
9 #include <string> 12 #include <string>
10 #include <utility> 13 #include <utility>
11 #include <vector> 14 #include <vector>
12 15
13 #include "base/bind.h" 16 #include "base/bind.h"
14 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
15 #include "base/logging.h" 18 #include "base/logging.h"
16 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
17 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
18 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
(...skipping 18 matching lines...) Expand all
37 #include "content/public/child/fixed_received_data.h" 40 #include "content/public/child/fixed_received_data.h"
38 #include "content/public/child/request_peer.h" 41 #include "content/public/child/request_peer.h"
39 #include "content/public/common/browser_side_navigation_policy.h" 42 #include "content/public/common/browser_side_navigation_policy.h"
40 #include "content/public/common/signed_certificate_timestamp_id_and_status.h" 43 #include "content/public/common/signed_certificate_timestamp_id_and_status.h"
41 #include "content/public/common/ssl_status.h" 44 #include "content/public/common/ssl_status.h"
42 #include "net/base/data_url.h" 45 #include "net/base/data_url.h"
43 #include "net/base/filename_util.h" 46 #include "net/base/filename_util.h"
44 #include "net/base/net_errors.h" 47 #include "net/base/net_errors.h"
45 #include "net/cert/cert_status_flags.h" 48 #include "net/cert/cert_status_flags.h"
46 #include "net/cert/sct_status_flags.h" 49 #include "net/cert/sct_status_flags.h"
50 #include "net/cert/signed_certificate_timestamp.h"
47 #include "net/http/http_response_headers.h" 51 #include "net/http/http_response_headers.h"
48 #include "net/http/http_util.h" 52 #include "net/http/http_util.h"
49 #include "net/ssl/ssl_cipher_suite_names.h" 53 #include "net/ssl/ssl_cipher_suite_names.h"
50 #include "net/ssl/ssl_connection_status_flags.h" 54 #include "net/ssl/ssl_connection_status_flags.h"
51 #include "net/url_request/url_request_data_job.h" 55 #include "net/url_request/url_request_data_job.h"
52 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h" 56 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h"
53 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 57 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
54 #include "third_party/WebKit/public/platform/WebTraceLocation.h" 58 #include "third_party/WebKit/public/platform/WebTraceLocation.h"
55 #include "third_party/WebKit/public/platform/WebURL.h" 59 #include "third_party/WebKit/public/platform/WebURL.h"
56 #include "third_party/WebKit/public/platform/WebURLError.h" 60 #include "third_party/WebKit/public/platform/WebURLError.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 info->headers = headers; 171 info->headers = headers;
168 info->mime_type.swap(mime_type); 172 info->mime_type.swap(mime_type);
169 info->charset.swap(charset); 173 info->charset.swap(charset);
170 info->security_info.clear(); 174 info->security_info.clear();
171 info->content_length = data->length(); 175 info->content_length = data->length();
172 info->encoded_data_length = 0; 176 info->encoded_data_length = 0;
173 177
174 return net::OK; 178 return net::OK;
175 } 179 }
176 180
181 const WebString HashAlgorithmToString(
Eran Messeri 2016/03/09 20:58:46 Perhaps we can extract the function https://code.g
dwaxweiler 2016/03/10 11:02:27 Acknowledged.
182 net::ct::DigitallySigned::HashAlgorithm hashAlgorithm) {
183 switch (hashAlgorithm) {
184 case net::ct::DigitallySigned::HASH_ALGO_NONE:
185 return "None / invalid";
186 case net::ct::DigitallySigned::HASH_ALGO_MD5:
187 return "MD5";
188 case net::ct::DigitallySigned::HASH_ALGO_SHA1:
189 return "SHA-1";
190 case net::ct::DigitallySigned::HASH_ALGO_SHA224:
191 return "SHA-224";
192 case net::ct::DigitallySigned::HASH_ALGO_SHA256:
193 return "SHA-256";
194 case net::ct::DigitallySigned::HASH_ALGO_SHA384:
195 return "SHA-384";
196 case net::ct::DigitallySigned::HASH_ALGO_SHA512:
197 return "SHA-512";
198 }
199 return "Unknown";
200 }
201
202 const WebString SignatureAlgorithmToString(
Eran Messeri 2016/03/09 20:58:47 Same for https://code.google.com/p/chromium/codese
dwaxweiler 2016/03/10 11:02:28 Acknowledged.
203 net::ct::DigitallySigned::SignatureAlgorithm signatureAlgorithm) {
204 switch (signatureAlgorithm) {
205 case net::ct::DigitallySigned::SIG_ALGO_ANONYMOUS:
206 return "Unknown";
207 case net::ct::DigitallySigned::SIG_ALGO_RSA:
208 return "RSA";
209 case net::ct::DigitallySigned::SIG_ALGO_DSA:
210 return "DSA";
211 case net::ct::DigitallySigned::SIG_ALGO_ECDSA:
212 return "ECDSA";
213 }
214 return "Unknown";
215 }
216
217 const WebString OriginToString(
Eran Messeri 2016/03/09 20:58:47 Same for https://code.google.com/p/chromium/codese
dwaxweiler 2016/03/10 11:02:27 Acknowledged.
218 net::ct::SignedCertificateTimestamp::Origin origin) {
219 switch (origin) {
220 case net::ct::SignedCertificateTimestamp::SCT_EMBEDDED:
221 return "Embedded";
222 case net::ct::SignedCertificateTimestamp::SCT_FROM_TLS_EXTENSION:
223 return "TLS extension";
224 case net::ct::SignedCertificateTimestamp::SCT_FROM_OCSP_RESPONSE:
225 return "OCSP";
226 }
227 return "Unknown";
228 }
229
230 const WebString StatusToString(net::ct::SCTVerifyStatus status) {
231 switch (status) {
232 case net::ct::SCT_STATUS_LOG_UNKNOWN:
233 return "From unknown log";
234 case net::ct::SCT_STATUS_INVALID:
235 return "Invalid";
236 case net::ct::SCT_STATUS_OK:
237 return "Verified";
238 case net::ct::SCT_STATUS_NONE:
239 return "None";
240 }
241 return "Unknown";
242 }
243
244 const WebString VersionToString(
245 net::ct::SignedCertificateTimestamp::Version version) {
246 switch (version) {
247 case net::ct::SignedCertificateTimestamp::SCT_VERSION_1:
248 return "1";
249 }
250 return "Unknown";
251 }
252
253 std::string ByteToHex(const unsigned char *data, int length) {
Eran Messeri 2016/03/09 20:58:47 How about using HexEncode in https://code.google.c
dwaxweiler 2016/03/10 11:02:28 Acknowledged.
254 std::stringstream stream;
255 for (int i = 0; i < length; ++i) {
256 stream << std::hex
257 << std::uppercase
258 << std::setw(2)
259 << std::setfill('0')
260 << (int)data[i];
261 }
262 return stream.str();
263 }
264
177 void SetSecurityStyleAndDetails(const GURL& url, 265 void SetSecurityStyleAndDetails(const GURL& url,
178 const std::string& security_info, 266 const std::string& security_info,
179 WebURLResponse* response, 267 WebURLResponse* response,
180 bool report_security_info) { 268 bool report_security_info) {
181 if (!report_security_info) { 269 if (!report_security_info) {
182 response->setSecurityStyle(WebURLResponse::SecurityStyleUnknown); 270 response->setSecurityStyle(WebURLResponse::SecurityStyleUnknown);
183 return; 271 return;
184 } 272 }
185 if (!url.SchemeIsCryptographic()) { 273 if (!url.SchemeIsCryptographic()) {
186 response->setSecurityStyle(WebURLResponse::SecurityStyleUnauthenticated); 274 response->setSecurityStyle(WebURLResponse::SecurityStyleUnauthenticated);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 330
243 response->setSecurityStyle(securityStyle); 331 response->setSecurityStyle(securityStyle);
244 332
245 SignedCertificateTimestampIDStatusList sct_list = 333 SignedCertificateTimestampIDStatusList sct_list =
246 ssl_status.signed_certificate_timestamp_ids; 334 ssl_status.signed_certificate_timestamp_ids;
247 335
248 size_t num_unknown_scts = 0; 336 size_t num_unknown_scts = 0;
249 size_t num_invalid_scts = 0; 337 size_t num_invalid_scts = 0;
250 size_t num_valid_scts = 0; 338 size_t num_valid_scts = 0;
251 339
340 blink::WebURLResponse::SignedCertificateTimestampList sctList;
341
252 SignedCertificateTimestampIDStatusList::iterator iter; 342 SignedCertificateTimestampIDStatusList::iterator iter;
253 for (iter = sct_list.begin(); iter < sct_list.end(); ++iter) { 343 for (iter = sct_list.begin(); iter < sct_list.end(); ++iter) {
344 // Extract SCT's details.
Eran Messeri 2016/03/09 21:04:35 I think this is where you'd use the SignedCertific
dwaxweiler 2016/03/10 11:02:27 I have thought of the SCT store too, but Retrieve(
Eran Messeri 2016/03/14 18:27:26 +lgarron - is that the reason pages have to be re-
345 blink::WebURLResponse::SignedCertificateTimestamp sct(
346 StatusToString(iter->status),
347 OriginToString(iter->origin),
348 VersionToString(iter->version),
349 WebString::fromUTF8(iter->logDescription),
350 WebString::fromUTF8(ByteToHex(
351 reinterpret_cast<const unsigned char*>(iter->logId.data()),
352 iter->logId.length())),
353 iter->timestamp,
354 HashAlgorithmToString(iter->signature.hash_algorithm),
355 SignatureAlgorithmToString(iter->signature.signature_algorithm),
356 WebString::fromUTF8(ByteToHex(
357 reinterpret_cast<const unsigned char*>(
358 iter->signature.signature_data.data()),
359 iter->signature.signature_data.length())));
360 sctList.push_back(sct);
361 // Count unknown, invalid and valid SCTs.
254 switch (iter->status) { 362 switch (iter->status) {
255 case net::ct::SCT_STATUS_LOG_UNKNOWN: 363 case net::ct::SCT_STATUS_LOG_UNKNOWN:
256 num_unknown_scts++; 364 num_unknown_scts++;
257 break; 365 break;
258 case net::ct::SCT_STATUS_INVALID: 366 case net::ct::SCT_STATUS_INVALID:
259 num_invalid_scts++; 367 num_invalid_scts++;
260 break; 368 break;
261 case net::ct::SCT_STATUS_OK: 369 case net::ct::SCT_STATUS_OK:
262 num_valid_scts++; 370 num_valid_scts++;
263 break; 371 break;
264 case net::ct::SCT_STATUS_NONE: 372 case net::ct::SCT_STATUS_NONE:
265 case net::ct::SCT_STATUS_MAX: 373 case net::ct::SCT_STATUS_MAX:
266 // These enum values do not represent SCTs that are taken into account 374 // These enum values do not represent SCTs that are taken into account
267 // for CT compliance calculations, so we ignore them. 375 // for CT compliance calculations, so we ignore them.
268 break; 376 break;
269 } 377 }
270 } 378 }
271 379
272 blink::WebURLResponse::WebSecurityDetails webSecurityDetails( 380 blink::WebURLResponse::WebSecurityDetails webSecurityDetails(
273 WebString::fromUTF8(protocol), WebString::fromUTF8(cipher), 381 WebString::fromUTF8(protocol), WebString::fromUTF8(cipher),
274 WebString::fromUTF8(key_exchange), WebString::fromUTF8(mac), 382 WebString::fromUTF8(key_exchange), WebString::fromUTF8(mac),
275 ssl_status.cert_id, num_unknown_scts, num_invalid_scts, num_valid_scts); 383 ssl_status.cert_id, num_unknown_scts, num_invalid_scts, num_valid_scts,
384 sctList);
276 385
277 response->setSecurityDetails(webSecurityDetails); 386 response->setSecurityDetails(webSecurityDetails);
278 } 387 }
279 388
280 } // namespace 389 } // namespace
281 390
282 // This inner class exists since the WebURLLoader may be deleted while inside a 391 // This inner class exists since the WebURLLoader may be deleted while inside a
283 // call to WebURLLoaderClient. Refcounting is to keep the context from being 392 // call to WebURLLoaderClient. Refcounting is to keep the context from being
284 // deleted if it may have work to do after calling into the client. 393 // deleted if it may have work to do after calling into the client.
285 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { 394 class WebURLLoaderImpl::Context : public base::RefCounted<Context> {
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 } 1263 }
1155 1264
1156 void WebURLLoaderImpl::setLoadingTaskRunner( 1265 void WebURLLoaderImpl::setLoadingTaskRunner(
1157 blink::WebTaskRunner* loading_task_runner) { 1266 blink::WebTaskRunner* loading_task_runner) {
1158 // There's no guarantee on the lifetime of |loading_task_runner| so we take a 1267 // There's no guarantee on the lifetime of |loading_task_runner| so we take a
1159 // copy. 1268 // copy.
1160 context_->SetWebTaskRunner(make_scoped_ptr(loading_task_runner->clone())); 1269 context_->SetWebTaskRunner(make_scoped_ptr(loading_task_runner->clone()));
1161 } 1270 }
1162 1271
1163 } // namespace content 1272 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698