RFC 7469

Public Key Pinning Extension for HTTP

๐Ÿ“… published April 2015, from ietf

Part 1 of 6 ๐ŸŽ€

Public Key Pinning Extension for HTTP ๐Ÿ’–

  • Series: Internet Engineering Task Force (IETF)
  • RFC number: 7469
  • Authors: C. Evans, C. Palmer, and R. Sleevi (R. Sleevi is at Google, Inc.)
  • Category: Standards Track
  • ISSN: 2070-1721
  • Date: April 2015
  • Obsoletes/Updates: The title block doesn't list anything this one obsoletes or updates.

Abstract ๐ŸŒธ

okay so this doc makes a brand new HTTP header that lets web host operators tell user agents (UAs) to remember ("pin") a host's cryptographic identity for a while. ๐Ÿ”’ During that window, UAs will require that the host shows up with a certificate chain that has at least one Subject Public Key Info structure whose fingerprint matches one of the pinned fingerprints for that host. โœจ Basically, fewer trusted authorities can vouch for the domain while the pin is alive, so pinning may cut down on man-in-the-middle attacks caused by compromised Certification Authorities. iconic ๐Ÿ’…


Status of This Memo ๐Ÿ“œ

bestie, this is an Internet Standards Track document. ๐Ÿ†

It's a product of the Internet Engineering Task Force (IETF), it represents the consensus of the IETF community, it got public review, and the Internet Engineering Steering Group (IESG) approved it for publication. If you want more on Internet Standards, check Section 2 of RFC 5741. ๐Ÿ“š

For the current status, any errata, and how to send feedback, look at http://www.rfc-editor.org/info/rfc7469. ๐Ÿ”—


Copyright (c) 2015 IETF Trust and the persons identified as the document authors. All rights reserved. ๐Ÿฆ‹

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) as in effect on the date of publication. Please read these carefully, because they spell out your rights and restrictions for this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions, and they come without warranty, as described in the Simplified BSD License. ๐Ÿซถ


Table of Contents ๐Ÿ—บ๏ธ

1.  Introduction  . . . . . . . . . . . . . . . . . . . . . . . .   4
  1.1.  Requirements Language . . . . . . . . . . . . . . . . . .   5
2.  Server and Client Behavior  . . . . . . . . . . . . . . . . .   5
  2.1.  Response Header Field Syntax  . . . . . . . . . . . . . .   5
    2.1.1.  The Pin Directive . . . . . . . . . . . . . . . . . .   6
    2.1.2.  The max-age Directive . . . . . . . . . . . . . . . .   7
    2.1.3.  The includeSubDomains Directive . . . . . . . . . . .   7
    2.1.4.  The report-uri Directive  . . . . . . . . . . . . . .   7
    2.1.5.  Examples  . . . . . . . . . . . . . . . . . . . . . .   8
  2.2.  Server Processing Model . . . . . . . . . . . . . . . . .   9
    2.2.1.  HTTP-over-Secure-Transport Request Type . . . . . . .   9
    2.2.2.  HTTP Request Type . . . . . . . . . . . . . . . . . .   9
  2.3.  User Agent Processing Model . . . . . . . . . . . . . . .  10
    2.3.1.  Public-Key-Pins Response Header Field Processing  . .  10
    2.3.2.  Interaction of Public-Key-Pins and Public-Key-Pins-
            Report-Only . . . . . . . . . . . . . . . . . . . . .  11
    2.3.3.  Noting a Pinned Host - Storage Model  . . . . . . . .  11
    2.3.4.  HTTP-Equiv <Meta> Element Attribute . . . . . . . . .  13
  2.4.  Semantics of Pins . . . . . . . . . . . . . . . . . . . .  13
  2.5.  Noting Pins . . . . . . . . . . . . . . . . . . . . . . .  14
  2.6.  Validating Pinned Connections . . . . . . . . . . . . . .  15
  2.7.  Interactions with Preloaded Pin Lists . . . . . . . . . .  16
  2.8.  Pinning Self-Signed End Entities  . . . . . . . . . . . .  16
3.  Reporting Pin Validation Failure  . . . . . . . . . . . . . .  16
4.  Security Considerations . . . . . . . . . . . . . . . . . . .  19
  4.1.  Maximum max-age . . . . . . . . . . . . . . . . . . . . .  19
  4.2.  Using includeSubDomains Safely  . . . . . . . . . . . . .  20
  4.3.  Backup Pins . . . . . . . . . . . . . . . . . . . . . . .  21
  4.4.  Interactions With Cookie Scoping  . . . . . . . . . . . .  21
  4.5.  Hostile Pinning . . . . . . . . . . . . . . . . . . . . .  21
5.  Privacy Considerations  . . . . . . . . . . . . . . . . . . .  22
6.  IANA Considerations . . . . . . . . . . . . . . . . . . . . .  24
7.  Usability Considerations  . . . . . . . . . . . . . . . . . .  24
8.  References  . . . . . . . . . . . . . . . . . . . . . . . . .  24
  8.1.  Normative References  . . . . . . . . . . . . . . . . . .  24
  8.2.  Informative References  . . . . . . . . . . . . . . . . .  26
Appendix A.  Fingerprint Generation . . . . . . . . . . . . . . .  27
Appendix B.  Deployment Guidance  . . . . . . . . . . . . . . . .  27
Acknowledgements  . . . . . . . . . . . . . . . . . . . . . . . .  28
Authors' Addresses  . . . . . . . . . . . . . . . . . . . . . . .  28

1. Introduction โœจ

okay so this doc defines a new HTTP header that lets UAs figure out which Subject Public Key Info (SPKI) structures will show up in a web host's certificate chain on future Transport Layer Security (TLS) [RFC5246] connections. ๐Ÿ”

Deploying Public Key Pinning (PKP) safely takes real operational and organizational maturity ๐Ÿง , because hosts can make themselves unreachable by pinning to a set of SPKIs that stops being valid (see Section 4). ๐Ÿ˜ฌ With care, though, host operators can seriously cut the risk of man-in-the-middle (MITM) attacks and other false-authentication problems for their users without taking on undue risk. ๐Ÿ’œ

PKP is meant to be used together with HTTP Strict Transport Security (HSTS) [RFC6797], but you can pin keys without HSTS too. ๐Ÿ“

A Pin is a relationship between a hostname and a cryptographic identity. In this document, that identity is one or more of the public keys in a chain of X.509 certificates. ๐Ÿฆ‹ Pin Validation is the process a UA goes through to make sure a host is actually authenticated with its previously established Pin. ๐Ÿ”

Key pinning is a trust-on-first-use (TOFU) mechanism. ๐Ÿซฃ The first time a UA connects to a host, it doesn't have the info it needs to do Pin Validation, so it can only apply its normal cryptographic identity validation. (In this document, it is assumed that UAs apply X.509 certificate chain validation in accord with [RFC5280].)

