[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_HTTP_HTTP_SECURITY_HEADERS_H_ |
| 6 | #define NET_HTTP_HTTP_SECURITY_HEADERS_H_ |
| 7 | |
avi | c027914 | 2015-12-04 22:38:52 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 10 | #include <string> |
| 11 | |
[email protected] | 66e96c4 | 2013-06-28 15:20:31 | [diff] [blame] | 12 | #include "base/time/time.h" |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 13 | #include "base/values.h" |
| 14 | #include "net/base/hash_value.h" |
| 15 | #include "net/base/net_export.h" |
| 16 | |
estark | 83487b6 | 2015-07-27 17:11:14 | [diff] [blame] | 17 | class GURL; |
| 18 | |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 19 | namespace net { |
| 20 | |
eroman | e8a43d8 | 2016-04-12 06:02:06 | [diff] [blame] | 21 | const uint32_t kMaxHSTSAgeSecs = 86400 * 365; // 1 year |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 22 | |
elawrence | a6c42bd | 2016-02-29 18:00:42 | [diff] [blame] | 23 | // RFC7469 suggests that 60 days is a reasonable maximum max-age value |
| 24 | // http://tools.ietf.org/html/rfc7469#section-4.1 |
eroman | e8a43d8 | 2016-04-12 06:02:06 | [diff] [blame] | 25 | const uint32_t kMaxHPKPAgeSecs = 86400 * 60; // 60 days |
elawrence | a6c42bd | 2016-02-29 18:00:42 | [diff] [blame] | 26 | |
estark | a57e816 | 2017-04-21 18:01:05 | [diff] [blame] | 27 | // https://tools.ietf.org/html/draft-ietf-httpbis-expect-ct-00 suggests a |
| 28 | // conservative maximum max-age, at least while Expect-CT is new. |
| 29 | const uint32_t kMaxExpectCTAgeSecs = 86400 * 30; // 30 days |
| 30 | |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 31 | // Parses |value| as a Strict-Transport-Security header value. If successful, |
[email protected] | b4e1f7e | 2013-05-25 13:59:09 | [diff] [blame] | 32 | // returns true and sets |*max_age| and |*include_subdomains|. |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 33 | // Otherwise returns false and leaves the output parameters unchanged. |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 34 | // |
| 35 | // value is the right-hand side of: |
| 36 | // |
| 37 | // "Strict-Transport-Security" ":" |
| 38 | // [ directive ] *( ";" [ directive ] ) |
[email protected] | b4e1f7e | 2013-05-25 13:59:09 | [diff] [blame] | 39 | bool NET_EXPORT_PRIVATE ParseHSTSHeader(const std::string& value, |
| 40 | base::TimeDelta* max_age, |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 41 | bool* include_subdomains); |
| 42 | |
[email protected] | 37fd55fb | 2013-06-29 13:13:27 | [diff] [blame] | 43 | // Parses |value| as a Public-Key-Pins header value. If successful, returns |
estark | 640590d4 | 2015-07-31 23:56:24 | [diff] [blame] | 44 | // true and populates the |*max_age|, |*include_subdomains|, |*hashes|, and |
| 45 | // |*report_uri| values. Otherwise returns false and leaves the output |
| 46 | // parameters unchanged. |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 47 | // |
| 48 | // value is the right-hand side of: |
| 49 | // |
| 50 | // "Public-Key-Pins" ":" |
| 51 | // "max-age" "=" delta-seconds ";" |
| 52 | // "pin-" algo "=" base64 [ ";" ... ] |
[email protected] | 37fd55fb | 2013-06-29 13:13:27 | [diff] [blame] | 53 | // [ ";" "includeSubdomains" ] |
estark | 83487b6 | 2015-07-27 17:11:14 | [diff] [blame] | 54 | // [ ";" "report-uri" "=" uri-reference ] |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 55 | // |
| 56 | // For this function to return true, the key hashes specified by the HPKP |
[email protected] | 37fd55fb | 2013-06-29 13:13:27 | [diff] [blame] | 57 | // header must pass two additional checks. There MUST be at least one key |
| 58 | // hash which matches the SSL certificate chain of the current site (as |
| 59 | // specified by the chain_hashes) parameter. In addition, there MUST be at |
| 60 | // least one key hash which does NOT match the site's SSL certificate chain |
| 61 | // (this is the "backup pin"). |
[email protected] | b4e1f7e | 2013-05-25 13:59:09 | [diff] [blame] | 62 | bool NET_EXPORT_PRIVATE ParseHPKPHeader(const std::string& value, |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 63 | const HashValueVector& chain_hashes, |
[email protected] | b4e1f7e | 2013-05-25 13:59:09 | [diff] [blame] | 64 | base::TimeDelta* max_age, |
[email protected] | 37fd55fb | 2013-06-29 13:13:27 | [diff] [blame] | 65 | bool* include_subdomains, |
estark | 83487b6 | 2015-07-27 17:11:14 | [diff] [blame] | 66 | HashValueVector* hashes, |
| 67 | GURL* report_uri); |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 68 | |
estark | 640590d4 | 2015-07-31 23:56:24 | [diff] [blame] | 69 | // Parses |value| as a Public-Key-Pins-Report-Only header value. If |
| 70 | // successful, returns true and populates the |*include_subdomains|, |
| 71 | // |*hashes|, and |*report_uri| values. Otherwise returns false and |
| 72 | // leaves the output parameters unchanged. |
| 73 | // |
| 74 | // value is the right-hand side of: |
| 75 | // |
| 76 | // "Public-Key-Pins-Report-Only" ":" |
| 77 | // [ "max-age" "=" delta-seconds ";" ] |
| 78 | // "pin-" algo "=" base64 [ ";" ... ] |
| 79 | // [ ";" "includeSubdomains" ] |
| 80 | // [ ";" "report-uri" "=" uri-reference ] |
| 81 | // |
| 82 | bool NET_EXPORT_PRIVATE ParseHPKPReportOnlyHeader(const std::string& value, |
| 83 | bool* include_subdomains, |
| 84 | HashValueVector* hashes, |
| 85 | GURL* report_uri); |
estark | a57e816 | 2017-04-21 18:01:05 | [diff] [blame] | 86 | |
| 87 | // Parses |value| as an Expect-CT header value. If successful, returns true and |
| 88 | // populates the |*max_age|, |*enforce|, and |*report_uri| values. Otherwise |
| 89 | // returns false and leaves the output parameters unchanged. |
| 90 | // |
| 91 | // |value| is the right-hand side of: |
| 92 | // "Expect-CT" ":" |
| 93 | // "max-age" "=" delta-seconds |
| 94 | // [ "," "enforce" ] |
| 95 | // [ "," "report-uri" "=" uri-reference ] |
| 96 | // |
| 97 | bool NET_EXPORT_PRIVATE ParseExpectCTHeader(const std::string& value, |
| 98 | base::TimeDelta* max_age, |
| 99 | bool* enforce, |
| 100 | GURL* report_uri); |
| 101 | |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 102 | } // namespace net |
| 103 | |
| 104 | #endif // NET_HTTP_HTTP_SECURITY_HEADERS_H_ |