| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/safe_browsing/browser_feature_extractor.h" | 5 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "base/task.h" | 12 #include "base/task.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "chrome/common/safe_browsing/csd.pb.h" | 14 #include "chrome/common/safe_browsing/csd.pb.h" |
| 15 #include "chrome/browser/history/history.h" | 15 #include "chrome/browser/history/history.h" |
| 16 #include "chrome/browser/history/history_types.h" | 16 #include "chrome/browser/history/history_types.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/safe_browsing/browser_features.h" | |
| 19 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 18 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
| 20 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | |
| 21 #include "content/common/page_transition_types.h" | 19 #include "content/common/page_transition_types.h" |
| 22 #include "content/browser/browser_thread.h" | 20 #include "content/browser/browser_thread.h" |
| 23 #include "content/browser/cancelable_request.h" | 21 #include "content/browser/cancelable_request.h" |
| 24 #include "content/browser/tab_contents/tab_contents.h" | 22 #include "content/browser/tab_contents/tab_contents.h" |
| 25 #include "crypto/sha2.h" | |
| 26 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
| 27 | 24 |
| 28 namespace safe_browsing { | 25 namespace safe_browsing { |
| 26 namespace features { |
| 27 const char kUrlHistoryVisitCount[] = "UrlHistoryVisitCount"; |
| 28 const char kUrlHistoryTypedCount[] = "UrlHistoryTypedCount"; |
| 29 const char kUrlHistoryLinkCount[] = "UrlHistoryLinkCount"; |
| 30 const char kUrlHistoryVisitCountMoreThan24hAgo[] = |
| 31 "UrlHistoryVisitCountMoreThan24hAgo"; |
| 32 const char kHttpHostVisitCount[] = "HttpHostVisitCount"; |
| 33 const char kHttpsHostVisitCount[] = "HttpsHostVisitCount"; |
| 34 const char kFirstHttpHostVisitMoreThan24hAgo[] = |
| 35 "FirstHttpHostVisitMoreThan24hAgo"; |
| 36 const char kFirstHttpsHostVisitMoreThan24hAgo[] = |
| 37 "FirstHttpsHostVisitMoreThan24hAgo"; |
| 29 | 38 |
| 30 const int BrowserFeatureExtractor::kSuffixPrefixHashLength = 5; | 39 const char kHostPrefix[] = "Host"; |
| 40 const char kRedirectPrefix[] = "Redirect"; |
| 41 const char kReferrer[] = "Referrer"; |
| 42 const char kHasSSLReferrer[] = "HasSSLReferrer"; |
| 43 const char kPageTransitionType[] = "PageTransitionType"; |
| 44 const char kIsFirstNavigation[] = "IsFirstNavigation"; |
| 45 const char kBadIpFetch[] = "BadIpFetch="; |
| 46 const char kSafeBrowsingMaliciousUrl[] = "SafeBrowsingMaliciousUrl="; |
| 47 const char kSafeBrowsingOriginalUrl[] = "SafeBrowsingOriginalUrl="; |
| 48 const char kSafeBrowsingIsSubresource[] = "SafeBrowsingIsSubresource"; |
| 49 const char kSafeBrowsingThreatType[] = "SafeBrowsingThreatType"; |
| 50 } // namespace features |
| 31 | 51 |
| 32 BrowseInfo::BrowseInfo() {} | 52 BrowseInfo::BrowseInfo() {} |
| 33 | 53 |
| 34 BrowseInfo::~BrowseInfo() {} | 54 BrowseInfo::~BrowseInfo() {} |
| 35 | 55 |
| 36 static void AddFeature(const std::string& feature_name, | 56 static void AddFeature(const std::string& feature_name, |
| 37 double feature_value, | 57 double feature_value, |
| 38 ClientPhishingRequest* request) { | 58 ClientPhishingRequest* request) { |
| 39 DCHECK(request); | 59 DCHECK(request); |
| 40 ClientPhishingRequest::Feature* feature = | 60 ClientPhishingRequest::Feature* feature = |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 controller, | 204 controller, |
| 185 first_host_index, | 205 first_host_index, |
| 186 request); | 206 request); |
| 187 PossiblyAddRedirectNavigationFeatures(features::kHostPrefix, | 207 PossiblyAddRedirectNavigationFeatures(features::kHostPrefix, |
| 188 controller, | 208 controller, |
| 189 first_host_index, | 209 first_host_index, |
| 190 request); | 210 request); |
| 191 } | 211 } |
| 192 | 212 |
| 193 ExtractBrowseInfoFeatures(*info, request); | 213 ExtractBrowseInfoFeatures(*info, request); |
| 194 ComputeURLHash(request); | |
| 195 pending_extractions_.insert(std::make_pair(request, callback)); | 214 pending_extractions_.insert(std::make_pair(request, callback)); |
| 196 MessageLoop::current()->PostTask( | 215 MessageLoop::current()->PostTask( |
| 197 FROM_HERE, | 216 FROM_HERE, |
| 198 method_factory_.NewRunnableMethod( | 217 method_factory_.NewRunnableMethod( |
| 199 &BrowserFeatureExtractor::StartExtractFeatures, | 218 &BrowserFeatureExtractor::StartExtractFeatures, |
| 200 request, callback)); | 219 request, callback)); |
| 201 } | 220 } |
| 202 | 221 |
| 203 void BrowserFeatureExtractor::ExtractBrowseInfoFeatures( | 222 void BrowserFeatureExtractor::ExtractBrowseInfoFeatures( |
| 204 const BrowseInfo& info, | 223 const BrowseInfo& info, |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 Profile* profile = Profile::FromBrowserContext(tab_->browser_context()); | 456 Profile* profile = Profile::FromBrowserContext(tab_->browser_context()); |
| 438 *history = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); | 457 *history = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 439 if (*history) { | 458 if (*history) { |
| 440 return true; | 459 return true; |
| 441 } | 460 } |
| 442 } | 461 } |
| 443 VLOG(2) << "Unable to query history. No history service available."; | 462 VLOG(2) << "Unable to query history. No history service available."; |
| 444 return false; | 463 return false; |
| 445 } | 464 } |
| 446 | 465 |
| 447 void BrowserFeatureExtractor::ComputeURLHash( | |
| 448 ClientPhishingRequest* request) { | |
| 449 // Put the url into SafeBrowsing host suffix / path prefix format, with | |
| 450 // query parameters stripped. | |
| 451 std::string host, path, query; | |
| 452 safe_browsing_util::CanonicalizeUrl(GURL(request->url()), | |
| 453 &host, &path, &query); | |
| 454 DCHECK(!host.empty()) << request->url(); | |
| 455 DCHECK(!path.empty()) << request->url(); | |
| 456 request->set_suffix_prefix_hash( | |
| 457 crypto::SHA256HashString(host + path).substr( | |
| 458 0, kSuffixPrefixHashLength)); | |
| 459 } | |
| 460 | |
| 461 }; // namespace safe_browsing | 466 }; // namespace safe_browsing |
| OLD | NEW |