The UA can't detect and stop a MITM attacking its first connection to the host. ๐Ÿ˜ญ (Still, the MITM has to provide an X.509 certificate chain that gets through the UA's validation requirements without error, which helps a little.) Worse, that MITM can inject its own PKP header into the HTTP stream and pin the UA to its own keys. ๐Ÿ’€ To avoid detection after the fact, the attacker would have to be in a position to intercept all future requests to the host from that UA.

So yeah, key pinning as described here is not a perfect defense against MITM attackers who can pass certificate chain validation procedures. Honestly, nothing short of pre-shared keys is. ๐Ÿ™ˆ But it's still hugely valuable, because it lets host operators limit how many certification authorities can vouch for the host's identity, and it lets UAs catch in-process MITM attacks after the initial communication. ๐Ÿ‘‘

1.1. Requirements Language ๐Ÿ“–

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [RFC2119]. ๐ŸŽ€


2. Server and Client Behavior ๐Ÿ’…

2.1. Response Header Field Syntax ๐Ÿงš

The "Public-Key-Pins" and "Public-Key-Pins-Report-Only" header fields are also called the PKP and PKP-RO header fields in this spec. They're new response headers defined here. ๐ŸŒˆ A server uses them to tell a UA that it should do Pin Validation (Section 2.6) for the host that sent the response, and they give the UA the info it needs to do that. ๐Ÿซถ

Figure 1 describes the syntax of the header fields in Augmented Backus-Naur Form (ABNF), using the grammar from [RFC5234] and the rules from Section 3.2 of [RFC7230]. Both header fields' values follow the same rules. โœจ

Public-Key-Directives = directive *( OWS ";" OWS directive )

directive             = directive-name [ "=" directive-value ]
directive-name        = token
directive-value       = token
                      / quoted-string

                    Figure 1: HPKP Header Syntax

Optional white space (OWS) works the way Section 3.2.3 of [RFC7230] says. token and quoted-string work the way Section 3.2.6 of [RFC7230] says. ๐Ÿ“

The directives this spec defines are described below. Here are the overall requirements for directives, lowkey the most important part of this section ๐Ÿ‘‡:

  1. The order that directives appear in doesn't matter. ๐Ÿ”„
  2. Except for pin-directives with the same pin-directive-name (more on that below), a given directive MUST NOT appear more than once in a given header field. Directives are either optional or required, depending on how they're defined. ๐Ÿ“
  3. Directive names are case insensitive. ๐Ÿ”ค
  4. UAs MUST ignore any header fields containing directives, or other header field value data, that don't conform to the syntax defined in this specification. Also, UAs must not attempt to fix malformed header fields. ๐Ÿ™…โ€โ™€๏ธ
  5. If a header field has any directive(s) the UA doesn't recognize, the UA MUST ignore those directives. ๐Ÿซฅ
  6. If the PKP or PKP-RO header field otherwise satisfies the above requirements (1 through 5), the UA MUST process the directives it recognizes. ๐Ÿ’–

Additional directives that extend the semantic functionality of these header fields can be defined in other specifications. The first such specification will need to define a registry for those directives. ๐Ÿ—‚๏ธ Future directives like that will be ignored by UAs that only implement this specification, and also by UAs that are generally non-conforming. ๐Ÿ™ƒ

When a connection passes Pin Validation using the UA's noted Pins for the host at that time, the host becomes a Known Pinned Host. ๐Ÿฆ‹๐Ÿ‘‘

2.1.1. The Pin Directive ๐Ÿ“Œ

okay so the pin directive is how web host operators say "hey, this cryptographic identity belongs to me" ๐Ÿ” its syntax is super simple:

pin-directive       = pin-directive-name "=" pin-directive-value

pin-directive-name  = "pin-" token
pin-directive-value = quoted-string

                      Figure 2: Pin Directive Syntax

the token is the name of a cryptographic hash algorithm ๐Ÿง the only one allowed right now is "sha256", aka the hash algorithm SHA256 [RFC6234]. more algorithms may be allowed in this context later, so keep your eyes peeled ๐Ÿ‘€ the quoted-string is a sequence of base 64 digits, which is the base64-encoded SPKI Fingerprint [RFC4648] (see Section 2.4). โœจ

now the drama ๐ŸŽญ according to the processing rules of Section 2.1, the UA MUST ignore pin-directives whose tokens name hash algorithms it doesn't recognize. if the set of remaining effective pin-directives is empty and the host is a Known Pinned Host, the UA MUST cease to consider the host as a Known Pinned Host (the UA should fail open). the UA should also tell users that the host is no longer a Known Pinned Host ๐Ÿซถ

quick note ๐Ÿ“ per the processing rules of Section 2.1, the pin-directive-name is case insensitive, so PIN-SHA256 and pin-sha256 are the same vibe ๐Ÿ’…

2.1.2. The max-age Directive โณ

the "max-age" directive is the number of seconds after the PKP header field is received during which the UA SHOULD regard the host (the one the message came from) as a Known Pinned Host. it's basically the timer โฐ

the "max-age" directive is REQUIRED to be present within a "Public-Key-Pins" header field. it's meaningless inside a "Public-Key-Pins-Report-Only" header field, so UAs MUST ignore it and not cache the header there. see Section 2.3.3 ๐Ÿ™ˆ

it also REQUIRED to have a directive value. after quoted-string unescaping (if needed), the syntax is:

max-age-value = delta-seconds
delta-seconds = 1*DIGIT

                   Figure 3: max-age Value Syntax

delta-seconds is used as defined in [RFC7234], Section 1.2.1 ๐Ÿ“ and for limits on how big (or small) max-age can get, check out Section 2.3.3 ๐Ÿ’œ

2.1.3. The includeSubDomains Directive ๐ŸŒธ

the OPTIONAL includeSubDomains directive is a valueless directive. if it's there (aka "asserted"), it tells the UA that the Pinning Policy covers this Pinned Host and any subdomains of the host's domain name. main character energy for your whole domain ๐Ÿ‘‘

2.1.4. The report-uri Directive ๐Ÿ“ฃ

the OPTIONAL report-uri directive points to the URI where the UA SHOULD report Pin Validation failures (Section 2.6). the UA POSTs the reports to that URI as described in Section 3 ๐Ÿฆ‹

when it shows up in a PKP or PKP-RO header, it tells the UA that if Pin Validation fails, it SHOULD POST a report to the report-uri. if the header is Public-Key-Pins, the UA should do this in addition to terminating the connection (as described in Section 2.6) ๐Ÿ’€

hosts can set report-uris that use HTTP or HTTPS. if the scheme uses TLS (like HTTPS), UAs MUST perform Pinning Validation when the host in the report-uri is a Known Pinned Host. similarly, UAs MUST apply HSTS if the host in the report-uri is a Known HSTS Host ๐Ÿ”ฅ

