OLD | NEW |
---|---|
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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "chrome/browser/ssl/ssl_error_classification.h" | 7 #include "chrome/browser/ssl/ssl_error_classification.h" |
8 | 8 |
9 #include "base/build_time.h" | 9 #include "base/build_time.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 } | 315 } |
316 | 316 |
317 SSLErrorClassification::Tokens SSLErrorClassification:: | 317 SSLErrorClassification::Tokens SSLErrorClassification:: |
318 Tokenize(const std::string& name) { | 318 Tokenize(const std::string& name) { |
319 Tokens name_tokens; | 319 Tokens name_tokens; |
320 base::SplitStringDontTrim(name, '.', &name_tokens); | 320 base::SplitStringDontTrim(name, '.', &name_tokens); |
321 return name_tokens; | 321 return name_tokens; |
322 } | 322 } |
323 | 323 |
324 // We accept the inverse case for www for historical reasons. | 324 // We accept the inverse case for www for historical reasons. |
325 bool SSLErrorClassification::IsWWWSubDomainMatch() const { | 325 bool SSLErrorClassification::GetWWWSubDomainMatch( |
326 std::string host_name = request_url_.host(); | 326 const std::string& host_name, |
327 const std::vector<std::string>& dns_names, | |
328 std::string* www_match_host_name) { | |
327 if (IsHostNameKnownTLD(host_name)) { | 329 if (IsHostNameKnownTLD(host_name)) { |
328 std::vector<std::string> dns_names; | |
329 cert_.GetDNSNames(&dns_names); | |
330 bool result = false; | |
331 // Need to account for all possible domains given in the SSL certificate. | 330 // Need to account for all possible domains given in the SSL certificate. |
332 for (size_t i = 0; i < dns_names.size(); ++i) { | 331 for (size_t i = 0; i < dns_names.size(); ++i) { |
333 if (dns_names[i].empty() || dns_names[i].find('\0') != std::string::npos | 332 if (dns_names[i].empty() || dns_names[i].find('\0') != std::string::npos |
334 || dns_names[i].length() == host_name.length() | 333 || dns_names[i].length() == host_name.length() |
335 || !(IsHostNameKnownTLD(dns_names[i]))) { | 334 || !(IsHostNameKnownTLD(dns_names[i]))) { |
336 result = result || false; | 335 continue; |
337 } else if (dns_names[i].length() > host_name.length()) { | 336 } else if (dns_names[i].length() > host_name.length()) { |
338 result = result || | 337 if (net::StripWWW(base::ASCIIToUTF16(dns_names[i])) == |
339 net::StripWWW(base::ASCIIToUTF16(dns_names[i])) == | 338 base::ASCIIToUTF16(host_name)) { |
340 base::ASCIIToUTF16(host_name); | 339 www_match_host_name->assign(dns_names[i].data(), dns_names[i].size()); |
340 return true; | |
341 } | |
341 } else { | 342 } else { |
342 result = result || | 343 if (net::StripWWW(base::ASCIIToUTF16(host_name)) == |
343 net::StripWWW(base::ASCIIToUTF16(host_name)) == | 344 base::ASCIIToUTF16(dns_names[i])) { |
344 base::ASCIIToUTF16(dns_names[i]); | 345 www_match_host_name->assign(dns_names[i].data(), dns_names[i].size()); |
346 return true; | |
347 } | |
345 } | 348 } |
346 } | 349 } |
347 return result; | |
348 } | 350 } |
349 return false; | 351 return false; |
350 } | 352 } |
351 | 353 |
354 bool SSLErrorClassification::IsWWWSubDomainMatch() const { | |
355 std::string host_name = request_url_.host(); | |
palmer
2015/07/17 00:16:00
Use a const std::string& here, for const-correctne
Bhanu Dev
2015/07/23 20:11:06
Done.
| |
356 std::vector<std::string> dns_names; | |
357 cert_.GetDNSNames(&dns_names); | |
358 std::string www_host; | |
359 return GetWWWSubDomainMatch(host_name, dns_names, &www_host); | |
360 } | |
361 | |
352 bool SSLErrorClassification::NameUnderAnyNames( | 362 bool SSLErrorClassification::NameUnderAnyNames( |
353 const Tokens& child, | 363 const Tokens& child, |
354 const std::vector<Tokens>& potential_parents) const { | 364 const std::vector<Tokens>& potential_parents) const { |
355 bool result = false; | 365 bool result = false; |
356 // Need to account for all the possible domains given in the SSL certificate. | 366 // Need to account for all the possible domains given in the SSL certificate. |
357 for (size_t i = 0; i < potential_parents.size(); ++i) { | 367 for (size_t i = 0; i < potential_parents.size(); ++i) { |
358 if (potential_parents[i].empty() || | 368 if (potential_parents[i].empty() || |
359 potential_parents[i].size() >= child.size()) { | 369 potential_parents[i].size() >= child.size()) { |
360 result = result || false; | 370 result = result || false; |
361 } else { | 371 } else { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 // sure we don't clear the captive protal flag, since the interstitial was | 503 // sure we don't clear the captive protal flag, since the interstitial was |
494 // potentially caused by the captive portal. | 504 // potentially caused by the captive portal. |
495 captive_portal_detected_ = captive_portal_detected_ || | 505 captive_portal_detected_ = captive_portal_detected_ || |
496 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); | 506 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
497 // Also keep track of non-HTTP portals and error cases. | 507 // Also keep track of non-HTTP portals and error cases. |
498 captive_portal_no_response_ = captive_portal_no_response_ || | 508 captive_portal_no_response_ = captive_portal_no_response_ || |
499 (results->result == captive_portal::RESULT_NO_RESPONSE); | 509 (results->result == captive_portal::RESULT_NO_RESPONSE); |
500 } | 510 } |
501 #endif | 511 #endif |
502 } | 512 } |
OLD | NEW |