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

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_tamper_detect.h

Issue 338483002: Chrome Participated Tamper Detect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 // This file implements the tamper detection logic, which detects whether
6 // there are middleboxes and whether they are tampering with the response
7 // which maybe break correct communication and data transfer between the
bengr 2014/07/28 21:56:49 maybe --> may
xingx1 2014/07/30 03:44:20 Done.
8 // Chromium client and the data reduction proxy.
9 //
10 // A high-level description of the tamper detection process works in two steps:
bengr 2014/07/28 21:56:50 Reword: "At a high level, the tamper detection pr
xingx1 2014/07/30 03:44:20 Done.
11 // 1. The data reduction proxy selects a fraction of responses to analyze;
bengr 2014/07/28 21:56:51 1. The data reduction proxy selects a fraction of
xingx1 2014/07/30 03:44:21 Done.
12 // for the selected ones, the data reduction proxy generates a series of
13 // fingerprints for the responses, and appends them to the Chrome-Proxy
14 // header;
15 // 2. At the Chromium client side, when the Chromium client sees such
16 // fingerprints, it uses the same method as the data reduction proxy to
17 // re-generate the fingerprints, and compares them to the fingerprints in
18 // the response, to see if the response has been tampered with and report to
19 // UMA.
20 //
21 // Four fingerprints are generated at the data reduction proxy side:
bengr 2014/07/28 21:56:49 Four fingerprints are generated by the proxy:
xingx1 2014/07/30 03:44:21 Done.
22 // 1. Fingerprint of the Chrome-Proxy header, which is designed to check
23 // whether the Chrome-Proxy header has been modified or not;
24 // 2. Fingerprint of the Via header, which is designed to check whether there
25 // are middleboxes between the Chromium client and the data reduction proxy;
26 // 3. Fingerprint of a list of headers, which is designed to check whether the
27 // values of a list of headers (list is defined by the data reduction proxy)
28 // have been modified or deleted;
29 // 4. Fingerprint of the Content-Length header, which is designed to check
30 // whether the response body has been modified or not (assume that different
bengr 2014/07/28 21:56:49 assume --> the code assumes value indicates --> va
xingx1 2014/07/30 03:44:20 Done.
31 // Content-Length value indicates different response body).
32 //
33 // At the Chromium client side, the fingerprint of the Chrome-Proxy header will
bengr 2014/07/28 21:56:51 At the Chromium client side -> On the client
xingx1 2014/07/30 03:44:20 Done.
34 // be checked first. If the fingerprint indicates that the Chrome-Proxy header
35 // has not been modified, then the other fingerprints will be considered to be
36 // reliable and will be checked next; if not, then it's possible that the other
37 // fingerprints have been tampered with and thus they will not be checked.
38 //
39 // Detected tampering information will be reported to UMA. In general, for each
bengr 2014/07/28 21:56:50 Do you also report when response have not been tam
xingx1 2014/07/30 03:44:20 Right now, no. But we have total number of "checke
40 // fingerprint, the Chromium client reports the number of responses that have
bengr 2014/07/28 21:56:49 Chromium client -> client
xingx1 2014/07/30 03:44:19 Done.
41 // been tampered with for different carriers. For the fingerprint of the
42 // Content-Length header, which indicates whether the response body has been
43 // modified or not, the reports of tampering are separated by MIME type of the
44 // response body.
45
46 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_TAMPER_DETE CTION_H_
47 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_TAMPER_DETE CTION_H_
48
49 #include <map>
50 #include <string>
51 #include <vector>
52
53 #include "net/proxy/proxy_service.h"
54
55 namespace net {
56 class HttpResponseHeaders;
57 }
58
59 namespace data_reduction_proxy {
60
61 // This class detects if the response sent by the data reduction proxy has been
bengr 2014/07/28 21:56:51 This class detects -> Detects the intermediaries -
xingx1 2014/07/30 03:44:20 Done.
62 // modified by the intermediaries on the Web.
63 class DataReductionProxyTamperDetection {
64 public:
65 // Checks if the response contains tamper detection fingerprints added by the
66 // data reduction proxy, and determines if the response had been tampered
67 // with if so. Results are reported to UMA. HTTP and HTTPS traffic are
68 // reported separately, specified by |is_secure_scheme|. Returns true if
69 // the response has been tampered with.
70 static bool DetectAndReport(const net::HttpResponseHeaders* header,
bengr 2014/07/28 21:56:51 header -> headers
xingx1 2014/07/30 03:44:19 Done.
71 bool is_secure_scheme);
bengr 2014/07/28 21:56:49 broken identation. This should be aligned with the
xingx1 2014/07/30 03:44:21 Done.
72
73 // Tamper detection checks |response_headers|. Histogram events are reported
74 // by |carrier_id|; |is_secure_scheme| determines which histogram to report
75 // (HTTP and HTTPS are reported separately). |chrome_proxy_header_values|
76 // points to the vector contains the values of the Chrome-Proxy header, but
bengr 2014/07/28 21:56:50 contains -> containing
xingx1 2014/07/30 03:44:20 Done.
77 // with the Chrome-Proxy header's fingerprint removed, which is a temporary
78 // result saved to use later to avoid parsing the header again.
79 DataReductionProxyTamperDetection(
80 const net::HttpResponseHeaders* response_headers,
81 bool is_secure_scheme,
82 unsigned carrier_id,
bengr 2014/07/28 21:56:50 Explain what a carrier id is.
xingx1 2014/07/30 03:44:20 Done.
83 std::vector<std::string>* chrome_proxy_header_values);
84
85 virtual ~DataReductionProxyTamperDetection();
bengr 2014/07/28 21:56:50 Constructors and destructors should come before ot
xingx1 2014/07/30 03:44:19 On 2014/07/28 21:56:50, bengr1 wrote: > Constructo
86
87 private:
88 friend class DataReductionProxyTamperDetectionTest;
bengr 2014/07/28 21:56:50 Why do you need this? Why isn't friending the spec
xingx1 2014/07/30 03:44:20 Previously I have a common function for testing al
89 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest,
90 TestFingerprintCommon);
91 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest,
92 ChromeProxy);
93 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest,
94 Via);
95 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest,
96 OtherHeaders);
97 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest,
98 ContentLength);
99 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest,
100 HeaderRemoving);
101 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest,
102 ValuesToSortedString);
103 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest,
104 GetHeaderValues);
105 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest,
106 Completed);
107
108 // Enum for fingerprint type.
109 enum FingerprintCode {
110 CHROMEPROXY = 1, /* Code of fingerprint of the Chrome-Proxy header */
bengr 2014/07/28 21:56:51 prefix all of these so there is no confusion. E.g.
xingx1 2014/07/30 03:44:20 Done.
111 VIA = 2, /* Code of fingerprint of the Via header */
112 OTHERHEADERS = 3, /* Code of fingerprint of a list of headers */
113 CONTENTLENGTH = 4, /* Code of fingerprint of the Content-Length header */
114 NONEXIST = 5,
bengr 2014/07/28 21:56:50 What does NONEEXIST mean? Also, rename these as F
xingx1 2014/07/30 03:44:21 Done.
115 };
116
117 // Returns true if the Chrome-Proxy header has been tampered with.
bengr 2014/07/28 21:56:50 Change the comment here and below if you change th
xingx1 2014/07/30 03:44:19 Done.
118 bool IsChromeProxyHeaderTampered(const std::string& fingerprint) const;
bengr 2014/07/28 21:56:50 This function and all similar ones need new names.
xingx1 2014/07/30 03:44:19 Done.
119 // Reports UMA for tampering of the Chrome-Proxy header.
120 void ReportChromeProxyHeaderTamperedUMA() const;
bengr 2014/07/28 21:56:50 rename as ReportUMAforChromeProxyHeaderValidation(
xingx1 2014/07/30 03:44:19 Done.
121
122 // Returns true if the Via header has been tampered with. |has_chrome_proxy|
123 // indicates that the data reduction proxy's Via header occurs or not.
124 bool IsViaHeaderTampered(const std::string& fingerprint,
125 bool* has_chrome_proxy_via_header) const;
126 // Reports UMA for tampering of the Via header.
127 void ReportViaHeaderTamperedUMA(bool has_chrome_proxy_via_header) const;
128
129 // Returns true if a list of headers have been tampered with.
130 bool AreOtherHeadersTampered(const std::string& fingerprint) const;
131 // Reports UMA for tampering of values of the list of headers.
132 void ReportOtherHeadersTamperedUMA() const;
133
134 // Returns true if the Content-Length header has been tampered with.
135 bool IsContentLengthHeaderTampered(const std::string& fingerprint) const;
136 // Reports UMA for tampering of the Content-Length header.
137 void ReportContentLengthHeaderTamperedUMA() const;
138
139 // Returns the fingerprint code (enum) for the given fingerprint name.
140 FingerprintCode GetFingerprintCode(const std::string& fingerprint_name);
141
142 // Removes the fingerprint of the Chrome-Proxy header from the Chrome-Proxy
143 // header's |values| vector. The data reduction proxy calculates the
144 // fingerprint for the Chrome-Proxy header and then appends calculated
145 // fingerprint to the Chrome-Proxy header, so at the Chromium client side,
bengr 2014/07/28 21:56:49 at the Chromium client --> on the client
xingx1 2014/07/30 03:44:20 Done.
146 // to re-generate the fingerprint, the Chrome-Proxy header's fingerprint value
147 // needs to be removed from the Chrome-Proxy header first.
148 static void RemoveChromeProxyFingerprint(std::vector<std::string>* values);
bengr 2014/07/28 21:56:51 can this method be const?
xingx1 2014/07/30 03:44:21 Acknowledged.
149
150 // Returns a string representation of |values|.
151 static std::string ValuesToSortedString(std::vector<std::string>* values);
bengr 2014/07/28 21:56:50 can this method be const?
xingx1 2014/07/30 03:44:20 Acknowledged.
152
153 // Returns raw MD5 hash value for a given string |input|. It is different to
154 // base::MD5String which is base16 encoded.
155 static std::string GetMD5(const std::string& input);
bengr 2014/07/28 21:56:50 can this method be const?
xingx1 2014/07/30 03:44:21 Acknowledged.
156
157 // Returns all the values of |header_name| of the response |headers| as a
158 // vector. This function is used for values that need to be sorted later.
159 static std::vector<std::string> GetHeaderValues(
160 const net::HttpResponseHeaders* headers,
161 const std::string& header_name);
162
163 // Pointer to response headers.
164 const net::HttpResponseHeaders* response_headers_;
165
166 // If true, the connection to the data reduction proxy is over HTTPS;
167 const bool is_secure_scheme_;
bengr 2014/07/28 21:56:51 can you just be more explicit and rename this sche
xingx1 2014/07/30 03:44:19 Done.
168
169 // Carrier ID.
170 const unsigned carrier_id_;
171
172 // Values of the Chrome-Proxy header, with fingerprint of the Chrome-Proxy
173 // header value removed. Save it as a temporary result to avoid parsing the
bengr 2014/07/28 21:56:49 I don't understand this comment. Do you mean: The
xingx1 2014/07/30 03:44:19 Exactly! Done.
174 // Chrome-Proxy header again.
175 std::vector<std::string>* clean_chrome_proxy_header_values_;
176
177 // Maps a fingerprint name (string) to a fingerprint code (enum).
bengr 2014/07/28 21:56:50 Why? What uses this?
xingx1 2014/07/30 03:44:20 Removed. Right now using three IF instead of SWITC
178 std::map<std::string, FingerprintCode> fingerprint_name_code_map_;
179 };
180
bengr 2014/07/28 21:56:49 DISALLOW_COPY_AND_ASSIGN
xingx1 2014/07/30 03:44:20 Done.
181 } // namespace data_reduction_proxy
182 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_TAMPER_D ETECTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698