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 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_TAMPER_DETE CT_H_ | |
| 6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_TAMPER_DETE CT_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "net/http/http_response_headers.h" | |
|
bengr
2014/07/02 17:31:01
add:
namespace net {
class HttpResponseHeaders;
}
xingx
2014/07/06 03:18:19
Done.
| |
| 11 | |
| 12 namespace data_reduction_proxy { | |
| 13 | |
| 14 // There are two fingerprints will be added to Chrome-Proxy header. | |
|
bengr
2014/07/02 17:31:00
Remove "There are"
xingx
2014/07/06 03:18:19
Done.
| |
| 15 // One starts with |kTamperDetectFingerprintChromeProxy|, which is the | |
| 16 // fingerprint for Chrome-Proxy header. | |
| 17 // The other one starts with |kTamperDetectFingerprint|, which includes | |
| 18 // all other fingerprints. | |
| 19 const char kTamperDetectFingerprint[] = "fp="; | |
| 20 const char kTamperDetectFingerprintChromeProxy[] = "cp="; | |
| 21 | |
| 22 // In fingerprint starts with |kTamperDetectFingerprint|, it contains multiple | |
|
bengr
2014/07/02 17:31:00
"In" --> "If |kTamperDetectFingerprint| contains
xingx
2014/07/06 03:18:19
Done.
| |
| 23 // fingerprints, each starts with a tag followed by "=" and its fingerprint | |
| 24 // value. Currently we have 3 of fingerprints and thus 3 tags, defined below. | |
|
bengr
2014/07/02 17:30:59
Currently --> Three fingerprints and their respect
xingx
2014/07/06 03:18:19
Done.
| |
| 25 const char kTamperDetectFingerprintVia[] = "via"; | |
|
bengr
2014/07/02 17:31:00
Are these needed outside the class? If not, define
xingx
2014/07/06 03:18:19
Done.
| |
| 26 const char kTamperDetectFingerprintOther[] = "oh"; | |
| 27 const char kTamperDetectFingerprintContengLength[] = "cl"; | |
| 28 | |
| 29 // Macro for UMA report. | |
|
bengr
2014/07/02 17:30:59
Why is this in the .h?
xingx
2014/07/06 03:18:19
Done.
| |
| 30 // If |is_secure_scheme| is true, report to |HTTPS_histogram|, | |
| 31 // otherwise report to |HTTP_histogram|. | |
| 32 // Both's bucket are Carrier IDs |mcc_mnc|. | |
| 33 // The other histogram counts the total number, |HTTP(S)_histogram| "_Total". | |
| 34 // which only has one bucket, 0. | |
| 35 #define UMA_REPORT(is_secure_scheme, HTTP_histogram, HTTPS_histogram, mcc_mnc) \ | |
|
bengr
2014/07/02 17:31:00
Unless you've seen this pattern in other UMA repor
xingx
2014/07/06 03:18:20
Done.
| |
| 36 do { \ | |
| 37 if (is_secure_scheme) { \ | |
|
bengr
2014/07/02 17:31:00
Is the scheme always https if |is_secure_scheme| i
xingx
2014/07/06 03:18:19
Done.
| |
| 38 UMA_HISTOGRAM_SPARSE_SLOWLY(HTTPS_histogram, mcc_mnc); \ | |
| 39 UMA_HISTOGRAM_SPARSE_SLOWLY(HTTPS_histogram "_Total", 0); \ | |
|
bolian
2014/07/02 23:47:37
Should use UMA_HISTOGRAM_COUNTS here.
xingx
2014/07/06 03:18:19
Done.
| |
| 40 } else { \ | |
| 41 UMA_HISTOGRAM_SPARSE_SLOWLY(HTTP_histogram, mcc_mnc); \ | |
| 42 UMA_HISTOGRAM_SPARSE_SLOWLY(HTTP_histogram "_Total", 0); \ | |
|
bolian
2014/07/02 23:47:37
same here, UMA_HISTOGRAM_COUNTS
xingx
2014/07/06 03:18:19
Done.
| |
| 43 }\ | |
| 44 } while (0) | |
| 45 | |
| 46 // Utility function, exposed for unittest. | |
| 47 // Return MD5 value for a given string |input|. | |
| 48 std::string GetMD5(const std::string& input); | |
|
bengr
2014/07/02 17:31:00
I don't think you should expose such a function to
xingx
2014/07/06 03:18:19
Done.
| |
| 49 | |
| 50 // Utility function, exposed for unittest. | |
| 51 // Return all the values of a header field |header_name| of the | |
| 52 // response header |headers|, as a vector. | |
| 53 std::vector<std::string> GetHeaderValues( | |
|
bengr
2014/07/02 17:31:00
Do you really need this? HttpResponseHeaders parse
xingx
2014/07/06 03:18:19
Discussed with you, reason is I need to sort the v
| |
| 54 const net::HttpResponseHeaders* headers, const std::string& header_name); | |
| 55 | |
| 56 // Utility function, exposed for unittest. | |
| 57 // Check whether values of a header field |values| contains the Chrome-Proxy | |
| 58 // header's fingerprint (starts with |kTamperDetectFingerprintChromeProxy|). | |
| 59 // If there is, return true, and save Chrome-Proxy header's fingerprint to | |
| 60 // |chrome_proxy_fingerprint|; | |
| 61 // and save other fingerprints (starts with |kTamperDetectFingerprintOther|) | |
| 62 // to |other_fingerprints|. | |
| 63 // Return false if there is no Chrome-Proxy header's fingerprint found. | |
| 64 bool ContainsTamperDetectFingerprints(std::vector<std::string>& values, | |
|
bengr
2014/07/02 17:31:00
Don't use non-const references.
xingx
2014/07/06 03:18:19
The function checks whether there is chrome-proxy
| |
| 65 std::string& chrome_proxy_fingerprint, | |
| 66 std::string& other_fingerprints); | |
| 67 | |
| 68 // The main function for detecting tamper. | |
|
bengr
2014/07/02 17:31:00
Fill out comments to the 80-char limit.
xingx
2014/07/06 03:18:19
Done.
| |
| 69 // It takes two parameters as input, | |
| 70 // 1. a pointer to HttpResponseHeaders, | |
| 71 // 2. a boolean variable indicates whether the connection | |
| 72 // between Chrome and data reduction proxy is on HTTPS or not. | |
| 73 // For such response, the function checks whether there is a tamper detect | |
| 74 // request (contains fingerprints) from data reduction proxy, if so, it checks | |
| 75 // whether there are tampers and report the results to UMA. | |
| 76 void CheckResponseFingerprint(const net::HttpResponseHeaders*, const bool); | |
| 77 | |
| 78 | |
| 79 | |
| 80 // The class for detecting tamper. | |
| 81 // It wraps up the functionalities for tamper detection. | |
| 82 // For each fingerprint, we need to implement two functions: | |
| 83 // * checking function: returns tamper or not for such fingerprint; | |
| 84 // (function name starts with Check...) | |
| 85 // * reporting function: reporting results to corresponding UMA | |
| 86 // when there are tampers detected. | |
| 87 // (function name starts with Report...) | |
| 88 class DataReductionProxyTamperDetect { | |
| 89 public: | |
| 90 DataReductionProxyTamperDetect(const net::HttpResponseHeaders*, const bool, | |
| 91 const unsigned, std::vector<std::string>*); | |
| 92 virtual ~DataReductionProxyTamperDetect(); | |
| 93 | |
| 94 // For Chrome-Proxy header tamper detection... | |
|
bolian
2014/07/02 23:47:37
Let's simplify and reformat the doc of this func a
xingx
2014/07/06 03:18:20
Done.
| |
| 95 // Check whether values of data reduction proxy's header Chrome-Proxy | |
| 96 // have been tampered or not. | |
| 97 // It takes one parameters as input, | |
| 98 // 1. fingerprint received from data reduction proxy | |
| 99 // Returns true if it has been tampered. | |
| 100 bool CheckHeaderChromeProxy(const std::string&); | |
|
bengr
2014/07/02 17:31:00
Can this function be const? What about others belo
xingx
2014/07/06 03:18:19
Done.
| |
| 101 | |
| 102 // For Via header tamper detection... | |
|
bengr
2014/07/02 17:31:00
Use complete sentences in comments.
xingx
2014/07/06 03:18:19
Done.
| |
| 103 // Check whether there are proxies/middleboxes between Chrome | |
| 104 // It takes one parameters as input, | |
| 105 // 1. fingerprint received from data reduction proxy | |
| 106 // Returns true if there are. | |
| 107 bool CheckHeaderVia(const std::string&); | |
|
bengr
2014/07/02 17:30:59
What does this function do?
xingx
2014/07/06 03:18:19
Done.
| |
| 108 // Reporting function for Via header tampering. | |
| 109 void ReportHeaderVia(); | |
| 110 | |
| 111 // For other headers tamper detection... | |
| 112 // Check whether values of a predefined list of headers have been tampered. | |
| 113 // It takes one parameters as input, | |
| 114 // 1. fingerprint received from data reduction proxy | |
| 115 // Returns true if tamper detected for these headers. | |
| 116 bool CheckHeaderOtherHeaders(const std::string&); | |
| 117 // Reporting function for tampering of values of the list of headers. | |
| 118 void ReportHeaderOtherHeaders(); | |
| 119 | |
| 120 // For Content-Length tamper detection... | |
| 121 // Check whether the Content-Length value is different from what | |
| 122 // data reduction proxy sees. This is an indicator that the response body | |
| 123 // have been modified. | |
| 124 // It takes one parameters as input, | |
| 125 // 1. fingerprint received from data reduction proxy | |
| 126 // Returns true if different Content-Length value is observed. | |
| 127 bool CheckHeaderContentLength(const std::string&); | |
| 128 // Reporting function for Content-Length tamper detected. | |
| 129 void ReportHeaderContentLength(); | |
| 130 | |
| 131 | |
| 132 // Function calls checking and reporting function for tamper detect. | |
| 133 // (i.e., above defined function pairs) | |
| 134 // Fingerprint type is specified by fingerprint name |key| | |
| 135 // (e.g., |kTamperDetectFingerprintVia|), and fingerprint from | |
| 136 // data reduction proxy is |fingerprint|. | |
| 137 // call it's corresponding check function as well as report function, | |
| 138 void CheckReportFingerprint(const std::string& key, | |
| 139 const std::string& fingerprint); | |
| 140 | |
| 141 | |
| 142 // Function pointer to checking function. | |
| 143 typedef bool (DataReductionProxyTamperDetect::*CheckTamper)( | |
|
bengr
2014/07/02 17:31:00
Why do you need function pointers?
xingx
2014/07/06 03:18:19
removed.
| |
| 144 const std::string&); | |
| 145 | |
| 146 // Function pointer to reporting function. | |
| 147 typedef void (DataReductionProxyTamperDetect::*ReportTamper)(); | |
| 148 | |
| 149 // Struct contains a pair of function pointers for one fingerprint: | |
| 150 // checking function pointer and one reporting function pointer. | |
| 151 struct CheckReportFuncs { | |
| 152 CheckTamper check_tamper_func; | |
|
bengr
2014/07/02 17:31:00
variable names should not be abbreviated. E.g., th
xingx
2014/07/06 03:18:19
Done.
| |
| 153 ReportTamper report_tamper_func; | |
| 154 }; | |
| 155 | |
| 156 private: | |
| 157 // Response header. | |
| 158 const net::HttpResponseHeaders* response_headers; | |
|
bengr
2014/07/02 17:31:00
Add a blank line after each variable.
xingx
2014/07/06 03:18:19
Done.
| |
| 159 // HTTPS or HTTP. | |
| 160 const bool is_secure_scheme; | |
| 161 // Carrier ID. | |
| 162 const unsigned mcc_mnc; | |
| 163 // Values for Chrome-Proxy header, with |kTamperDetectFingerprintChromeProxy| | |
| 164 // removed. Save it as temporary result so we don't need to parse | |
| 165 // Chrome-Proxy header twice. | |
| 166 std::vector<std::string>* clean_chrome_proxy_header_values; | |
| 167 // The checking function and reporting function pointers map, which maps | |
| 168 // a fingerprint name to |CheckReportFuncs| which contains pointers to | |
| 169 // corresponding checking function and reporting function. | |
| 170 std::map<std::string, CheckReportFuncs> check_report_func_map; | |
| 171 }; | |
| 172 | |
| 173 } // namespace data_reduction_proxy | |
| 174 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_TAMPER_D ETECT_H_ | |
| OLD | NEW |