idnits 2.17.1 draft-ietf-websec-key-pinning-07.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** There are 2 instances of too long lines in the document, the longest one being 5 characters in excess of 72. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (July 09, 2013) is 3945 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Unused Reference: 'RFC5226' is defined on line 935, but no explicit reference was found in the text == Outdated reference: A later version (-10) exists of draft-josefsson-pkix-textual-01 ** Obsolete normative reference: RFC 2616 (Obsoleted by RFC 7230, RFC 7231, RFC 7232, RFC 7233, RFC 7234, RFC 7235) ** Obsolete normative reference: RFC 4627 (Obsoleted by RFC 7158, RFC 7159) ** Obsolete normative reference: RFC 4634 (Obsoleted by RFC 6234) ** Obsolete normative reference: RFC 5226 (Obsoleted by RFC 8126) ** Obsolete normative reference: RFC 5246 (Obsoleted by RFC 8446) Summary: 6 errors (**), 0 flaws (~~), 3 warnings (==), 1 comment (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Web Security C. Evans 3 Internet-Draft C. Palmer 4 Intended status: Standards Track R. Sleevi 5 Expires: January 10, 2014 Google, Inc. 6 July 09, 2013 8 Public Key Pinning Extension for HTTP 9 draft-ietf-websec-key-pinning-07 11 Abstract 13 This memo describes an extension to the HTTP protocol allowing web 14 host operators to instruct user agents (UAs) to remember ("pin") the 15 hosts' cryptographic identities for a given period of time. During 16 that time, UAs will require that the host present a certificate chain 17 including at least one Subject Public Key Info structure whose 18 fingerprint matches one of the pinned fingerprints for that host. By 19 effectively reducing the number of authorities who can authenticate 20 the domain during the lifetime of the pin, pinning may reduce the 21 incidence of man-in-the-middle attacks due to compromised 22 Certification Authorities. 24 Status of This Memo 26 This Internet-Draft is submitted in full conformance with the 27 provisions of BCP 78 and BCP 79. 29 Internet-Drafts are working documents of the Internet Engineering 30 Task Force (IETF). Note that other groups may also distribute 31 working documents as Internet-Drafts. The list of current Internet- 32 Drafts is at http://datatracker.ietf.org/drafts/current/. 34 Internet-Drafts are draft documents valid for a maximum of six months 35 and may be updated, replaced, or obsoleted by other documents at any 36 time. It is inappropriate to use Internet-Drafts as reference 37 material or to cite them other than as "work in progress." 39 This Internet-Draft will expire on January 10, 2014. 41 Copyright Notice 43 Copyright (c) 2013 IETF Trust and the persons identified as the 44 document authors. All rights reserved. 46 This document is subject to BCP 78 and the IETF Trust's Legal 47 Provisions Relating to IETF Documents 48 (http://trustee.ietf.org/license-info) in effect on the date of 49 publication of this document. Please review these documents 50 carefully, as they describe your rights and restrictions with respect 51 to this document. Code Components extracted from this document must 52 include Simplified BSD License text as described in Section 4.e of 53 the Trust Legal Provisions and are provided without warranty as 54 described in the Simplified BSD License. 56 Table of Contents 58 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 59 1.1. Requirements Language . . . . . . . . . . . . . . . . . . 3 60 2. Server and Client Behavior . . . . . . . . . . . . . . . . . 3 61 2.1. Response Header Field Syntax . . . . . . . . . . . . . . 3 62 2.1.1. The max-age Directive . . . . . . . . . . . . . . . . 5 63 2.1.2. The includeSubDomains Directive . . . . . . . . . . . 5 64 2.1.3. The report-uri Directive . . . . . . . . . . . . . . 5 65 2.1.4. The strict Directive . . . . . . . . . . . . . . . . 6 66 2.1.5. Examples . . . . . . . . . . . . . . . . . . . . . . 6 67 2.2. Server Processing Model . . . . . . . . . . . . . . . . . 7 68 2.2.1. HTTP-over-Secure-Transport Request Type . . . . . . . 7 69 2.2.2. HTTP Request Type . . . . . . . . . . . . . . . . . . 8 70 2.3. User Agent Processing Model . . . . . . . . . . . . . . . 8 71 2.3.1. Public-Key-Pins Response Header Field Processing . . 8 72 2.3.2. Noting a Pinned Host - Storage Model . . . . . . . . 9 73 2.3.3. HTTP-Equiv Element Attribute . . . . . . . . . 10 74 2.4. Semantics of Pins . . . . . . . . . . . . . . . . . . . . 10 75 2.5. Noting Pins . . . . . . . . . . . . . . . . . . . . . . . 11 76 2.6. Validating Pinned Connections . . . . . . . . . . . . . . 12 77 2.7. Interactions With Preloaded Pin Lists . . . . . . . . . . 13 78 2.8. Pinning Self-Signed End Entities . . . . . . . . . . . . 13 79 3. Reporting Pin Validation Failure . . . . . . . . . . . . . . 13 80 4. Security Considerations . . . . . . . . . . . . . . . . . . . 15 81 4.1. Maximum max-age . . . . . . . . . . . . . . . . . . . . . 15 82 4.2. Using includeSubDomains Safely . . . . . . . . . . . . . 16 83 4.3. Backup Pins . . . . . . . . . . . . . . . . . . . . . . . 17 84 5. Privacy Considerations . . . . . . . . . . . . . . . . . . . 17 85 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 18 86 7. Usability Considerations . . . . . . . . . . . . . . . . . . 19 87 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 19 88 9. What's Changed . . . . . . . . . . . . . . . . . . . . . . . 19 89 10. References . . . . . . . . . . . . . . . . . . . . . . . . . 20 90 10.1. Normative References . . . . . . . . . . . . . . . . . . 20 91 10.2. Informative References . . . . . . . . . . . . . . . . . 21 92 Appendix A. Fingerprint Generation . . . . . . . . . . . . . . . 21 93 Appendix B. Deployment Guidance . . . . . . . . . . . . . . . . 21 94 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 22 96 1. Introduction 98 We propose a new HTTP header to enable a web host to express to user 99 agents (UAs) which Subject Public Key Info (SPKI) structure(s) UAs 100 SHOULD expect to be present in the host's certificate chain in future 101 connections using TLS (see [RFC5246]). We call this "public key 102 pinning". At least one UA (Google Chrome) has experimented with the 103 idea by shipping with a user-extensible embedded set of pins. 104 Although effective, this does not scale. This proposal addresses the 105 scale problem. 107 Deploying public key pinning safely will require operational and 108 organizational maturity due to the risk that hosts may make 109 themselves unavailable by pinning to a SPKI that becomes invalid. 110 (See Section 4.) We believe that, with care, host operators can 111 greatly reduce the risk of MITM attacks and other false- 112 authentication problems for their users without incurring undue risk. 114 We intend for hosts to use public key pinning together with HSTS 115 ([RFC6797]), but is possible to pin keys without requiring HSTS. 117 This draft is being discussed on the WebSec Working Group mailing 118 list, websec@ietf.org. 120 1.1. Requirements Language 122 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 123 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 124 document are to be interpreted as described in RFC 2119 [RFC2119]. 126 2. Server and Client Behavior 128 2.1. Response Header Field Syntax 130 The Public-Key-Pins HTTP response header field (PKP header field) 131 indicates to a UA that it should perform Pin Validation (Section 2.6) 132 in regards to the host emitting the response message containing this 133 header field, and provides the necessary information for the UA to do 134 so. 136 Figure 1 describes the ABNF (Augmented Backus-Naur Form) syntax of 137 the header field. It is based on the Generic Grammar defined in 138 Section 2 of [RFC2616] (which includes a notion of "implied linear 139 whitespace", also known as "implied *LWS"). 141 Public-Key-Pins = 142 "Public-Key-Pins" ":" [ directive ] *( ";" [ directive ] ) 143 Public-Key-Pins-Report-Only = 144 "Public-Key-Pins-Report-Only" ":" [ directive ] *( ";" [ directive ] ) 146 directive = simple-directive 147 / pin-directive 149 simple-directive = directive-name [ "=" directive-value ] 150 directive-name = token 151 directive-value = token 152 / quoted-string 154 pin-directive = "pin-" token "=" quoted-string 156 Figure 1: HPKP Header Syntax 158 token and quoted-string are used as defined in [RFC2616], 159 Section 2.2. 161 The directives defined in this specification are described below. 162 The overall requirements for directives are: 164 1. The order of appearance of directives is not significant. 166 2. All simple-directives MUST appear only once in a PKP header 167 field. Directives are either optional or required, as stipulated 168 in their definitions. 170 3. Directive names are case-insensitive. 172 4. UAs MUST ignore any PKP header fields containing directives, or 173 other header field value data, that do not conform to the syntax 174 defined in this specification. 176 5. If a PKP header field contains any directive(s) the UA does not 177 recognize, the UA MUST ignore the those directives. 179 6. If the PKP header field otherwise satisfies the above 180 requirements (1 through 5), the UA MUST process the directives it 181 recognizes. 183 Additional directives extending the semantic functionality of the PKP 184 header field can be defined in other specifications, with a registry 185 (having an IANA policy definition of IETF Review [RFC2616]) defined 186 for them at such time. Such future directives will be ignored by UAs 187 implementing only this specification, as well as by generally non- 188 conforming UAs. 190 In the pin-directive, the token is the name of a cryptographic hash 191 algorithm, and MUST be either "sha1" or "sha256". The quoted-string 192 is a sequence of base 64 digits: the base 64-encoded SPKI Fingerprint 193 ([RFC4648]). See Section 2.4. 195 2.1.1. The max-age Directive 197 The REQUIRED "max-age" directive specifies the number of seconds, 198 after the reception of the PKP header field, during which the UA 199 SHOULD regard the host (from whom the message was received) as a 200 Known Pinned Host. The delta-seconds production is specified in 201 [RFC2616]. 203 The syntax of the max-age directive's REQUIRED value (after quoted- 204 string unescaping, if necessary) is defined as: 206 max-age-value = delta-seconds 207 delta-seconds = 1*DIGIT 209 Figure 2: max-age Value Syntax 211 delta-seconds is used as defined in [RFC2616], Section 3.3.2. 213 NOTE: A max-age value of zero (i.e., "max-age=0") signals the UA to 214 cease regarding the host as a Known Pinned Host, including the 215 includeSubDomains directive (if asserted for that Known Pinned Host). 216 See Section 2.3.1. 218 2.1.2. The includeSubDomains Directive 220 The OPTIONAL "includeSubDomains" directive is a valueless directive 221 which, if present (i.e., it is "asserted"), signals to the UA that 222 the Pinning Policy applies to this Pinned Host as well as any 223 subdomains of the host's domain name. 225 2.1.3. The report-uri Directive 227 The OPTIONAL "report-uri" directive indicates the URI to which the UA 228 SHOULD report Pin Validation failures (Section 2.6). The UA POSTs 229 the reports to the given URI as described in Section 3. 231 When used in the Public-Key-Pins-Report-Only header, the UA SHOULD 232 POST reports for Pin Validation failures to the indicated report-uri, 233 although the UA MUST NOT enforce Pin Validation. That is, in the 234 event of Pin Validation failure when the host has set the Public-Key- 235 Pins-Report-Only header, the UA performs Pin Validation only to check 236 whether or not it should POST a report, but not for causing 237 connection failure. 239 If a Host sets both the Public-Key-Pins header and the Public-Key- 240 Pins-Report-Only header, the UA MUST NOT enforce Pin Validation, and 241 MUST note only the pins and directives given in the Public-Key-Pins- 242 Report-Only header. 244 When used in the Public-Key-Pins header, the presence of a report-uri 245 directive indicates to the UA that the UA MUST enforce Pin 246 Validation, and the UA SHOULD also, in the event of Pin Validation 247 failure, POST a report to the report-uri. 249 Note that the report-uri need not necessarily be in the same Internet 250 domain or web origin as the Known Pinned Host. 252 Hosts may set report-uris that use HTTP, HTTPS, or other schemes. If 253 the scheme in the report-uri is HTTPS, UAs MUST perform Pinning 254 Validation when the host in the report-uri is a Known Pinned Host; 255 similarly, UAs MUST apply HSTS if the host in the report-uri is a 256 Known HSTS Host. 258 UAs SHOULD make their best effort to report Pin Validation failures 259 to the report-uri, but may fail to report in exceptional conditions. 260 For example, if connecting the report-uri itself incurs a Pinning 261 Validation failure or other certificate validation failure, the UA 262 MUST cancel the connection (and MAY attempt to re-send the report 263 later). Similarly, if Known Pinned Host A sets a report-uri 264 referring to Known Pinned Host B, and if B sets a report-uri 265 referring to A, and if both hosts fail Pin Validation, the UA SHOULD 266 detect and break the loop by failing to send reports to and about 267 those hosts. 269 UAs SHOULD limit the rate at which they send reports. For example, 270 it is unnecessary to send the same report to the same report-uri more 271 than once. 273 2.1.4. The strict Directive 275 The OPTIONAL "strict" directive is a valueless directive which, if 276 present (i.e., it is "asserted"), signals to the UA that it should 277 apply to the Pinned Host the Pinning Policy expressed in the PKP 278 header exactly as specified, ignoring local client policy. 280 2.1.5. Examples 282 Figure 3 shows some example response header fields using the pins 283 extension (folded for clarity). 285 Public-Key-Pins: max-age=3000; 286 pin-sha1="4n972HfV354KP560yw4uqe/baXc="; 287 pin-sha1="IvGeLsbqzPxdI0b0wuj2xVTdXgc=" 289 Public-Key-Pins: max-age=2592000; 290 pin-sha1="4n972HfV354KP560yw4uqe/baXc="; 291 pin-sha256="LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=" 293 Public-Key-Pins: max-age=2592000; 294 pin-sha1="4n972HfV354KP560yw4uqe/baXc="; 295 pin-sha256="LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ="; 296 report-uri="http://example.com/pkp-report" 298 Public-Key-Pins-Report-Only: max-age=2592000; 299 pin-sha1="4n972HfV354KP560yw4uqe/baXc="; 300 pin-sha256="LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ="; 301 report-uri="http://example.com/pkp-report" 303 Public-Key-Pins: pin-sha1="4n972HfV354KP560yw4uqe/baXc="; 304 pin-sha1="qvTGHdzF6KLavt4PO0gs2a6pQ00="; 305 pin-sha256="LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ="; 306 max-age=259200 308 Public-Key-Pins: pin-sha1="4n972HfV354KP560yw4uqe/baXc="; 309 pin-sha1="qvTGHdzF6KLavt4PO0gs2a6pQ00="; 310 pin-sha256="LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ="; 311 max-age=10000; includeSubDomains 313 Figure 3: HPKP Header Examples 315 2.2. Server Processing Model 317 This section describes the processing model that Pinned Hosts 318 implement. The model comprises two facets: the processing rules for 319 HTTP request messages received over a secure transport (e.g. TLS 320 [RFC5246]); and the processing rules for HTTP request messages 321 received over non-secure transports, such as TCP. 323 2.2.1. HTTP-over-Secure-Transport Request Type 325 When replying to an HTTP request that was conveyed over a secure 326 transport, a Pinned Host SHOULD include in its response exactly one 327 PKP header field that MUST satisfy the grammar specified above in 328 Section 2.1. If the Pinned Host does not include the PKP header 329 field, and if the connection passed Pin Validation, UAs MUST treat 330 the host as if it had set its max-age to 0 (see Section 2.3.1). 332 Establishing a given host as a Known Pinned Host, in the context of a 333 given UA, MAY be accomplished over the HTTP protocol, which is in 334 turn running over secure transport, by correctly returning (per this 335 specification) at least one valid PKP header field to the UA. Other 336 mechanisms, such as a client-side pre-loaded Known Pinned Host list 337 MAY also be used. 339 2.2.2. HTTP Request Type 341 Pinned Hosts SHOULD NOT include the PKP header field in HTTP 342 responses conveyed over non-secure transport. UAs MUST ignore any 343 PKP header received in an HTTP response conveyed over non-secure 344 transport. 346 2.3. User Agent Processing Model 348 This section describes the HTTP Public Key Pinning processing model 349 for UAs. 351 The UA processing model relies on parsing domain names. Note that 352 internationalized domain names SHALL be canonicalized according to 353 the scheme in Section 10 of [RFC6797]. 355 2.3.1. Public-Key-Pins Response Header Field Processing 357 If the UA receives, over a secure transport, an HTTP response that 358 includes a PKP header field conforming to the grammar specified in 359 Section 2.1, and there are no underlying secure transport errors or 360 warnings (see Section 2.5), the UA MUST either: 362 o Note the host as a Known HSTS Host if it is not already so noted 363 (see Section 2.3.2), 365 or, 367 o Update the UA's cached information for the Known Pinned Host if 368 any of of the max-age, includeSubDomains, strict, or report-uri 369 header field value directives convey information different than 370 that already maintained by the UA. 372 o The max-age value is essentially a "time to live" value relative 373 to the time of the most recent observation of the PKP header 374 field. 376 o If the max-age header field value token has a value of 0, the UA 377 MUST remove its cached Pinning Policy information (including the 378 includeSubDomains and strict directives, if asserted) if the 379 Pinned Host is Known, or, MUST NOT note this Pinned Host if it is 380 not yet Known. 382 o If a UA receives more than one PKP header field in an HTTP 383 response message over secure transport, then the UA MUST process 384 only the first such header field. 386 Otherwise: 388 o If the UA receives the HTTP response over insecure transport, or 389 if the PKP header is not a Valid Pinning Header (see Section 2.5), 390 the UA MUST ignore any present PKP header field(s). 392 o The UA MUST ignore any PKP header fields not conforming to the 393 grammar specified in Section 2.1. 395 2.3.2. Noting a Pinned Host - Storage Model 397 If the substring matching the host production from the Request-URI 398 (of the message to which the host responded) syntactically matches 399 the IP-literal or IPv4address productions from Section 3.2.2 of 400 [RFC3986], then the UA MUST NOT note this host as a Known Pinned 401 Host. 403 Otherwise, if the substring does not congruently match a Known Pinned 404 Host's domain name, per the matching procedure specified in 405 Section 8.2 of [RFC6797], then the UA MUST note this host as a Known 406 Pinned Host, caching the Pinned Host's domain name and noting along 407 with it the time of the observation (also known as the Effective Pin 408 Date), the value of the max-age directive, whether or not the 409 includeSubDomains or strict directives are asserted, the value of the 410 report-uri directive (if present), and any other metadata from 411 optional or future PKP header directives. 413 UAs MAY set an upper limit on the value of max-age, so that UAs that 414 have noted erroneous pins (whether by accident or due to attack) have 415 some chance of recovering over time. If the server sets a max-age 416 greater than the UA's upper limit, the UA MAY behave as if the server 417 set the max-age to the UA's upper limit. For example, if the UA caps 418 max-age at 5184000 seconds (60 days), and a Pinned Host sets a max- 419 age directive of 90 days in its Valid Pinning Header, the UA MAY 420 behave as if the max-age were effectively 60 days. (One way to 421 achieve this behavior is for the UA to simply store a value of 60 422 days instead of the 90 day value provided by the Pinned Host.) For 423 UA implementation guidance on how to select a maximum max-age, see 424 Section 4.1. 426 The UA MUST NOT modify any pinning metadata of any superdomain 427 matched Known Pinned Host. 429 A Known Pinned Host is "expired" if the Effective Pin Date plus the 430 max-age refers to a date in the past. The UA MUST ignore all expired 431 Known Pinned Hosts from its cache if, at any time, an expired Known 432 Pinned Host exists in the cache. 434 2.3.3. HTTP-Equiv Element Attribute 436 UAs MUST NOT heed http-equiv="Public-Key-Pins" attribute settings on 437 elements [W3C.REC-html401-19991224] in received content. 439 2.4. Semantics of Pins 441 An SPKI Fingerprint is defined as the output of a known cryptographic 442 hash algorithm whose input is the DER-encoded ASN.1 representation of 443 the SubjectPublicKeyInfo (SPKI) field of an X.509 certificate. A Pin 444 is defined as the combination of the known algorithm identifier and 445 the SPKI Fingerprint computed using that algorithm. 447 The SPKI Fingerprint is encoded in base 64 for use in an HTTP header. 448 (See [RFC4648].) 450 In this version of the specification, the known cryptographic hash 451 algorithms are SHA-1, identified as "sha1", and SHA-256, identified 452 as "sha256" ([RFC4634]). (Future versions of this specification may 453 add new algorithms and deprecate old ones.) UAs MUST ignore Pins for 454 which they do not recognize the algorithm identifier. UAs MUST 455 continue to process the rest of a PKP response header field and note 456 Pins for algorithms they do recognize; UAs MUST recognize "sha1" and 457 "sha256". 459 Figure 4 reproduces the definition of the SubjectPublicKeyInfo 460 structure in [RFC5280]. 462 SubjectPublicKeyInfo ::= SEQUENCE { 463 algorithm AlgorithmIdentifier, 464 subjectPublicKey BIT STRING } 466 AlgorithmIdentifier ::= SEQUENCE { 467 algorithm OBJECT IDENTIFIER, 468 parameters ANY DEFINED BY algorithm OPTIONAL } 470 Figure 4: SPKI Definition 472 If the SubjectPublicKeyInfo of a certificate is incomplete when taken 473 in isolation, such as when holding a DSA key without domain 474 parameters, a public key pin cannot be formed. 476 We pin public keys, rather than entire certificates, to enable 477 operators to generate new certificates containing old public keys 478 (see [why-pin-key]). 480 See Appendix A for an example non-normative program that generates 481 SPKI Fingerprints from SubjectPublicKeyInfo fields in certificates. 483 2.5. Noting Pins 485 Upon receipt of the Public-Key-Pins response header field, the UA 486 notes the host as a Pinned Host, storing the Pins and their 487 associated directives in non-volatile storage (for example, along 488 with the HSTS metadata). The Pins and their associated directives 489 are collectively known as Pinning Metadata. 491 The UA MUST observe these conditions when noting a Host: 493 o The UA MUST note the Pins if and only if it received the Public- 494 Key-Pins response header field over an error-free TLS connection. 495 If the host is a Pinned Host, this includes the validation added 496 in Section 2.6. 498 o The UA MUST note the Pins if and only if the TLS connection was 499 authenticated with a certificate chain containing at least one of 500 the SPKI structures indicated by at least one of the given SPKI 501 Fingerprints. (See Section 2.6.) 503 o The UA MUST note the Pins if and only if the given set of Pins 504 contains at least one Pin that does NOT refer to an SPKI in the 505 certificate chain. (That is, the host must set a Backup Pin; see 506 Section 4.3.) 508 If the Public-Key-Pins response header field does not meet all three 509 of these criteria, the UA MUST NOT note the host as a Pinned Host. A 510 Public-Key-Pins response header field that meets all these critera is 511 known as a Valid Pinning Header. 513 The UA MUST ignore Public-Key-Pins response header fields received on 514 connections that do not meet the first criterion. 516 Whenever a UA receives a Valid Pinning Header, it MUST set its 517 Pinning Metadata to the exact Pins, max-age, and (if any) report-uri 518 and strict mode given in the most recently received Valid Pinning 519 Header. 521 For forward compatibility, the UA MUST ignore any unrecognized 522 Public-Key-Pins header directives, while still processing those 523 directives it does recognize. Section 2.1 specifies the directives 524 max-age, pins, includeSubDomains, report-uri, and strict, but future 525 specifications and implementations might use additional directives. 527 2.6. Validating Pinned Connections 529 When a UA connects to a Pinned Host, if the TLS connection has 530 errors, the UA MUST terminate the connection without allowing the 531 user to proceed anyway. (This behavior is the same as that required 532 by [RFC6797].) 534 If the connection has no errors, then the UA will determine whether 535 to apply a new, additional correctness check: Pin Validation. A UA 536 SHOULD perform Pin Validation whenever connecting to a Known Pinned 537 Host, but MAY allow Pin Validation to be disabled for Hosts according 538 to local policy. For example, a UA may disable Pin Validation for 539 Pinned Hosts whose validated certificate chain terminates at a user- 540 defined trust anchor, rather than a trust anchor built-in to the UA. 541 However, if the Pinned Host Metadata indicates that the Pinned Host 542 is operating in "strict mode" (see Section 2.1.4), then the UA MUST 543 perform Pin Validation. 545 To perform Pin Validation, the UA will compute the SPKI Fingerprints 546 for each certificate in the Pinned Host's validated certificate 547 chain, using each supported hash algorithm for each certificate. 548 (For the purposes of Pin Validation, the UA MUST ignore certificates 549 whose SPKI cannot be taken in isolation, and MUST ignore superfluous 550 certificates in the chain that do not form part of the validating 551 chain.) The UA will then check that the set of these SPKI 552 Fingerprints intersects the set of SPKI Fingerprints in that Pinned 553 Host's Pinning Metadata. If there is set intersection, the UA 554 continues with the connection as normal. Otherwise, the UA MUST 555 treat this Pin Failure as a non-recoverable error. Any procedure 556 that matches the results of this Pin Validation procedure is 557 considered equivalent. 559 Note that, although the UA has previously received Pins at the HTTP 560 layer, it can and MUST perform Pin Validation at the TLS layer, 561 before beginning an HTTP conversation over the TLS channel. The TLS 562 layer thus evaluates TLS connections with pinning information the UA 563 received previously, regardless of mechanism: statically preloaded, 564 via HTTP header, or some other means (possibly in the TLS layer 565 itself). 567 2.7. Interactions With Preloaded Pin Lists 569 UAs MAY choose to implement additional sources of pinning 570 information, such as through built-in lists of pinning information. 571 Such UAs SHOULD allow users to override such additional sources, 572 including disabling them from consideration. 574 UAs that support additional sources of pinning information MUST use 575 the most recently observed pinning information when performing Pin 576 Validation for a host. The most recently observed pinning 577 information is determined based upon the most recent Effective Pin 578 Date, as described in Section 2.3.2. 580 If the result of noting a Valid Pinning Header is to disable pinning 581 for the host, such as through supplying a max-age directive with a 582 value of 0, UAs MUST allow this new information to override any other 583 pinning data. That is, a host must be able to un-pin itself, even in 584 the presence of built-in pins. 586 Example: A UA may ship with a pre-configured list of pins that are 587 collected from past observations of Valid Pinning Headers supplied by 588 hosts. In such a solution, the pre-configured list should track when 589 the Valid Pinning Header was last observed, in order to permit site 590 operators to later update the value by supplying a new Valid Pinning 591 Header. Updates to such a pre-configured list should not update the 592 Effective Pin Dates for each host unless the list vendor has actually 593 observed a more recent header. This is to prevent situations where 594 updating the Effective Pin Date on a pre-configured list of pins may 595 effectively extend the max-age beyond the site operator's stated 596 policy. 598 Example: A UA may ship with a pre-configured list of pins that are 599 collected through out-of-band means, such as direct contact with the 600 site operator. In such a solution, the site operator accepts 601 responsibility for keeping the configured Valid Pinning Header in 602 sync with the vendor's list, allowing the UA vendor to have each 603 update to the list be treated as as an update of the Effective Pin 604 Date. 606 2.8. Pinning Self-Signed End Entities 608 If UAs accept hosts that authenticate themselves with self-signed end 609 entity certificates, they MAY also allow hosts to pin the public keys 610 in such certificates. The usability and security implications of 611 this practice are outside the scope of this specification. 613 3. Reporting Pin Validation Failure 614 When a Known Pinned Host has set the report-uri directive, the UA 615 SHOULD report Pin Validation failures to the indicated URI. The UA 616 does this by POSTing a JSON ([RFC4627]) message to the URI; the JSON 617 message takes this form: 619 { 620 "date-time": date-time, 621 "hostname": hostname, 622 "port": port, 623 "certificate-chain": [ 624 pem1, ... pemN 625 ], 626 "known-pins": [ 627 known-pin1, ... known-pinN 628 ] 629 } 631 Figure 5: JSON Report Format 633 Whitespace outside of quoted strings is not significant. The key/ 634 value pairs may appear in any order, but each SHOULD appear only 635 once. 637 The date-time indicates the time the UA observed the Pin Validation 638 failure. It is provided as a string formatted according to 639 Section 5.6, "Internet Date/Time Format", of [RFC3339]. 641 The hostname is the hostname to which the UA made the original 642 request that failed Pin Validation. It is provided as a string. 644 The port is the port to which the UA made the original request that 645 failed Pin Validation. It is provided either as a string or as an 646 integer. 648 The certificate-chain is the certificate chain, as constructed by the 649 UA during certificate chain verification. (This may differ from the 650 certificate chain as served by the Known Pinned Host, of course.) It 651 is provided as an array of strings; each string pem1, ... pemN is the 652 PEM representation of each X.509 certificate as described in 653 [I-D.josefsson-pkix-textual]. 655 The known-pins are the Pins that the UA has noted for the Known 656 Pinned Host. They are provided as an array of strings with the 657 syntax: 659 known-pin = token "=" quoted-string 661 Figure 6: Known Pin Syntax 663 As in Section 2.4, the token refers to the algorithm name, and the 664 quoted-string refers to the base 64 encoding of the SPKI Fingerprint. 666 4. Security Considerations 668 Pinning public keys helps hosts strongly assert their cryptographic 669 identity even in the face of issuer error, malfeasance or compromise. 670 But there is some risk that a host operator could lose or lose 671 control of their host's private key (such as by operator error or 672 host compromise). If the operator had pinned only the key of the 673 host's end entity certificate, the operator would not be able to 674 serve their web site or application in a way that UAs would trust for 675 the duration of their pin's max-age. (Recall that UAs MUST close the 676 connection to a host upon Pin Failure.) 678 Therefore, there is a necessary trade-off between two competing 679 goods: pin specificity and maximal reduction of the scope of issuers 680 on the one hand; and flexibility and resilience of the host's 681 cryptographic identity on the other hand. One way to resolve this 682 trade-off is to compromise by pinning to the key(s) of the issuer(s) 683 of the host's end entity certificate(s). Often, a valid certificate 684 chain will have at least two certificates above the end entity 685 certificate: the intermediate issuer, and the trust anchor. 686 Operators can pin any one or more of the public keys in this chain, 687 and indeed could pin to issuers not in the chain (as, for example, a 688 Backup Pin). Pinning to an intermediate issuer, or even to a trust 689 anchor or root, still significantly reduces the number of issuers who 690 can issue end entity certificates for the Known Pinned Host, while 691 still giving that host flexibility to change keys without a 692 disruption of service. 694 4.1. Maximum max-age 696 As mentioned in Section 2.3.2, UAs MAY cap the max-age value at some 697 upper limit. There is a security trade-off in that low maximum 698 values provide a narrow window of protection for users who visit the 699 Known Pinned Host only infrequently, while high maximum values might 700 potentially result in a UA's inability to successfully perform Pin 701 Validation for a Known Pinned Host if the UA's noted pins and the 702 Host's true pins diverge. 704 Such divergence could occur for several reasons, including: UA error; 705 Host operator error; network attack; or a Known Pinned Host that 706 intentionally migrates all pinned keys, combined with a UA that has 707 noted true pins with a high max-age value and has not had a chance to 708 observe the new true pins for the Host. (This last example 709 underscores the importance for Host operators to phase in new keys 710 gradually, and to set the max-age value in accordance with their 711 planned key migration schedule.) 713 There is probably no ideal upper limit to the max-age directive that 714 would satisfy all use cases. However, a value on the order of 60 715 days (5184000 seconds) may be considered a balance between the two 716 competing security concerns. 718 4.2. Using includeSubDomains Safely 720 It may happen that Pinned Hosts whose hostnames share a parent domain 721 use different Valid Pinning Headers. If a Host whose hostname is a 722 parent domain for another Host sets the includeSubDomains directive, 723 the two Hosts' pins may conflict with each other. For example, 724 consider two Known Pinned Hosts, example.com and 725 subdomain.example.com. Assume example.com sets a Valid Pinning 726 Header such as this: 728 Public-Key-Pins: pin-sha1="ABC..."; pin-sha1="DEF..."; includeSubDomains 730 Figure 7: example.com Valid Pinning Header 732 Assume subdomain.example.com sets a Valid Pinning Header such as 733 this: 735 Public-Key-Pins: pin-sha1="GHI..."; pin-sha1="JKL..." 737 Figure 8: subdomain.example.com Valid Pinning Header 739 Assume a UA that has not previously noted any pins for either of 740 these Hosts. If the UA first contacts subdomain.example.com, it will 741 note the pins in the Valid Pinning Header, and perform Pin Validation 742 as normal on subsequent conections. If the UA then contacts 743 example.com, again it will note the pins and perform Pin Validation 744 on future connections. However, if the UA happened to first 745 example.com before subdomain.example.com, the UA would, due to 746 example.com's use of the includeSubDomains directive, attempt to 747 perform Pin Validation for subdomain.example.com using the SPKI 748 hashes ABC... and DEF..., which are not valid for the certificate 749 chains subdomain.example.com (which uses certificates with SPKIs 750 GHI... and JLK...). Thus, depending on the order in which the UA 751 observes the Valid Pinning Headers for hosts example.com and 752 subdomain.example.com, Pin Validation might or might not fail for 753 subdomain.example.com, even if the certificate chain the UA receives 754 for subdomain.example.com is perfectly valid. 756 Thus, Pinned Host operators must use the includeSubDomains directive 757 with care. For example, they may choose to use overlapping pin sets 758 for hosts under a parent domain that uses includeSubDomains, or to 759 not use the includeSubDomains directive in their effective-second- 760 level domains, or to simply use the same pin set for all hosts under 761 a given parent domain. 763 4.3. Backup Pins 765 The primary way to cope with the risk of inadvertent Pin Failure is 766 to keep a Backup Pin. A Backup Pin is a fingerprint for the public 767 key of a secondary, not-yet-deployed key pair. The operator keeps 768 the backup key pair offline, and sets a pin for it in the Public-Key- 769 Pins header. Then, in case the operator loses control of their 770 primary private key, they can deploy the backup key pair. UAs, who 771 have had the backup key pair pinned (when it was set in previous 772 Valid Pinning Headers), can connect to the host without error. 774 Because having a backup key pair is so important to recovery, UAs 775 MUST require that hosts set a Backup Pin. (See Section 2.5.) 777 5. Privacy Considerations 779 Conforming implementations (as well as implementations conforming to 780 [RFC6797]) must store state about which domains have set policies, 781 hence which domains the UA has contacted. A forensic attacker might 782 find this information useful, even if the user has cleared other 783 parts of the UA's state. 785 More importantly, Hosts can use HSTS or HPKP as a "super-cookie", by 786 setting distinct policies for a number of subdomains. For example, 787 assume example.com wishes to track distinct UAs without explicitly 788 setting a cookie, or if a previously-set cookie is deleted from the 789 UA's cookie store. Here are two attack scenarios. 791 1. example.com can use report-uri and the ability to pin arbitrary 792 identifiers to distinguish UAs. 794 2. 796 1. example.com sets a Valid Pinning Header in its response to 797 requests. The header asserts the includeSubDomains 798 directive, and specifies a report-uri directive as well. 799 Pages served by the host also include references to 800 subresource https://bad.example.com/foo.png. 802 2. The Valid Pinning Header includes a "pin" that is not really 803 the hash of an SPKI, but is instead an arbitrary 804 distinguishing string sent only in response to a particular 805 request. For each request, the Host creates a new, distinct 806 distinguishing string and sets it as if it were a pin. 808 3. The certificate chain served by bad.example.com does not pass 809 Pin Validation given the pin set the Host asserted in (1). 810 The HPKP-conforming UA attempts to report the Pin Validation 811 failure to the specified report-uri, including the 812 certificate chain it observed and the SPKI hashes it expected 813 to see. Among the SPKI hashes is the distinguishing string 814 in step (2). 816 3. example.com can use SNI and subdomains to distinguish UAs. 818 4. 820 1. example.com sets a Valid Pinning Header in its response to 821 requests. The header asserts the includeSubDomains 822 directive. 824 2. On a subsequent page view, the Host responds with a page 825 including the subresource https://0.fingerprint.example.com/ 826 foo.png, and the server responds using a certificate chain 827 that does not pass Pin Validation for the pin-set defined in 828 the Valid Pinning Header in step (1). The HPKP-conforming UA 829 will close the connection, never completing the request to 830 0.fingerprint.example.com. The Host may thus note that this 831 particular UA had noted the (good) pins for that subdomain. 833 3. example.com can distinguish 2^N UAs by serving Valid Pinning 834 Headers from an arbitrary number N distinct subdomains, 835 giving some UAs Valid Pinning Headers for some, but not all 836 subdomains (causing subsequent requests for 837 n.fingerprint.example.com to fail), and giving some UAs no 838 Valid Pinning Header for other subdomains (causing subsequent 839 requests for m.fingerprint.example.com to succeed). 841 6. IANA Considerations 842 This document has no actions for IANA. However, in the future there 843 may arise a need for a registry of extension directives (see 844 Section 2.1). 846 7. Usability Considerations 848 When pinning works to detect impostor Pinned Hosts, users will 849 experience denial of service. UAs MUST explain the reason why, i.e. 850 that it was impossible to verify the confirmed cryptographic identity 851 of the host. 853 UAs MUST have a way for users to clear current pins for Pinned Hosts. 854 UAs SHOULD have a way for users to query the current state of Pinned 855 Hosts. 857 8. Acknowledgements 859 Thanks to Tobias Gondrom, Jeff Hodges, Ivan Krstic, Adam Langley, 860 Nicolas Lidzborski, SM, James Manger, Eric Rescorla, Paul Hoffman, 861 and Yoav Nir for suggestions and edits that clarified the text. 862 Thanks to Trevor Perrin for suggesting a mechanism to affirmatively 863 break pins ([pin-break-codes]). 865 9. What's Changed 867 Added normative references for SHA, JSON, and base-64. 869 Added the Privacy Considerations section. 871 Changed non-normative pin generation code from Go to POSIX shell 872 script using openssl. 874 Changed max-max-age from SHOULD to MAY, and used the example of 60 875 days instead of 30. 877 Removed the section "Pin Validity Times", which was intended to be in 878 harmony with [I-D.perrin-tls-tack]. Now using max-age purely as 879 specified in [RFC6797]. 881 Added new directives: includeSubDomains, report-uri and strict. 883 Added a new variant of the PKP Header: Public-Key-Pins-Report-Only. 885 Removed the section on pin break codes and verifiers, in favor the of 886 most-recently-received policy (Section 2.5). 888 Now using a new header field, Public-Key-Pins, separate from HSTS. 889 This allows hosts to use pinning separately from Strict Transport 890 Security. 892 Explicitly requiring that UAs perform Pin Validation before the HTTP 893 conversation begins. 895 Backup Pins are now required. 897 Separated normative from non-normative material. Removed tangential 898 and out-of-scope non-normative discussion. 900 10. References 902 10.1. Normative References 904 [I-D.josefsson-pkix-textual] 905 Josefsson, S. and S. Leonard, "Text Encodings of PKIX and 906 CMS Structures", draft-josefsson-pkix-textual-01 (work in 907 progress), July 2012. 909 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 910 Requirement Levels", BCP 14, RFC 2119, March 1997. 912 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 913 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 914 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 916 [RFC3339] Klyne, G., Ed. and C. Newman, "Date and Time on the 917 Internet: Timestamps", RFC 3339, July 2002. 919 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 920 Resource Identifier (URI): Generic Syntax", STD 66, RFC 921 3986, January 2005. 923 [RFC4627] Crockford, D., "The application/json Media Type for 924 JavaScript Object Notation (JSON)", RFC 4627, July 2006. 926 [RFC4634] Eastlake, D. and T. Hansen, "US Secure Hash Algorithms 927 (SHA and HMAC-SHA)", RFC 4634, July 2006. 929 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data 930 Encodings", RFC 4648, October 2006. 932 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data 933 Encodings", RFC 4648, October 2006. 935 [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an 936 IANA Considerations Section in RFCs", BCP 26, RFC 5226, 937 May 2008. 939 [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security 940 (TLS) Protocol Version 1.2", RFC 5246, August 2008. 942 [RFC5280] Cooper, D., Santesson, S., Farrell, S., Boeyen, S., 943 Housley, R., and W. Polk, "Internet X.509 Public Key 944 Infrastructure Certificate and Certificate Revocation List 945 (CRL) Profile", RFC 5280, May 2008. 947 [RFC6797] Hodges, J., Jackson, C., and A. Barth, "HTTP Strict 948 Transport Security (HSTS)", RFC 6797, November 2012. 950 [W3C.REC-html401-19991224] 951 Hors, A., Raggett, D., and I. Jacobs, "HTML 4.01 952 Specification", World Wide Web Consortium Recommendation 953 REC-html401-19991224, December 1999, 954 . 956 10.2. Informative References 958 [I-D.perrin-tls-tack] 959 Marlinspike, M., "Trust Assertions for Certificate Keys", 960 draft-perrin-tls-tack-02 (work in progress), January 2013. 962 [pin-break-codes] 963 Perrin, T., "Self-Asserted Key Pinning", September 2011, 964 . 966 [why-pin-key] 967 Langley, A., "Public Key Pinning", May 2011, 968 . 970 Appendix A. Fingerprint Generation 972 This POSIX shell program generates SPKI Fingerprints, suitable for 973 use in pinning, from PEM-encoded certificates. It is non-normative. 975 openssl x509 -noout -in certificate.pem -pubkey | \ 976 openssl asn1parse -inform pem -out public.key 977 openssl dgst -sha1 -binary public.key | base64 979 Figure 9: Example SPKI Fingerprint Generation Code 981 Appendix B. Deployment Guidance 982 This section is non-normative guidance which may smooth the adoption 983 of public key pinning. 985 o Operators SHOULD get the backup public key signed by a different 986 (root and/or intermediary) CA than their primary certificate, and 987 store the backup key pair safely offline. The semantics of an 988 SPKI Fingerprint do not require the issuance of a certificate to 989 construct a valid Pin. However, in many deployment scenarios, in 990 order to make a Backup Pin operational the server operator will 991 need to have a certificate to deploy TLS on the host. Failure to 992 obtain a certificate through prior arrangement will leave clients 993 that recognize the site as a Known Pinned Host unable to 994 successfully perform Pin Validation until such a time as the 995 operator can obtain a new certificate from their desired 996 certificate issuer. 998 o It is most economical to have the backup certificate signed by a 999 completely different signature chain than the live certificate, to 1000 maximize recoverability in the event of either root or 1001 intermediary signer compromise. 1003 o Operators SHOULD periodically exercise their Backup Pin plan 1004 -\u002D an untested backup is no backup at all. 1006 o Operators SHOULD start small. Operators SHOULD first deploy 1007 public key pinning by using the report-only mode together with a 1008 report-uri directive that points to a reliable report collection 1009 endpoint. When moving out of report-only mode, operators should 1010 start by setting a max-age of minutes or a few hours, and 1011 gradually increase max-age as they gain confidence in their 1012 operational capability. 1014 Authors' Addresses 1016 Chris Evans 1017 Google, Inc. 1018 1600 Amphitheatre Pkwy 1019 Mountain View, CA 94043 1020 US 1022 Email: cevans@google.com 1023 Chris Palmer 1024 Google, Inc. 1025 1600 Amphitheatre Pkwy 1026 Mountain View, CA 94043 1027 US 1029 Email: palmer@google.com 1031 Ryan Sleevi 1032 Google, Inc. 1033 1600 Amphitheatre Pkwy 1034 Mountain View, CA 94043 1035 US 1037 Email: sleevi@google.com