also, the report-uri doesn't have to be in the same Internet domain or web origin as the host it's reporting about. no rules there, just vibes ๐ŸŒˆ

UAs SHOULD make their best effort to report Pin Validation failures to the report-uri, but they may fail to report in exceptional conditions. for example, if connecting to the report-uri itself hits a Pinning Validation failure or some other certificate validation failure, the UA MUST cancel the connection. ๐Ÿšซ

and then there's the loop situation ๐Ÿ” if Known Pinned Host A sets a report-uri pointing at Known Pinned Host B, and B sets a report-uri pointing back at A, and both hosts fail Pin Validation, the UA SHOULD detect and break the loop by not sending reports to or about those hosts. nobody wants an infinite ping-pong match ๐Ÿ“

if a report fails, the UA MAY attempt to re-send it later ๐Ÿ”„

last one: UAs SHOULD limit the rate at which they send reports. for example, there's no point sending the same report to the same report-uri more than once per distinct set of declared Pins ๐Ÿ›‘

2.1.5. Examples ๐ŸŽ€

Figure 4 shows some example PKP and PKP-RO response header fields. (Lines are folded so they fit ๐Ÿงš)

Public-Key-Pins: max-age=3000;
    pin-sha256="d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=";
    pin-sha256="E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g="

Public-Key-Pins: max-age=2592000;
    pin-sha256="E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g=";
    pin-sha256="LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ="

Public-Key-Pins: max-age=2592000;
    pin-sha256="E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g=";
    pin-sha256="LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=";
    report-uri="http://example.com/pkp-report"

Public-Key-Pins-Report-Only: max-age=2592000;
    pin-sha256="E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g=";
    pin-sha256="LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=";
    report-uri="https://other.example.net/pkp-report"

Public-Key-Pins:
    pin-sha256="d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=";
    pin-sha256="LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=";
    max-age=259200

Public-Key-Pins:
    pin-sha256="d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=";
    pin-sha256="E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g=";
    pin-sha256="LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=";
    max-age=10000; includeSubDomains

          Figure 4: HTTP Public Key Pinning (HPKP) Header Examples

2.2. Server Processing Model ๐Ÿ–ฅ๏ธ

this section describes the processing model that Pinned Hosts implement ๐Ÿ’– the model has 2 parts: (1) the processing rules for HTTP request messages received over a secure transport (e.g., authenticated, non-anonymous TLS), and (2) the processing rules for HTTP request messages received over non-secure transports, such as TCP.

2.2.1. HTTP-over-Secure-Transport Request Type ๐Ÿ”

when replying to an HTTP request that came in over a secure transport, a Pinned Host SHOULD include in its response exactly one PKP header field, exactly one PKP-RO header field, or one of each. every instance of either header field MUST satisfy the grammar in Section 2.1 โœจ

establishing a given host as a Known Pinned Host (for a given UA) happens in one of two ways:

  1. Over the HTTP protocol running over secure transport, by correctly returning (per this specification) at least one valid PKP header field to the UA.
  2. Through other mechanisms, such as a client-side preloaded Known Pinned Host List. ๐Ÿ“œ

2.2.2. HTTP Request Type ๐Ÿšช

Pinned Hosts SHOULD NOT include the PKP header field in HTTP responses conveyed over non-secure transport. UAs MUST ignore any PKP header received in an HTTP response conveyed over non-secure transport. no PKP over the insecure lane, bestie ๐Ÿšซ

2.3. User Agent Processing Model ๐Ÿง 

the UA processing model relies on parsing domain names. note that internationalized domain names SHALL be canonicalized according to the scheme in Section 10 of [RFC6797] ๐ŸŒ

2.3.1. Public-Key-Pins Response Header Field Processing ๐ŸŽฏ

if the UA receives, over a secure transport, an HTTP response that includes a PKP header field conforming to the grammar in Section 2.1, and there are no underlying secure transport errors or warnings (see Section 2.5), the UA MUST do one of these:

  • Note the host as a Known Pinned Host if it isn't already noted (see Section 2.3.3),

or,

  • Update the UA's cached information for the Known Pinned Host if any of the max-age, includeSubDomains, or report-uri header field value directives convey information different from what the UA already has ๐Ÿ”„

the max-age value is basically a "time to live" counted from the most recent time the PKP header field was seen โณ if the max-age header field value token is 0, the UA MUST remove its cached Pinning Policy information (including the includeSubDomains directive, if asserted) when the Pinned Host is Known. if it isn't Known yet, the UA MUST NOT note this Pinned Host ๐Ÿ’€

if a UA gets more than one PKP header field, or more than one PKP-RO header field, in one HTTP response over a secure transport, the UA MUST process only the first PKP header field (if present) and only the first PKP-RO header field (if present) ๐Ÿฅ‡

if the UA gets the HTTP response over an insecure transport, or the PKP header isn't a Valid Pinning Header (see Section 2.5), the UA MUST ignore any present PKP header field(s). similarly, if the UA gets the HTTP response over an insecure transport, the UA MUST ignore any present PKP-RO header field(s). and the UA MUST ignore any PKP or PKP-RO header fields that don't conform to the grammar in Section 2.1 ๐Ÿ™…

2.3.2. Interaction of Public-Key-Pins and Public-Key-Pins-Report-Only ๐Ÿค

a server MAY set both the "Public-Key-Pins" and "Public-Key-Pins-Report-Only" headers at the same time ๐Ÿญ the headers don't interact with each other, but the UA MUST process the PKP header and SHOULD process both.

the headers are processed according to Section 2.3.1 ๐Ÿ“‹

when the PKP-RO header is used with a report-uri, the UA SHOULD POST reports for Pin Validation failures to the indicated report-uri, although the UA MUST NOT enforce Pin Validation. so when the host has set the PKP-RO header and Pin Validation fails, the UA runs Pin Validation to decide whether it should POST a report, but not whether it should cause a connection failure ๐Ÿ‘€

Note: there is no purpose to using the PKP-RO header without the report-uri directive. User Agents MAY discard such headers without interpreting them further. ๐Ÿ—‘๏ธ

when the PKP header is used with a report-uri, the UA SHOULD POST reports for Pin Validation failures to the indicated report-uri, as well as enforce Pin Validation ๐Ÿ’ช

if a host sets the PKP-RO header, the UA SHOULD note the Pins and directives given in it, ignoring any max-age directive. if the UA does note them, it SHOULD evaluate the specified policy and SHOULD report any would-be Pin Validation failures that would happen if the report-only policy were enforced ๐Ÿงช

if a host sets both the PKP header and the PKP-RO header, the UA MUST note and enforce Pin Validation as specified by the PKP header, and SHOULD process the Pins and directives given in the PKP-RO header. if the UA does process them, it SHOULD evaluate the specified policy and SHOULD report any would-be Pin Validation failures that would occur if the report-only policy were enforced ๐Ÿซง

