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, which detects whether | |
| 6 // there are middleboxes and whether they are tampering with the response | |
| 7 // which may break correct communication and data transfer between the Chromium | |
| 8 // client and the data reduction proxy. | |
| 9 // | |
| 10 // At a high level, the tamper detection process works in two steps: | |
| 11 // 1. The data reduction proxy selects a fraction of responses to analyze, | |
| 12 // generates a series of fingerprints for each, and appends them to the | |
| 13 // Chrome-Proxy response headers; | |
| 14 // 2. The client re-generate the fingerprints using the same method as the | |
| 15 // proxy, compares them to the fingerprints in the response, and generates | |
| 16 // UMA. A response is considered to have been tampered with if the | |
| 17 // fingerprints do not match. | |
| 18 // | |
| 19 // Four fingerprints are generated by the data reduction proxy: | |
| 20 // 1. Fingerprint of the Chrome-Proxy header, which is designed to check | |
| 21 // whether the Chrome-Proxy header has been modified or not; | |
| 22 // 2. Fingerprint of the Via header, which is designed to check whether there | |
| 23 // are middleboxes between the Chromium client and the data reduction proxy; | |
| 24 // 3. Fingerprint of a list of headers, which is designed to check whether the | |
| 25 // values of a list of headers (list is defined by the data reduction proxy) | |
| 26 // have been modified or deleted; | |
| 27 // 4. Fingerprint of the Content-Length header, which is designed to check | |
| 28 // whether the response body has been modified or not (the code assumes that | |
| 29 // different Content-Length values indicate different response bodies). | |
| 30 // | |
| 31 // On the client side, the fingerprint of the Chrome-Proxy header will be | |
| 32 // checked first. If the fingerprint indicates that the Chrome-Proxy header has | |
| 33 // not been modified, then the other fingerprints will be considered to be | |
| 34 // reliable and will be checked next; if not, then it's possible that the other | |
| 35 // fingerprints have been tampered with and thus they will not be checked. | |
| 36 // If middlebox removes all the fingerprints then such tampering will not be | |
| 37 // detected. | |
| 38 // | |
| 39 // Detected tampering information will be reported to UMA. In general, for each | |
| 40 // fingerprint, the client reports the number of responses that have been | |
| 41 // 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 // Detects if the response sent by the data reduction proxy has been modified | |
| 62 // by 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 |scheme_is_https|. Returns true if | |
| 69 // the response has been tampered with. | |
| 70 static bool DetectAndReport(const net::HttpResponseHeaders* headers, | |
| 71 bool scheme_is_https); | |
| 72 | |
| 73 // Tamper detection checks |response_headers|. Histogram events are reported | |
| 74 // by |carrier_id|; |scheme_is_https| determines which histogram to report | |
| 75 // (HTTP and HTTPS are reported separately). |chrome_proxy_header_values| | |
| 76 // points to the vector containing the values of the Chrome-Proxy header, but | |
| 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 scheme_is_https, | |
| 82 unsigned carrier_id); | |
| 83 | |
| 84 virtual ~DataReductionProxyTamperDetection(); | |
| 85 | |
| 86 private: | |
| 87 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest, | |
| 88 TestFingerprintCommon); | |
| 89 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest, | |
| 90 ChromeProxy); | |
| 91 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest, | |
| 92 Via); | |
| 93 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest, | |
| 94 OtherHeaders); | |
| 95 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest, | |
| 96 ContentLength); | |
| 97 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest, | |
| 98 HeaderRemoving); | |
| 99 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest, | |
| 100 ValuesToSortedString); | |
| 101 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest, | |
| 102 GetHeaderValues); | |
| 103 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest, | |
| 104 DetectAndReport); | |
| 105 | |
| 106 // Returns the result of validating Chrome-Proxy header.. | |
|
bengr
2014/08/04 16:54:21
..
xingx1
2014/08/04 18:17:12
Done.
| |
| 107 bool ValidateChromeProxyHeader(const std::string& fingerprint) const; | |
| 108 // Reports UMA for tampering of the Chrome-Proxy header. | |
| 109 void ReportUMAforChromeProxyHeaderValidation() const; | |
| 110 | |
| 111 // Returns the result of validating the Via header. |has_chrome_proxy| | |
| 112 // indicates that the data reduction proxy's Via header occurs or not. | |
| 113 bool ValidateViaHeader(const std::string& fingerprint, | |
| 114 bool* has_chrome_proxy_via_header) const; | |
|
bengr
2014/08/04 16:54:21
indentation
xingx1
2014/08/04 18:17:12
Done.
| |
| 115 // Reports UMA for tampering of the Via header. | |
| 116 void ReportUMAforViaHeaderValidation(bool has_chrome_proxy_via_header) const; | |
| 117 | |
| 118 // Returns the result of validating a list of headers. | |
| 119 bool ValidateOtherHeaders(const std::string& fingerprint) const; | |
| 120 // Reports UMA for tampering of values of the list of headers. | |
|
bengr
2014/08/04 16:54:21
add blank line above
xingx1
2014/08/04 18:17:12
Done.
| |
| 121 void ReportUMAforOtherHeadersValidation() const; | |
| 122 | |
| 123 // Returns the result of validating the Content-Length header. | |
| 124 bool ValidateContentLengthHeader(const std::string& fingerprint) const; | |
| 125 // Reports UMA for tampering of the Content-Length header. | |
|
bengr
2014/08/04 16:54:21
add blank line above
xingx1
2014/08/04 18:17:12
Done.
| |
| 126 void ReportUMAforContentLengthHeaderValidation() const; | |
| 127 | |
| 128 // Returns a string representation of |values|. | |
| 129 static std::string ValuesToSortedString(std::vector<std::string>* values); | |
| 130 | |
| 131 // Returns raw MD5 hash value for a given string |input|. It is different to | |
| 132 // base::MD5String which is base16 encoded. | |
| 133 static void GetMD5(const std::string& input, std::string* output); | |
| 134 | |
| 135 // Returns all the values of |header_name| of the response |headers| as a | |
| 136 // vector. This function is used for values that need to be sorted later. | |
| 137 static std::vector<std::string> GetHeaderValues( | |
| 138 const net::HttpResponseHeaders* headers, | |
| 139 const std::string& header_name); | |
| 140 | |
| 141 // Pointer to response headers. | |
| 142 const net::HttpResponseHeaders* response_headers_; | |
| 143 | |
| 144 // If true, the connection to the data reduction proxy is over HTTPS; | |
| 145 const bool scheme_is_https_; | |
| 146 | |
| 147 // Carrier ID: the numeric name of the current registered operator. | |
| 148 const unsigned carrier_id_; | |
| 149 | |
| 150 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyTamperDetection); | |
| 151 }; | |
| 152 | |
| 153 } // namespace data_reduction_proxy | |
| 154 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_TAMPER_D ETECTION_H_ | |
| OLD | NEW |