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 "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" | |
| 9 | |
| 10 #include "net/http/http_response_headers.h" | |
|
bengr
2014/07/11 18:22:48
#include <string>
#include <vector>
xingx
2014/07/15 04:51:36
Done.
| |
| 11 | |
|
bengr
2014/07/11 18:22:47
namespace net {
class HttpResponseHeaders;
}
xingx
2014/07/15 04:51:36
Done.
| |
| 12 namespace data_reduction_proxy { | |
| 13 | |
| 14 // The class for detecting tampering. | |
|
bengr
2014/07/11 18:22:48
Explain what that means. E.g., "This class that de
xingx
2014/07/15 04:51:35
Done.
| |
| 15 // For each type of fingerprint, we have a pair of functions: | |
| 16 // * checking function: returns true if such fingerprint got tampered; | |
| 17 // (function name Is...Tampered) | |
| 18 // * reporting function: reporting tampering to corresponding UMA. | |
| 19 // (function name Report...TamperedUMA) | |
| 20 class DataReductionProxyTamperDetect { | |
| 21 public: | |
| 22 DataReductionProxyTamperDetect( | |
|
bengr
2014/07/11 18:22:48
suggest: DataReductionProxyTamperDetection
bengr
2014/07/11 18:22:48
Add a comment. What are all these parameters? How
xingx
2014/07/15 04:51:35
Done.
xingx
2014/07/15 04:51:36
Done.
| |
| 23 const net::HttpResponseHeaders* response_headers, | |
| 24 bool is_secure_scheme, | |
| 25 unsigned mcc_mnc, | |
|
bengr
2014/07/11 18:22:49
rename: carrier_id.
xingx
2014/07/15 04:51:36
Done.
| |
| 26 std::vector<std::string>* chrome_proxy_header_values); | |
| 27 | |
| 28 virtual ~DataReductionProxyTamperDetect(); | |
| 29 | |
| 30 // The main function for detecting tampering, which checks whether there is | |
| 31 // tamper detect request (i.e., contains fingerprints added by data reduction | |
|
bengr
2014/07/11 18:22:48
Be clearer, e.g.:
"Checks if the response contain
xingx
2014/07/15 04:51:35
Done.
| |
| 32 // proxy) in the response from data reduction proxy. if so, it checks whether | |
| 33 // there are tampers and report the results to UMA. HTTP and HTTPS traffic | |
| 34 // would be reported independently, specified by |is_secure_scheme|. | |
| 35 static void CheckResponseFingerprint(const net::HttpResponseHeaders* header, | |
|
bengr
2014/07/11 18:22:48
Move this static method above the constructor.
xingx
2014/07/15 04:51:36
Done.
| |
| 36 bool is_secure_scheme); | |
| 37 | |
| 38 private: | |
| 39 friend class DataReductionProxyTamperDetectTest; | |
| 40 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
| 41 TestFingerprintCommon); | |
| 42 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
| 43 ChromeProxy); | |
| 44 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
| 45 Via); | |
| 46 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
| 47 OtherHeaders); | |
| 48 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
| 49 ContentLength); | |
| 50 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
| 51 Parsing); | |
| 52 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
| 53 Completed); | |
| 54 | |
| 55 // Enum for fingerprint type. | |
|
bengr
2014/07/11 18:22:48
Put each value on its own line and add a comment f
xingx
2014/07/15 04:51:36
Done.
| |
| 56 enum FingerprintCode { CHROMEPROXY, | |
| 57 VIA, | |
| 58 OTHERHEADERS, | |
| 59 CONTENTLENGTH, | |
| 60 NONEXIST }; | |
| 61 | |
| 62 // Returns true if the Chrome-Proxy header has been tampered. | |
| 63 bool IsChromeProxyHeaderTampered(const std::string& fingerprint) const; | |
|
bengr
2014/07/11 18:22:48
Where's the reporting function fo this one?
xingx
2014/07/15 04:51:35
Done.
| |
| 64 | |
| 65 // Returns true if the Via header has been tampered. | |
| 66 bool IsViaHeaderTampered(const std::string& fingerprint) const; | |
| 67 // Reports UMA for tampering of the Via header. | |
| 68 void ReportViaHeaderTamperedUMA() const; | |
| 69 | |
| 70 // Returns true if a list of data reductin proxy defined headers have been | |
| 71 // tampered. | |
| 72 bool AreOtherHeadersTampered(const std::string& fingerprint) const; | |
| 73 // Reports UMA for tampering of values of the list of headers. | |
| 74 void ReportOtherHeadersTamperedUMA() const; | |
| 75 | |
| 76 // Returns true if Content-Length has been tampered. | |
| 77 bool IsContentLengthHeaderTampered(const std::string& fingerprint) const; | |
| 78 // Reports UMA for tampering of Content-Length. | |
| 79 void ReportContentLengthHeaderTamperedUMA() const; | |
| 80 | |
| 81 // Returns fingerprint code (enum) for the given fingerprint tag. | |
| 82 FingerprintCode GetFingerprintCode(const std::string& fingerprint_tag); | |
| 83 | |
| 84 // Check whether values of a Chrome-Proxy header contains fingerprints added | |
|
bengr
2014/07/11 18:22:48
contain
xingx
2014/07/15 04:51:35
Done.
| |
| 85 // by data reduction proxy. If it does, return true, and save Chrome-Proxy | |
|
bengr
2014/07/11 18:22:48
the data reduction
If they do
and save the
xingx
2014/07/15 04:51:36
Done.
| |
| 86 // header's fingerprint to |chrome_proxy_fingerprint|; also save other | |
| 87 // fingerprints to |other_fingerprints|. Return false if there is no | |
| 88 // fingerprint found. Chrome-Proxy header's fingerprint will be removed from | |
| 89 // |values| to get |clean_chrome_proxy_header_values| for later use. | |
| 90 static bool GetTamperDetectFingerprints(std::vector<std::string>* values, | |
|
bengr
2014/07/11 18:22:48
Move this first param to a new line or align the s
xingx
2014/07/15 04:51:36
Done.
| |
| 91 std::string* chrome_proxy_fingerprint, | |
| 92 std::string* other_fingerprints); | |
| 93 | |
| 94 // Utility function. Return string of sorted values of |values|. | |
|
bengr
2014/07/11 18:22:48
Returns
And no need to call it a utility function
xingx
2014/07/15 04:51:36
Done.
| |
| 95 static std::string ValuesToSortedString(std::vector<std::string> &values); | |
|
bengr
2014/07/11 18:22:48
Do not use non-const references.
And the & should
xingx
2014/07/15 04:51:36
Done.
| |
| 96 | |
| 97 // Utility function. Return MD5 hash value for a given string |input|. | |
|
bengr
2014/07/11 18:22:48
Remove "Utility function"
Returns the
xingx
2014/07/15 04:51:35
Done.
| |
| 98 // We need raw MD5 hash value so it's different to base::MD5String which is | |
|
bengr
2014/07/11 18:22:48
Remove "We". I.e., don't personify code or comment
xingx
2014/07/15 04:51:36
Done.
| |
| 99 // base16 encoded. It's similar to base::MD5Sum but with digest converted to | |
| 100 // string. | |
| 101 static std::string GetMD5(const std::string& input); | |
| 102 | |
| 103 // Utility function. Return all the values of a header field |header_name| | |
| 104 // of the response header |headers|, as a vector. | |
| 105 static std::vector<std::string> GetHeaderValues( | |
| 106 const net::HttpResponseHeaders* headers, const std::string& header_name); | |
| 107 | |
| 108 const net::HttpResponseHeaders* response_headers_; | |
| 109 | |
| 110 // If true, the connection to the data reduction proxy is over HTTPS. | |
| 111 const bool is_secure_scheme_; | |
| 112 | |
| 113 // Carrier ID. | |
| 114 const unsigned mcc_mnc_; | |
|
bengr
2014/07/11 18:22:48
Don't use abbreviations in variable names. Can you
xingx
2014/07/15 04:51:36
Done.
| |
| 115 | |
| 116 // Values for Chrome-Proxy header, with its fingerprint value removed. | |
| 117 // Save it as temporary result so we don't need to parse Chrome-Proxy header | |
|
bengr
2014/07/11 18:22:49
as a
parse the
xingx
2014/07/15 04:51:35
Done.
| |
| 118 // twice. | |
| 119 std::vector<std::string>* clean_chrome_proxy_header_values_; | |
| 120 | |
| 121 // Map a fingerprint tag (string) to a fingerprint code (enum). | |
| 122 std::map<std::string, FingerprintCode> fingperprint_tag_code_map_; | |
| 123 }; | |
| 124 | |
| 125 } // namespace data_reduction_proxy | |
| 126 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_TAMPER_D ETECT_H_ | |
| OLD | NEW |