2.3.3. Noting a Pinned Host - Storage Model ๐ŸŽ€

okay so the Effective Pin Date of a Known Pinned Host is literally the moment the UA saw a Valid Pinning Header for that host ๐Ÿ•ฐ๏ธโœจ The Effective Expiration Date is that Effective Pin Date plus the max-age. A Known Pinned Host is "expired" if its Effective Expiration Date is in the past. The UA MUST ignore any expired Known Pinned Hosts in its cache. ๐Ÿ’€

For example, say a UA is about to do Pin Validation for a Known Pinned Host and the cached info shows an Effective Expiration Date in the past. The UA MUST NOT continue with Pin Validation for that host, and MUST consider the host to no longer be a Known Pinned Host. no cap, that's a hard stop ๐Ÿ™…โ€โ™€๏ธ

Known Pinned Hosts are only identified by domain names, never IP addresses ๐Ÿšซ๐ŸŒ If the substring matching the host production from the Request-URI (of the message the host responded to) syntactically matches the IP-literal or IPv4address productions from Section 3.2.2 of [RFC3986], then the UA MUST NOT note this host as a Known Pinned Host.

Otherwise, if the substring does not congruently match an existing Known Pinned Host's domain name, per the matching procedure specified in Section 8.2 of [RFC6797], then the UA MUST add this host to the Known Pinned Host cache. The UA caches:

  • the Pinned Host's domain name,
  • the Effective Expiration Date, or enough information to calculate it (the Effective Pin Date and the value of the max-age directive),
  • whether or not the includeSubDomains directive is asserted, and
  • the value of the report-uri directive, if present.

If any other metadata from optional or future PKP header directives are present in the Valid Pinning Header, and the UA understands them, the UA MAY note them as well. ๐Ÿง โœจ

UAs MAY set an upper limit on the value of max-age, so that UAs that have noted erroneous Pins (whether by accident or due to attack) have some chance of recovering over time. ๐Ÿ”„ If the server sets a max-age greater than the UA's upper limit, the UA MAY behave as if the server set the max-age to the UA's upper limit. For example, if the UA caps max-age at 5,184,000 seconds (60 days), and a Pinned Host sets a max- age directive of 90 days in its Valid Pinning Header, the UA MAY behave as if the max-age were effectively 60 days. (One way to achieve this behavior is for the UA to simply store a value of 60 days instead of the 90-day value provided by the Pinned Host.) For UA implementation guidance on how to select a maximum max-age, see Section 4.1. ๐ŸŽฏ

The UA MUST NOT modify any pinning metadata of any superdomain matched Known Pinned Host. ๐Ÿ™…โ€โ™€๏ธ

The UA MUST NOT cache information derived from a PKP-RO header. (PKP-RO headers are useful only at the time of receipt and processing.) ๐Ÿซถ

2.3.4. HTTP-Equiv <Meta> Element Attribute ๐Ÿ“

UAs MUST NOT heed http-equiv="Public-Key-Pins" or http-equiv="Public-Key-Pins-Report-Only" attribute settings on <meta> elements [W3C.REC-html401-19991224] in received content. ๐Ÿ™ˆ


2.4. Semantics of Pins ๐Ÿ”

okay the SPKI Fingerprint is the output of a known cryptographic hash algorithm whose input is the DER-encoded ASN.1 representation of the Subject Public Key Info (SPKI) of an X.509 certificate. ๐Ÿง A Pin is the combination of the known algorithm identifier and the SPKI Fingerprint computed using that algorithm. ๐Ÿ’œ

The SPKI Fingerprint is encoded in base 64 for use in an HTTP header [RFC4648]. ๐Ÿฌ

In this version of the specification, the known cryptographic hash algorithm is SHA-256, identified as "sha256" [RFC6234]. (Future specifications may add new algorithms and deprecate old ones.) UAs MUST ignore Pins for which they do not recognize the algorithm identifier. UAs MUST continue to process the rest of a PKP response header field and note Pins for algorithms they do recognize. ๐Ÿซง

Figure 5 reproduces the definition of the SubjectPublicKeyInfo structure in [RFC5280]. ๐Ÿ‘€

SubjectPublicKeyInfo  ::=  SEQUENCE  {
    algorithm            AlgorithmIdentifier,
    subjectPublicKey     BIT STRING  }

AlgorithmIdentifier  ::=  SEQUENCE  {
    algorithm            OBJECT IDENTIFIER,
    parameters           ANY DEFINED BY algorithm OPTIONAL  }

Figure 5: SPKI Definition

If the certificate's Subject Public Key Info is incomplete when taken in isolation, such as when holding a DSA key without domain parameters, a public key pin cannot be formed. ๐Ÿ™…

We pin public keys, rather than entire certificates, to enable operators to generate new certificates containing old public keys (see [why-pin-key]). It's giving smart design ๐Ÿง ๐Ÿ’…

See Appendix A for an example non-normative program that generates SPKI Fingerprints from certificates. ๐Ÿงš


2.5. Noting Pins ๐Ÿ“

Upon receipt of the PKP response header field, the UA notes the host as a Known Pinned Host, storing the Pins and their associated directives in non-volatile storage (for example, along with the HSTS metadata). The Pins and their associated directives are collectively known as Pinning Metadata. ๐Ÿ—‚๏ธโœจ

The UA MUST note the Pins for a Host if and only if all three of the following conditions hold:

  • It received the PKP response header field over an error-free TLS connection. If the host is a Pinned Host, this includes the validation added in Section 2.6.
  • The TLS connection was authenticated with a certificate chain containing at least one of the SPKI structures indicated by at least one of the given SPKI Fingerprints (see Section 2.6).
  • The given set of Pins contains at least one Pin that does NOT refer to an SPKI in the certificate chain. (That is, the host must set a Backup Pin; see Section 4.3.)

If the PKP response header field does not meet all three of these criteria, the UA MUST NOT note the host as a Pinned Host. A PKP response header field that meets all these criteria is known as a Valid Pinning Header. โœ…

Whenever a UA receives a Valid Pinning Header, it MUST set its Pinning Metadata to the exact Pins, Effective Expiration Date (computed from max-age), and (if any) report-uri given in the most recently received Valid Pinning Header. ๐Ÿ”

For forward compatibility, the UA MUST ignore any unrecognized PKP and PKP-RO header directives, while still processing those directives it does recognize. Section 2.1 specifies the directives max-age, Pins, includeSubDomains, and report-uri, but future specifications and implementations might use additional directives. ๐Ÿ”ฎ

Upon receipt of a PKP-RO response header field, the UA SHOULD evaluate the policy expressed in the field, and SHOULD generate and send a report (see Section 3). However, failure to validate the Pins in the field MUST have no effect on the validity or non-validity of the policy expressed in the PKP field or in previously noted Pins for the Known Pinned Host. ๐Ÿ™Œ

