Chromium Code Reviews| OLD | NEW |
|---|---|
| (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, where we want to detect | |
| 6 // whether there are middleboxes and whether they are tampering the response | |
|
bengr
2014/07/16 21:24:49
with the response
xingx
2014/07/18 17:25:02
Done.
| |
| 7 // which maybe break correct communication and data transfer between Chrome | |
|
bengr
2014/07/16 21:24:48
Chrome -> a Chromium client
xingx
2014/07/18 17:25:03
Done.
| |
| 8 // and the data reduction proxy. | |
| 9 // | |
| 10 // A high-level description of our tamper detection process works in two steps: | |
| 11 // 1. The data reduction proxy selects the requests we want to detect tamper; | |
|
bengr
2014/07/16 21:24:49
detect tamper -> analyze
xingx
2014/07/18 17:25:02
Done.
| |
| 12 // for the selected ones, the data reduction proxy generates a series of | |
| 13 // fingerprints for the response , and appends it to the Chrome-Proxy header; | |
|
bengr
2014/07/16 21:24:49
response , --> response,
xingx
2014/07/18 17:25:03
Done.
| |
| 14 // 2. At Chrome client side, when Chrome sees such fingerprints, it uses the | |
|
bengr
2014/07/16 21:24:48
At Chrome client side, when Chrome sees such finge
xingx
2014/07/18 17:25:02
Done.
xingx
2014/07/18 17:25:03
Done.
| |
| 15 // same method as the data reduction proxy to generate the fingerprints, and | |
|
bengr
2014/07/16 21:24:49
generate --> re-generate
xingx
2014/07/18 17:25:03
Done.
| |
| 16 // compares them to the fingerprints in the response, to see if there is any | |
| 17 // tamper detected. | |
|
bengr
2014/07/16 21:24:49
there is any tamper detected -> the response has b
xingx
2014/07/18 17:25:02
Done.
| |
| 18 // | |
| 19 // Four fingerprints are defined (listed below). Chrome first checks the | |
|
bengr
2014/07/16 21:24:49
Chrome first checks --> The fingerprint of the Chr
xingx
2014/07/18 17:25:02
Done.
| |
| 20 // fingerprint of the Chrome-Proxy header. If the Chrome-Proxy header has been | |
| 21 // tampered, then other fingerprints would not be checked; if not, Chrome | |
|
bengr
2014/07/16 21:24:49
tampered with
xingx
2014/07/18 17:25:03
Done.
| |
| 22 // parses the rest of the fingerprints and checks whether there is tampering | |
| 23 // on each of them. | |
|
bengr
2014/07/16 21:24:49
Tamper is a strange word. You might want to stop u
xingx
2014/07/18 17:25:02
Done.
| |
| 24 // | |
| 25 // 1. Fingerprint for Chrome-Proxy header checks whether values of Chrome-Proxy | |
| 26 // have been tampered with; | |
| 27 // 2. Fingerprint for Via header checks whether there are middleboxes between | |
| 28 // Chrome and the data reduction proxy; | |
| 29 // 3. Fingerprint for some other headers checks whether the values of a list of | |
| 30 // headers (defined by the data reduction proxy) have been tampered with; | |
| 31 // 4. Fingerprint for Content-Length header checks whether the value of | |
| 32 // Content-Length is different to what the data reduction proxy sends, which | |
| 33 // indicates that the response body has been tampered with. | |
| 34 // | |
| 35 // Chrome reports tampered information for each fingerprint to UMA. In general, | |
|
bengr
2014/07/16 21:24:48
Again, not Chrome, and use of tampered is awkward.
xingx
2014/07/18 17:25:03
Done.
| |
| 36 // Chrome reports the number of tampers for each fingerprint on different | |
| 37 // carriers, as well as total number of tamper detection handled. The only | |
| 38 // special case is the 4th fingerprint, Content-Length, which we have another | |
| 39 // dimension, MIME types, Chrome reports the tamper on different MIME type | |
|
bengr
2014/07/16 21:24:49
You can use phrases like "tamper detection", "tamp
xingx
2014/07/18 17:25:03
Done.
| |
| 40 // independently. | |
| 41 | |
| 42 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_TAMPER_DETE CTION_H_ | |
| 43 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_TAMPER_DETE CTION_H_ | |
| 44 | |
| 45 #include <string> | |
|
bengr
2014/07/16 21:24:48
#include <map>
xingx
2014/07/18 17:25:02
Done.
| |
| 46 #include <vector> | |
| 47 | |
| 48 #include "net/proxy/proxy_service.h" | |
| 49 | |
| 50 namespace net { | |
| 51 class HttpResponseHeaders; | |
| 52 } | |
| 53 | |
| 54 namespace data_reduction_proxy { | |
| 55 | |
| 56 // This class detects if response header information sent by the data reduction | |
| 57 // proxy has been modified or deleted by intermediaries on the Web. | |
| 58 class DataReductionProxyTamperDetection { | |
| 59 public: | |
| 60 | |
|
bengr
2014/07/16 21:24:49
remove blank line
xingx
2014/07/18 17:25:02
Done.
| |
| 61 // Checks if the response contains tamper detection fingerprints added by the | |
| 62 // data reduction proxy, and determines if the response had been tampered | |
| 63 // with if so. Results are reported to UMA. HTTP and HTTPS traffic would be | |
|
bengr
2014/07/16 21:24:49
would be -> are
xingx
2014/07/18 17:25:03
Done.
| |
| 64 // reported independently, specified by |is_secure_scheme|. | |
| 65 static void CheckResponseFingerprint(const net::HttpResponseHeaders* header, | |
| 66 bool is_secure_scheme); | |
| 67 | |
| 68 // Tamper detection checks the response |respose_headers|. |is_secure_scheme| | |
|
bengr
2014/07/16 21:24:49
checks the response |response_headers| --> checks
xingx
2014/07/18 17:25:03
Done.
| |
| 69 // and |carrier_id| are parameters specify correct UMA histogram to report. | |
|
bengr
2014/07/16 21:24:49
I don't understand this sentence.
xingx
2014/07/18 17:25:02
Done.
| |
| 70 // |chrome_proxy_header_values| points to the vector contains the values of | |
| 71 // Chrome-Proxy header, but with Chrome-Proxy header's fingerprint removed, | |
| 72 // which is an temporary result saved to use later for avoiding parsing the | |
|
bengr
2014/07/16 21:24:49
a temporary
Also, I don't understand this sentenc
xingx
2014/07/18 17:25:02
Done.
| |
| 73 // header twice. | |
| 74 DataReductionProxyTamperDetection( | |
| 75 const net::HttpResponseHeaders* response_headers, | |
| 76 bool is_secure_scheme, | |
| 77 unsigned carrier_id, | |
| 78 std::vector<std::string>* chrome_proxy_header_values); | |
| 79 | |
| 80 virtual ~DataReductionProxyTamperDetection(); | |
| 81 | |
| 82 private: | |
| 83 friend class DataReductionProxyTamperDetectTest; | |
| 84 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
| 85 TestFingerprintCommon); | |
| 86 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
| 87 ChromeProxy); | |
| 88 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
| 89 Via); | |
| 90 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
| 91 OtherHeaders); | |
| 92 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
| 93 ContentLength); | |
| 94 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
| 95 Parsing); | |
| 96 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
| 97 Completed); | |
| 98 | |
| 99 // Enum for fingerprint type. | |
| 100 enum FingerprintCode { | |
| 101 CHROMEPROXY, // 1. Code of fingerprint for Chrome-Proxy header. | |
|
bengr
2014/07/16 21:24:49
Give these explicit values, e.g.,:
CHROMEPROXY = 1
xingx
2014/07/18 17:25:02
Done.
xingx
2014/07/18 17:25:03
Done.
| |
| 102 VIA, // 2. Code of fingerprint for Via header. | |
| 103 OTHERHEADERS, // 3. Code of fingerprint for a list of headers. | |
| 104 CONTENTLENGTH, // 4. Code of fingerprint for Content-Length header. | |
| 105 NONEXIST, | |
| 106 }; | |
| 107 | |
| 108 // Returns true if the Chrome-Proxy header has been tampered with. | |
| 109 bool IsChromeProxyHeaderTampered(const std::string& fingerprint) const; | |
| 110 // Reports UMA for tampering of the Chrome-Proxy header. | |
| 111 void ReportChromeProxyHeaderTamperedUMA() const; | |
| 112 | |
| 113 // Returns true if the Via header has been tampered with. | |
| 114 bool IsViaHeaderTampered(const std::string& fingerprint) const; | |
| 115 // Reports UMA for tampering of the Via header. | |
| 116 void ReportViaHeaderTamperedUMA() const; | |
| 117 | |
| 118 // Returns true if a list of headers have been tampered with. | |
| 119 bool AreOtherHeadersTampered(const std::string& fingerprint) const; | |
| 120 // Reports UMA for tampering of values of the list of headers. | |
| 121 void ReportOtherHeadersTamperedUMA() const; | |
| 122 | |
| 123 // Returns true if the Content-Length header has been tampered with. | |
| 124 bool IsContentLengthHeaderTampered(const std::string& fingerprint) const; | |
| 125 // Reports UMA for tampering of the Content-Length header. | |
| 126 void ReportContentLengthHeaderTamperedUMA() const; | |
| 127 | |
| 128 // Returns the fingerprint code (enum) for the given fingerprint tag. | |
| 129 FingerprintCode GetFingerprintCode(const std::string& fingerprint_tag); | |
| 130 | |
| 131 // Checks whether values of a Chrome-Proxy header contain fingerprints added | |
| 132 // by the data reduction proxy (four fingerprints will be added as two action | |
| 133 // value pairs, one is the fingerprint for Chrome-Proxy header, the other | |
| 134 // concatenates other fingerprints together). If they do, returns true, and | |
| 135 // saves the Chrome-Proxy header's fingerprint to |chrome_proxy_fingerprint|, | |
| 136 // saves other fingerprints to |other_fingerprints|; also removes fingerprint | |
| 137 // for Chrome-Proxy header from |values| and saves it as temporary result for | |
| 138 // later use. Return false if there is no fingerprint found. | |
| 139 static bool GetTamperDetectionFingerprints( | |
| 140 std::vector<std::string>* values, | |
| 141 std::string* chrome_proxy_fingerprint, | |
| 142 std::string* other_fingerprints); | |
| 143 | |
| 144 // Returns a string of sorted values of |values|. | |
| 145 static std::string ValuesToSortedString( | |
| 146 std::vector<std::string>* values); | |
| 147 | |
| 148 // Returns raw MD5 hash value for a given string |input|. It is different to | |
| 149 // base::MD5String which is base16 encoded. | |
| 150 static std::string GetMD5(const std::string& input); | |
| 151 | |
| 152 // Returns all the values of a header field |header_name| of the response | |
| 153 // header |headers|, as a vector. This function is used for values that need | |
| 154 // to be sorted later. | |
| 155 static std::vector<std::string> GetHeaderValues( | |
| 156 const net::HttpResponseHeaders* headers, | |
| 157 const std::string& header_name); | |
| 158 | |
| 159 // Pointer to response headers. | |
| 160 const net::HttpResponseHeaders* response_headers_; | |
| 161 | |
| 162 // If true, the connection to the data reduction proxy is over HTTPS; | |
| 163 const bool is_secure_scheme_; | |
| 164 | |
| 165 // Carrier ID. | |
| 166 const unsigned carrier_id_; | |
| 167 | |
| 168 // Values for Chrome-Proxy header, with fingerprint for Chrome-Proxy header | |
| 169 // value removed. Save it as a temporary result so we don't need to parse | |
| 170 // the Chrome-Proxy header twice. | |
| 171 std::vector<std::string>* clean_chrome_proxy_header_values_; | |
| 172 | |
| 173 // Map a fingerprint tag (string) to a fingerprint code (enum). | |
| 174 std::map<std::string, FingerprintCode> fingperprint_tag_code_map_; | |
| 175 }; | |
| 176 | |
| 177 } // namespace data_reduction_proxy | |
| 178 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_TAMPER_D ETECTION_H_ | |
| OLD | NEW |