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 // Helper class which handles communication with the SafeBrowsing backends for | 5 // Helper class which handles communication with the SafeBrowsing backends for |
6 // client-side phishing detection. This class is used to fetch the client-side | 6 // client-side phishing detection. This class is used to fetch the client-side |
7 // model and send it to all renderers. This class is also used to send a ping | 7 // model and send it to all renderers. This class is also used to send a ping |
8 // back to Google to verify if a particular site is really phishing or not. | 8 // back to Google to verify if a particular site is really phishing or not. |
9 // | 9 // |
10 // This class is not thread-safe and expects all calls to be made on the UI | 10 // This class is not thread-safe and expects all calls to be made on the UI |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // Enum used to keep stats about why we fail to get the client model. | 123 // Enum used to keep stats about why we fail to get the client model. |
124 enum ClientModelStatus { | 124 enum ClientModelStatus { |
125 MODEL_SUCCESS, | 125 MODEL_SUCCESS, |
126 MODEL_NOT_CHANGED, | 126 MODEL_NOT_CHANGED, |
127 MODEL_FETCH_FAILED, | 127 MODEL_FETCH_FAILED, |
128 MODEL_EMPTY, | 128 MODEL_EMPTY, |
129 MODEL_TOO_LARGE, | 129 MODEL_TOO_LARGE, |
130 MODEL_PARSE_ERROR, | 130 MODEL_PARSE_ERROR, |
131 MODEL_MISSING_FIELDS, | 131 MODEL_MISSING_FIELDS, |
132 MODEL_INVALID_VERSION_NUMBER, | 132 MODEL_INVALID_VERSION_NUMBER, |
| 133 MODEL_BAD_HASH_IDS, |
133 MODEL_STATUS_MAX // Always add new values before this one. | 134 MODEL_STATUS_MAX // Always add new values before this one. |
134 }; | 135 }; |
135 | 136 |
136 // Starts fetching the model from the network or the cache. This method | 137 // Starts fetching the model from the network or the cache. This method |
137 // is called periodically to check whether a new client model is available | 138 // is called periodically to check whether a new client model is available |
138 // for download. | 139 // for download. |
139 void StartFetchModel(); | 140 void StartFetchModel(); |
140 | 141 |
141 // This method is called when we're done fetching the model either because | 142 // This method is called when we're done fetching the model either because |
142 // we hit an error somewhere or because we're actually done fetch and | 143 // we hit an error somewhere or because we're actually done fetch and |
143 // validating the model. | 144 // validating the model. |
144 virtual void EndFetchModel(ClientModelStatus status); // Virtual for testing. | 145 virtual void EndFetchModel(ClientModelStatus status); // Virtual for testing. |
145 | 146 |
146 private: | 147 private: |
147 friend class ClientSideDetectionServiceTest; | 148 friend class ClientSideDetectionServiceTest; |
148 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, FetchModelTest); | 149 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, FetchModelTest); |
149 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, SetBadSubnets); | 150 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, SetBadSubnets); |
150 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, IsBadIpAddress); | 151 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, IsBadIpAddress); |
| 152 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, |
| 153 ModelHasValidHashIds); |
151 | 154 |
152 // CacheState holds all information necessary to respond to a caller without | 155 // CacheState holds all information necessary to respond to a caller without |
153 // actually making a HTTP request. | 156 // actually making a HTTP request. |
154 struct CacheState { | 157 struct CacheState { |
155 bool is_phishing; | 158 bool is_phishing; |
156 base::Time timestamp; | 159 base::Time timestamp; |
157 | 160 |
158 CacheState(bool phish, base::Time time); | 161 CacheState(bool phish, base::Time time); |
159 }; | 162 }; |
160 typedef std::map<GURL, linked_ptr<CacheState> > PhishingCache; | 163 typedef std::map<GURL, linked_ptr<CacheState> > PhishingCache; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 220 |
218 // Same as above but sends the model to all rendereres. | 221 // Same as above but sends the model to all rendereres. |
219 void SendModelToRenderers(); | 222 void SendModelToRenderers(); |
220 | 223 |
221 // Reads the bad subnets from the client model and inserts them into | 224 // Reads the bad subnets from the client model and inserts them into |
222 // |bad_subnets| for faster lookups. This method is static to simplify | 225 // |bad_subnets| for faster lookups. This method is static to simplify |
223 // testing. | 226 // testing. |
224 static void SetBadSubnets(const ClientSideModel& model, | 227 static void SetBadSubnets(const ClientSideModel& model, |
225 BadSubnetMap* bad_subnets); | 228 BadSubnetMap* bad_subnets); |
226 | 229 |
| 230 |
| 231 // Returns true iff all the hash id's in the client-side model point to |
| 232 // valid hashes in the model. |
| 233 static bool ModelHasValidHashIds(const ClientSideModel& model); |
| 234 |
227 std::string model_str_; | 235 std::string model_str_; |
228 scoped_ptr<ClientSideModel> model_; | 236 scoped_ptr<ClientSideModel> model_; |
229 scoped_ptr<base::TimeDelta> model_max_age_; | 237 scoped_ptr<base::TimeDelta> model_max_age_; |
230 scoped_ptr<URLFetcher> model_fetcher_; | 238 scoped_ptr<URLFetcher> model_fetcher_; |
231 | 239 |
232 // Map of client report phishing request to the corresponding callback that | 240 // Map of client report phishing request to the corresponding callback that |
233 // has to be invoked when the request is done. | 241 // has to be invoked when the request is done. |
234 struct ClientReportInfo; | 242 struct ClientReportInfo; |
235 std::map<const URLFetcher*, ClientReportInfo*> client_phishing_reports_; | 243 std::map<const URLFetcher*, ClientReportInfo*> client_phishing_reports_; |
236 | 244 |
(...skipping 24 matching lines...) Expand all Loading... |
261 // this map to speed up lookups. | 269 // this map to speed up lookups. |
262 BadSubnetMap bad_subnets_; | 270 BadSubnetMap bad_subnets_; |
263 | 271 |
264 NotificationRegistrar registrar_; | 272 NotificationRegistrar registrar_; |
265 | 273 |
266 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService); | 274 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService); |
267 }; | 275 }; |
268 } // namepsace safe_browsing | 276 } // namepsace safe_browsing |
269 | 277 |
270 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_ | 278 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_ |
OLD | NEW |