The UA need not note any Pins or other policy expressed in the PKP-RO response header field, except for the purpose of determining that it has already sent a report for a given policy. UAs SHOULD make a best effort not to inundate report-uris with redundant reports. ๐Ÿ“ฌ๐Ÿ™…โ€โ™€๏ธ


2.6. Validating Pinned Connections ๐Ÿ”’

When a UA connects to a Pinned Host using a TLS connection, if the TLS connection has errors, the UA MUST terminate the connection without allowing the user to proceed anyway. (This behavior is the same as that required by [RFC6797].) ๐Ÿšจ

If the connection has no errors, then the UA will determine whether to apply a new, additional correctness check: Pin Validation. A UA SHOULD perform Pin Validation whenever connecting to a Known Pinned Host, as soon as possible (e.g., immediately after receiving the Server Certificate message). It is acceptable to allow Pin Validation to be disabled for some Hosts according to local policy. For example, a UA may disable Pin Validation for Pinned Hosts whose validated certificate chain terminates at a user-defined trust anchor, rather than a trust anchor built-in to the UA (or underlying platform). ๐Ÿง

To perform Pin Validation, the UA will compute the SPKI Fingerprints for each certificate in the Pinned Host's validated certificate chain, using each supported hash algorithm for each certificate. (As described in Section 2.4, certificates whose SPKI cannot be taken in isolation cannot be pinned.) The UA MUST ignore superfluous certificates in the chain that do not form part of the validating chain. The UA will then check that the set of these SPKI Fingerprints intersects the set of SPKI Fingerprints in that Pinned Host's Pinning Metadata. If there is set intersection, the UA continues with the connection as normal. Otherwise, the UA MUST treat this Pin Validation failure as a non-recoverable error. Any procedure that matches the results of this Pin Validation procedure is considered equivalent. ๐Ÿ”๐Ÿ’–

A UA that has previously noted a host as a Known Pinned Host MUST perform Pin Validation when setting up the TLS session, before beginning an HTTP conversation over the TLS channel. ๐Ÿค

UAs send validation failure reports only when Pin Validation is actually in effect. Pin Validation might not be in effect, e.g., because the user has elected to disable it, or because a presented certificate chain chains up to a user-defined trust anchor. In such cases, UAs SHOULD NOT send reports. ๐Ÿ“ต


2.7. Interactions with Preloaded Pin Lists ๐Ÿ“š

UAs MAY choose to implement additional sources of pinning information, such as through built-in lists of pinning information. Such UAs should allow users to override such additional sources, including disabling them from consideration. ๐ŸŽ›๏ธ

The effective policy for a Known Pinned Host that has both built-in Pins and Pins from previously observed PKP header response fields is implementation-defined. ๐Ÿคทโ€โ™€๏ธ


2.8. Pinning Self-Signed End Entities ๐ŸŒธ

If UAs accept hosts that authenticate themselves with self-signed end entity certificates, they MAY also allow hosts to pin the public keys in such certificates. The usability and security implications of this practice are outside the scope of this specification. ๐Ÿ™ˆโœจ

3. Reporting Pin Validation Failure โœจ

okay so bestie, if a Known Pinned Host has set the report-uri directive, the UA SHOULD report Pin Validation failures to that URI ๐Ÿ“ฌ It does this by POSTing a JSON [RFC7159] message to the URI, and the JSON message looks like this ๐ŸŽ€

{
  "date-time": date-time,
  "hostname": hostname,
  "port": port,
  "effective-expiration-date": expiration-date,
  "include-subdomains": include-subdomains,
  "noted-hostname": noted-hostname,
  "served-certificate-chain": [
    pem1, ... pemN
  ],
  "validated-certificate-chain": [
    pem1, ... pemN
  ],
  "known-pins": [
    known-pin1, ... known-pinN
  ]
}

Figure 6: JSON Report Format

whitespace outside of quoted strings is not significant ๐Ÿซถ the key/value pairs can show up in any order, but each one MUST appear only once, no duplicates, periodt ๐Ÿ’…

the date-time is the time the UA observed the Pin Validation failure ๐Ÿ•ฐ๏ธ it's a string formatted according to Section 5.6, "Internet Date/Time Format", of [RFC3339].

the hostname is the hostname the UA originally made the request to that failed Pin Validation ๐ŸŒธ it's a string.

the port is the port the UA originally made that request to ๐Ÿ”Œ it's an integer.

the effective-expiration-date is the Effective Expiration Date for the noted Pins โณ it's a string formatted according to Section 5.6, "Internet Date/Time Format", of [RFC3339].

include-subdomains tells you whether the UA noted the includeSubDomains directive for the Known Pinned Host ๐ŸŒˆ it's one of the JSON identifiers "true" or "false".

noted-hostname is the hostname the UA noted when it noted the Known Pinned Host ๐Ÿ” this is the bit that helps operators understand why Pin Validation was performed for, e.g., foo.example.com when the noted Known Pinned Host was example.com with includeSubDomains set. it's giving clarity, lowkey iconic ๐Ÿงš

the served-certificate-chain is the certificate chain exactly as the Known Pinned Host served it during TLS session setup ๐Ÿ” it's an array of strings, and each string pem1, ... pemN is the Privacy-Enhanced Mail (PEM) representation of each X.509 certificate, as described in [RFC7468].

the validated-certificate-chain is the certificate chain the UA built itself during certificate chain verification ๐Ÿ› ๏ธ this may differ from the served-certificate-chain, so don't be shook if they don't match. it's also an array of strings, with each string pem1, ... pemN being the PEM representation of each X.509 certificate as described in [RFC7468]. UAs that build certificate chains in more than one way during the validation process SHOULD send the last chain built ๐Ÿ’œ that way they avoid keeping too much state around during validation, which is very much a "less is more" moment ๐Ÿ“

the known-pins are the Pins the UA has noted for the Known Pinned Host ๐Ÿ“Œ they're an array of strings with this syntax:

known-pin = token "=" quoted-string

Figure 7: Known Pin Syntax

as in Section 2.4, the token refers to the algorithm name, and the quoted-string refers to the base64 encoding of the SPKI Fingerprint ๐Ÿง when the UA formulates the JSON POST body, it MUST either use single-quoted JSON strings, or use double-quoted JSON strings and backslash-escape the embedded double quotes in the quoted-string part of the known-pin. no skipping this one, bestie ๐Ÿ™ˆ

here's an example of a Pin Validation failure report ๐Ÿฆ‹ (the PEM strings are split across multiple lines so they're easier to read, btw โœจ)

