]> git.ipfire.org Git - thirdparty/cups.git/blob - standards/rfc2617.txt
Load cups into easysw/current.
[thirdparty/cups.git] / standards / rfc2617.txt
1
2
3
4
5
6
7 Network Working Group J. Franks
8 Request for Comments: 2617 Northwestern University
9 Obsoletes: 2069 P. Hallam-Baker
10 Category: Standards Track Verisign, Inc.
11 J. Hostetler
12 AbiSource, Inc.
13 S. Lawrence
14 Agranat Systems, Inc.
15 P. Leach
16 Microsoft Corporation
17 A. Luotonen
18 Netscape Communications Corporation
19 L. Stewart
20 Open Market, Inc.
21 June 1999
22
23
24 HTTP Authentication: Basic and Digest Access Authentication
25
26 Status of this Memo
27
28 This document specifies an Internet standards track protocol for the
29 Internet community, and requests discussion and suggestions for
30 improvements. Please refer to the current edition of the "Internet
31 Official Protocol Standards" (STD 1) for the standardization state
32 and status of this protocol. Distribution of this memo is unlimited.
33
34 Copyright Notice
35
36 Copyright (C) The Internet Society (1999). All Rights Reserved.
37
38 Abstract
39
40 "HTTP/1.0", includes the specification for a Basic Access
41 Authentication scheme. This scheme is not considered to be a secure
42 method of user authentication (unless used in conjunction with some
43 external secure system such as SSL [5]), as the user name and
44 password are passed over the network as cleartext.
45
46 This document also provides the specification for HTTP's
47 authentication framework, the original Basic authentication scheme
48 and a scheme based on cryptographic hashes, referred to as "Digest
49 Access Authentication". It is therefore also intended to serve as a
50 replacement for RFC 2069 [6]. Some optional elements specified by
51 RFC 2069 have been removed from this specification due to problems
52 found since its publication; other new elements have been added for
53 compatibility, those new elements have been made optional, but are
54 strongly recommended.
55
56
57
58 Franks, et al. Standards Track [Page 1]
59 \f
60 RFC 2617 HTTP Authentication June 1999
61
62
63 Like Basic, Digest access authentication verifies that both parties
64 to a communication know a shared secret (a password); unlike Basic,
65 this verification can be done without sending the password in the
66 clear, which is Basic's biggest weakness. As with most other
67 authentication protocols, the greatest sources of risks are usually
68 found not in the core protocol itself but in policies and procedures
69 surrounding its use.
70
71 Table of Contents
72
73 1 Access Authentication................................ 3
74 1.1 Reliance on the HTTP/1.1 Specification............ 3
75 1.2 Access Authentication Framework................... 3
76 2 Basic Authentication Scheme.......................... 5
77 3 Digest Access Authentication Scheme.................. 6
78 3.1 Introduction...................................... 6
79 3.1.1 Purpose......................................... 6
80 3.1.2 Overall Operation............................... 6
81 3.1.3 Representation of digest values................. 7
82 3.1.4 Limitations..................................... 7
83 3.2 Specification of Digest Headers................... 7
84 3.2.1 The WWW-Authenticate Response Header............ 8
85 3.2.2 The Authorization Request Header................ 11
86 3.2.3 The Authentication-Info Header.................. 15
87 3.3 Digest Operation.................................. 17
88 3.4 Security Protocol Negotiation..................... 18
89 3.5 Example........................................... 18
90 3.6 Proxy-Authentication and Proxy-Authorization...... 19
91 4 Security Considerations.............................. 19
92 4.1 Authentication of Clients using Basic
93 Authentication.................................... 19
94 4.2 Authentication of Clients using Digest
95 Authentication.................................... 20
96 4.3 Limited Use Nonce Values.......................... 21
97 4.4 Comparison of Digest with Basic Authentication.... 22
98 4.5 Replay Attacks.................................... 22
99 4.6 Weakness Created by Multiple Authentication
100 Schemes........................................... 23
101 4.7 Online dictionary attacks......................... 23
102 4.8 Man in the Middle................................. 24
103 4.9 Chosen plaintext attacks.......................... 24
104 4.10 Precomputed dictionary attacks.................... 25
105 4.11 Batch brute force attacks......................... 25
106 4.12 Spoofing by Counterfeit Servers................... 25
107 4.13 Storing passwords................................. 26
108 4.14 Summary........................................... 26
109 5 Sample implementation................................ 27
110 6 Acknowledgments...................................... 31
111
112
113
114 Franks, et al. Standards Track [Page 2]
115 \f
116 RFC 2617 HTTP Authentication June 1999
117
118
119 7 References........................................... 31
120 8 Authors' Addresses................................... 32
121 9 Full Copyright Statement............................. 34
122
123 1 Access Authentication
124
125 1.1 Reliance on the HTTP/1.1 Specification
126
127 This specification is a companion to the HTTP/1.1 specification [2].
128 It uses the augmented BNF section 2.1 of that document, and relies on
129 both the non-terminals defined in that document and other aspects of
130 the HTTP/1.1 specification.
131
132 1.2 Access Authentication Framework
133
134 HTTP provides a simple challenge-response authentication mechanism
135 that MAY be used by a server to challenge a client request and by a
136 client to provide authentication information. It uses an extensible,
137 case-insensitive token to identify the authentication scheme,
138 followed by a comma-separated list of attribute-value pairs which
139 carry the parameters necessary for achieving authentication via that
140 scheme.
141
142 auth-scheme = token
143 auth-param = token "=" ( token | quoted-string )
144
145 The 401 (Unauthorized) response message is used by an origin server
146 to challenge the authorization of a user agent. This response MUST
147 include a WWW-Authenticate header field containing at least one
148 challenge applicable to the requested resource. The 407 (Proxy
149 Authentication Required) response message is used by a proxy to
150 challenge the authorization of a client and MUST include a Proxy-
151 Authenticate header field containing at least one challenge
152 applicable to the proxy for the requested resource.
153
154 challenge = auth-scheme 1*SP 1#auth-param
155
156 Note: User agents will need to take special care in parsing the WWW-
157 Authenticate or Proxy-Authenticate header field value if it contains
158 more than one challenge, or if more than one WWW-Authenticate header
159 field is provided, since the contents of a challenge may itself
160 contain a comma-separated list of authentication parameters.
161
162 The authentication parameter realm is defined for all authentication
163 schemes:
164
165 realm = "realm" "=" realm-value
166 realm-value = quoted-string
167
168
169
170 Franks, et al. Standards Track [Page 3]
171 \f
172 RFC 2617 HTTP Authentication June 1999
173
174
175 The realm directive (case-insensitive) is required for all
176 authentication schemes that issue a challenge. The realm value
177 (case-sensitive), in combination with the canonical root URL (the
178 absoluteURI for the server whose abs_path is empty; see section 5.1.2
179 of [2]) of the server being accessed, defines the protection space.
180 These realms allow the protected resources on a server to be
181 partitioned into a set of protection spaces, each with its own
182 authentication scheme and/or authorization database. The realm value
183 is a string, generally assigned by the origin server, which may have
184 additional semantics specific to the authentication scheme. Note that
185 there may be multiple challenges with the same auth-scheme but
186 different realms.
187
188 A user agent that wishes to authenticate itself with an origin
189 server--usually, but not necessarily, after receiving a 401
190 (Unauthorized)--MAY do so by including an Authorization header field
191 with the request. A client that wishes to authenticate itself with a
192 proxy--usually, but not necessarily, after receiving a 407 (Proxy
193 Authentication Required)--MAY do so by including a Proxy-
194 Authorization header field with the request. Both the Authorization
195 field value and the Proxy-Authorization field value consist of
196 credentials containing the authentication information of the client
197 for the realm of the resource being requested. The user agent MUST
198 choose to use one of the challenges with the strongest auth-scheme it
199 understands and request credentials from the user based upon that
200 challenge.
201
202 credentials = auth-scheme #auth-param
203
204 Note that many browsers will only recognize Basic and will require
205 that it be the first auth-scheme presented. Servers should only
206 include Basic if it is minimally acceptable.
207
208 The protection space determines the domain over which credentials can
209 be automatically applied. If a prior request has been authorized, the
210 same credentials MAY be reused for all other requests within that
211 protection space for a period of time determined by the
212 authentication scheme, parameters, and/or user preference. Unless
213 otherwise defined by the authentication scheme, a single protection
214 space cannot extend outside the scope of its server.
215
216 If the origin server does not wish to accept the credentials sent
217 with a request, it SHOULD return a 401 (Unauthorized) response. The
218 response MUST include a WWW-Authenticate header field containing at
219 least one (possibly new) challenge applicable to the requested
220 resource. If a proxy does not accept the credentials sent with a
221 request, it SHOULD return a 407 (Proxy Authentication Required). The
222 response MUST include a Proxy-Authenticate header field containing a
223
224
225
226 Franks, et al. Standards Track [Page 4]
227 \f
228 RFC 2617 HTTP Authentication June 1999
229
230
231 (possibly new) challenge applicable to the proxy for the requested
232 resource.
233
234 The HTTP protocol does not restrict applications to this simple
235 challenge-response mechanism for access authentication. Additional
236 mechanisms MAY be used, such as encryption at the transport level or
237 via message encapsulation, and with additional header fields
238 specifying authentication information. However, these additional
239 mechanisms are not defined by this specification.
240
241 Proxies MUST be completely transparent regarding user agent
242 authentication by origin servers. That is, they must forward the
243 WWW-Authenticate and Authorization headers untouched, and follow the
244 rules found in section 14.8 of [2]. Both the Proxy-Authenticate and
245 the Proxy-Authorization header fields are hop-by-hop headers (see
246 section 13.5.1 of [2]).
247
248 2 Basic Authentication Scheme
249
250 The "basic" authentication scheme is based on the model that the
251 client must authenticate itself with a user-ID and a password for
252 each realm. The realm value should be considered an opaque string
253 which can only be compared for equality with other realms on that
254 server. The server will service the request only if it can validate
255 the user-ID and password for the protection space of the Request-URI.
256 There are no optional authentication parameters.
257
258 For Basic, the framework above is utilized as follows:
259
260 challenge = "Basic" realm
261 credentials = "Basic" basic-credentials
262
263 Upon receipt of an unauthorized request for a URI within the
264 protection space, the origin server MAY respond with a challenge like
265 the following:
266
267 WWW-Authenticate: Basic realm="WallyWorld"
268
269 where "WallyWorld" is the string assigned by the server to identify
270 the protection space of the Request-URI. A proxy may respond with the
271 same challenge using the Proxy-Authenticate header field.
272
273 To receive authorization, the client sends the userid and password,
274 separated by a single colon (":") character, within a base64 [7]
275 encoded string in the credentials.
276
277 basic-credentials = base64-user-pass
278 base64-user-pass = <base64 [4] encoding of user-pass,
279
280
281
282 Franks, et al. Standards Track [Page 5]
283 \f
284 RFC 2617 HTTP Authentication June 1999
285
286
287 except not limited to 76 char/line>
288 user-pass = userid ":" password
289 userid = *<TEXT excluding ":">
290 password = *TEXT
291
292 Userids might be case sensitive.
293
294 If the user agent wishes to send the userid "Aladdin" and password
295 "open sesame", it would use the following header field:
296
297 Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
298
299 A client SHOULD assume that all paths at or deeper than the depth of
300 the last symbolic element in the path field of the Request-URI also
301 are within the protection space specified by the Basic realm value of
302 the current challenge. A client MAY preemptively send the
303 corresponding Authorization header with requests for resources in
304 that space without receipt of another challenge from the server.
305 Similarly, when a client sends a request to a proxy, it may reuse a
306 userid and password in the Proxy-Authorization header field without
307 receiving another challenge from the proxy server. See section 4 for
308 security considerations associated with Basic authentication.
309
310 3 Digest Access Authentication Scheme
311
312 3.1 Introduction
313
314 3.1.1 Purpose
315
316 The protocol referred to as "HTTP/1.0" includes the specification for
317 a Basic Access Authentication scheme[1]. That scheme is not
318 considered to be a secure method of user authentication, as the user
319 name and password are passed over the network in an unencrypted form.
320 This section provides the specification for a scheme that does not
321 send the password in cleartext, referred to as "Digest Access
322 Authentication".
323
324 The Digest Access Authentication scheme is not intended to be a
325 complete answer to the need for security in the World Wide Web. This
326 scheme provides no encryption of message content. The intent is
327 simply to create an access authentication method that avoids the most
328 serious flaws of Basic authentication.
329
330 3.1.2 Overall Operation
331
332 Like Basic Access Authentication, the Digest scheme is based on a
333 simple challenge-response paradigm. The Digest scheme challenges
334 using a nonce value. A valid response contains a checksum (by
335
336
337
338 Franks, et al. Standards Track [Page 6]
339 \f
340 RFC 2617 HTTP Authentication June 1999
341
342
343 default, the MD5 checksum) of the username, the password, the given
344 nonce value, the HTTP method, and the requested URI. In this way, the
345 password is never sent in the clear. Just as with the Basic scheme,
346 the username and password must be prearranged in some fashion not
347 addressed by this document.
348
349 3.1.3 Representation of digest values
350
351 An optional header allows the server to specify the algorithm used to
352 create the checksum or digest. By default the MD5 algorithm is used
353 and that is the only algorithm described in this document.
354
355 For the purposes of this document, an MD5 digest of 128 bits is
356 represented as 32 ASCII printable characters. The bits in the 128 bit
357 digest are converted from most significant to least significant bit,
358 four bits at a time to their ASCII presentation as follows. Each four
359 bits is represented by its familiar hexadecimal notation from the
360 characters 0123456789abcdef. That is, binary 0000 gets represented by
361 the character '0', 0001, by '1', and so on up to the representation
362 of 1111 as 'f'.
363
364 3.1.4 Limitations
365
366 The Digest authentication scheme described in this document suffers
367 from many known limitations. It is intended as a replacement for
368 Basic authentication and nothing more. It is a password-based system
369 and (on the server side) suffers from all the same problems of any
370 password system. In particular, no provision is made in this protocol
371 for the initial secure arrangement between user and server to
372 establish the user's password.
373
374 Users and implementors should be aware that this protocol is not as
375 secure as Kerberos, and not as secure as any client-side private-key
376 scheme. Nevertheless it is better than nothing, better than what is
377 commonly used with telnet and ftp, and better than Basic
378 authentication.
379
380 3.2 Specification of Digest Headers
381
382 The Digest Access Authentication scheme is conceptually similar to
383 the Basic scheme. The formats of the modified WWW-Authenticate header
384 line and the Authorization header line are specified below. In
385 addition, a new header, Authentication-Info, is specified.
386
387
388
389
390
391
392
393
394 Franks, et al. Standards Track [Page 7]
395 \f
396 RFC 2617 HTTP Authentication June 1999
397
398
399 3.2.1 The WWW-Authenticate Response Header
400
401 If a server receives a request for an access-protected object, and an
402 acceptable Authorization header is not sent, the server responds with
403 a "401 Unauthorized" status code, and a WWW-Authenticate header as
404 per the framework defined above, which for the digest scheme is
405 utilized as follows:
406
407 challenge = "Digest" digest-challenge
408
409 digest-challenge = 1#( realm | [ domain ] | nonce |
410 [ opaque ] |[ stale ] | [ algorithm ] |
411 [ qop-options ] | [auth-param] )
412
413
414 domain = "domain" "=" <"> URI ( 1*SP URI ) <">
415 URI = absoluteURI | abs_path
416 nonce = "nonce" "=" nonce-value
417 nonce-value = quoted-string
418 opaque = "opaque" "=" quoted-string
419 stale = "stale" "=" ( "true" | "false" )
420 algorithm = "algorithm" "=" ( "MD5" | "MD5-sess" |
421 token )
422 qop-options = "qop" "=" <"> 1#qop-value <">
423 qop-value = "auth" | "auth-int" | token
424
425 The meanings of the values of the directives used above are as
426 follows:
427
428 realm
429 A string to be displayed to users so they know which username and
430 password to use. This string should contain at least the name of
431 the host performing the authentication and might additionally
432 indicate the collection of users who might have access. An example
433 might be "registered_users@gotham.news.com".
434
435 domain
436 A quoted, space-separated list of URIs, as specified in RFC XURI
437 [7], that define the protection space. If a URI is an abs_path, it
438 is relative to the canonical root URL (see section 1.2 above) of
439 the server being accessed. An absoluteURI in this list may refer to
440 a different server than the one being accessed. The client can use
441 this list to determine the set of URIs for which the same
442 authentication information may be sent: any URI that has a URI in
443 this list as a prefix (after both have been made absolute) may be
444 assumed to be in the same protection space. If this directive is
445 omitted or its value is empty, the client should assume that the
446 protection space consists of all URIs on the responding server.
447
448
449
450 Franks, et al. Standards Track [Page 8]
451 \f
452 RFC 2617 HTTP Authentication June 1999
453
454
455 This directive is not meaningful in Proxy-Authenticate headers, for
456 which the protection space is always the entire proxy; if present
457 it should be ignored.
458
459 nonce
460 A server-specified data string which should be uniquely generated
461 each time a 401 response is made. It is recommended that this
462 string be base64 or hexadecimal data. Specifically, since the
463 string is passed in the header lines as a quoted string, the
464 double-quote character is not allowed.
465
466 The contents of the nonce are implementation dependent. The quality
467 of the implementation depends on a good choice. A nonce might, for
468 example, be constructed as the base 64 encoding of
469
470 time-stamp H(time-stamp ":" ETag ":" private-key)
471
472 where time-stamp is a server-generated time or other non-repeating
473 value, ETag is the value of the HTTP ETag header associated with
474 the requested entity, and private-key is data known only to the
475 server. With a nonce of this form a server would recalculate the
476 hash portion after receiving the client authentication header and
477 reject the request if it did not match the nonce from that header
478 or if the time-stamp value is not recent enough. In this way the
479 server can limit the time of the nonce's validity. The inclusion of
480 the ETag prevents a replay request for an updated version of the
481 resource. (Note: including the IP address of the client in the
482 nonce would appear to offer the server the ability to limit the
483 reuse of the nonce to the same client that originally got it.
484 However, that would break proxy farms, where requests from a single
485 user often go through different proxies in the farm. Also, IP
486 address spoofing is not that hard.)
487
488 An implementation might choose not to accept a previously used
489 nonce or a previously used digest, in order to protect against a
490 replay attack. Or, an implementation might choose to use one-time
491 nonces or digests for POST or PUT requests and a time-stamp for GET
492 requests. For more details on the issues involved see section 4.
493 of this document.
494
495 The nonce is opaque to the client.
496
497 opaque
498 A string of data, specified by the server, which should be returned
499 by the client unchanged in the Authorization header of subsequent
500 requests with URIs in the same protection space. It is recommended
501 that this string be base64 or hexadecimal data.
502
503
504
505
506 Franks, et al. Standards Track [Page 9]
507 \f
508 RFC 2617 HTTP Authentication June 1999
509
510
511 stale
512 A flag, indicating that the previous request from the client was
513 rejected because the nonce value was stale. If stale is TRUE
514 (case-insensitive), the client may wish to simply retry the request
515 with a new encrypted response, without reprompting the user for a
516 new username and password. The server should only set stale to TRUE
517 if it receives a request for which the nonce is invalid but with a
518 valid digest for that nonce (indicating that the client knows the
519 correct username/password). If stale is FALSE, or anything other
520 than TRUE, or the stale directive is not present, the username
521 and/or password are invalid, and new values must be obtained.
522
523 algorithm
524 A string indicating a pair of algorithms used to produce the digest
525 and a checksum. If this is not present it is assumed to be "MD5".
526 If the algorithm is not understood, the challenge should be ignored
527 (and a different one used, if there is more than one).
528
529 In this document the string obtained by applying the digest
530 algorithm to the data "data" with secret "secret" will be denoted
531 by KD(secret, data), and the string obtained by applying the
532 checksum algorithm to the data "data" will be denoted H(data). The
533 notation unq(X) means the value of the quoted-string X without the
534 surrounding quotes.
535
536 For the "MD5" and "MD5-sess" algorithms
537
538 H(data) = MD5(data)
539
540 and
541
542 KD(secret, data) = H(concat(secret, ":", data))
543
544 i.e., the digest is the MD5 of the secret concatenated with a colon
545 concatenated with the data. The "MD5-sess" algorithm is intended to
546 allow efficient 3rd party authentication servers; for the
547 difference in usage, see the description in section 3.2.2.2.
548
549 qop-options
550 This directive is optional, but is made so only for backward
551 compatibility with RFC 2069 [6]; it SHOULD be used by all
552 implementations compliant with this version of the Digest scheme.
553 If present, it is a quoted string of one or more tokens indicating
554 the "quality of protection" values supported by the server. The
555 value "auth" indicates authentication; the value "auth-int"
556 indicates authentication with integrity protection; see the
557
558
559
560
561
562 Franks, et al. Standards Track [Page 10]
563 \f
564 RFC 2617 HTTP Authentication June 1999
565
566
567 descriptions below for calculating the response directive value for
568 the application of this choice. Unrecognized options MUST be
569 ignored.
570
571 auth-param
572 This directive allows for future extensions. Any unrecognized
573 directive MUST be ignored.
574
575 3.2.2 The Authorization Request Header
576
577 The client is expected to retry the request, passing an Authorization
578 header line, which is defined according to the framework above,
579 utilized as follows.
580
581 credentials = "Digest" digest-response
582 digest-response = 1#( username | realm | nonce | digest-uri
583 | response | [ algorithm ] | [cnonce] |
584 [opaque] | [message-qop] |
585 [nonce-count] | [auth-param] )
586
587 username = "username" "=" username-value
588 username-value = quoted-string
589 digest-uri = "uri" "=" digest-uri-value
590 digest-uri-value = request-uri ; As specified by HTTP/1.1
591 message-qop = "qop" "=" qop-value
592 cnonce = "cnonce" "=" cnonce-value
593 cnonce-value = nonce-value
594 nonce-count = "nc" "=" nc-value
595 nc-value = 8LHEX
596 response = "response" "=" request-digest
597 request-digest = <"> 32LHEX <">
598 LHEX = "0" | "1" | "2" | "3" |
599 "4" | "5" | "6" | "7" |
600 "8" | "9" | "a" | "b" |
601 "c" | "d" | "e" | "f"
602
603 The values of the opaque and algorithm fields must be those supplied
604 in the WWW-Authenticate response header for the entity being
605 requested.
606
607 response
608 A string of 32 hex digits computed as defined below, which proves
609 that the user knows a password
610
611 username
612 The user's name in the specified realm.
613
614
615
616
617
618 Franks, et al. Standards Track [Page 11]
619 \f
620 RFC 2617 HTTP Authentication June 1999
621
622
623 digest-uri
624 The URI from Request-URI of the Request-Line; duplicated here
625 because proxies are allowed to change the Request-Line in transit.
626
627 qop
628 Indicates what "quality of protection" the client has applied to
629 the message. If present, its value MUST be one of the alternatives
630 the server indicated it supports in the WWW-Authenticate header.
631 These values affect the computation of the request-digest. Note
632 that this is a single token, not a quoted list of alternatives as
633 in WWW- Authenticate. This directive is optional in order to
634 preserve backward compatibility with a minimal implementation of
635 RFC 2069 [6], but SHOULD be used if the server indicated that qop
636 is supported by providing a qop directive in the WWW-Authenticate
637 header field.
638
639 cnonce
640 This MUST be specified if a qop directive is sent (see above), and
641 MUST NOT be specified if the server did not send a qop directive in
642 the WWW-Authenticate header field. The cnonce-value is an opaque
643 quoted string value provided by the client and used by both client
644 and server to avoid chosen plaintext attacks, to provide mutual
645 authentication, and to provide some message integrity protection.
646 See the descriptions below of the calculation of the response-
647 digest and request-digest values.
648
649 nonce-count
650 This MUST be specified if a qop directive is sent (see above), and
651 MUST NOT be specified if the server did not send a qop directive in
652 the WWW-Authenticate header field. The nc-value is the hexadecimal
653 count of the number of requests (including the current request)
654 that the client has sent with the nonce value in this request. For
655 example, in the first request sent in response to a given nonce
656 value, the client sends "nc=00000001". The purpose of this
657 directive is to allow the server to detect request replays by
658 maintaining its own copy of this count - if the same nc-value is
659 seen twice, then the request is a replay. See the description
660 below of the construction of the request-digest value.
661
662 auth-param
663 This directive allows for future extensions. Any unrecognized
664 directive MUST be ignored.
665
666 If a directive or its value is improper, or required directives are
667 missing, the proper response is 400 Bad Request. If the request-
668 digest is invalid, then a login failure should be logged, since
669 repeated login failures from a single client may indicate an attacker
670 attempting to guess passwords.
671
672
673
674 Franks, et al. Standards Track [Page 12]
675 \f
676 RFC 2617 HTTP Authentication June 1999
677
678
679 The definition of request-digest above indicates the encoding for its
680 value. The following definitions show how the value is computed.
681
682 3.2.2.1 Request-Digest
683
684 If the "qop" value is "auth" or "auth-int":
685
686 request-digest = <"> < KD ( H(A1), unq(nonce-value)
687 ":" nc-value
688 ":" unq(cnonce-value)
689 ":" unq(qop-value)
690 ":" H(A2)
691 ) <">
692
693 If the "qop" directive is not present (this construction is for
694 compatibility with RFC 2069):
695
696 request-digest =
697 <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) >
698 <">
699
700 See below for the definitions for A1 and A2.
701
702 3.2.2.2 A1
703
704 If the "algorithm" directive's value is "MD5" or is unspecified, then
705 A1 is:
706
707 A1 = unq(username-value) ":" unq(realm-value) ":" passwd
708
709 where
710
711 passwd = < user's password >
712
713 If the "algorithm" directive's value is "MD5-sess", then A1 is
714 calculated only once - on the first request by the client following
715 receipt of a WWW-Authenticate challenge from the server. It uses the
716 server nonce from that challenge, and the first client nonce value to
717 construct A1 as follows:
718
719 A1 = H( unq(username-value) ":" unq(realm-value)
720 ":" passwd )
721 ":" unq(nonce-value) ":" unq(cnonce-value)
722
723 This creates a 'session key' for the authentication of subsequent
724 requests and responses which is different for each "authentication
725 session", thus limiting the amount of material hashed with any one
726 key. (Note: see further discussion of the authentication session in
727
728
729
730 Franks, et al. Standards Track [Page 13]
731 \f
732 RFC 2617 HTTP Authentication June 1999
733
734
735 section 3.3.) Because the server need only use the hash of the user
736 credentials in order to create the A1 value, this construction could
737 be used in conjunction with a third party authentication service so
738 that the web server would not need the actual password value. The
739 specification of such a protocol is beyond the scope of this
740 specification.
741
742 3.2.2.3 A2
743
744 If the "qop" directive's value is "auth" or is unspecified, then A2
745 is:
746
747 A2 = Method ":" digest-uri-value
748
749 If the "qop" value is "auth-int", then A2 is:
750
751 A2 = Method ":" digest-uri-value ":" H(entity-body)
752
753 3.2.2.4 Directive values and quoted-string
754
755 Note that the value of many of the directives, such as "username-
756 value", are defined as a "quoted-string". However, the "unq" notation
757 indicates that surrounding quotation marks are removed in forming the
758 string A1. Thus if the Authorization header includes the fields
759
760 username="Mufasa", realm=myhost@testrealm.com
761
762 and the user Mufasa has password "Circle Of Life" then H(A1) would be
763 H(Mufasa:myhost@testrealm.com:Circle Of Life) with no quotation marks
764 in the digested string.
765
766 No white space is allowed in any of the strings to which the digest
767 function H() is applied unless that white space exists in the quoted
768 strings or entity body whose contents make up the string to be
769 digested. For example, the string A1 illustrated above must be
770
771 Mufasa:myhost@testrealm.com:Circle Of Life
772
773 with no white space on either side of the colons, but with the white
774 space between the words used in the password value. Likewise, the
775 other strings digested by H() must not have white space on either
776 side of the colons which delimit their fields unless that white space
777 was in the quoted strings or entity body being digested.
778
779 Also note that if integrity protection is applied (qop=auth-int), the
780 H(entity-body) is the hash of the entity body, not the message body -
781 it is computed before any transfer encoding is applied by the sender
782
783
784
785
786 Franks, et al. Standards Track [Page 14]
787 \f
788 RFC 2617 HTTP Authentication June 1999
789
790
791 and after it has been removed by the recipient. Note that this
792 includes multipart boundaries and embedded headers in each part of
793 any multipart content-type.
794
795 3.2.2.5 Various considerations
796
797 The "Method" value is the HTTP request method as specified in section
798 5.1.1 of [2]. The "request-uri" value is the Request-URI from the
799 request line as specified in section 5.1.2 of [2]. This may be "*",
800 an "absoluteURL" or an "abs_path" as specified in section 5.1.2 of
801 [2], but it MUST agree with the Request-URI. In particular, it MUST
802 be an "absoluteURL" if the Request-URI is an "absoluteURL". The
803 "cnonce-value" is an optional client-chosen value whose purpose is
804 to foil chosen plaintext attacks.
805
806 The authenticating server must assure that the resource designated by
807 the "uri" directive is the same as the resource specified in the
808 Request-Line; if they are not, the server SHOULD return a 400 Bad
809 Request error. (Since this may be a symptom of an attack, server
810 implementers may want to consider logging such errors.) The purpose
811 of duplicating information from the request URL in this field is to
812 deal with the possibility that an intermediate proxy may alter the
813 client's Request-Line. This altered (but presumably semantically
814 equivalent) request would not result in the same digest as that
815 calculated by the client.
816
817 Implementers should be aware of how authenticated transactions
818 interact with shared caches. The HTTP/1.1 protocol specifies that
819 when a shared cache (see section 13.7 of [2]) has received a request
820 containing an Authorization header and a response from relaying that
821 request, it MUST NOT return that response as a reply to any other
822 request, unless one of two Cache-Control (see section 14.9 of [2])
823 directives was present in the response. If the original response
824 included the "must-revalidate" Cache-Control directive, the cache MAY
825 use the entity of that response in replying to a subsequent request,
826 but MUST first revalidate it with the origin server, using the
827 request headers from the new request to allow the origin server to
828 authenticate the new request. Alternatively, if the original response
829 included the "public" Cache-Control directive, the response entity
830 MAY be returned in reply to any subsequent request.
831
832 3.2.3 The Authentication-Info Header
833
834 The Authentication-Info header is used by the server to communicate
835 some information regarding the successful authentication in the
836 response.
837
838
839
840
841
842 Franks, et al. Standards Track [Page 15]
843 \f
844 RFC 2617 HTTP Authentication June 1999
845
846
847 AuthenticationInfo = "Authentication-Info" ":" auth-info
848 auth-info = 1#(nextnonce | [ message-qop ]
849 | [ response-auth ] | [ cnonce ]
850 | [nonce-count] )
851 nextnonce = "nextnonce" "=" nonce-value
852 response-auth = "rspauth" "=" response-digest
853 response-digest = <"> *LHEX <">
854
855 The value of the nextnonce directive is the nonce the server wishes
856 the client to use for a future authentication response. The server
857 may send the Authentication-Info header with a nextnonce field as a
858 means of implementing one-time or otherwise changing nonces. If the
859 nextnonce field is present the client SHOULD use it when constructing
860 the Authorization header for its next request. Failure of the client
861 to do so may result in a request to re-authenticate from the server
862 with the "stale=TRUE".
863
864 Server implementations should carefully consider the performance
865 implications of the use of this mechanism; pipelined requests will
866 not be possible if every response includes a nextnonce directive
867 that must be used on the next request received by the server.
868 Consideration should be given to the performance vs. security
869 tradeoffs of allowing an old nonce value to be used for a limited
870 time to permit request pipelining. Use of the nonce-count can
871 retain most of the security advantages of a new server nonce
872 without the deleterious affects on pipelining.
873
874 message-qop
875 Indicates the "quality of protection" options applied to the
876 response by the server. The value "auth" indicates authentication;
877 the value "auth-int" indicates authentication with integrity
878 protection. The server SHOULD use the same value for the message-
879 qop directive in the response as was sent by the client in the
880 corresponding request.
881
882 The optional response digest in the "response-auth" directive
883 supports mutual authentication -- the server proves that it knows the
884 user's secret, and with qop=auth-int also provides limited integrity
885 protection of the response. The "response-digest" value is calculated
886 as for the "request-digest" in the Authorization header, except that
887 if "qop=auth" or is not specified in the Authorization header for the
888 request, A2 is
889
890 A2 = ":" digest-uri-value
891
892 and if "qop=auth-int", then A2 is
893
894 A2 = ":" digest-uri-value ":" H(entity-body)
895
896
897
898 Franks, et al. Standards Track [Page 16]
899 \f
900 RFC 2617 HTTP Authentication June 1999
901
902
903 where "digest-uri-value" is the value of the "uri" directive on the
904 Authorization header in the request. The "cnonce-value" and "nc-
905 value" MUST be the ones for the client request to which this message
906 is the response. The "response-auth", "cnonce", and "nonce-count"
907 directives MUST BE present if "qop=auth" or "qop=auth-int" is
908 specified.
909
910 The Authentication-Info header is allowed in the trailer of an HTTP
911 message transferred via chunked transfer-coding.
912
913 3.3 Digest Operation
914
915 Upon receiving the Authorization header, the server may check its
916 validity by looking up the password that corresponds to the submitted
917 username. Then, the server must perform the same digest operation
918 (e.g., MD5) performed by the client, and compare the result to the
919 given request-digest value.
920
921 Note that the HTTP server does not actually need to know the user's
922 cleartext password. As long as H(A1) is available to the server, the
923 validity of an Authorization header may be verified.
924
925 The client response to a WWW-Authenticate challenge for a protection
926 space starts an authentication session with that protection space.
927 The authentication session lasts until the client receives another
928 WWW-Authenticate challenge from any server in the protection space. A
929 client should remember the username, password, nonce, nonce count and
930 opaque values associated with an authentication session to use to
931 construct the Authorization header in future requests within that
932 protection space. The Authorization header may be included
933 preemptively; doing so improves server efficiency and avoids extra
934 round trips for authentication challenges. The server may choose to
935 accept the old Authorization header information, even though the
936 nonce value included might not be fresh. Alternatively, the server
937 may return a 401 response with a new nonce value, causing the client
938 to retry the request; by specifying stale=TRUE with this response,
939 the server tells the client to retry with the new nonce, but without
940 prompting for a new username and password.
941
942 Because the client is required to return the value of the opaque
943 directive given to it by the server for the duration of a session,
944 the opaque data may be used to transport authentication session state
945 information. (Note that any such use can also be accomplished more
946 easily and safely by including the state in the nonce.) For example,
947 a server could be responsible for authenticating content that
948 actually sits on another server. It would achieve this by having the
949 first 401 response include a domain directive whose value includes a
950 URI on the second server, and an opaque directive whose value
951
952
953
954 Franks, et al. Standards Track [Page 17]
955 \f
956 RFC 2617 HTTP Authentication June 1999
957
958
959 contains the state information. The client will retry the request, at
960 which time the server might respond with a 301/302 redirection,
961 pointing to the URI on the second server. The client will follow the
962 redirection, and pass an Authorization header , including the
963 <opaque> data.
964
965 As with the basic scheme, proxies must be completely transparent in
966 the Digest access authentication scheme. That is, they must forward
967 the WWW-Authenticate, Authentication-Info and Authorization headers
968 untouched. If a proxy wants to authenticate a client before a request
969 is forwarded to the server, it can be done using the Proxy-
970 Authenticate and Proxy-Authorization headers described in section 3.6
971 below.
972
973 3.4 Security Protocol Negotiation
974
975 It is useful for a server to be able to know which security schemes a
976 client is capable of handling.
977
978 It is possible that a server may want to require Digest as its
979 authentication method, even if the server does not know that the
980 client supports it. A client is encouraged to fail gracefully if the
981 server specifies only authentication schemes it cannot handle.
982
983 3.5 Example
984
985 The following example assumes that an access-protected document is
986 being requested from the server via a GET request. The URI of the
987 document is "http://www.nowhere.org/dir/index.html". Both client and
988 server know that the username for this document is "Mufasa", and the
989 password is "Circle Of Life" (with one space between each of the
990 three words).
991
992 The first time the client requests the document, no Authorization
993 header is sent, so the server responds with:
994
995 HTTP/1.1 401 Unauthorized
996 WWW-Authenticate: Digest
997 realm="testrealm@host.com",
998 qop="auth,auth-int",
999 nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
1000 opaque="5ccc069c403ebaf9f0171e9517f40e41"
1001
1002 The client may prompt the user for the username and password, after
1003 which it will respond with a new request, including the following
1004 Authorization header:
1005
1006
1007
1008
1009
1010 Franks, et al. Standards Track [Page 18]
1011 \f
1012 RFC 2617 HTTP Authentication June 1999
1013
1014
1015 Authorization: Digest username="Mufasa",
1016 realm="testrealm@host.com",
1017 nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
1018 uri="/dir/index.html",
1019 qop=auth,
1020 nc=00000001,
1021 cnonce="0a4f113b",
1022 response="6629fae49393a05397450978507c4ef1",
1023 opaque="5ccc069c403ebaf9f0171e9517f40e41"
1024
1025 3.6 Proxy-Authentication and Proxy-Authorization
1026
1027 The digest authentication scheme may also be used for authenticating
1028 users to proxies, proxies to proxies, or proxies to origin servers by
1029 use of the Proxy-Authenticate and Proxy-Authorization headers. These
1030 headers are instances of the Proxy-Authenticate and Proxy-
1031 Authorization headers specified in sections 10.33 and 10.34 of the
1032 HTTP/1.1 specification [2] and their behavior is subject to
1033 restrictions described there. The transactions for proxy
1034 authentication are very similar to those already described. Upon
1035 receiving a request which requires authentication, the proxy/server
1036 must issue the "407 Proxy Authentication Required" response with a
1037 "Proxy-Authenticate" header. The digest-challenge used in the
1038 Proxy-Authenticate header is the same as that for the WWW-
1039 Authenticate header as defined above in section 3.2.1.
1040
1041 The client/proxy must then re-issue the request with a Proxy-
1042 Authorization header, with directives as specified for the
1043 Authorization header in section 3.2.2 above.
1044
1045 On subsequent responses, the server sends Proxy-Authentication-Info
1046 with directives the same as those for the Authentication-Info header
1047 field.
1048
1049 Note that in principle a client could be asked to authenticate itself
1050 to both a proxy and an end-server, but never in the same response.
1051
1052 4 Security Considerations
1053
1054 4.1 Authentication of Clients using Basic Authentication
1055
1056 The Basic authentication scheme is not a secure method of user
1057 authentication, nor does it in any way protect the entity, which is
1058 transmitted in cleartext across the physical network used as the
1059 carrier. HTTP does not prevent additional authentication schemes and
1060 encryption mechanisms from being employed to increase security or the
1061 addition of enhancements (such as schemes to use one-time passwords)
1062 to Basic authentication.
1063
1064
1065
1066 Franks, et al. Standards Track [Page 19]
1067 \f
1068 RFC 2617 HTTP Authentication June 1999
1069
1070
1071 The most serious flaw in Basic authentication is that it results in
1072 the essentially cleartext transmission of the user's password over
1073 the physical network. It is this problem which Digest Authentication
1074 attempts to address.
1075
1076 Because Basic authentication involves the cleartext transmission of
1077 passwords it SHOULD NOT be used (without enhancements) to protect
1078 sensitive or valuable information.
1079
1080 A common use of Basic authentication is for identification purposes
1081 -- requiring the user to provide a user name and password as a means
1082 of identification, for example, for purposes of gathering accurate
1083 usage statistics on a server. When used in this way it is tempting to
1084 think that there is no danger in its use if illicit access to the
1085 protected documents is not a major concern. This is only correct if
1086 the server issues both user name and password to the users and in
1087 particular does not allow the user to choose his or her own password.
1088 The danger arises because naive users frequently reuse a single
1089 password to avoid the task of maintaining multiple passwords.
1090
1091 If a server permits users to select their own passwords, then the
1092 threat is not only unauthorized access to documents on the server but
1093 also unauthorized access to any other resources on other systems that
1094 the user protects with the same password. Furthermore, in the
1095 server's password database, many of the passwords may also be users'
1096 passwords for other sites. The owner or administrator of such a
1097 system could therefore expose all users of the system to the risk of
1098 unauthorized access to all those sites if this information is not
1099 maintained in a secure fashion.
1100
1101 Basic Authentication is also vulnerable to spoofing by counterfeit
1102 servers. If a user can be led to believe that he is connecting to a
1103 host containing information protected by Basic authentication when,
1104 in fact, he is connecting to a hostile server or gateway, then the
1105 attacker can request a password, store it for later use, and feign an
1106 error. This type of attack is not possible with Digest
1107 Authentication. Server implementers SHOULD guard against the
1108 possibility of this sort of counterfeiting by gateways or CGI
1109 scripts. In particular it is very dangerous for a server to simply
1110 turn over a connection to a gateway. That gateway can then use the
1111 persistent connection mechanism to engage in multiple transactions
1112 with the client while impersonating the original server in a way that
1113 is not detectable by the client.
1114
1115 4.2 Authentication of Clients using Digest Authentication
1116
1117 Digest Authentication does not provide a strong authentication
1118 mechanism, when compared to public key based mechanisms, for example.
1119
1120
1121
1122 Franks, et al. Standards Track [Page 20]
1123 \f
1124 RFC 2617 HTTP Authentication June 1999
1125
1126
1127 However, it is significantly stronger than (e.g.) CRAM-MD5, which has
1128 been proposed for use with LDAP [10], POP and IMAP (see RFC 2195
1129 [9]). It is intended to replace the much weaker and even more
1130 dangerous Basic mechanism.
1131
1132 Digest Authentication offers no confidentiality protection beyond
1133 protecting the actual password. All of the rest of the request and
1134 response are available to an eavesdropper.
1135
1136 Digest Authentication offers only limited integrity protection for
1137 the messages in either direction. If qop=auth-int mechanism is used,
1138 those parts of the message used in the calculation of the WWW-
1139 Authenticate and Authorization header field response directive values
1140 (see section 3.2 above) are protected. Most header fields and their
1141 values could be modified as a part of a man-in-the-middle attack.
1142
1143 Many needs for secure HTTP transactions cannot be met by Digest
1144 Authentication. For those needs TLS or SHTTP are more appropriate
1145 protocols. In particular Digest authentication cannot be used for any
1146 transaction requiring confidentiality protection. Nevertheless many
1147 functions remain for which Digest authentication is both useful and
1148 appropriate. Any service in present use that uses Basic should be
1149 switched to Digest as soon as practical.
1150
1151 4.3 Limited Use Nonce Values
1152
1153 The Digest scheme uses a server-specified nonce to seed the
1154 generation of the request-digest value (as specified in section
1155 3.2.2.1 above). As shown in the example nonce in section 3.2.1, the
1156 server is free to construct the nonce such that it may only be used
1157 from a particular client, for a particular resource, for a limited
1158 period of time or number of uses, or any other restrictions. Doing
1159 so strengthens the protection provided against, for example, replay
1160 attacks (see 4.5). However, it should be noted that the method
1161 chosen for generating and checking the nonce also has performance and
1162 resource implications. For example, a server may choose to allow
1163 each nonce value to be used only once by maintaining a record of
1164 whether or not each recently issued nonce has been returned and
1165 sending a next-nonce directive in the Authentication-Info header
1166 field of every response. This protects against even an immediate
1167 replay attack, but has a high cost checking nonce values, and perhaps
1168 more important will cause authentication failures for any pipelined
1169 requests (presumably returning a stale nonce indication). Similarly,
1170 incorporating a request-specific element such as the Etag value for a
1171 resource limits the use of the nonce to that version of the resource
1172 and also defeats pipelining. Thus it may be useful to do so for
1173 methods with side effects but have unacceptable performance for those
1174 that do not.
1175
1176
1177
1178 Franks, et al. Standards Track [Page 21]
1179 \f
1180 RFC 2617 HTTP Authentication June 1999
1181
1182
1183 4.4 Comparison of Digest with Basic Authentication
1184
1185 Both Digest and Basic Authentication are very much on the weak end of
1186 the security strength spectrum. But a comparison between the two
1187 points out the utility, even necessity, of replacing Basic by Digest.
1188
1189 The greatest threat to the type of transactions for which these
1190 protocols are used is network snooping. This kind of transaction
1191 might involve, for example, online access to a database whose use is
1192 restricted to paying subscribers. With Basic authentication an
1193 eavesdropper can obtain the password of the user. This not only
1194 permits him to access anything in the database, but, often worse,
1195 will permit access to anything else the user protects with the same
1196 password.
1197
1198 By contrast, with Digest Authentication the eavesdropper only gets
1199 access to the transaction in question and not to the user's password.
1200 The information gained by the eavesdropper would permit a replay
1201 attack, but only with a request for the same document, and even that
1202 may be limited by the server's choice of nonce.
1203
1204 4.5 Replay Attacks
1205
1206 A replay attack against Digest authentication would usually be
1207 pointless for a simple GET request since an eavesdropper would
1208 already have seen the only document he could obtain with a replay.
1209 This is because the URI of the requested document is digested in the
1210 client request and the server will only deliver that document. By
1211 contrast under Basic Authentication once the eavesdropper has the
1212 user's password, any document protected by that password is open to
1213 him.
1214
1215 Thus, for some purposes, it is necessary to protect against replay
1216 attacks. A good Digest implementation can do this in various ways.
1217 The server created "nonce" value is implementation dependent, but if
1218 it contains a digest of the client IP, a time-stamp, the resource
1219 ETag, and a private server key (as recommended above) then a replay
1220 attack is not simple. An attacker must convince the server that the
1221 request is coming from a false IP address and must cause the server
1222 to deliver the document to an IP address different from the address
1223 to which it believes it is sending the document. An attack can only
1224 succeed in the period before the time-stamp expires. Digesting the
1225 client IP and time-stamp in the nonce permits an implementation which
1226 does not maintain state between transactions.
1227
1228 For applications where no possibility of replay attack can be
1229 tolerated the server can use one-time nonce values which will not be
1230 honored for a second use. This requires the overhead of the server
1231
1232
1233
1234 Franks, et al. Standards Track [Page 22]
1235 \f
1236 RFC 2617 HTTP Authentication June 1999
1237
1238
1239 remembering which nonce values have been used until the nonce time-
1240 stamp (and hence the digest built with it) has expired, but it
1241 effectively protects against replay attacks.
1242
1243 An implementation must give special attention to the possibility of
1244 replay attacks with POST and PUT requests. Unless the server employs
1245 one-time or otherwise limited-use nonces and/or insists on the use of
1246 the integrity protection of qop=auth-int, an attacker could replay
1247 valid credentials from a successful request with counterfeit form
1248 data or other message body. Even with the use of integrity protection
1249 most metadata in header fields is not protected. Proper nonce
1250 generation and checking provides some protection against replay of
1251 previously used valid credentials, but see 4.8.
1252
1253 4.6 Weakness Created by Multiple Authentication Schemes
1254
1255 An HTTP/1.1 server may return multiple challenges with a 401
1256 (Authenticate) response, and each challenge may use a different
1257 auth-scheme. A user agent MUST choose to use the strongest auth-
1258 scheme it understands and request credentials from the user based
1259 upon that challenge.
1260
1261 Note that many browsers will only recognize Basic and will require
1262 that it be the first auth-scheme presented. Servers should only
1263 include Basic if it is minimally acceptable.
1264
1265 When the server offers choices of authentication schemes using the
1266 WWW-Authenticate header, the strength of the resulting authentication
1267 is only as good as that of the of the weakest of the authentication
1268 schemes. See section 4.8 below for discussion of particular attack
1269 scenarios that exploit multiple authentication schemes.
1270
1271 4.7 Online dictionary attacks
1272
1273 If the attacker can eavesdrop, then it can test any overheard
1274 nonce/response pairs against a list of common words. Such a list is
1275 usually much smaller than the total number of possible passwords. The
1276 cost of computing the response for each password on the list is paid
1277 once for each challenge.
1278
1279 The server can mitigate this attack by not allowing users to select
1280 passwords that are in a dictionary.
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290 Franks, et al. Standards Track [Page 23]
1291 \f
1292 RFC 2617 HTTP Authentication June 1999
1293
1294
1295 4.8 Man in the Middle
1296
1297 Both Basic and Digest authentication are vulnerable to "man in the
1298 middle" (MITM) attacks, for example, from a hostile or compromised
1299 proxy. Clearly, this would present all the problems of eavesdropping.
1300 But it also offers some additional opportunities to the attacker.
1301
1302 A possible man-in-the-middle attack would be to add a weak
1303 authentication scheme to the set of choices, hoping that the client
1304 will use one that exposes the user's credentials (e.g. password). For
1305 this reason, the client should always use the strongest scheme that
1306 it understands from the choices offered.
1307
1308 An even better MITM attack would be to remove all offered choices,
1309 replacing them with a challenge that requests only Basic
1310 authentication, then uses the cleartext credentials from the Basic
1311 authentication to authenticate to the origin server using the
1312 stronger scheme it requested. A particularly insidious way to mount
1313 such a MITM attack would be to offer a "free" proxy caching service
1314 to gullible users.
1315
1316 User agents should consider measures such as presenting a visual
1317 indication at the time of the credentials request of what
1318 authentication scheme is to be used, or remembering the strongest
1319 authentication scheme ever requested by a server and produce a
1320 warning message before using a weaker one. It might also be a good
1321 idea for the user agent to be configured to demand Digest
1322 authentication in general, or from specific sites.
1323
1324 Or, a hostile proxy might spoof the client into making a request the
1325 attacker wanted rather than one the client wanted. Of course, this is
1326 still much harder than a comparable attack against Basic
1327 Authentication.
1328
1329 4.9 Chosen plaintext attacks
1330
1331 With Digest authentication, a MITM or a malicious server can
1332 arbitrarily choose the nonce that the client will use to compute the
1333 response. This is called a "chosen plaintext" attack. The ability to
1334 choose the nonce is known to make cryptanalysis much easier [8].
1335
1336 However, no way to analyze the MD5 one-way function used by Digest
1337 using chosen plaintext is currently known.
1338
1339 The countermeasure against this attack is for clients to be
1340 configured to require the use of the optional "cnonce" directive;
1341 this allows the client to vary the input to the hash in a way not
1342 chosen by the attacker.
1343
1344
1345
1346 Franks, et al. Standards Track [Page 24]
1347 \f
1348 RFC 2617 HTTP Authentication June 1999
1349
1350
1351 4.10 Precomputed dictionary attacks
1352
1353 With Digest authentication, if the attacker can execute a chosen
1354 plaintext attack, the attacker can precompute the response for many
1355 common words to a nonce of its choice, and store a dictionary of
1356 (response, password) pairs. Such precomputation can often be done in
1357 parallel on many machines. It can then use the chosen plaintext
1358 attack to acquire a response corresponding to that challenge, and
1359 just look up the password in the dictionary. Even if most passwords
1360 are not in the dictionary, some might be. Since the attacker gets to
1361 pick the challenge, the cost of computing the response for each
1362 password on the list can be amortized over finding many passwords. A
1363 dictionary with 100 million password/response pairs would take about
1364 3.2 gigabytes of disk storage.
1365
1366 The countermeasure against this attack is to for clients to be
1367 configured to require the use of the optional "cnonce" directive.
1368
1369 4.11 Batch brute force attacks
1370
1371 With Digest authentication, a MITM can execute a chosen plaintext
1372 attack, and can gather responses from many users to the same nonce.
1373 It can then find all the passwords within any subset of password
1374 space that would generate one of the nonce/response pairs in a single
1375 pass over that space. It also reduces the time to find the first
1376 password by a factor equal to the number of nonce/response pairs
1377 gathered. This search of the password space can often be done in
1378 parallel on many machines, and even a single machine can search large
1379 subsets of the password space very quickly -- reports exist of
1380 searching all passwords with six or fewer letters in a few hours.
1381
1382 The countermeasure against this attack is to for clients to be
1383 configured to require the use of the optional "cnonce" directive.
1384
1385 4.12 Spoofing by Counterfeit Servers
1386
1387 Basic Authentication is vulnerable to spoofing by counterfeit
1388 servers. If a user can be led to believe that she is connecting to a
1389 host containing information protected by a password she knows, when
1390 in fact she is connecting to a hostile server, then the hostile
1391 server can request a password, store it away for later use, and feign
1392 an error. This type of attack is more difficult with Digest
1393 Authentication -- but the client must know to demand that Digest
1394 authentication be used, perhaps using some of the techniques
1395 described above to counter "man-in-the-middle" attacks. Again, the
1396 user can be helped in detecting this attack by a visual indication of
1397 the authentication mechanism in use with appropriate guidance in
1398 interpreting the implications of each scheme.
1399
1400
1401
1402 Franks, et al. Standards Track [Page 25]
1403 \f
1404 RFC 2617 HTTP Authentication June 1999
1405
1406
1407 4.13 Storing passwords
1408
1409 Digest authentication requires that the authenticating agent (usually
1410 the server) store some data derived from the user's name and password
1411 in a "password file" associated with a given realm. Normally this
1412 might contain pairs consisting of username and H(A1), where H(A1) is
1413 the digested value of the username, realm, and password as described
1414 above.
1415
1416 The security implications of this are that if this password file is
1417 compromised, then an attacker gains immediate access to documents on
1418 the server using this realm. Unlike, say a standard UNIX password
1419 file, this information need not be decrypted in order to access
1420 documents in the server realm associated with this file. On the other
1421 hand, decryption, or more likely a brute force attack, would be
1422 necessary to obtain the user's password. This is the reason that the
1423 realm is part of the digested data stored in the password file. It
1424 means that if one Digest authentication password file is compromised,
1425 it does not automatically compromise others with the same username
1426 and password (though it does expose them to brute force attack).
1427
1428 There are two important security consequences of this. First the
1429 password file must be protected as if it contained unencrypted
1430 passwords, because for the purpose of accessing documents in its
1431 realm, it effectively does.
1432
1433 A second consequence of this is that the realm string should be
1434 unique among all realms which any single user is likely to use. In
1435 particular a realm string should include the name of the host doing
1436 the authentication. The inability of the client to authenticate the
1437 server is a weakness of Digest Authentication.
1438
1439 4.14 Summary
1440
1441 By modern cryptographic standards Digest Authentication is weak. But
1442 for a large range of purposes it is valuable as a replacement for
1443 Basic Authentication. It remedies some, but not all, weaknesses of
1444 Basic Authentication. Its strength may vary depending on the
1445 implementation. In particular the structure of the nonce (which is
1446 dependent on the server implementation) may affect the ease of
1447 mounting a replay attack. A range of server options is appropriate
1448 since, for example, some implementations may be willing to accept the
1449 server overhead of one-time nonces or digests to eliminate the
1450 possibility of replay. Others may satisfied with a nonce like the one
1451 recommended above restricted to a single IP address and a single ETag
1452 or with a limited lifetime.
1453
1454
1455
1456
1457
1458 Franks, et al. Standards Track [Page 26]
1459 \f
1460 RFC 2617 HTTP Authentication June 1999
1461
1462
1463 The bottom line is that *any* compliant implementation will be
1464 relatively weak by cryptographic standards, but *any* compliant
1465 implementation will be far superior to Basic Authentication.
1466
1467 5 Sample implementation
1468
1469 The following code implements the calculations of H(A1), H(A2),
1470 request-digest and response-digest, and a test program which computes
1471 the values used in the example of section 3.5. It uses the MD5
1472 implementation from RFC 1321.
1473
1474 File "digcalc.h":
1475
1476 #define HASHLEN 16
1477 typedef char HASH[HASHLEN];
1478 #define HASHHEXLEN 32
1479 typedef char HASHHEX[HASHHEXLEN+1];
1480 #define IN
1481 #define OUT
1482
1483 /* calculate H(A1) as per HTTP Digest spec */
1484 void DigestCalcHA1(
1485 IN char * pszAlg,
1486 IN char * pszUserName,
1487 IN char * pszRealm,
1488 IN char * pszPassword,
1489 IN char * pszNonce,
1490 IN char * pszCNonce,
1491 OUT HASHHEX SessionKey
1492 );
1493
1494 /* calculate request-digest/response-digest as per HTTP Digest spec */
1495 void DigestCalcResponse(
1496 IN HASHHEX HA1, /* H(A1) */
1497 IN char * pszNonce, /* nonce from server */
1498 IN char * pszNonceCount, /* 8 hex digits */
1499 IN char * pszCNonce, /* client nonce */
1500 IN char * pszQop, /* qop-value: "", "auth", "auth-int" */
1501 IN char * pszMethod, /* method from the request */
1502 IN char * pszDigestUri, /* requested URL */
1503 IN HASHHEX HEntity, /* H(entity body) if qop="auth-int" */
1504 OUT HASHHEX Response /* request-digest or response-digest */
1505 );
1506
1507 File "digcalc.c":
1508
1509 #include <global.h>
1510 #include <md5.h>
1511
1512
1513
1514 Franks, et al. Standards Track [Page 27]
1515 \f
1516 RFC 2617 HTTP Authentication June 1999
1517
1518
1519 #include <string.h>
1520 #include "digcalc.h"
1521
1522 void CvtHex(
1523 IN HASH Bin,
1524 OUT HASHHEX Hex
1525 )
1526 {
1527 unsigned short i;
1528 unsigned char j;
1529
1530 for (i = 0; i < HASHLEN; i++) {
1531 j = (Bin[i] >> 4) & 0xf;
1532 if (j <= 9)
1533 Hex[i*2] = (j + '0');
1534 else
1535 Hex[i*2] = (j + 'a' - 10);
1536 j = Bin[i] & 0xf;
1537 if (j <= 9)
1538 Hex[i*2+1] = (j + '0');
1539 else
1540 Hex[i*2+1] = (j + 'a' - 10);
1541 };
1542 Hex[HASHHEXLEN] = '\0';
1543 };
1544
1545 /* calculate H(A1) as per spec */
1546 void DigestCalcHA1(
1547 IN char * pszAlg,
1548 IN char * pszUserName,
1549 IN char * pszRealm,
1550 IN char * pszPassword,
1551 IN char * pszNonce,
1552 IN char * pszCNonce,
1553 OUT HASHHEX SessionKey
1554 )
1555 {
1556 MD5_CTX Md5Ctx;
1557 HASH HA1;
1558
1559 MD5Init(&Md5Ctx);
1560 MD5Update(&Md5Ctx, pszUserName, strlen(pszUserName));
1561 MD5Update(&Md5Ctx, ":", 1);
1562 MD5Update(&Md5Ctx, pszRealm, strlen(pszRealm));
1563 MD5Update(&Md5Ctx, ":", 1);
1564 MD5Update(&Md5Ctx, pszPassword, strlen(pszPassword));
1565 MD5Final(HA1, &Md5Ctx);
1566 if (stricmp(pszAlg, "md5-sess") == 0) {
1567
1568
1569
1570 Franks, et al. Standards Track [Page 28]
1571 \f
1572 RFC 2617 HTTP Authentication June 1999
1573
1574
1575 MD5Init(&Md5Ctx);
1576 MD5Update(&Md5Ctx, HA1, HASHLEN);
1577 MD5Update(&Md5Ctx, ":", 1);
1578 MD5Update(&Md5Ctx, pszNonce, strlen(pszNonce));
1579 MD5Update(&Md5Ctx, ":", 1);
1580 MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
1581 MD5Final(HA1, &Md5Ctx);
1582 };
1583 CvtHex(HA1, SessionKey);
1584 };
1585
1586 /* calculate request-digest/response-digest as per HTTP Digest spec */
1587 void DigestCalcResponse(
1588 IN HASHHEX HA1, /* H(A1) */
1589 IN char * pszNonce, /* nonce from server */
1590 IN char * pszNonceCount, /* 8 hex digits */
1591 IN char * pszCNonce, /* client nonce */
1592 IN char * pszQop, /* qop-value: "", "auth", "auth-int" */
1593 IN char * pszMethod, /* method from the request */
1594 IN char * pszDigestUri, /* requested URL */
1595 IN HASHHEX HEntity, /* H(entity body) if qop="auth-int" */
1596 OUT HASHHEX Response /* request-digest or response-digest */
1597 )
1598 {
1599 MD5_CTX Md5Ctx;
1600 HASH HA2;
1601 HASH RespHash;
1602 HASHHEX HA2Hex;
1603
1604 // calculate H(A2)
1605 MD5Init(&Md5Ctx);
1606 MD5Update(&Md5Ctx, pszMethod, strlen(pszMethod));
1607 MD5Update(&Md5Ctx, ":", 1);
1608 MD5Update(&Md5Ctx, pszDigestUri, strlen(pszDigestUri));
1609 if (stricmp(pszQop, "auth-int") == 0) {
1610 MD5Update(&Md5Ctx, ":", 1);
1611 MD5Update(&Md5Ctx, HEntity, HASHHEXLEN);
1612 };
1613 MD5Final(HA2, &Md5Ctx);
1614 CvtHex(HA2, HA2Hex);
1615
1616 // calculate response
1617 MD5Init(&Md5Ctx);
1618 MD5Update(&Md5Ctx, HA1, HASHHEXLEN);
1619 MD5Update(&Md5Ctx, ":", 1);
1620 MD5Update(&Md5Ctx, pszNonce, strlen(pszNonce));
1621 MD5Update(&Md5Ctx, ":", 1);
1622 if (*pszQop) {
1623
1624
1625
1626 Franks, et al. Standards Track [Page 29]
1627 \f
1628 RFC 2617 HTTP Authentication June 1999
1629
1630
1631 MD5Update(&Md5Ctx, pszNonceCount, strlen(pszNonceCount));
1632 MD5Update(&Md5Ctx, ":", 1);
1633 MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
1634 MD5Update(&Md5Ctx, ":", 1);
1635 MD5Update(&Md5Ctx, pszQop, strlen(pszQop));
1636 MD5Update(&Md5Ctx, ":", 1);
1637 };
1638 MD5Update(&Md5Ctx, HA2Hex, HASHHEXLEN);
1639 MD5Final(RespHash, &Md5Ctx);
1640 CvtHex(RespHash, Response);
1641 };
1642
1643 File "digtest.c":
1644
1645
1646 #include <stdio.h>
1647 #include "digcalc.h"
1648
1649 void main(int argc, char ** argv) {
1650
1651 char * pszNonce = "dcd98b7102dd2f0e8b11d0f600bfb0c093";
1652 char * pszCNonce = "0a4f113b";
1653 char * pszUser = "Mufasa";
1654 char * pszRealm = "testrealm@host.com";
1655 char * pszPass = "Circle Of Life";
1656 char * pszAlg = "md5";
1657 char szNonceCount[9] = "00000001";
1658 char * pszMethod = "GET";
1659 char * pszQop = "auth";
1660 char * pszURI = "/dir/index.html";
1661 HASHHEX HA1;
1662 HASHHEX HA2 = "";
1663 HASHHEX Response;
1664
1665 DigestCalcHA1(pszAlg, pszUser, pszRealm, pszPass, pszNonce,
1666 pszCNonce, HA1);
1667 DigestCalcResponse(HA1, pszNonce, szNonceCount, pszCNonce, pszQop,
1668 pszMethod, pszURI, HA2, Response);
1669 printf("Response = %s\n", Response);
1670 };
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682 Franks, et al. Standards Track [Page 30]
1683 \f
1684 RFC 2617 HTTP Authentication June 1999
1685
1686
1687 6 Acknowledgments
1688
1689 Eric W. Sink, of AbiSource, Inc., was one of the original authors
1690 before the specification underwent substantial revision.
1691
1692 In addition to the authors, valuable discussion instrumental in
1693 creating this document has come from Peter J. Churchyard, Ned Freed,
1694 and David M. Kristol.
1695
1696 Jim Gettys and Larry Masinter edited this document for update.
1697
1698 7 References
1699
1700 [1] Berners-Lee, T., Fielding, R. and H. Frystyk, "Hypertext
1701 Transfer Protocol -- HTTP/1.0", RFC 1945, May 1996.
1702
1703 [2] Fielding, R., Gettys, J., Mogul, J., Frysyk, H., Masinter, L.,
1704 Leach, P. and T. Berners-Lee, "Hypertext Transfer Protocol --
1705 HTTP/1.1", RFC 2616, June 1999.
1706
1707 [3] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, April
1708 1992.
1709
1710 [4] Freed, N. and N. Borenstein. "Multipurpose Internet Mail
1711 Extensions (MIME) Part One: Format of Internet Message Bodies",
1712 RFC 2045, November 1996.
1713
1714 [5] Dierks, T. and C. Allen "The TLS Protocol, Version 1.0", RFC
1715 2246, January 1999.
1716
1717 [6] Franks, J., Hallam-Baker, P., Hostetler, J., Leach, P.,
1718 Luotonen, A., Sink, E. and L. Stewart, "An Extension to HTTP :
1719 Digest Access Authentication", RFC 2069, January 1997.
1720
1721 [7] Berners Lee, T, Fielding, R. and L. Masinter, "Uniform Resource
1722 Identifiers (URI): Generic Syntax", RFC 2396, August 1998.
1723
1724 [8] Kaliski, B.,Robshaw, M., "Message Authentication with MD5",
1725 CryptoBytes, Sping 1995, RSA Inc,
1726 (http://www.rsa.com/rsalabs/pubs/cryptobytes/spring95/md5.htm)
1727
1728 [9] Klensin, J., Catoe, R. and P. Krumviede, "IMAP/POP AUTHorize
1729 Extension for Simple Challenge/Response", RFC 2195, September
1730 1997.
1731
1732 [10] Morgan, B., Alvestrand, H., Hodges, J., Wahl, M.,
1733 "Authentication Methods for LDAP", Work in Progress.
1734
1735
1736
1737
1738 Franks, et al. Standards Track [Page 31]
1739 \f
1740 RFC 2617 HTTP Authentication June 1999
1741
1742
1743 8 Authors' Addresses
1744
1745 John Franks
1746 Professor of Mathematics
1747 Department of Mathematics
1748 Northwestern University
1749 Evanston, IL 60208-2730, USA
1750
1751 EMail: john@math.nwu.edu
1752
1753
1754 Phillip M. Hallam-Baker
1755 Principal Consultant
1756 Verisign Inc.
1757 301 Edgewater Place
1758 Suite 210
1759 Wakefield MA 01880, USA
1760
1761 EMail: pbaker@verisign.com
1762
1763
1764 Jeffery L. Hostetler
1765 Software Craftsman
1766 AbiSource, Inc.
1767 6 Dunlap Court
1768 Savoy, IL 61874
1769
1770 EMail: jeff@AbiSource.com
1771
1772
1773 Scott D. Lawrence
1774 Agranat Systems, Inc.
1775 5 Clocktower Place, Suite 400
1776 Maynard, MA 01754, USA
1777
1778 EMail: lawrence@agranat.com
1779
1780
1781 Paul J. Leach
1782 Microsoft Corporation
1783 1 Microsoft Way
1784 Redmond, WA 98052, USA
1785
1786 EMail: paulle@microsoft.com
1787
1788
1789
1790
1791
1792
1793
1794 Franks, et al. Standards Track [Page 32]
1795 \f
1796 RFC 2617 HTTP Authentication June 1999
1797
1798
1799 Ari Luotonen
1800 Member of Technical Staff
1801 Netscape Communications Corporation
1802 501 East Middlefield Road
1803 Mountain View, CA 94043, USA
1804
1805
1806 Lawrence C. Stewart
1807 Open Market, Inc.
1808 215 First Street
1809 Cambridge, MA 02142, USA
1810
1811 EMail: stewart@OpenMarket.com
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850 Franks, et al. Standards Track [Page 33]
1851 \f
1852 RFC 2617 HTTP Authentication June 1999
1853
1854
1855 9. Full Copyright Statement
1856
1857 Copyright (C) The Internet Society (1999). All Rights Reserved.
1858
1859 This document and translations of it may be copied and furnished to
1860 others, and derivative works that comment on or otherwise explain it
1861 or assist in its implementation may be prepared, copied, published
1862 and distributed, in whole or in part, without restriction of any
1863 kind, provided that the above copyright notice and this paragraph are
1864 included on all such copies and derivative works. However, this
1865 document itself may not be modified in any way, such as by removing
1866 the copyright notice or references to the Internet Society or other
1867 Internet organizations, except as needed for the purpose of
1868 developing Internet standards in which case the procedures for
1869 copyrights defined in the Internet Standards process must be
1870 followed, or as required to translate it into languages other than
1871 English.
1872
1873 The limited permissions granted above are perpetual and will not be
1874 revoked by the Internet Society or its successors or assigns.
1875
1876 This document and the information contained herein is provided on an
1877 "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
1878 TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
1879 BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
1880 HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
1881 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
1882
1883 Acknowledgement
1884
1885 Funding for the RFC Editor function is currently provided by the
1886 Internet Society.
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906 Franks, et al. Standards Track [Page 34]
1907 \f