idnits 2.17.1 draft-ietf-websec-key-pinning-08.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 12, 2013) is 3941 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 934, 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 13, 2014 Google, Inc. 6 July 12, 2013 8 Public Key Pinning Extension for HTTP 9 draft-ietf-websec-key-pinning-08 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 13, 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 . . . . . . . . . . 12 78 2.8. Pinning Self-Signed End Entities . . . . . . . . . . . . 13 79 3. Reporting Pin Validation Failure . . . . . . . . . . . . . . 13 80 4. Security Considerations . . . . . . . . . . . . . . . . . . . 14 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 Whenever a UA receives a Valid Pinning Header, it MUST set its 514 Pinning Metadata to the exact Pins, max-age, and (if any) report-uri 515 and strict mode given in the most recently received Valid Pinning 516 Header. 518 For forward compatibility, the UA MUST ignore any unrecognized 519 Public-Key-Pins header directives, while still processing those 520 directives it does recognize. Section 2.1 specifies the directives 521 max-age, pins, includeSubDomains, report-uri, and strict, but future 522 specifications and implementations might use additional directives. 524 2.6. Validating Pinned Connections 526 When a UA connects to a Pinned Host, if the TLS connection has 527 errors, the UA MUST terminate the connection without allowing the 528 user to proceed anyway. (This behavior is the same as that required 529 by [RFC6797].) 531 If the connection has no errors, then the UA will determine whether 532 to apply a new, additional correctness check: Pin Validation. A UA 533 SHOULD perform Pin Validation whenever connecting to a Known Pinned 534 Host, but MAY allow Pin Validation to be disabled for Hosts according 535 to local policy. For example, a UA may disable Pin Validation for 536 Pinned Hosts whose validated certificate chain terminates at a user- 537 defined trust anchor, rather than a trust anchor built-in to the UA. 538 However, if the Pinned Host Metadata indicates that the Pinned Host 539 is operating in "strict mode" (see Section 2.1.4), then the UA MUST 540 perform Pin Validation. 542 To perform Pin Validation, the UA will compute the SPKI Fingerprints 543 for each certificate in the Pinned Host's validated certificate 544 chain, using each supported hash algorithm for each certificate. 545 (For the purposes of Pin Validation, the UA MUST ignore certificates 546 whose SPKI cannot be taken in isolation, and MUST ignore superfluous 547 certificates in the chain that do not form part of the validating 548 chain.) The UA will then check that the set of these SPKI 549 Fingerprints intersects the set of SPKI Fingerprints in that Pinned 550 Host's Pinning Metadata. If there is set intersection, the UA 551 continues with the connection as normal. Otherwise, the UA MUST 552 treat this Pin Failure as a non-recoverable error. Any procedure 553 that matches the results of this Pin Validation procedure is 554 considered equivalent. 556 Note that, although the UA has previously received Pins at the HTTP 557 layer, it can and MUST perform Pin Validation at the TLS layer, 558 before beginning an HTTP conversation over the TLS channel. The TLS 559 layer thus evaluates TLS connections with pinning information the UA 560 received previously, regardless of mechanism: statically preloaded, 561 via HTTP header, or some other means (possibly in the TLS layer 562 itself). 564 2.7. Interactions With Preloaded Pin Lists 566 UAs MAY choose to implement additional sources of pinning 567 information, such as through built-in lists of pinning information. 568 Such UAs SHOULD allow users to override such additional sources, 569 including disabling them from consideration. 571 UAs that support additional sources of pinning information MUST use 572 the most recently observed pinning information when performing Pin 573 Validation for a host. The most recently observed pinning 574 information is determined based upon the most recent Effective Pin 575 Date, as described in Section 2.3.2. 577 If the result of noting a Valid Pinning Header is to disable pinning 578 for the host, such as through supplying a max-age directive with a 579 value of 0, UAs MUST allow this new information to override any other 580 pinning data. That is, a host must be able to un-pin itself, even in 581 the presence of built-in pins. 583 Example: A UA may ship with a pre-configured list of pins that are 584 collected from past observations of Valid Pinning Headers supplied by 585 hosts. In such a solution, the pre-configured list should track when 586 the Valid Pinning Header was last observed, in order to permit site 587 operators to later update the value by supplying a new Valid Pinning 588 Header. Updates to such a pre-configured list should not update the 589 Effective Pin Dates for each host unless the list vendor has actually 590 observed a more recent header. This is to prevent situations where 591 updating the Effective Pin Date on a pre-configured list of pins may 592 effectively extend the max-age beyond the site operator's stated 593 policy. 595 Example: A UA may ship with a pre-configured list of pins that are 596 collected through out-of-band means, such as direct contact with the 597 site operator. In such a solution, the site operator accepts 598 responsibility for keeping the configured Valid Pinning Header in 599 sync with the vendor's list, allowing the UA vendor to have each 600 update to the list be treated as as an update of the Effective Pin 601 Date. 603 2.8. Pinning Self-Signed End Entities 605 If UAs accept hosts that authenticate themselves with self-signed end 606 entity certificates, they MAY also allow hosts to pin the public keys 607 in such certificates. The usability and security implications of 608 this practice are outside the scope of this specification. 610 3. Reporting Pin Validation Failure 612 When a Known Pinned Host has set the report-uri directive, the UA 613 SHOULD report Pin Validation failures to the indicated URI. The UA 614 does this by POSTing a JSON ([RFC4627]) message to the URI; the JSON 615 message takes this form: 617 { 618 "date-time": date-time, 619 "hostname": hostname, 620 "port": port, 621 "certificate-chain": [ 622 pem1, ... pemN 623 ], 624 "known-pins": [ 625 known-pin1, ... known-pinN 626 ] 627 } 629 Figure 5: JSON Report Format 631 Whitespace outside of quoted strings is not significant. The key/ 632 value pairs may appear in any order, but each SHOULD appear only 633 once. 635 The date-time indicates the time the UA observed the Pin Validation 636 failure. It is provided as a string formatted according to 637 Section 5.6, "Internet Date/Time Format", of [RFC3339]. 639 The hostname is the hostname to which the UA made the original 640 request that failed Pin Validation. It is provided as a string. 642 The port is the port to which the UA made the original request that 643 failed Pin Validation. It is provided either as a string or as an 644 integer. 646 The certificate-chain is the certificate chain, as constructed by the 647 UA during certificate chain verification. (This may differ from the 648 certificate chain as served by the Known Pinned Host, of course.) It 649 is provided as an array of strings; each string pem1, ... pemN is the 650 PEM representation of each X.509 certificate as described in 651 [I-D.josefsson-pkix-textual]. 653 The known-pins are the Pins that the UA has noted for the Known 654 Pinned Host. They are provided as an array of strings with the 655 syntax: 657 known-pin = token "=" quoted-string 659 Figure 6: Known Pin Syntax 661 As in Section 2.4, the token refers to the algorithm name, and the 662 quoted-string refers to the base 64 encoding of the SPKI Fingerprint. 664 4. Security Considerations 665 Pinning public keys helps hosts strongly assert their cryptographic 666 identity even in the face of issuer error, malfeasance or compromise. 667 But there is some risk that a host operator could lose or lose 668 control of their host's private key (such as by operator error or 669 host compromise). If the operator had pinned only the key of the 670 host's end entity certificate, the operator would not be able to 671 serve their web site or application in a way that UAs would trust for 672 the duration of their pin's max-age. (Recall that UAs MUST close the 673 connection to a host upon Pin Failure.) 675 Therefore, there is a necessary trade-off between two competing 676 goods: pin specificity and maximal reduction of the scope of issuers 677 on the one hand; and flexibility and resilience of the host's 678 cryptographic identity on the other hand. One way to resolve this 679 trade-off is to compromise by pinning to the key(s) of the issuer(s) 680 of the host's end entity certificate(s). Often, a valid certificate 681 chain will have at least two certificates above the end entity 682 certificate: the intermediate issuer, and the trust anchor. 683 Operators can pin any one or more of the public keys in this chain, 684 and indeed could pin to issuers not in the chain (as, for example, a 685 Backup Pin). Pinning to an intermediate issuer, or even to a trust 686 anchor or root, still significantly reduces the number of issuers who 687 can issue end entity certificates for the Known Pinned Host, while 688 still giving that host flexibility to change keys without a 689 disruption of service. 691 4.1. Maximum max-age 693 As mentioned in Section 2.3.2, UAs MAY cap the max-age value at some 694 upper limit. There is a security trade-off in that low maximum 695 values provide a narrow window of protection for users who visit the 696 Known Pinned Host only infrequently, while high maximum values might 697 potentially result in a UA's inability to successfully perform Pin 698 Validation for a Known Pinned Host if the UA's noted pins and the 699 Host's true pins diverge. 701 Such divergence could occur for several reasons, including: UA error; 702 Host operator error; network attack; or a Known Pinned Host that 703 intentionally migrates all pinned keys, combined with a UA that has 704 noted true pins with a high max-age value and has not had a chance to 705 observe the new true pins for the Host. (This last example 706 underscores the importance for Host operators to phase in new keys 707 gradually, and to set the max-age value in accordance with their 708 planned key migration schedule.) 709 There is probably no ideal upper limit to the max-age directive that 710 would satisfy all use cases. However, a value on the order of 60 711 days (5184000 seconds) may be considered a balance between the two 712 competing security concerns. 714 4.2. Using includeSubDomains Safely 716 It may happen that Pinned Hosts whose hostnames share a parent domain 717 use different Valid Pinning Headers. If a Host whose hostname is a 718 parent domain for another Host sets the includeSubDomains directive, 719 the two Hosts' pins may conflict with each other. For example, 720 consider two Known Pinned Hosts, example.com and 721 subdomain.example.com. Assume example.com sets a Valid Pinning 722 Header such as this: 724 Public-Key-Pins: pin-sha1="ABC..."; pin-sha1="DEF..."; includeSubDomains 726 Figure 7: example.com Valid Pinning Header 728 Assume subdomain.example.com sets a Valid Pinning Header such as 729 this: 731 Public-Key-Pins: pin-sha1="GHI..."; pin-sha1="JKL..." 733 Figure 8: subdomain.example.com Valid Pinning Header 735 Assume a UA that has not previously noted any pins for either of 736 these Hosts. If the UA first contacts subdomain.example.com, it will 737 note the pins in the Valid Pinning Header, and perform Pin Validation 738 as normal on subsequent conections. If the UA then contacts 739 example.com, again it will note the pins and perform Pin Validation 740 on future connections. However, if the UA happened to first 741 example.com before subdomain.example.com, the UA would, due to 742 example.com's use of the includeSubDomains directive, attempt to 743 perform Pin Validation for subdomain.example.com using the SPKI 744 hashes ABC... and DEF..., which are not valid for the certificate 745 chains subdomain.example.com (which uses certificates with SPKIs 746 GHI... and JLK...). Thus, depending on the order in which the UA 747 observes the Valid Pinning Headers for hosts example.com and 748 subdomain.example.com, Pin Validation might or might not fail for 749 subdomain.example.com, even if the certificate chain the UA receives 750 for subdomain.example.com is perfectly valid. 752 Thus, Pinned Host operators must use the includeSubDomains directive 753 with care. For example, they may choose to use overlapping pin sets 754 for hosts under a parent domain that uses includeSubDomains, or to 755 not use the includeSubDomains directive in their effective-second- 756 level domains, or to simply use the same pin set for all hosts under 757 a given parent domain. 759 4.3. Backup Pins 761 The primary way to cope with the risk of inadvertent Pin Failure is 762 to keep a Backup Pin. A Backup Pin is a fingerprint for the public 763 key of a secondary, not-yet-deployed key pair. The operator keeps 764 the backup key pair offline, and sets a pin for it in the Public-Key- 765 Pins header. Then, in case the operator loses control of their 766 primary private key, they can deploy the backup key pair. UAs, who 767 have had the backup key pair pinned (when it was set in previous 768 Valid Pinning Headers), can connect to the host without error. 770 Because having a backup key pair is so important to recovery, UAs 771 MUST require that hosts set a Backup Pin. (See Section 2.5.) 773 5. Privacy Considerations 775 Conforming implementations (as well as implementations conforming to 776 [RFC6797]) must store state about which domains have set policies, 777 hence which domains the UA has contacted. A forensic attacker might 778 find this information useful, even if the user has cleared other 779 parts of the UA's state. 781 More importantly, Hosts can use HSTS or HPKP as a "super-cookie", by 782 setting distinct policies for a number of subdomains. For example, 783 assume example.com wishes to track distinct UAs without explicitly 784 setting a cookie, or if a previously-set cookie is deleted from the 785 UA's cookie store. Here are two attack scenarios. 787 1. example.com can use report-uri and the ability to pin arbitrary 788 identifiers to distinguish UAs. 790 2. 792 1. example.com sets a Valid Pinning Header in its response to 793 requests. The header asserts the includeSubDomains 794 directive, and specifies a report-uri directive as well. 795 Pages served by the host also include references to 796 subresource https://bad.example.com/foo.png. 798 2. The Valid Pinning Header includes a "pin" that is not really 799 the hash of an SPKI, but is instead an arbitrary 800 distinguishing string sent only in response to a particular 801 request. For each request, the Host creates a new, distinct 802 distinguishing string and sets it as if it were a pin. 804 3. The certificate chain served by bad.example.com does not pass 805 Pin Validation given the pin set the Host asserted in (1). 806 The HPKP-conforming UA attempts to report the Pin Validation 807 failure to the specified report-uri, including the 808 certificate chain it observed and the SPKI hashes it expected 809 to see. Among the SPKI hashes is the distinguishing string 810 in step (2). 812 3. example.com can use SNI and subdomains to distinguish UAs. 814 4. 816 1. example.com sets a Valid Pinning Header in its response to 817 requests. The header asserts the includeSubDomains 818 directive. 820 2. On a subsequent page view, the Host responds with a page 821 including the subresource https://0.fingerprint.example.com/ 822 foo.png, and the server responds using a certificate chain 823 that does not pass Pin Validation for the pin-set defined in 824 the Valid Pinning Header in step (1). The HPKP-conforming UA 825 will close the connection, never completing the request to 826 0.fingerprint.example.com. The Host may thus note that this 827 particular UA had noted the (good) pins for that subdomain. 829 3. example.com can distinguish 2^N UAs by serving Valid Pinning 830 Headers from an arbitrary number N distinct subdomains, 831 giving some UAs Valid Pinning Headers for some, but not all 832 subdomains (causing subsequent requests for 833 n.fingerprint.example.com to fail), and giving some UAs no 834 Valid Pinning Header for other subdomains (causing subsequent 835 requests for m.fingerprint.example.com to succeed). 837 6. IANA Considerations 839 This document has no actions for IANA. However, in the future there 840 may arise a need for a registry of extension directives (see 841 Section 2.1). 843 7. Usability Considerations 845 When pinning works to detect impostor Pinned Hosts, users will 846 experience denial of service. UAs MUST explain the reason why, i.e. 847 that it was impossible to verify the confirmed cryptographic identity 848 of the host. 850 UAs MUST have a way for users to clear current pins for Pinned Hosts. 851 UAs SHOULD have a way for users to query the current state of Pinned 852 Hosts. 854 8. Acknowledgements 856 Thanks to Tobias Gondrom, Jeff Hodges, Ivan Krstic, Adam Langley, 857 Nicolas Lidzborski, SM, James Manger, Eric Rescorla, Paul Hoffman, 858 and Yoav Nir for suggestions and edits that clarified the text. 859 Thanks to Trevor Perrin for suggesting a mechanism to affirmatively 860 break pins ([pin-break-codes]). 862 9. What's Changed 864 [RFC EDITOR: PLEASE REMOVE THIS SECTION] 866 Added normative references for SHA, JSON, and base-64. 868 Added the Privacy Considerations section. 870 Changed non-normative pin generation code from Go to POSIX shell 871 script using openssl. 873 Changed max-max-age from SHOULD to MAY, and used the example of 60 874 days instead of 30. 876 Removed the section "Pin Validity Times", which was intended to be in 877 harmony with [I-D.perrin-tls-tack]. Now using max-age purely as 878 specified in [RFC6797]. 880 Added new directives: includeSubDomains, report-uri and strict. 882 Added a new variant of the PKP Header: Public-Key-Pins-Report-Only. 884 Removed the section on pin break codes and verifiers, in favor the of 885 most-recently-received policy (Section 2.5). 887 Now using a new header field, Public-Key-Pins, separate from HSTS. 888 This allows hosts to use pinning separately from Strict Transport 889 Security. 891 Explicitly requiring that UAs perform Pin Validation before the HTTP 892 conversation begins. 894 Backup Pins are now required. 896 Separated normative from non-normative material. Removed tangential 897 and out-of-scope non-normative discussion. 899 10. References 901 10.1. Normative References 903 [I-D.josefsson-pkix-textual] 904 Josefsson, S. and S. Leonard, "Text Encodings of PKIX and 905 CMS Structures", draft-josefsson-pkix-textual-01 (work in 906 progress), July 2012. 908 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 909 Requirement Levels", BCP 14, RFC 2119, March 1997. 911 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 912 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 913 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 915 [RFC3339] Klyne, G., Ed. and C. Newman, "Date and Time on the 916 Internet: Timestamps", RFC 3339, July 2002. 918 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 919 Resource Identifier (URI): Generic Syntax", STD 66, RFC 920 3986, January 2005. 922 [RFC4627] Crockford, D., "The application/json Media Type for 923 JavaScript Object Notation (JSON)", RFC 4627, July 2006. 925 [RFC4634] Eastlake, D. and T. Hansen, "US Secure Hash Algorithms 926 (SHA and HMAC-SHA)", RFC 4634, July 2006. 928 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data 929 Encodings", RFC 4648, October 2006. 931 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data 932 Encodings", RFC 4648, October 2006. 934 [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an 935 IANA Considerations Section in RFCs", BCP 26, RFC 5226, 936 May 2008. 938 [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security 939 (TLS) Protocol Version 1.2", RFC 5246, August 2008. 941 [RFC5280] Cooper, D., Santesson, S., Farrell, S., Boeyen, S., 942 Housley, R., and W. Polk, "Internet X.509 Public Key 943 Infrastructure Certificate and Certificate Revocation List 944 (CRL) Profile", RFC 5280, May 2008. 946 [RFC6797] Hodges, J., Jackson, C., and A. Barth, "HTTP Strict 947 Transport Security (HSTS)", RFC 6797, November 2012. 949 [W3C.REC-html401-19991224] 950 Hors, A., Raggett, D., and I. Jacobs, "HTML 4.01 951 Specification", World Wide Web Consortium Recommendation 952 REC-html401-19991224, December 1999, 953 . 955 10.2. Informative References 957 [I-D.perrin-tls-tack] 958 Marlinspike, M., "Trust Assertions for Certificate Keys", 959 draft-perrin-tls-tack-02 (work in progress), January 2013. 961 [pin-break-codes] 962 Perrin, T., "Self-Asserted Key Pinning", September 2011, 963 . 965 [why-pin-key] 966 Langley, A., "Public Key Pinning", May 2011, 967 . 969 Appendix A. Fingerprint Generation 971 This POSIX shell program generates SPKI Fingerprints, suitable for 972 use in pinning, from PEM-encoded certificates. It is non-normative. 974 openssl x509 -noout -in certificate.pem -pubkey | \ 975 openssl asn1parse -inform pem -out public.key 976 openssl dgst -sha1 -binary public.key | base64 978 Figure 9: Example SPKI Fingerprint Generation Code 980 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 1024 Chris Palmer 1025 Google, Inc. 1026 1600 Amphitheatre Pkwy 1027 Mountain View, CA 94043 1028 US 1030 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