{
  "date-time": "2014-04-06T13:00:50Z",
  "hostname": "www.example.com",
  "port": 443,
  "effective-expiration-date": "2014-05-01T12:40:50Z"
  "include-subdomains": false,
  "served-certificate-chain": [
    "-----BEGIN CERTIFICATE-----\n
    MIIEBDCCAuygAwIBAgIDAjppMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT\n
    ...
    HFa9llF7b1cq26KqltyMdMKVvvBulRP/F/A8rLIQjcxz++iPAsbw+zOzlTvjwsto\n
    WHPbqCRiOwY1nQ2pM714A5AuTHhdUDqB1O6gyHA43LL5Z/qHQF1hwFGPa4NrzQU6\n
    yuGnBXj8ytqU0CwIPX4WecigUCAkVDNx\n
    -----END CERTIFICATE-----",
    ...
  ],
  "validated-certificate-chain": [
    "-----BEGIN CERTIFICATE-----\n
    MIIEBDCCAuygAwIBAgIDAjppMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT\n
    ...
    HFa9llF7b1cq26KqltyMdMKVvvBulRP/F/A8rLIQjcxz++iPAsbw+zOzlTvjwsto\n
    WHPbqCRiOwY1nQ2pM714A5AuTHhdUDqB1O6gyHA43LL5Z/qHQF1hwFGPa4NrzQU6\n
    yuGnBXj8ytqU0CwIPX4WecigUCAkVDNx\n
    -----END CERTIFICATE-----",
    ...
  ],
  "known-pins": [
    'pin-sha256="d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM="',
    "pin-sha256=\"E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g=\""
  ]
}

Figure 8: Pin Validation Failure Report Example


4. Security Considerations ๐Ÿ”

okay this section is serious, so let's get into it ๐Ÿ’€ pinning public keys helps hosts strongly assert their cryptographic identity, even when an issuer makes a mistake, acts badly, or gets compromised ๐Ÿ›ก๏ธ but there's some risk that a host operator could lose (or lose control of) their host's private key, like through operator error or host compromise ๐Ÿ˜ญ if the operator had pinned only the key of the host's end-entity certificate, they wouldn't be able to serve their web site or application in a way UAs would trust for the duration of their pin's max-age. (recall that UAs MUST close the connection to a host upon Pin Failure ๐Ÿšช)

so there's a necessary trade-off between two competing goods ๐ŸŽญ on one side you've got pin specificity and maximal reduction of the scope of issuers, and on the other side you've got flexibility and resilience of the host's cryptographic identity. one way to balance it is to pin to the key(s) of the issuer(s) of the host's end-entity certificate(s) โœจ often a valid certificate chain has at least two certificates above the end-entity certificate: the intermediate issuer and the trust anchor. operators can pin any one or more of the public keys in this chain, and they indeed MUST pin to issuers not in the chain (as, for example, a Backup Pin) ๐Ÿงท pinning to an intermediate issuer, or even to a trust anchor or root, still significantly reduces the number of issuers who can issue end-entity certificates for the Known Pinned Host, while still giving that host the flexibility to change keys without a disruption of service ๐ŸŒท

4.1. Maximum max-age

as mentioned in Section 2.3.3, UAs MAY cap the max-age value at some upper limit ๐Ÿงข there's a security trade-off here: low maximum values give a narrow window of protection for users who only visit the Known Pinned Host infrequently, while high maximum values might mean a UA can't successfully perform Pin Validation for a Known Pinned Host if the UA's noted Pins and the host's true Pins diverge ๐Ÿ˜ฌ

that divergence could happen for several reasons, including UA error, host operator error, a network attack, or a Known Pinned Host that intentionally migrates all pinned keys, combined with a UA that has noted true Pins with a high max-age value and hasn't had a chance to observe the new true Pins for the host. (this last example really underscores why host operators should phase in new keys gradually, and set the max-age value in line with their planned key migration schedule ๐Ÿ“…) there's probably no ideal upper limit to the max-age directive that satisfies every use case ๐Ÿคทโ€โ™€๏ธ however, a value on the order of 60 days (5,184,000 seconds) may be considered a balance between the two competing security concerns ๐ŸŒˆ

4.2. Using includeSubDomains Safely

it can happen that Pinned Hosts whose hostnames share a parent domain use different Valid Pinning Headers ๐Ÿ‘ฏ if a host whose hostname is a parent domain for another host sets the includeSubDomains directive, the two hosts' Pins may conflict with each other. for example, consider two Known Pinned Hosts, example.com and subdomain.example.com. assume example.com sets a Valid Pinning Header like this:

Public-Key-Pins: max-age=12000; pin-sha256="ABC...";
    pin-sha256="DEF..."; includeSubDomains

Figure 9: example.com Valid Pinning Header

assume subdomain.example.com sets a Valid Pinning Header like this:

Public-Key-Pins: pin-sha256="GHI..."; pin-sha256="JKL..."

Figure 10: subdomain.example.com Valid Pinning Header

now assume a UA that hasn't previously noted any Pins for either of these hosts ๐Ÿซ  if the UA first contacts subdomain.example.com, it will note the Pins in the Valid Pinning Header and perform Pin Validation as normal on subsequent connections. if the UA then contacts example.com, again it will note the Pins and perform Pin Validation on future connections. easy peasy ๐Ÿญ

but, if the UA happened to visit example.com before subdomain.example.com, then because of example.com's use of the includeSubDomains directive, the UA would attempt to perform Pin Validation for subdomain.example.com using the SPKI hashes ABC... and DEF..., which are not valid for the certificate chains subdomain.example.com uses (the ones with SPKIs GHI... and JLK...) ๐Ÿ˜ฑ so depending on the order the UA sees the Valid Pinning Headers for example.com and subdomain.example.com, Pin Validation might or might not fail for subdomain.example.com, even if the certificate chain the UA gets for subdomain.example.com is perfectly valid. chaotic, I know ๐ŸŒ€

so Pinned Host operators have to use the includeSubDomains directive with care ๐Ÿง  for example, they may choose to use overlapping pin sets for hosts under a parent domain that uses includeSubDomains, or not use the includeSubDomains directive in their effective-second-level domains, or simply use the same pin set for all hosts under a given parent domain ๐Ÿ’–

4.3. Backup Pins

the main way to cope with the risk of inadvertent Pin Validation failure is to keep a Backup Pin ๐Ÿงณ a Backup Pin is a fingerprint for the public key of a secondary, not-yet-deployed key pair. the operator keeps that backup key pair offline and sets a pin for it in the PKP header. then, if the operator loses control of their primary private key, they can deploy the backup key pair ๐Ÿฆธโ€โ™€๏ธ UAs that had the backup key pair pinned (when it was set in previous Valid Pinning Headers) can connect to the host without error. โœจ

because having a backup key pair is so important for recovery, UAs MUST require that hosts set a Backup Pin (see Section 2.5) ๐Ÿ™Œ the downside of keeping a not-yet-deployed key pair is that if an attacker gains control of the private key, she can perform a MITM attack without being discovered ๐Ÿ‘€ so operators must take care to avoid leaking the key, such as by keeping it offline.

