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" | |
11 | |
12 namespace data_reduction_proxy { | |
13 | |
14 // The class for detecting tampering. | |
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( | |
23 const net::HttpResponseHeaders* response_headers, | |
24 bool is_secure_scheme, | |
25 unsigned mcc_mnc, | |
26 std::vector<std::string>* chrome_proxy_header_values); | |
27 | |
28 virtual ~DataReductionProxyTamperDetect(); | |
29 | |
30 // The main function for detecting tampering, which takes two parameters: | |
31 // 1. a pointer to HttpResponseHeaders, | |
32 // 2. a boolean variable that indicates whether the connection between | |
33 // Chrome and data reduction proxy is on HTTPS or HTTP. | |
34 // The function checks whether there is a tamper detect request | |
35 // (i.e., contains fingerprints) from data reduction proxy, if so, it checks | |
36 // whether there are tampers and report the results to UMA. | |
37 static void CheckResponseFingerprint(const net::HttpResponseHeaders*, bool); | |
bolian
2014/07/09 22:51:06
Name the parameters.
xingx
2014/07/10 03:07:41
Done.
| |
38 | |
39 private: | |
40 friend class DataReductionProxyTamperDetectTest; | |
41 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
42 TestFingerprintCommon); | |
43 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
44 ChromeProxy); | |
45 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
46 Via); | |
47 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
48 OtherHeaders); | |
49 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
50 ContentLength); | |
51 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
52 Parsing); | |
53 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectTest, | |
54 Completed); | |
55 | |
56 // Enum for each fingerprint type. | |
57 enum FingerprintCode { CHROMEPROXY, | |
58 VIA, | |
59 OTHERHEADERS, | |
60 CONTENTLENGTH, | |
61 NONEXIST }; | |
62 | |
63 // Returns true if the Chrome-Proxy header has been tampered. | |
64 bool IsChromeProxyHeaderTampered(const std::string& fingerprint) const; | |
65 | |
66 // Returns true if the Via header has been tampered. | |
67 bool IsViaHeaderTampered(const std::string& fingerprint) const; | |
68 // Report UMA for tampering of the Via header. | |
bolian
2014/07/09 22:51:06
s/Report/Reports/ here and below.
xingx
2014/07/10 03:07:41
Done.
| |
69 void ReportViaHeaderTamperedUMA() const; | |
70 | |
71 // Returns true if other headers (a list of headers) have been tampered. | |
bolian
2014/07/09 22:51:06
How about
// Returns true if a list of server def
xingx
2014/07/10 03:07:41
Done.
| |
72 bool AreOtherHeadersTampered(const std::string& fingerprint) const; | |
73 // Report 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 // Report UMA for tampering of Content-Length. | |
79 void ReportContentLengthHeaderTamperedUMA() const; | |
80 | |
81 // Return fingerprint code (enum) for the given fingerprint tag. | |
bolian
2014/07/09 22:51:06
Returns
xingx
2014/07/10 03:07:41
Done.
| |
82 FingerprintCode GetFingerprintCode(const std::string& fingerprint_tag); | |
83 | |
84 // Utility function. Check whether values of a header field |values| contains | |
85 // the Chrome-Proxy header's fingerprint. If it does, return true, and save | |
86 // Chrome-Proxy header's fingerprint to |chrome_proxy_fingerprint|; also save | |
87 // other fingerprints to |other_fingerprints|. Return false if there is no | |
88 // Chrome-Proxy header fingerprint found. | |
89 static bool ContainsTamperDetectFingerprints(std::vector<std::string>* values, | |
90 std::string* chrome_proxy_fingerprint, | |
91 std::string* other_fingerprints); | |
92 | |
93 // Utility function. Return string of sorted values of |values|. | |
94 static std::string ValuesToSortedString(std::vector<std::string> &values); | |
95 | |
96 // Utility function. Return MD5 hash value for a given string |input|. | |
97 // We need raw MD5 hash value so it's different to MD5String which is base16 | |
98 // encoded. It's similar to MD5Sum but with digest converted to string. | |
99 static std::string GetMD5(const std::string& input); | |
100 | |
101 // Utility function. Return all the values of a header field |header_name| | |
102 // of the response header |headers|, as a vector. | |
103 static std::vector<std::string> GetHeaderValues( | |
104 const net::HttpResponseHeaders* headers, const std::string& header_name); | |
105 | |
106 const net::HttpResponseHeaders* response_headers; | |
107 | |
108 // The communication to data reduction proxy is on HTTPS or not. | |
109 const bool is_secure_scheme; | |
bolian
2014/07/09 22:51:06
// If true, the connection to the data reduction p
bolian
2014/07/09 22:51:06
Add trailing "_" to all private member vars.
xingx
2014/07/10 03:07:41
Done.
xingx
2014/07/10 03:07:41
Done.
| |
110 | |
111 // Carrier ID. | |
112 const unsigned mcc_mnc; | |
113 | |
114 // Values for Chrome-Proxy header, with its fingerprint value removed. | |
115 // Save it as temporary result so we don't need to parse Chrome-Proxy header | |
116 // twice. | |
117 std::vector<std::string>* clean_chrome_proxy_header_values; | |
118 | |
119 // Map a fingerprint tag (string) to a fingerprint code (enum). | |
120 std::map<std::string, FingerprintCode> fingperprint_tag_code_map; | |
121 }; | |
122 | |
123 } // namespace data_reduction_proxy | |
124 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_TAMPER_D ETECT_H_ | |
OLD | NEW |