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

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

Issue 1579063002: Implement a skeleton version of Expect CT reports (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove unnecessary (?) NET_EXPORTs Created 4 years, 9 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
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>
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // An interface for asynchronously sending HPKP violation reports. 199 // An interface for asynchronously sending HPKP violation reports.
200 class NET_EXPORT ReportSender { 200 class NET_EXPORT ReportSender {
201 public: 201 public:
202 // Sends the given serialized |report| to |report_uri|. 202 // Sends the given serialized |report| to |report_uri|.
203 virtual void Send(const GURL& report_uri, const std::string& report) = 0; 203 virtual void Send(const GURL& report_uri, const std::string& report) = 0;
204 204
205 protected: 205 protected:
206 virtual ~ReportSender() {} 206 virtual ~ReportSender() {}
207 }; 207 };
208 208
209 // An interface for building and asynchronously sending reports when a
210 // site expects valid Certificate Transparency information but it
211 // wasn't supplied.
212 class NET_EXPORT ExpectCTReporter {
213 public:
214 // Called when the host in |host_port_pair| has opted in to have
215 // reports about Expect CT policy violations sent to |report_uri|,
216 // and such a violation has occurred.
217 virtual void OnExpectCTFailed(const net::HostPortPair& host_port_pair,
218 const GURL& report_uri,
219 const net::SSLInfo& ssl_info) = 0;
220
221 protected:
222 virtual ~ExpectCTReporter() {}
223 };
224
209 // Indicates whether or not a public key pin check should send a 225 // Indicates whether or not a public key pin check should send a
210 // report if a violation is detected. 226 // report if a violation is detected.
211 enum PublicKeyPinReportStatus { ENABLE_PIN_REPORTS, DISABLE_PIN_REPORTS }; 227 enum PublicKeyPinReportStatus { ENABLE_PIN_REPORTS, DISABLE_PIN_REPORTS };
212 228
213 TransportSecurityState(); 229 TransportSecurityState();
214 ~TransportSecurityState(); 230 ~TransportSecurityState();
215 231
216 // These functions search for static and dynamic STS and PKP states, and 232 // These functions search for static and dynamic STS and PKP states, and
217 // invoke the functions of the same name on them. These functions are the 233 // invoke the functions of the same name on them. These functions are the
218 // primary public interface; direct access to STS and PKP states is best 234 // primary public interface; direct access to STS and PKP states is best
(...skipping 11 matching lines...) Expand all
230 246
231 // Assign a |Delegate| for persisting the transport security state. If 247 // Assign a |Delegate| for persisting the transport security state. If
232 // |NULL|, state will not be persisted. The caller retains 248 // |NULL|, state will not be persisted. The caller retains
233 // ownership of |delegate|. 249 // ownership of |delegate|.
234 // Note: This is only used for serializing/deserializing the 250 // Note: This is only used for serializing/deserializing the
235 // TransportSecurityState. 251 // TransportSecurityState.
236 void SetDelegate(Delegate* delegate); 252 void SetDelegate(Delegate* delegate);
237 253
238 void SetReportSender(ReportSender* report_sender); 254 void SetReportSender(ReportSender* report_sender);
239 255
256 void SetExpectCTReporter(ExpectCTReporter* expect_ct_reporter);
257
240 // Clears all dynamic data (e.g. HSTS and HPKP data). 258 // Clears all dynamic data (e.g. HSTS and HPKP data).
241 // 259 //
242 // Does NOT persist changes using the Delegate, as this function is only 260 // Does NOT persist changes using the Delegate, as this function is only
243 // used to clear any dynamic data prior to re-loading it from a file. 261 // used to clear any dynamic data prior to re-loading it from a file.
244 // Note: This is only used for serializing/deserializing the 262 // Note: This is only used for serializing/deserializing the
245 // TransportSecurityState. 263 // TransportSecurityState.
246 void ClearDynamicData(); 264 void ClearDynamicData();
247 265
248 // Inserts |state| into |enabled_sts_hosts_| under the key |hashed_host|. 266 // Inserts |state| into |enabled_sts_hosts_| under the key |hashed_host|.
249 // |hashed_host| is already in the internal representation. 267 // |hashed_host| is already in the internal representation.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 bool GetStaticDomainState(const std::string& host, 299 bool GetStaticDomainState(const std::string& host,
282 STSState* sts_result, 300 STSState* sts_result,
283 PKPState* pkp_result) const; 301 PKPState* pkp_result) const;
284 302
285 // Returns true iff there is static (built-in) state for |host| that 303 // Returns true iff there is static (built-in) state for |host| that
286 // references the Google pins. 304 // references the Google pins.
287 // TODO(rch): Remove this temporary gross layering violation once QUIC 32 is 305 // TODO(rch): Remove this temporary gross layering violation once QUIC 32 is
288 // deployed. 306 // deployed.
289 bool IsGooglePinnedHost(const std::string& host) const; 307 bool IsGooglePinnedHost(const std::string& host) const;
290 308
291 // Returns true and updates |*expect_ct_result| iff there is a static
292 // (built-in) state for |host| with expect_ct=true.
293 bool GetStaticExpectCTState(const std::string& host,
294 ExpectCTState* expect_ct_result) const;
295
296 // Returns true and updates |*result| iff |host| has HSTS (respectively, HPKP) 309 // Returns true and updates |*result| iff |host| has HSTS (respectively, HPKP)
297 // state. If multiple HSTS (respectively, HPKP) entries match |host|, the 310 // state. If multiple HSTS (respectively, HPKP) entries match |host|, the
298 // most specific match determines the HSTS (respectively, HPKP) return value. 311 // most specific match determines the HSTS (respectively, HPKP) return value.
299 // 312 //
300 // Note that these methods are not const because they opportunistically remove 313 // Note that these methods are not const because they opportunistically remove
301 // entries that have expired. 314 // entries that have expired.
302 bool GetDynamicSTSState(const std::string& host, STSState* result); 315 bool GetDynamicSTSState(const std::string& host, STSState* result);
303 bool GetDynamicPKPState(const std::string& host, PKPState* result); 316 bool GetDynamicPKPState(const std::string& host, PKPState* result);
304 317
305 // Processes an HSTS header value from the host, adding entries to 318 // Processes an HSTS header value from the host, adding entries to
(...skipping 23 matching lines...) Expand all
329 const GURL& report_uri); 342 const GURL& report_uri);
330 343
331 // Parses |value| as a Public-Key-Pins-Report-Only header value and 344 // Parses |value| as a Public-Key-Pins-Report-Only header value and
332 // sends a HPKP report for |host_port_pair| if |ssl_info| violates the 345 // sends a HPKP report for |host_port_pair| if |ssl_info| violates the
333 // pin. Returns true if |value| parses and includes a valid 346 // pin. Returns true if |value| parses and includes a valid
334 // report-uri, and false otherwise. 347 // report-uri, and false otherwise.
335 bool ProcessHPKPReportOnlyHeader(const std::string& value, 348 bool ProcessHPKPReportOnlyHeader(const std::string& value,
336 const HostPortPair& host_port_pair, 349 const HostPortPair& host_port_pair,
337 const SSLInfo& ssl_info); 350 const SSLInfo& ssl_info);
338 351
352 // Parses |value| as a Expect CT header value and sends an Expect CT
353 // report for |host_port_pair| if the following conditions are true:
354 // 1. The header value is "preload", indicating that the site wants to
355 // be opted in to Expect CT.
356 // 2. The given host is present on the Expect CT preload list with a
357 // valid report-uri, and the build is timely (i.e. preload list is fresh).
358 // 3. |ssl_info| indicates that the connection violated the Expect CT policy.
359 // 4. An Expect CT reporter has been provided with SetExpectCTReporter().
360 void ProcessExpectCTHeader(const std::string& value,
361 const HostPortPair& host_port_pair,
362 const SSLInfo& ssl_info);
363
339 // The maximum number of seconds for which we'll cache an HSTS request. 364 // The maximum number of seconds for which we'll cache an HSTS request.
340 static const long int kMaxHSTSAgeSecs; 365 static const long int kMaxHSTSAgeSecs;
341 366
342 private: 367 private:
343 friend class TransportSecurityStateTest; 368 friend class TransportSecurityStateTest;
344 FRIEND_TEST_ALL_PREFIXES(HttpSecurityHeadersTest, UpdateDynamicPKPOnly); 369 FRIEND_TEST_ALL_PREFIXES(HttpSecurityHeadersTest, UpdateDynamicPKPOnly);
345 FRIEND_TEST_ALL_PREFIXES(HttpSecurityHeadersTest, UpdateDynamicPKPMaxAge0); 370 FRIEND_TEST_ALL_PREFIXES(HttpSecurityHeadersTest, UpdateDynamicPKPMaxAge0);
346 FRIEND_TEST_ALL_PREFIXES(HttpSecurityHeadersTest, NoClobberPins); 371 FRIEND_TEST_ALL_PREFIXES(HttpSecurityHeadersTest, NoClobberPins);
372 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, ExpectCTHeader);
347 373
348 typedef std::map<std::string, STSState> STSStateMap; 374 typedef std::map<std::string, STSState> STSStateMap;
349 typedef std::map<std::string, PKPState> PKPStateMap; 375 typedef std::map<std::string, PKPState> PKPStateMap;
350 376
351 // Send an UMA report on pin validation failure, if the host is in a 377 // Send an UMA report on pin validation failure, if the host is in a
352 // statically-defined list of domains. 378 // statically-defined list of domains.
353 // 379 //
354 // TODO(palmer): This doesn't really belong here, and should be moved into 380 // TODO(palmer): This doesn't really belong here, and should be moved into
355 // the exactly one call site. This requires unifying |struct HSTSPreload| 381 // the exactly one call site. This requires unifying |struct HSTSPreload|
356 // (an implementation detail of this class) with a more generic 382 // (an implementation detail of this class) with a more generic
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 // |validated_certificate_chain|. 432 // |validated_certificate_chain|.
407 bool CheckPinsAndMaybeSendReport( 433 bool CheckPinsAndMaybeSendReport(
408 const HostPortPair& host_port_pair, 434 const HostPortPair& host_port_pair,
409 const TransportSecurityState::PKPState& pkp_state, 435 const TransportSecurityState::PKPState& pkp_state,
410 const HashValueVector& hashes, 436 const HashValueVector& hashes,
411 const X509Certificate* served_certificate_chain, 437 const X509Certificate* served_certificate_chain,
412 const X509Certificate* validated_certificate_chain, 438 const X509Certificate* validated_certificate_chain,
413 const TransportSecurityState::PublicKeyPinReportStatus report_status, 439 const TransportSecurityState::PublicKeyPinReportStatus report_status,
414 std::string* failure_log); 440 std::string* failure_log);
415 441
442 // Returns true and updates |*expect_ct_result| iff there is a static
443 // (built-in) state for |host| with expect_ct=true.
444 bool GetStaticExpectCTState(const std::string& host,
445 ExpectCTState* expect_ct_result) const;
446
416 // The sets of hosts that have enabled TransportSecurity. |domain| will always 447 // The sets of hosts that have enabled TransportSecurity. |domain| will always
417 // be empty for a STSState or PKPState in these maps; the domain 448 // be empty for a STSState or PKPState in these maps; the domain
418 // comes from the map keys instead. In addition, |upgrade_mode| in the 449 // comes from the map keys instead. In addition, |upgrade_mode| in the
419 // STSState is never MODE_DEFAULT and |HasPublicKeyPins| in the PKPState 450 // STSState is never MODE_DEFAULT and |HasPublicKeyPins| in the PKPState
420 // always returns true. 451 // always returns true.
421 STSStateMap enabled_sts_hosts_; 452 STSStateMap enabled_sts_hosts_;
422 PKPStateMap enabled_pkp_hosts_; 453 PKPStateMap enabled_pkp_hosts_;
423 454
424 Delegate* delegate_; 455 Delegate* delegate_;
425 456
426 ReportSender* report_sender_; 457 ReportSender* report_sender_;
427 458
428 // True if static pins should be used. 459 // True if static pins should be used.
429 bool enable_static_pins_; 460 bool enable_static_pins_;
430 461
431 // True if static expect-CT state should be used. 462 // True if static expect-CT state should be used.
432 bool enable_static_expect_ct_; 463 bool enable_static_expect_ct_;
433 464
465 ExpectCTReporter* expect_ct_reporter_;
466
434 // Keeps track of reports that have been sent recently for 467 // Keeps track of reports that have been sent recently for
435 // rate-limiting. 468 // rate-limiting.
436 ExpiringCache<std::string, bool, base::TimeTicks, std::less<base::TimeTicks>> 469 ExpiringCache<std::string, bool, base::TimeTicks, std::less<base::TimeTicks>>
437 sent_reports_cache_; 470 sent_reports_cache_;
438 471
439 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); 472 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState);
440 }; 473 };
441 474
442 } // namespace net 475 } // namespace net
443 476
444 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ 477 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698