HTTP cookies [RFC6265] set by a Known Pinned Host can be stolen by a network attacker who can forge web and DNS responses so that a client sends the cookies to a phony subdomain of the host ๐Ÿช๐Ÿ˜ค to prevent this, hosts SHOULD set the "secure" attribute and precisely scope the "domain" attribute on all security-sensitive cookies, like session cookies ๐Ÿ”’ these settings tell the browser that the cookie should only be sent back to the specific host(s) (and not, e.g., all subdomains of a given domain), and that it should only be sent over HTTPS (not HTTP). main character energy for cookie safety ๐Ÿ’œ

4.5. Hostile Pinning ๐Ÿ˜ˆโœจ

okay so this one's a lil spicy ๐ŸŒถ๏ธ An attacker who can get a valid certificate for a domain, whether a Certification Authority misissued one or they got it some other way (like being the prior owner of the domain), may try 'hostile' pinning ๐Ÿ’€. In that case the attacker sends a Valid Pinning Header that pins to a set of SPKIs they picked. If a UA hasn't noted pins for that host before, it may note the attacker's pins, and suddenly the legit site is locked out ๐Ÿ™…โ€โ™€๏ธ

Thankfully there are a few ways to stop this ๐Ÿ›ก๏ธ Most prominently, the attack can only persist for the maximum max-age (see Section 4.1). Web host operators can also shut it down earlier by working to preload the host's pins within the UA ๐Ÿง Operators may further detect misissuance through other means, such as certificate transparency ([RFC6962]).


5. Privacy Considerations ๐Ÿ•ต๏ธโ€โ™€๏ธ๐Ÿ”’

bestie, this section is giving sneaky ๐Ÿ‘€ Hosts can use HSTS or HPKP as a "super-cookie" by setting distinct policies for a bunch of subdomains. For example, say example.com wants to track distinct UAs without explicitly setting a cookie, or wants to keep tracking after a previously set cookie gets deleted from the UA's cookie store. Here are two attack scenarios.

  • example.com can use report-uri and the ability to pin arbitrary identifiers to distinguish UAs ๐Ÿซฃ
    1. example.com sets a Valid Pinning Header in its response to requests. The header asserts the includeSubDomains directive and specifies a report-uri directive as well. Pages served by the host also include references to the subresource https://bad.example.com/foo.png ๐Ÿ–ผ๏ธ
    2. The Valid Pinning Header includes a "pin" that is not really the hash of an SPKI but is instead an arbitrary distinguishing string sent only in response to a particular request. For each request, the host creates a new, distinct distinguishing string and sets it as if it were a pin ๐Ÿงฉ
    3. The certificate chain served by bad.example.com does not pass Pin Validation given the pin set the host asserted in step (1). The HPKP-conforming UA attempts to report the Pin Validation failure to the specified report-uri, including the certificate chain it observed and the SPKI hashes it expected to see. Among the SPKI hashes is the distinguishing string in step (2) ๐Ÿ“จ
  • Different site operators/origins can optionally collaborate by setting the report-uri to be in an origin they share administrative control of. UAs MAY, therefore, refuse to send reports outside of the origin that set the PKP or PKP-RO header ๐Ÿค
  • example.com can use server name indication (SNI; [RFC3546]) and subdomains to distinguish UAs ๐Ÿ•ธ๏ธ
    1. example.com sets a Valid Pinning Header in its response to requests. The header asserts the includeSubDomains directive.
    2. On a subsequent page view, the host responds with a page including the subresource https://0.fingerprint.example.com/foo.png, and the server responds using a certificate chain that does not pass Pin Validation for the pin-set defined in the Valid Pinning Header in step (1). The HPKP-conforming UA will close the connection, never completing the request to 0.fingerprint.example.com. The host may thus note that this particular UA had noted the (good) Pins for that subdomain ๐Ÿ‘ป
    3. example.com can distinguish 2^N UAs by serving Valid Pinning Headers from an arbitrary number N of distinct subdomains. For any given subdomain n.fingerprint.example.com, the host may deliver a Valid Pinning Header to one UA, but not deliver it to a different UA. The server may then change the configuration for n.fingerprint.example.com. If the UA fails to connect, it was in the set of UAs that were pinned, which can be distinguished from the UAs that were not pinned, as they will succeed in connecting. The host may repeat this for a sufficient number of subdomains necessary to distinguish individual UAs ๐Ÿฆ‹
  • Conforming implementations (as well as implementations conforming to [RFC6797]) must store state about which domains have set policies, hence which domains the UA has contacted. Because these policies cause remotely detectable behaviors, it is advisable that UAs have a way for privacy-sensitive users to clear current Pins for Pinned Hosts and that UAs allow users to query the current state of Pinned Hosts. In addition, note that because pinning a host implies a degree of persistent state, an attacker with physical access to a device may be able to recover information about hosts a user has visited, even if the user has cleared other parts of the UA's state ๐Ÿง
  • Pin reports, as noted in Section 3, contain information about the certificate chain that has failed pin validation. In some cases, such as organization-wide compromise of the end-to-end security of TLS, this may include information about the interception tools and design used by the organization that the organization would otherwise prefer not be disclosed ๐Ÿซ 

6. IANA Considerations ๐Ÿ“š

IANA has registered the response headers described in this document under "Permanent Message Header Field Names" in the "Message Headers" registry [message-headers] with the following parameters:

  • Header Field Names: Public-Key-Pins and Public-Key-Pins-Report-Only
  • Protocol: http
  • Status: standard
  • Reference: RFC 7469

7. Usability Considerations ๐Ÿฅบ

When pinning works to detect impostor Pinned Hosts, users will experience denial of service ๐Ÿ˜ญ It is advisable for UAs to explain the reason why, i.e., that it was impossible to verify the confirmed cryptographic identity of the host ๐Ÿ’ฌ

It is advisable that UAs have a way for users to clear current Pins for Pinned Hosts and that UAs allow users to query the current state of Pinned Hosts ๐Ÿงน


8. References ๐Ÿ“–

8.1. Normative References

[RFC2119]  Bradner, S., "Key words for use in RFCs to Indicate
           Requirement Levels", BCP 14, RFC 2119, March 1997,
           <http://www.rfc-editor.org/info/rfc2119>.

[RFC3339]  Klyne, G. and C. Newman, "Date and Time on the Internet:
           Timestamps", RFC 3339, July 2002,
           <http://www.rfc-editor.org/info/rfc3339>.

[RFC3986]  Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform
           Resource Identifier (URI): Generic Syntax", STD 66, RFC
           3986, January 2005,
           <http://www.rfc-editor.org/info/rfc3986>.

