blob: 9c63798781c41ed1ffd921f5efc17d0deecebe79 [file] [log] [blame]
[email protected]6ed72be2013-01-08 22:07:331// 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
avic0279142015-12-04 22:38:528#include <stdint.h>
9
[email protected]6ed72be2013-01-08 22:07:3310#include <string>
11
[email protected]66e96c42013-06-28 15:20:3112#include "base/time/time.h"
[email protected]6ed72be2013-01-08 22:07:3313#include "base/values.h"
14#include "net/base/hash_value.h"
15#include "net/base/net_export.h"
16
estark83487b62015-07-27 17:11:1417class GURL;
18
[email protected]6ed72be2013-01-08 22:07:3319namespace net {
20
eromane8a43d82016-04-12 06:02:0621const uint32_t kMaxHSTSAgeSecs = 86400 * 365; // 1 year
[email protected]6ed72be2013-01-08 22:07:3322
elawrencea6c42bd2016-02-29 18:00:4223// RFC7469 suggests that 60 days is a reasonable maximum max-age value
24// http://tools.ietf.org/html/rfc7469#section-4.1
eromane8a43d82016-04-12 06:02:0625const uint32_t kMaxHPKPAgeSecs = 86400 * 60; // 60 days
elawrencea6c42bd2016-02-29 18:00:4226
estarka57e8162017-04-21 18:01:0527// 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.
29const uint32_t kMaxExpectCTAgeSecs = 86400 * 30; // 30 days
30
[email protected]6ed72be2013-01-08 22:07:3331// Parses |value| as a Strict-Transport-Security header value. If successful,
[email protected]b4e1f7e2013-05-25 13:59:0932// returns true and sets |*max_age| and |*include_subdomains|.
[email protected]6ed72be2013-01-08 22:07:3333// Otherwise returns false and leaves the output parameters unchanged.
[email protected]6ed72be2013-01-08 22:07:3334//
35// value is the right-hand side of:
36//
37// "Strict-Transport-Security" ":"
38// [ directive ] *( ";" [ directive ] )
[email protected]b4e1f7e2013-05-25 13:59:0939bool NET_EXPORT_PRIVATE ParseHSTSHeader(const std::string& value,
40 base::TimeDelta* max_age,
[email protected]6ed72be2013-01-08 22:07:3341 bool* include_subdomains);
42
[email protected]37fd55fb2013-06-29 13:13:2743// Parses |value| as a Public-Key-Pins header value. If successful, returns
estark640590d42015-07-31 23:56:2444// 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]6ed72be2013-01-08 22:07:3347//
48// value is the right-hand side of:
49//
50// "Public-Key-Pins" ":"
51// "max-age" "=" delta-seconds ";"
52// "pin-" algo "=" base64 [ ";" ... ]
[email protected]37fd55fb2013-06-29 13:13:2753// [ ";" "includeSubdomains" ]
estark83487b62015-07-27 17:11:1454// [ ";" "report-uri" "=" uri-reference ]
[email protected]6ed72be2013-01-08 22:07:3355//
56// For this function to return true, the key hashes specified by the HPKP
[email protected]37fd55fb2013-06-29 13:13:2757// 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]b4e1f7e2013-05-25 13:59:0962bool NET_EXPORT_PRIVATE ParseHPKPHeader(const std::string& value,
[email protected]6ed72be2013-01-08 22:07:3363 const HashValueVector& chain_hashes,
[email protected]b4e1f7e2013-05-25 13:59:0964 base::TimeDelta* max_age,
[email protected]37fd55fb2013-06-29 13:13:2765 bool* include_subdomains,
estark83487b62015-07-27 17:11:1466 HashValueVector* hashes,
67 GURL* report_uri);
[email protected]6ed72be2013-01-08 22:07:3368
estark640590d42015-07-31 23:56:2469// 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//
82bool NET_EXPORT_PRIVATE ParseHPKPReportOnlyHeader(const std::string& value,
83 bool* include_subdomains,
84 HashValueVector* hashes,
85 GURL* report_uri);
estarka57e8162017-04-21 18:01:0586
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//
97bool NET_EXPORT_PRIVATE ParseExpectCTHeader(const std::string& value,
98 base::TimeDelta* max_age,
99 bool* enforce,
100 GURL* report_uri);
101
[email protected]6ed72be2013-01-08 22:07:33102} // namespace net
103
104#endif // NET_HTTP_HTTP_SECURITY_HEADERS_H_