[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 | |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 27 | // Parses |value| as a Strict-Transport-Security header value. If successful, |
[email protected] | b4e1f7e | 2013-05-25 13:59:09 | [diff] [blame] | 28 | // returns true and sets |*max_age| and |*include_subdomains|. |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 29 | // Otherwise returns false and leaves the output parameters unchanged. |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 30 | // |
| 31 | // value is the right-hand side of: |
| 32 | // |
| 33 | // "Strict-Transport-Security" ":" |
| 34 | // [ directive ] *( ";" [ directive ] ) |
[email protected] | b4e1f7e | 2013-05-25 13:59:09 | [diff] [blame] | 35 | bool NET_EXPORT_PRIVATE ParseHSTSHeader(const std::string& value, |
| 36 | base::TimeDelta* max_age, |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 37 | bool* include_subdomains); |
| 38 | |
[email protected] | 37fd55fb | 2013-06-29 13:13:27 | [diff] [blame] | 39 | // Parses |value| as a Public-Key-Pins header value. If successful, returns |
estark | 640590d4 | 2015-07-31 23:56:24 | [diff] [blame] | 40 | // true and populates the |*max_age|, |*include_subdomains|, |*hashes|, and |
| 41 | // |*report_uri| values. Otherwise returns false and leaves the output |
| 42 | // parameters unchanged. |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 43 | // |
| 44 | // value is the right-hand side of: |
| 45 | // |
| 46 | // "Public-Key-Pins" ":" |
| 47 | // "max-age" "=" delta-seconds ";" |
| 48 | // "pin-" algo "=" base64 [ ";" ... ] |
[email protected] | 37fd55fb | 2013-06-29 13:13:27 | [diff] [blame] | 49 | // [ ";" "includeSubdomains" ] |
estark | 83487b6 | 2015-07-27 17:11:14 | [diff] [blame] | 50 | // [ ";" "report-uri" "=" uri-reference ] |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 51 | // |
| 52 | // For this function to return true, the key hashes specified by the HPKP |
[email protected] | 37fd55fb | 2013-06-29 13:13:27 | [diff] [blame] | 53 | // header must pass two additional checks. There MUST be at least one key |
| 54 | // hash which matches the SSL certificate chain of the current site (as |
| 55 | // specified by the chain_hashes) parameter. In addition, there MUST be at |
| 56 | // least one key hash which does NOT match the site's SSL certificate chain |
| 57 | // (this is the "backup pin"). |
[email protected] | b4e1f7e | 2013-05-25 13:59:09 | [diff] [blame] | 58 | bool NET_EXPORT_PRIVATE ParseHPKPHeader(const std::string& value, |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 59 | const HashValueVector& chain_hashes, |
[email protected] | b4e1f7e | 2013-05-25 13:59:09 | [diff] [blame] | 60 | base::TimeDelta* max_age, |
[email protected] | 37fd55fb | 2013-06-29 13:13:27 | [diff] [blame] | 61 | bool* include_subdomains, |
estark | 83487b6 | 2015-07-27 17:11:14 | [diff] [blame] | 62 | HashValueVector* hashes, |
| 63 | GURL* report_uri); |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 64 | |
estark | 640590d4 | 2015-07-31 23:56:24 | [diff] [blame] | 65 | // Parses |value| as a Public-Key-Pins-Report-Only header value. If |
| 66 | // successful, returns true and populates the |*include_subdomains|, |
| 67 | // |*hashes|, and |*report_uri| values. Otherwise returns false and |
| 68 | // leaves the output parameters unchanged. |
| 69 | // |
| 70 | // value is the right-hand side of: |
| 71 | // |
| 72 | // "Public-Key-Pins-Report-Only" ":" |
| 73 | // [ "max-age" "=" delta-seconds ";" ] |
| 74 | // "pin-" algo "=" base64 [ ";" ... ] |
| 75 | // [ ";" "includeSubdomains" ] |
| 76 | // [ ";" "report-uri" "=" uri-reference ] |
| 77 | // |
| 78 | bool NET_EXPORT_PRIVATE ParseHPKPReportOnlyHeader(const std::string& value, |
| 79 | bool* include_subdomains, |
| 80 | HashValueVector* hashes, |
| 81 | GURL* report_uri); |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 82 | } // namespace net |
| 83 | |
| 84 | #endif // NET_HTTP_HTTP_SECURITY_HEADERS_H_ |