[RFC4648]  Josefsson, S., "The Base16, Base32, and Base64 Data
           Encodings", RFC 4648, October 2006,
           <http://www.rfc-editor.org/info/rfc4648>.

[RFC5234]  Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax
           Specifications: ABNF", STD 68, RFC 5234, January 2008,
           <http://www.rfc-editor.org/info/rfc5234>.

[RFC5246]  Dierks, T. and E. Rescorla, "The Transport Layer Security
           (TLS) Protocol Version 1.2", RFC 5246, August 2008,
           <http://www.rfc-editor.org/info/rfc5246>.

[RFC5280]  Cooper, D., Santesson, S., Farrell, S., Boeyen, S.,
           Housley, R., and W. Polk, "Internet X.509 Public Key
           Infrastructure Certificate and Certificate Revocation List
           (CRL) Profile", RFC 5280, May 2008,
           <http://www.rfc-editor.org/info/rfc5280>.

[RFC6234]  Eastlake 3rd, D. and T. Hansen, "US Secure Hash Algorithms
           (SHA and SHA-based HMAC and HKDF)", RFC 6234, May 2011,
           <http://www.rfc-editor.org/info/rfc6234>.

[RFC6265]  Barth, A., "HTTP State Management Mechanism", RFC 6265,
           April 2011, <http://www.rfc-editor.org/info/rfc6265>.

[RFC6797]  Hodges, J., Jackson, C., and A. Barth, "HTTP Strict
           Transport Security (HSTS)", RFC 6797, November 2012,
           <http://www.rfc-editor.org/info/rfc6797>.

[RFC7159]  Bray, T., Ed., "The JavaScript Object Notation (JSON) Data
           Interchange Format", RFC 7159, March 2014,
           <http://www.rfc-editor.org/info/rfc7159>.

[RFC7230]  Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer
           Protocol (HTTP/1.1): Message Syntax and Routing", RFC
           7230, June 2014, <http://www.rfc-editor.org/info/rfc7230>.

[RFC7234]  Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke,
           Ed., "Hypertext Transfer Protocol (HTTP/1.1): Caching",
           RFC 7234, June 2014,
           <http://www.rfc-editor.org/info/rfc7234>.

[RFC7468]  Josefsson, S. and S. Leonard, "Textual Encodings of PKIX,
           PKCS, and CMS Structures", RFC 7468, April 2015,
           <http://www.rfc-editor.org/info/rfc7468>.

[W3C.REC-html401-19991224]
           Raggett, D., Hors, A., and I. Jacobs, "HTML 4.01
           Specification", World Wide Web Consortium Recommendation
           REC-html401-19991224, December 1999,
           <http://www.w3.org/TR/1999/REC-html401-19991224>.

[message-headers]
           IANA, "Message Headers",
           <http://www.iana.org/assignments/message-headers/>.

8.2. Informative References

[RFC3546]  Blake-Wilson, S., Nystrom, M., Hopwood, D., Mikkelsen, J.,
           and T. Wright, "Transport Layer Security (TLS)
           Extensions", RFC 3546, June 2003,
           <http://www.rfc-editor.org/info/rfc3546>.

[RFC6962]  Laurie, B., Langley, A., and E. Kasper, "Certificate
           Transparency", RFC 6962, June 2013,
           <http://www.rfc-editor.org/info/rfc6962>.

[TACK]     Marlinspike, M., "Trust Assertions for Certificate Keys",
           Work in Progress, draft-perrin-tls-tack-02, January 2013.

[why-pin-key]
           Langley, A., "Public Key Pinning", Imperial Violet: Adam
           Langley's Weblog, May 2011,
           <https://www.imperialviolet.org/2011/05/04/pinning.html>.

Appendix A. Fingerprint Generation ๐Ÿงพ๐Ÿ”‘

This Portable Operating System Interface (POSIX) shell program generates SPKI Fingerprints, suitable for use in pinning, from PEM-encoded certificates. It is non-normative ๐Ÿ’…

openssl x509 -noout -in certificate.pem -pubkey | \
    openssl asn1parse -noout -inform pem -out public.key
openssl dgst -sha256 -binary public.key | openssl enc -base64

Figure 11: Example SPKI Fingerprint Generation Code

Appendix B. Deployment Guidance ๐Ÿš€

okay so this section is non-normative guidance, which just means it's friendly advice and not a rulebook. it can still totally smooth out your adoption of public key pinning ๐ŸŽ€

  • okay so operators should get the backup public key signed by a different (root and/or intermediary) CA than their primary certificate, and store the backup key pair safely offline ๐Ÿ”. the semantics of an SPKI Fingerprint don't require the issuance of a certificate to construct a valid Pin. however, in lots of deployment scenarios, to make a Backup Pin operational, the server operator will need to have a certificate to deploy TLS on the host. if you don't get a certificate through prior arrangement, clients that recognize the site as a Known Pinned Host won't be able to successfully perform Pin Validation until the operator can get a new certificate from their desired certificate issuer ๐Ÿ˜ญ
  • it's most economical to have the backup certificate signed by a completely different signature chain than the live certificate, to maximize recoverability in the event of compromise of either the root or intermediary signer. the whole point is recoverability, bestie ๐Ÿฆ‹
  • operators should periodically exercise their Backup Pin plan -- an untested backup is no backup at all ๐Ÿ’€ seriously, test it
  • operators should start small ๐ŸŒธ. first deploy public key pinning using report-only mode together with a report-uri directive that points to a reliable report collection endpoint. when moving out of report-only mode, operators should start by setting a max-age of minutes or a few hours, and then gradually increase max-age as they gain confidence in their operational capability. baby steps are iconic, no cap โœจ

Acknowledgements ๐Ÿซถ

huge thank you to Tobias Gondrom, Jeff Hodges, Paul Hoffman, Ivan Krstic, Adam Langley, Barry Leiba, Nicolas Lidzborski, SM, James Manger, Yoav Nir, Trevor Perrin, Eric Rescorla, Pete Resnick, Tom Ritter, and Yan Zhu for the suggestions and edits that clarified the text ๐Ÿ’–

TACK [TACK] is a fruitful source of alternative design considerations ๐Ÿงš


Authors' Addresses ๐Ÿ’Œ

Chris Evans, the first author ๐Ÿ‘‘

Chris Evans
Google, Inc.
1600 Amphitheatre Pkwy
Mountain View, CA  94043
United States

EMail: cevans@google.com

Chris Palmer, slay ๐Ÿ’…

Chris Palmer
Google, Inc.
1600 Amphitheatre Pkwy
Mountain View, CA  94043
United States

EMail: palmer@google.com

Ryan Sleevi, the last one, and they're iconic too ๐ŸŒˆ

Ryan Sleevi
Google, Inc.
1600 Amphitheatre Pkwy
Mountain View, CA  94043
United States

EMail: sleevi@google.com
๐Ÿ“ฆ where this page comes from