Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: net/http/transport_security_state.h

Issue 1213783005: Send HPKP violation reports when a pin check fails (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_security_headers_unittest.cc ('k') | net/http/transport_security_state.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_HTTP_TRANSPORT_SECURITY_STATE_H_ 5 #ifndef NET_HTTP_TRANSPORT_SECURITY_STATE_H_
6 #define NET_HTTP_TRANSPORT_SECURITY_STATE_H_ 6 #define NET_HTTP_TRANSPORT_SECURITY_STATE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/threading/non_thread_safe.h" 16 #include "base/threading/non_thread_safe.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "net/base/net_export.h" 18 #include "net/base/net_export.h"
19 #include "net/cert/x509_cert_types.h" 19 #include "net/cert/x509_cert_types.h"
20 #include "net/cert/x509_certificate.h" 20 #include "net/cert/x509_certificate.h"
21 #include "url/gurl.h" 21 #include "url/gurl.h"
22 22
23 class GURL; 23 class GURL;
24 24
25 class GURL;
26
25 namespace net { 27 namespace net {
26 28
27 class SSLInfo; 29 class SSLInfo;
28 30
29 // Tracks which hosts have enabled strict transport security and/or public 31 // Tracks which hosts have enabled strict transport security and/or public
30 // key pins. 32 // key pins.
31 // 33 //
32 // This object manages the in-memory store. Register a Delegate with 34 // This object manages the in-memory store. Register a Delegate with
33 // |SetDelegate| to persist the state to disk. 35 // |SetDelegate| to persist the state to disk.
34 // 36 //
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 std::map<std::string, PKPState>::const_iterator iterator_; 180 std::map<std::string, PKPState>::const_iterator iterator_;
179 std::map<std::string, PKPState>::const_iterator end_; 181 std::map<std::string, PKPState>::const_iterator end_;
180 }; 182 };
181 183
182 class NET_EXPORT Reporter { 184 class NET_EXPORT Reporter {
183 public: 185 public:
184 // Determines if a HPKP violation report should be sent for the 186 // Determines if a HPKP violation report should be sent for the
185 // given |hostname|, which was found to violate the pins in 187 // given |hostname|, which was found to violate the pins in
186 // |pkp_state|. Returns true if the report should be sent, with the 188 // |pkp_state|. Returns true if the report should be sent, with the
187 // report URI in |report_uri| and the serialized report in 189 // report URI in |report_uri| and the serialized report in
188 // |serialized_report|, and false otherwise. Allows embedders to 190 // |serialized_report|, and false otherwise. Allows the reporter to
189 // override the report uri and/or format for some pins. 191 // override the reporting state in some cases (for example, if
192 // reports should always be sent for certain hostnames regardless of
193 // the HPKP state).
190 // 194 //
191 // Additional information to be included in the report (beyond 195 // Additional information to be included in the report (beyond
192 // fields in |pkp_state|): 196 // fields in |pkp_state|):
193 // 197 //
194 // - The |port| of the request that violated the pin. 198 // - The |port| of the request that violated the pin.
195 // - |served_certificate_chain| and |validated_certificate_chain|, 199 // - |served_certificate_chain| and |validated_certificate_chain|,
196 // the certificate chains as received by the client and as built 200 // the certificate chains as received by the client and as built
197 // during certificate verification. 201 // during certificate verification.
198 virtual bool GetHPKPReport( 202 virtual bool GetHPKPReport(
199 const std::string& hostname, 203 const std::string& hostname,
200 const PKPState& pkp_state, 204 const PKPState& pkp_state,
201 bool is_static_pin, 205 bool is_static_pin,
202 uint16_t port, 206 uint16_t port,
203 const X509Certificate* served_certificate_chain, 207 const X509Certificate* served_certificate_chain,
204 const X509Certificate* validated_certificate_chain, 208 const X509Certificate* validated_certificate_chain,
205 GURL* report_uri, 209 GURL* report_uri,
206 std::string* serialized_report) = 0; 210 std::string* serialized_report) = 0;
207 211
208 // Sends the given serialized |report| to |report_uri|. 212 // Sends the given serialized |report| to |report_uri|.
209 virtual void SendHPKPReport(const GURL& report_uri, 213 virtual void SendHPKPReport(const GURL& report_uri,
210 const std::string& report) = 0; 214 const std::string& report) = 0;
211 215
212 protected: 216 protected:
213 virtual ~Reporter() {} 217 virtual ~Reporter() {}
214 }; 218 };
215 219
220 // Indicates whether or not a public key pin check should send a
221 // report if a violation is detected.
222 enum PublicKeyPinReportStatus { ENABLE_PIN_REPORTS, DISABLE_PIN_REPORTS };
223
216 TransportSecurityState(); 224 TransportSecurityState();
217 ~TransportSecurityState(); 225 ~TransportSecurityState();
218 226
219 // These functions search for static and dynamic STS and PKP states, and 227 // These functions search for static and dynamic STS and PKP states, and
220 // invoke the functions of the same name on them. These functions are the 228 // invoke the functions of the same name on them. These functions are the
221 // primary public interface; direct access to STS and PKP states is best 229 // primary public interface; direct access to STS and PKP states is best
222 // left to tests. 230 // left to tests.
223 bool ShouldSSLErrorsBeFatal(const std::string& host); 231 bool ShouldSSLErrorsBeFatal(const std::string& host);
224 bool ShouldUpgradeToSSL(const std::string& host); 232 bool ShouldUpgradeToSSL(const std::string& host);
225 bool CheckPublicKeyPins(const std::string& host, 233 bool CheckPublicKeyPins(const std::string& host,
226 bool is_issued_by_known_root, 234 bool is_issued_by_known_root,
227 const HashValueVector& hashes, 235 const HashValueVector& hashes,
236 uint16_t port,
237 const X509Certificate* served_certificate_chain,
238 const X509Certificate* validated_certificate_chain,
239 const PublicKeyPinReportStatus report_status,
228 std::string* failure_log); 240 std::string* failure_log);
229 bool HasPublicKeyPins(const std::string& host); 241 bool HasPublicKeyPins(const std::string& host);
230 242
231 // Assign a |Delegate| for persisting the transport security state. If 243 // Assign a |Delegate| for persisting the transport security state. If
232 // |NULL|, state will not be persisted. The caller retains 244 // |NULL|, state will not be persisted. The caller retains
233 // ownership of |delegate|. 245 // ownership of |delegate|.
234 // Note: This is only used for serializing/deserializing the 246 // Note: This is only used for serializing/deserializing the
235 // TransportSecurityState. 247 // TransportSecurityState.
236 void SetDelegate(Delegate* delegate); 248 void SetDelegate(Delegate* delegate);
237 249
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 // representation of first-class DomainStates, and exposing the preloads 356 // representation of first-class DomainStates, and exposing the preloads
345 // to the caller with |GetStaticDomainState|. 357 // to the caller with |GetStaticDomainState|.
346 static void ReportUMAOnPinFailure(const std::string& host); 358 static void ReportUMAOnPinFailure(const std::string& host);
347 359
348 // IsBuildTimely returns true if the current build is new enough ensure that 360 // IsBuildTimely returns true if the current build is new enough ensure that
349 // built in security information (i.e. HSTS preloading and pinning 361 // built in security information (i.e. HSTS preloading and pinning
350 // information) is timely. 362 // information) is timely.
351 static bool IsBuildTimely(); 363 static bool IsBuildTimely();
352 364
353 // Helper method for actually checking pins. 365 // Helper method for actually checking pins.
354 bool CheckPublicKeyPinsImpl(const std::string& host, 366 bool CheckPublicKeyPinsImpl(
355 const HashValueVector& hashes, 367 const std::string& host,
356 std::string* failure_log); 368 const HashValueVector& hashes,
369 uint16_t port,
370 const X509Certificate* served_certificate_chain,
371 const X509Certificate* validated_certificate_chain,
372 const PublicKeyPinReportStatus report_status,
373 std::string* failure_log);
357 374
358 // If a Delegate is present, notify it that the internal state has 375 // If a Delegate is present, notify it that the internal state has
359 // changed. 376 // changed.
360 void DirtyNotify(); 377 void DirtyNotify();
361 378
362 // Adds HSTS state to |host|. 379 // Adds HSTS state to |host|.
363 void AddHSTSInternal(const std::string& host, 380 void AddHSTSInternal(const std::string& host,
364 STSState::UpgradeMode upgrade_mode, 381 STSState::UpgradeMode upgrade_mode,
365 const base::Time& expiry, 382 const base::Time& expiry,
366 bool include_subdomains); 383 bool include_subdomains);
(...skipping 27 matching lines...) Expand all
394 411
395 // True if static pins should be used. 412 // True if static pins should be used.
396 bool enable_static_pins_; 413 bool enable_static_pins_;
397 414
398 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); 415 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState);
399 }; 416 };
400 417
401 } // namespace net 418 } // namespace net
402 419
403 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ 420 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_
OLDNEW
« no previous file with comments | « net/http/http_security_headers_unittest.cc ('k') | net/http/transport_security_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698