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 servers for | 5 // Helper class which handles communication with the SafeBrowsing servers for |
6 // improved binary download protection. | 6 // improved binary download protection. |
7 | 7 |
8 #ifndef CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ | 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ |
9 #define CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ | 9 #define CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ |
10 #pragma once | 10 #pragma once |
11 | 11 |
12 #include <set> | 12 #include <set> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/callback.h" | 17 #include "base/callback.h" |
18 #include "base/file_path.h" | 18 #include "base/file_path.h" |
19 #include "base/gtest_prod_util.h" | 19 #include "base/gtest_prod_util.h" |
20 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
22 | 22 |
23 class DownloadItem; | 23 class DownloadItem; |
24 class SafeBrowsingService; | 24 class SafeBrowsingService; |
25 | 25 |
26 namespace net { | 26 namespace net { |
27 class URLRequestContextGetter; | 27 class URLRequestContextGetter; |
| 28 class X509Certificate; |
28 } // namespace net | 29 } // namespace net |
29 | 30 |
30 namespace safe_browsing { | 31 namespace safe_browsing { |
31 class SignatureUtil; | 32 class SignatureUtil; |
32 | 33 |
33 // This class provides an asynchronous API to check whether a particular | 34 // This class provides an asynchronous API to check whether a particular |
34 // client download is malicious or not. | 35 // client download is malicious or not. |
35 class DownloadProtectionService { | 36 class DownloadProtectionService { |
36 public: | 37 public: |
37 // TODO(noelutz): we're missing some fields here: server IPs, | 38 // TODO(noelutz): we're missing some fields here: server IPs, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 class CheckClientDownloadRequest; // Per-request state | 133 class CheckClientDownloadRequest; // Per-request state |
133 friend class DownloadProtectionServiceTest; | 134 friend class DownloadProtectionServiceTest; |
134 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, | 135 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, |
135 CheckClientDownloadValidateRequest); | 136 CheckClientDownloadValidateRequest); |
136 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, | 137 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, |
137 CheckClientDownloadSuccess); | 138 CheckClientDownloadSuccess); |
138 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, | 139 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, |
139 CheckClientDownloadFetchFailed); | 140 CheckClientDownloadFetchFailed); |
140 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, | 141 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, |
141 TestDownloadRequestTimeout); | 142 TestDownloadRequestTimeout); |
142 | |
143 static const char kDownloadRequestUrl[]; | 143 static const char kDownloadRequestUrl[]; |
144 | 144 |
145 // Cancels all requests in |download_requests_|, and empties it, releasing | 145 // Cancels all requests in |download_requests_|, and empties it, releasing |
146 // the references to the requests. | 146 // the references to the requests. |
147 void CancelPendingRequests(); | 147 void CancelPendingRequests(); |
148 | 148 |
149 // Called by a CheckClientDownloadRequest instance when it finishes, to | 149 // Called by a CheckClientDownloadRequest instance when it finishes, to |
150 // remove it from |download_requests_|. | 150 // remove it from |download_requests_|. |
151 void RequestFinished(CheckClientDownloadRequest* request); | 151 void RequestFinished(CheckClientDownloadRequest* request); |
152 | 152 |
153 static void FillDownloadInfo(const DownloadItem& item, | 153 static void FillDownloadInfo(const DownloadItem& item, |
154 DownloadInfo* download_info); | 154 DownloadInfo* download_info); |
155 | 155 |
| 156 // Given a certificate and its immediate issuer certificate, generates the |
| 157 // list of strings that need to be checked against the download whitelist to |
| 158 // determine whether the certificate is whitelisted. |
| 159 static void GetCertificateWhitelistStrings( |
| 160 const net::X509Certificate& certificate, |
| 161 const net::X509Certificate& issuer, |
| 162 std::vector<std::string>* whitelist_strings); |
| 163 |
156 // This pointer may be NULL if SafeBrowsing is disabled. The | 164 // This pointer may be NULL if SafeBrowsing is disabled. The |
157 // SafeBrowsingService owns us, so we don't need to hold a reference to it. | 165 // SafeBrowsingService owns us, so we don't need to hold a reference to it. |
158 SafeBrowsingService* sb_service_; | 166 SafeBrowsingService* sb_service_; |
159 | 167 |
160 // The context we use to issue network requests. | 168 // The context we use to issue network requests. |
161 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 169 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
162 | 170 |
163 // Map of client download request to the corresponding callback that | 171 // Map of client download request to the corresponding callback that |
164 // has to be invoked when the request is done. This map contains all | 172 // has to be invoked when the request is done. This map contains all |
165 // pending server requests. | 173 // pending server requests. |
166 std::set<scoped_refptr<CheckClientDownloadRequest> > download_requests_; | 174 std::set<scoped_refptr<CheckClientDownloadRequest> > download_requests_; |
167 | 175 |
168 // Keeps track of the state of the service. | 176 // Keeps track of the state of the service. |
169 bool enabled_; | 177 bool enabled_; |
170 | 178 |
171 // SignatureUtil object, may be overridden for testing. | 179 // SignatureUtil object, may be overridden for testing. |
172 scoped_refptr<SignatureUtil> signature_util_; | 180 scoped_refptr<SignatureUtil> signature_util_; |
173 | 181 |
174 int64 download_request_timeout_ms_; | 182 int64 download_request_timeout_ms_; |
175 | 183 |
176 DISALLOW_COPY_AND_ASSIGN(DownloadProtectionService); | 184 DISALLOW_COPY_AND_ASSIGN(DownloadProtectionService); |
177 }; | 185 }; |
178 } // namespace safe_browsing | 186 } // namespace safe_browsing |
179 | 187 |
180 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ | 188 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ |
OLD | NEW |