idnits 2.17.1 draft-ietf-websec-key-pinning-05.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 (June 07, 2013) is 3948 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) -- Looks like a reference, but probably isn't: '0' on line 914 -- Looks like a reference, but probably isn't: '1' on line 901 == Unused Reference: 'RFC5226' is defined on line 844, 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 5226 (Obsoleted by RFC 8126) ** Obsolete normative reference: RFC 5246 (Obsoleted by RFC 8446) Summary: 4 errors (**), 0 flaws (~~), 3 warnings (==), 3 comments (--). 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: December 09, 2013 Google, Inc. 6 June 07, 2013 8 Public Key Pinning Extension for HTTP 9 draft-ietf-websec-key-pinning-05 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 December 09, 2013. 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 . . . . . . . . . . . . . . . . . . 7 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 . . . . . . . . . 9 74 2.3.4. UA Processing Examples . . . . . . . . . . . . . . . 9 75 2.4. Semantics of Pins . . . . . . . . . . . . . . . . . . . . 10 76 2.5. Noting Pins . . . . . . . . . . . . . . . . . . . . . . . 11 77 2.6. Validating Pinned Connections . . . . . . . . . . . . . . 11 78 2.7. Interactions With Preloaded Pin Lists . . . . . . . . . . 12 79 2.8. Pinning Self-Signed End Entities . . . . . . . . . . . . 13 80 3. Reporting Pin Validation Failure . . . . . . . . . . . . . . 13 81 4. Security Considerations . . . . . . . . . . . . . . . . . . . 14 82 4.1. Maximum max-age . . . . . . . . . . . . . . . . . . . . . 15 83 4.2. Using includeSubdomains Safely . . . . . . . . . . . . . 16 84 4.3. Backup Pins . . . . . . . . . . . . . . . . . . . . . . . 16 85 5. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 17 86 6. Usability Considerations . . . . . . . . . . . . . . . . . . 17 87 7. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 17 88 8. What's Changed . . . . . . . . . . . . . . . . . . . . . . . 17 89 9. References . . . . . . . . . . . . . . . . . . . . . . . . . 18 90 9.1. Normative References . . . . . . . . . . . . . . . . . . 18 91 9.2. Informative References . . . . . . . . . . . . . . . . . 19 92 Appendix A. Fingerprint Generation . . . . . . . . . . . . . . . 19 93 Appendix B. Deployment Guidance . . . . . . . . . . . . . . . . 20 94 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 21 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 103 shipping with a user-extensible embedded set of pins. Although 104 effective, this does not scale. This proposal addresses the scale 105 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 193 Fingerprint. 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 the Pinning 277 Policy contained should be applied to the Pinned Host exactly as 278 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=500; 286 pin-sha1="4n972HfV354KP560yw4uqe/baXc="; 287 pin-sha1="IvGeLsbqzPxdI0b0wuj2xVTdXgc=" 289 Public-Key-Pins: max-age=31536000; 290 pin-sha1="4n972HfV354KP560yw4uqe/baXc="; 291 pin-sha256="LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=" 293 Public-Key-Pins: pin-sha1="4n972HfV354KP560yw4uqe/baXc="; 294 pin-sha1="qvTGHdzF6KLavt4PO0gs2a6pQ00="; 295 pin-sha256="LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ="; 296 max-age=2592000 298 Public-Key-Pins: pin-sha1="4n972HfV354KP560yw4uqe/baXc="; 299 pin-sha1="qvTGHdzF6KLavt4PO0gs2a6pQ00="; 300 pin-sha256="LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ="; 301 max-age=2592000; includeSubDomains 303 Figure 3: HPKP Header Examples 305 2.2. Server Processing Model 307 This section describes the processing model that Pinned Hosts 308 implement. The model comprises two facets: the processing rules for 309 HTTP request messages received over a secure transport (e.g. TLS 310 [RFC5246]); and the processing rules for HTTP request messages 311 received over non-secure transports, such as TCP. 313 2.2.1. HTTP-over-Secure-Transport Request Type 315 When replying to an HTTP request that was conveyed over a secure 316 transport, a Pinned Host SHOULD include in its response exactly one 317 PKP header field that MUST satisfy the grammar specified above in 318 Section 2.1. If the Pinned Host does not include the PKP header 319 field, and if the connection passed Pin Validation, UAs MUST treat 320 the host as if it had set its max-age to 0 (see Section 2.3.1). 322 Establishing a given host as a Known Pinned Host, in the context of a 323 given UA, MAY be accomplished over the HTTP protocol, which is in 324 turn running over secure transport, by correctly returning (per this 325 specification) at least one valid PKP header field to the UA. Other 326 mechanisms, such as a client-side pre-loaded Known Pinned Host list 327 MAY also be used. 329 2.2.2. HTTP Request Type 331 Pinned Hosts SHOULD NOT include the PKP header field in HTTP 332 responses conveyed over non-secure transport. UAs MUST ignore any 333 PKP header received in an HTTP response conveyed over non-secure 334 transport. 336 2.3. User Agent Processing Model 338 This section describes the HTTP Public Key Pinning processing model 339 for UAs. 341 The UA processing model relies on parsing domain names. Note that 342 internationalized domain names SHALL be canonicalized according to 343 the scheme in Section 10 of [RFC6797]. 345 2.3.1. Public-Key-Pins Response Header Field Processing 347 If the UA receives, over a secure transport, an HTTP response that 348 includes a PKP header field conforming to the grammar specified in 349 Section 2.1, and there are no underlying secure transport errors or 350 warnings (see Section 2.5), the UA MUST either: 352 o Note the host as a Known HSTS Host if it is not already so noted 353 (see Section 2.3.2), 355 or, 357 o Update the UA's cached information for the Known Pinned Host if 358 any of of the max-age, includeSubDomains, strict, or report-uri 359 header field value directives convey information different than 360 that already maintained by the UA. 362 o The max-age value is essentially a "time to live" value relative 363 to the time of the most recent observation of the PKP header 364 field. 366 o If the max-age header field value token has a value of 0, the UA 367 MUST remove its cached Pinning Policy information (including the 368 includeSubDomains and strict directives, if asserted) if the 369 Pinned Host is Known, or, MUST NOT note this Pinned Host if it is 370 not yet Known. 372 o If a UA receives more than one PKP header field in an HTTP 373 response message over secure transport, then the UA MUST process 374 only the first such header field. 376 Otherwise: 378 o If the UA receives the HTTP response over insecure transport, or 379 if the PKP header is not a Valid Pinning Header (see Section 2.5), 380 the UA MUST ignore any present PKP header field(s). 382 o The UA MUST ignore any PKP header fields not conforming to the 383 grammar specified in Section 2.1. 385 2.3.2. Noting a Pinned Host - Storage Model 387 If the substring matching the host production from the Request-URI 388 (of the message to which the host responded) syntactically matches 389 the IP-literal or IPv4address productions from Section 3.2.2 of 390 [RFC3986], then the UA MUST NOT note this host as a Known Pinned 391 Host. 393 Otherwise, if the substring does not congruently match a Known Pinned 394 Host's domain name, per the matching procedure specified in 395 Section 8.2 of [RFC6797], then the UA MUST note this host as a Known 396 Pinned Host, caching the Pinned Host's domain name and noting along 397 with it the time of the observation (also known as the Effective Pin 398 Date), the value of the max-age directive, whether or not the 399 includeSubDomains or strict directives are asserted, the value of the 400 report-uri directive (if present), and any other metadata from 401 optional or future PKP header directives. 403 UAs SHOULD set an upper limit on the value of max-age, so that UAs 404 that have noted erroneous pins (whether by accident or due to attack) 405 have some chance of recovering over time. If the server sets a max- 406 age greater than the UA's upper limit, the UA SHOULD behave as if the 407 server set the max-age to the UA's upper limit. For example, if the 408 UA caps max-age at 2592000 seconds (30 days), and a Pinned Host sets 409 a max-age directive of 60 days in its Valid Pinning Header, the UA 410 SHOULD behave as if the max-age were effectively 30 days. (One way 411 to achieve this behavior is for the UA to simply store a value of 30 412 days instead of the 60 day value provided by the Pinned Host.) For 413 UA implementation guidance on how to select a maximum max-age, see 414 Section 4.1. 416 The UA MUST NOT modify any pinning metadata of any superdomain 417 matched Known Pinned Host. 419 A Known Pinned Host is "expired" if the Effective Pin Date plus the 420 max-age refers to a date in the past. The UA MUST ignore all expired 421 Known Pinned Hosts from its cache, if at any time, an expired Known 422 Pinned Host exists in the cache. 424 2.3.3. HTTP-Equiv Element Attribute 426 UAs MUST NOT heed http-equiv="Public-Key-Pins" attribute settings on 427 elements [W3C.REC-html401-19991224] in received content. 429 2.3.4. UA Processing Examples 431 TODO. 433 2.4. Semantics of Pins 435 An SPKI Fingerprint is defined as the output of a known cryptographic 436 hash algorithm whose input is the DER-encoded ASN.1 representation of 437 the SubjectPublicKeyInfo (SPKI) field of an X.509 certificate. A Pin 438 is defined as the combination of the known algorithm identifier and 439 the SPKI Fingerprint computed using that algorithm. 441 The SPKI Fingerprint is encoded in base 64 for use in an HTTP header. 442 (See [RFC4648].) 444 In this version of the specification, the known cryptographic hash 445 algorithms are SHA-1, identified as "sha1", and SHA-256, identified 446 as "sha256". (Future versions of this specification may add new 447 algorithms and deprecate old ones.) UAs MUST ignore Pins for which 448 they do not recognize the algorithm identifier. UAs MUST continue to 449 process the rest of a PKP response header field and note Pins for 450 algorithms they do recognize; UAs MUST recognize "sha1" and "sha256". 452 Figure 4 reproduces the definition of the SubjectPublicKeyInfo 453 structure in [RFC5280]. 455 SubjectPublicKeyInfo ::= SEQUENCE { 456 algorithm AlgorithmIdentifier, 457 subjectPublicKey BIT STRING } 459 AlgorithmIdentifier ::= SEQUENCE { 460 algorithm OBJECT IDENTIFIER, 461 parameters ANY DEFINED BY algorithm OPTIONAL } 463 Figure 4: SPKI Definition 465 If the SubjectPublicKeyInfo of a certificate is incomplete when taken 466 in isolation, such as when holding a DSA key without domain 467 parameters, a public key pin cannot be formed. 469 We pin public keys, rather than entire certificates, to enable 470 operators to generate new certificates containing old public keys 471 (see [why-pin-key]). 473 See Appendix A for an example non-normative program that generates 474 SPKI Fingerprints from SubjectPublicKeyInfo fields in certificates. 476 2.5. Noting Pins 478 Upon receipt of the Public-Key-Pins response header field, the UA 479 notes the host as a Pinned Host, storing the Pins and their 480 associated directives in non-volatile storage (for example, along 481 with the HSTS metadata). The Pins and their associated directives 482 collectively known as Pinning Metadata. 484 The UA MUST observe these conditions when noting a Host: 486 o The UA MUST note the Pins if and only if it received the Public- 487 Key-Pins response header field over an error-free TLS connection. 488 If the host is a Pinned Host, this includes the validation added 489 in Section 2.6. 491 o The UA MUST note the Pins if and only if the TLS connection was 492 authenticated with a certificate chain containing at least one of 493 the SPKI structures indicated by at least one of the given SPKI 494 Fingerprints. (See Section 2.6.) 496 o The UA MUST note the Pins if and only if the given set of Pins 497 contains at least one Pin that does NOT refer to an SPKI in the 498 certificate chain. (That is, the host must set a Backup Pin; see 499 Section 4.3.) 501 If the Public-Key-Pins response header field does not meet all three 502 of these criteria, the UA MUST NOT note the host as a Pinned Host. A 503 Public-Key-Pins response header field that meets all these critera is 504 known as a Valid Pinning Header. 506 The UA MUST ignore Public-Key-Pins response header fields received on 507 connections that do not meet the first criterion. 509 Whenever a UA receives a Valid Pinning Header, it MUST set its 510 Pinning Metadata to the exact Pins, max-age, and (if any) report-uri 511 and strict mode given in the most recently received Valid Pinning 512 Header. 514 For forward compatibility, the UA MUST ignore any unrecognized 515 Public-Key-Pins header directives, while still processing those 516 directives it does recognize. Section 2.1 specifies the directives 517 max-age, pins, includeSubDomains, report-uri, and strict, but future 518 specifications and implementations might use additional directives. 520 2.6. Validating Pinned Connections 522 When a UA connects to a Pinned Host, if the TLS connection has 523 errors, the UA MUST terminate the connection without allowing the 524 user to proceed anyway. (This behavior is the same as that required 525 by [RFC6797].) 527 If the connection has no errors, then the UA will determine whether 528 to apply a new, additional correctness check: Pin Validation. A UA 529 SHOULD perform Pin Validation whenever connecting to a Known Pinned 530 Host, but MAY allow Pin Validation to be disabled for Hosts according 531 to local policy. For example, a UA may disable Pin Validation for 532 Pinned Hosts whose validated certificate chain terminates at a user- 533 defined trust anchor, rather than a trust anchor built-in to the UA. 534 However, if the Pinned Host Metadata indicates that the Pinned Host 535 is operating in "strict mode" (see Section 2.1.4), then the UA MUST 536 perform Pin Validation. 538 To perform Pin Validation, the UA will compute the SPKI Fingerprints 539 for each certificate in the Pinned Host's validated certificate 540 chain, using each supported hash algorithm for each certificate. 541 (For the purposes of Pin Validation, the UA MUST ignore certificates 542 whose SPKI cannot be taken in isolation and superfluous certificates 543 in the chain that do not form part of the validating chain.) The UA 544 will then check that the set of these SPKI Fingerprints intersects 545 the set of SPKI Fingerprints in that Pinned Host's Pinning Metadata. 546 If there is set intersection, the UA continues with the connection as 547 normal. Otherwise, the UA MUST treat this Pin Failure as a non- 548 recoverable error. Any procedure that matches the results of this 549 Pin Validation procedure is considered equivalent. 551 Note that, although the UA has previously received Pins at the HTTP 552 layer, it can and MUST perform Pin Validation at the TLS layer, 553 before beginning an HTTP conversation over the TLS channel. The TLS 554 layer thus evaluates TLS connections with pinning information the UA 555 received previously, regardless of mechanism: statically preloaded, 556 via HTTP header, or some other means (possibly in the TLS layer 557 itself). 559 2.7. Interactions With Preloaded Pin Lists 561 UAs MAY choose to implement additional sources of pinning 562 information, such as through built-in lists of pinning information. 563 Such UAs SHOULD allow users to override such additional sources, 564 including disabling them from consideration. 566 UAs that support additional sources of pinning information MUST use 567 the most recently observed pinning information when performing Pin 568 Validation for a host. The most recently observed pinning 569 information is determined based upon the most recent Effective Pin 570 Date, as described in Section 2.3.2. 572 If the result of noting a Valid Pinning Header is to disable pinning 573 for the host, such as through supplying a max-age directive with a 574 value of 0, UAs MUST allow this new information to override any other 575 pinning data. That is, a host must be able to un-pin itself, even in 576 the presence of built-in pins. 578 Example: A UA may ship with a pre-configured list of pins that are 579 collected from past observations of Valid Pinning Headers supplied by 580 hosts. In such a solution, the pre-configured list should track when 581 the Valid Pinning Header was last observed, in order to permit site 582 operators to later update the value by supplying a new Valid Pinning 583 Header. Updates to such a pre-configured list should not update the 584 Effective Pin Dates for each host unless the list vendor has actually 585 observed a more recent header. This is to prevent situations where 586 updating the Effective Pin Date on a pre-configured list of pins may 587 effectively extend the max-age beyond the site operator's stated 588 policy. 590 Example: An alternative example would be a UA that ships with a pre- 591 configured list of pins that are collected through out-of-band means, 592 such as direct contact with the site operator. In such a solution, 593 the site operator accepts responsibility for keeping the configured 594 Valid Pinning Header in sync with the vendor's list, allowing the UA 595 vendor to have each update to the list be treated as as an update of 596 the Effective Pin Date. 598 2.8. Pinning Self-Signed End Entities 600 If UAs accept hosts that authenticate themselves with self-signed end 601 entity certificates, they MAY also allow hosts to pin the public keys 602 in such certificates. The usability and security implications of 603 this practice are outside the scope of this specification. 605 3. Reporting Pin Validation Failure 607 When a Known Pinned Host has set the report-uri directive, the UA 608 SHOULD report Pin Validation failures to the indicated URI. The UA 609 does this by POSTing a JSON message to the URI; the JSON message 610 takes this form: 612 { 613 "date-time": date-time, 614 "hostname": hostname, 615 "port": port, 616 "certificate-chain": [ 617 pem1, ... pemN 618 ], 619 "known-pins": [ 620 known-pin1, ... known-pinN 621 ] 622 } 624 Figure 5: JSON Report Format 626 Whitespace outside of quoted strings is not significant. The key/ 627 value pairs may appear in any order, but each SHOULD appear only 628 once. 630 The date-time indicates the time the UA observed the Pin Validation 631 failure. It is provided as a string formatted according to 632 Section 5.6, "Internet Date/Time Format", of [RFC3339]. 634 The hostname is the hostname to which the UA made the original 635 request that failed Pin Validation. It is provided as a string. 637 The port is the port to which the UA made the original request that 638 failed Pin Validation. It is provided either as a string or as an 639 integer. 641 The certificate-chain is the certificate chain, as constructed by the 642 UA during certificate chain verification. (This may differ from the 643 certificate chain as served by the Known Pinned Host, of course.) It 644 is provided as an array of strings; each string pem1, ... pemN is the 645 PEM representation of each X.509 certificate as described in 646 [I-D.josefsson-pkix-textual]. 648 The known-pins are the Pins that the UA has noted for the Known 649 Pinned Host. They are provided as an array of strings with the 650 syntax: 652 known-pin = token "=" quoted-string 654 Figure 6: Known Pin Syntax 656 As in Section 2.4, the token refers to the algorithm name, and the 657 quoted-string refers to the base 64 encoding of the SPKI Fingerprint. 659 4. Security Considerations 661 Pinning public keys helps hosts strongly assert their cryptographic 662 identity even in the face of issuer error, malfeasance or compromise. 663 But there is some risk that a host operator could lose or lose 664 control of their host's private key (such as by operator error or 665 host compromise). If the operator had pinned only the key of the 666 host's end entity certificate, the operator would not be able to 667 serve their web site or application in a way that UAs would trust for 668 the duration of their pin's max-age. (Recall that UAs MUST close the 669 connection to a host upon Pin Failure.) 671 Therefore, there is a necessary trade-off between two competing 672 goods: pin specificity and maximal reduction of the scope of issuers 673 on the one hand; and flexibility and resilience of the host's 674 cryptographic identity on the other hand. One way to resolve this 675 trade-off is to compromise by pinning to the key(s) of the issuer(s) 676 of the host's end entity certificate(s). Often, a valid certificate 677 chain will have at least two certificates above the end entity 678 certificate: the intermediate issuer, and the trust anchor. 679 Operators can pin any one or more of the public keys in this chain, 680 and indeed could pin to issuers not in the chain (as, for example, a 681 Backup Pin). Pinning to an intermediate issuer, or even to a trust 682 anchor or root, still significantly reduces the number of issuers who 683 can issue end entity certificates for the Known Pinned Host, while 684 still giving that host flexibility to change keys without a 685 disruption of service. 687 4.1. Maximum max-age 689 As mentioned in Section 2.3.2, UAs SHOULD cap the max-age value at 690 some upper limit. There is a security trade-off in that low maximum 691 values provide a narrow window of protection for users who visit the 692 Known Pinned Host only infrequently, while high maximum values might 693 potentially result in a UA's inability to successfully perform Pin 694 Validation for a Known Pinned Host if the UA's noted pins and the 695 Host's true pins diverge. 697 Such divergence could occur for several reasons, including: UA error; 698 Host operator error; network attack; or a Known Pinned Host that 699 intentionally migrates all pinned keys, combined with a UA that has 700 noted true pins with a high max-age value and has not had a chance to 701 observe the new true pins for the Host. (This last example 702 underscores the importance for Host operators to phase in new keys 703 gradually, and to set the max-age value in accordance with their 704 planned key migration schedule.) 706 There is probably no ideal upper limit to the max-age directive that 707 would satisfy all use cases. However, a value on the order of 30 708 days (2592000 seconds) may be considered a balance between the two 709 competing security concerns. 711 4.2. Using includeSubdomains Safely 713 It may happen that Pinned Hosts whose hostnames share a parent domain 714 use different Valid Pinning Headers. If a Host whose hostname is a 715 parent domain for another Host sets the includeSubdomains directive, 716 the Hosts' pins may conflict with each other. For example, consider 717 two Known Pinned Hosts, example.com and subdomain.example.com. 718 Assume example.com sets a Valid Pinning Header such as this: 720 Public-Key-Pins: pin-sha1="ABC..."; pin-sha1="DEF..."; includeSubdomains 722 Figure 7: example.com Valid Pinning Header 724 Assume subdomain.example.com sets a Valid Pinning Header such as 725 this: 727 Public-Key-Pins: pin-sha1="GHI..."; pin-sha1="JKL..." 729 Figure 8: subdomain.example.com Valid Pinning Header 731 Assume a UA that has not previously noted any pins for either of 732 these Hosts. If the UA first contacts subdomain.example.com, it will 733 note the pins in the Valid Pinning Header, and perform Pin Validation 734 as normal on subsequent conections. If the UA then contacts 735 example.com, again it will note the pins and perform Pin Validation 736 on future connections. However, if the UA happened to first 737 example.com before subdomain.example.com, the UA would, due to 738 example.com's use of the includeSubdomains directive, attempt to 739 perform Pin Validation for subdomain.example.com using the SPKI 740 hashes ABC... and DEF..., which are not valid for the certificate 741 chains subdomain.example.com (which uses certificates with SPKIs 742 GHI... and JLK...). Thus, depending on the order in which the UA 743 observes the Valid Pinning Headers for hosts example.com and 744 subdomain.example.com, Pin Validation might or might not fail for 745 subdomain.example.com, even if the certificate chain the UA receives 746 for subdomain.example.com is perfectly valid. 748 Thus, Pinned Host operators must take care that they use the 749 includeSubdomains directive with care. For example, they may choose 750 to use overlapping pin sets for hosts under a parent domain that uses 751 includeSubdomains, or to not use the includeSubdomains directive in 752 their effective-second-level domains, or to simply use the same pin 753 set for all hosts under a given parent domain. 755 4.3. Backup Pins 757 The primary way to cope with the risk of inadvertant Pin Failure is 758 to keep a Backup Pin. A Backup Pin is a fingerprint for the public 759 key of a secondary, not-yet-deployed key pair. The operator keeps 760 the backup key pair offline, and sets a pin for it in the Public-Key- 761 Pins header. Then, in case the operator loses control of their 762 primary private key, they can deploy the backup key pair. UAs, who 763 have had the backup key pair pinned (when it was set in previous 764 Valid Pinning Headers), can connect to the host without error. 766 Because having a backup key pair is so important to recovery, UAs 767 MUST require that hosts set a Backup Pin. (See Section 2.5.) 769 5. IANA Considerations 771 This document has no actions for IANA. 773 6. Usability Considerations 775 When pinning works to detect impostor Pinned Hosts, users will 776 experience denial of service. UAs MUST explain the reason why, i.e. 777 that it was impossible to verify the confirmed cryptographic identity 778 of the host. 780 UAs MUST have a way for users to clear current pins for Pinned Hosts. 781 UAs SHOULD have a way for users to query the current state of Pinned 782 Hosts. 784 7. Acknowledgements 786 Thanks to Tobias Gondrom, Jeff Hodges, Adam Langley, Nicolas 787 Lidzborski, SM, James Manger, Eric Rescorla, Paul Hoffman, and Yoav 788 Nir for suggestions and edits that clarified the text. Thanks to 789 Trevor Perrin for suggesting a mechanism to affirmatively break pins 790 ([pin-break-codes]). Adam Langley provided the SPKI fingerprint 791 generation code. 793 8. What's Changed 795 Removed the section "Pin Validity Times", which was intended to be in 796 harmony with [I-D.perrin-tls-tack]. Now using max-age purely as 797 specified in [RFC6797]. 799 Added new directives: includeSubDomains, report-uri and strict. 801 Added a new variant of the PKP Header: Public-Key-Pins-Report-Only. 803 Removed the section on pin break codes and verifiers, in favor the of 804 most-recently-received policy (Section 2.5). 806 Now using a new header field, Public-Key-Pins, separate from HSTS. 807 This allows hosts to use pinning separately from Strict Transport 808 Security. 810 Explicitly requiring that UAs perform Pin Validation before the HTTP 811 conversation begins. 813 Backup Pins are now required. 815 Separated normative from non-normative material. Removed tangential 816 and out-of-scope non-normative discussion. 818 9. References 820 9.1. Normative References 822 [I-D.josefsson-pkix-textual] 823 Josefsson, S. and S. Leonard, "Text Encodings of PKIX and 824 CMS Structures", draft-josefsson-pkix-textual-01 (work in 825 progress), July 2012. 827 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 828 Requirement Levels", BCP 14, RFC 2119, March 1997. 830 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 831 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 832 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 834 [RFC3339] Klyne, G., Ed. and C. Newman, "Date and Time on the 835 Internet: Timestamps", RFC 3339, July 2002. 837 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 838 Resource Identifier (URI): Generic Syntax", STD 66, RFC 839 3986, January 2005. 841 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data 842 Encodings", RFC 4648, October 2006. 844 [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an 845 IANA Considerations Section in RFCs", BCP 26, RFC 5226, 846 May 2008. 848 [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security 849 (TLS) Protocol Version 1.2", RFC 5246, August 2008. 851 [RFC5280] Cooper, D., Santesson, S., Farrell, S., Boeyen, S., 852 Housley, R., and W. Polk, "Internet X.509 Public Key 853 Infrastructure Certificate and Certificate Revocation List 854 (CRL) Profile", RFC 5280, May 2008. 856 [RFC6797] Hodges, J., Jackson, C., and A. Barth, "HTTP Strict 857 Transport Security (HSTS)", RFC 6797, November 2012. 859 [W3C.REC-html401-19991224] 860 Hors, A., Raggett, D., and I. Jacobs, "HTML 4.01 861 Specification", World Wide Web Consortium Recommendation 862 REC-html401-19991224, December 1999, 863 . 865 9.2. Informative References 867 [I-D.perrin-tls-tack] 868 Marlinspike, M., "Trust Assertions for Certificate Keys", 869 draft-perrin-tls-tack-02 (work in progress), January 2013. 871 [pin-break-codes] 872 Perrin, T., "Self-Asserted Key Pinning", September 2011, 873 . 875 [why-pin-key] 876 Langley, A., "Public Key Pinning", May 2011, 877 . 879 Appendix A. Fingerprint Generation 881 This Go program generates SPKI Fingerprints, suitable for use in 882 pinning, from PEM-encoded certificates. It is non-normative. 884 package main 886 import ( 887 "io/ioutil" 888 "os" 889 "crypto/sha1" 890 "crypto/x509" 891 "encoding/base64" 892 "encoding/pem" 893 "fmt" 894 ) 896 func main() { 897 if len(os.Args) < 2 { 898 fmt.Printf("Usage: %s PEM-filename\n", os.Args[0]) 899 os.Exit(1) 900 } 901 pemBytes, err := ioutil.ReadFile(os.Args[1]) 902 if err != nil { 903 panic(err.String()) 904 } 905 block, _ := pem.Decode(pemBytes) 906 if block == nil { 907 panic("No PEM structure found") 908 } 909 derBytes := block.Bytes 910 certs, err := x509.ParseCertificates(derBytes) 911 if err != nil { 912 panic(err.String()) 913 } 914 cert := certs[0] 915 h := sha1.New() 916 h.Write(cert.RawSubjectPublicKeyInfo) 917 digest := h.Sum() 919 fmt.Printf("Hex: %x\nBase64: %s\n", digest, 920 base64.StdEncoding.EncodeToString(digest)) 921 } 923 Figure 9: Example SPKI Fingerprint Generation Code 925 Appendix B. Deployment Guidance 927 This section is non-normative guidance which may smooth the adoption 928 of public key pinning. 930 o Operators SHOULD get the backup public key signed by a different 931 (root and/or intermediary) CA than their primary certificate, and 932 store the backup key pair safely offline. The semantics of an 933 SPKI Fingerprint do not require the issuance of a certificate to 934 construct a valid Pin. However, in many deployment scenarios, in 935 order to make a Backup Pin operational the server operator will 936 need to have a certificate to deploy TLS on the host. Failure to 937 obtain a certificate through prior arrangement will leave clients 938 that recognize the site as a Known Pinned Host unable to 939 successfully perform Pin Validation until such a time as the 940 operator can obtain a new certificate from their desired 941 certificate issuer. 943 o It is most economical to have the backup certificate signed by a 944 completely different signature chain than the live certificate, to 945 maximize recoverability in the event of either root or 946 intermediary signer compromise. 948 o Operators SHOULD periodically exercise their Backup Pin plan 949 -\u002D an untested backup is no backup at all. 951 o Operators SHOULD start small. Operators SHOULD first deploy 952 public key pinning by using the report-only mode together with a 953 report-uri directive that points to a reliable report collection 954 endpoint. When moving out of report-only mode, operators should 955 start by setting a max-age of minutes or a few hours, and 956 gradually increase max-age as they gain confidence in their 957 operational capability. 959 Authors' Addresses 961 Chris Evans 962 Google, Inc. 963 1600 Amphitheatre Pkwy 964 Mountain View, CA 94043 965 US 967 Email: cevans@google.com 969 Chris Palmer 970 Google, Inc. 971 1600 Amphitheatre Pkwy 972 Mountain View, CA 94043 973 US 975 Email: palmer@google.com 977 Ryan Sleevi 978 Google, Inc. 979 1600 Amphitheatre Pkwy 980 Mountain View, CA 94043 981 US 983 Email: sleevi@google.com