2 [[ Text in double brackets is from the unofficial errata at ]]
3 [[ http://skrb.org/ietf/http_errata.html ]]
5 Network Working Group J. Franks
6 Request for Comments: 2617 Northwestern University
7 Obsoletes: 2069 P. Hallam-Baker
8 Category: Standards Track Verisign, Inc.
16 Netscape Communications Corporation
22 HTTP Authentication: Basic and Digest Access Authentication
26 This document specifies an Internet standards track protocol for the
27 Internet community, and requests discussion and suggestions for
28 improvements. Please refer to the current edition of the "Internet
29 Official Protocol Standards" (STD 1) for the standardization state
30 and status of this protocol. Distribution of this memo is unlimited.
34 Copyright (C) The Internet Society (1999). All Rights Reserved.
38 "HTTP/1.0", includes the specification for a Basic Access
39 Authentication scheme. This scheme is not considered to be a secure
40 method of user authentication (unless used in conjunction with some
41 external secure system such as SSL [5]), as the user name and
42 password are passed over the network as cleartext.
44 This document also provides the specification for HTTP's
45 authentication framework, the original Basic authentication scheme
46 and a scheme based on cryptographic hashes, referred to as "Digest
47 Access Authentication". It is therefore also intended to serve as a
48 replacement for RFC 2069 [6]. Some optional elements specified by
49 RFC 2069 have been removed from this specification due to problems
50 found since its publication; other new elements have been added for
51 compatibility, those new elements have been made optional, but are
56 Franks, et al. Standards Track [Page 1]
58 RFC 2617 HTTP Authentication June 1999
61 Like Basic, Digest access authentication verifies that both parties
62 to a communication know a shared secret (a password); unlike Basic,
63 this verification can be done without sending the password in the
64 clear, which is Basic's biggest weakness. As with most other
65 authentication protocols, the greatest sources of risks are usually
66 found not in the core protocol itself but in policies and procedures
71 1 Access Authentication................................ 3
72 1.1 Reliance on the HTTP/1.1 Specification............ 3
73 1.2 Access Authentication Framework................... 3
74 2 Basic Authentication Scheme.......................... 5
75 3 Digest Access Authentication Scheme.................. 6
76 3.1 Introduction...................................... 6
77 3.1.1 Purpose......................................... 6
78 3.1.2 Overall Operation............................... 6
79 3.1.3 Representation of digest values................. 7
80 3.1.4 Limitations..................................... 7
81 3.2 Specification of Digest Headers................... 7
82 3.2.1 The WWW-Authenticate Response Header............ 8
83 3.2.2 The Authorization Request Header................ 11
84 3.2.3 The Authentication-Info Header.................. 15
85 3.3 Digest Operation.................................. 17
86 3.4 Security Protocol Negotiation..................... 18
87 3.5 Example........................................... 18
88 3.6 Proxy-Authentication and Proxy-Authorization...... 19
89 4 Security Considerations.............................. 19
90 4.1 Authentication of Clients using Basic
91 Authentication.................................... 19
92 4.2 Authentication of Clients using Digest
93 Authentication.................................... 20
94 4.3 Limited Use Nonce Values.......................... 21
95 4.4 Comparison of Digest with Basic Authentication.... 22
96 4.5 Replay Attacks.................................... 22
97 4.6 Weakness Created by Multiple Authentication
98 Schemes........................................... 23
99 4.7 Online dictionary attacks......................... 23
100 4.8 Man in the Middle................................. 24
101 4.9 Chosen plaintext attacks.......................... 24
102 4.10 Precomputed dictionary attacks.................... 25
103 4.11 Batch brute force attacks......................... 25
104 4.12 Spoofing by Counterfeit Servers................... 25
105 4.13 Storing passwords................................. 26
106 4.14 Summary........................................... 26
107 5 Sample implementation................................ 27
108 6 Acknowledgments...................................... 31
112 Franks, et al. Standards Track [Page 2]
114 RFC 2617 HTTP Authentication June 1999
117 7 References........................................... 31
118 8 Authors' Addresses................................... 32
119 9 Full Copyright Statement............................. 34
121 1 Access Authentication
123 1.1 Reliance on the HTTP/1.1 Specification
125 This specification is a companion to the HTTP/1.1 specification [2].
126 It uses the augmented BNF section 2.1 of that document, and relies on
127 both the non-terminals defined in that document and other aspects of
128 the HTTP/1.1 specification.
130 1.2 Access Authentication Framework
132 HTTP provides a simple challenge-response authentication mechanism
133 that MAY be used by a server to challenge a client request and by a
134 client to provide authentication information. It uses an extensible,
135 case-insensitive token to identify the authentication scheme,
136 followed by a comma-separated list of attribute-value pairs which
137 carry the parameters necessary for achieving authentication via that
141 auth-param = token "=" ( token | quoted-string )
143 The 401 (Unauthorized) response message is used by an origin server
144 to challenge the authorization of a user agent. This response MUST
145 include a WWW-Authenticate header field containing at least one
146 challenge applicable to the requested resource. The 407 (Proxy
147 Authentication Required) response message is used by a proxy to
148 challenge the authorization of a client and MUST include a Proxy-
149 Authenticate header field containing at least one challenge
150 applicable to the proxy for the requested resource.
152 challenge = auth-scheme 1*SP 1#auth-param
154 Note: User agents will need to take special care in parsing the WWW-
155 Authenticate or Proxy-Authenticate header field value if it contains
156 more than one challenge, or if more than one WWW-Authenticate header
157 field is provided, since the contents of a challenge may itself
158 contain a comma-separated list of authentication parameters.
160 The authentication parameter realm is defined for all authentication
163 realm = "realm" "=" realm-value
164 realm-value = quoted-string
168 Franks, et al. Standards Track [Page 3]
170 RFC 2617 HTTP Authentication June 1999
173 The realm directive (case-insensitive) is required for all
174 authentication schemes that issue a challenge. The realm value
175 (case-sensitive), in combination with the canonical root URL (the
176 absoluteURI for the server whose abs_path is empty; see section 5.1.2
177 of [2]) of the server being accessed, defines the protection space.
178 These realms allow the protected resources on a server to be
179 partitioned into a set of protection spaces, each with its own
180 authentication scheme and/or authorization database. The realm value
181 is a string, generally assigned by the origin server, which may have
182 additional semantics specific to the authentication scheme. Note that
183 there may be multiple challenges with the same auth-scheme but
186 A user agent that wishes to authenticate itself with an origin
187 server--usually, but not necessarily, after receiving a 401
188 (Unauthorized)--MAY do so by including an Authorization header field
189 with the request. A client that wishes to authenticate itself with a
190 proxy--usually, but not necessarily, after receiving a 407 (Proxy
191 Authentication Required)--MAY do so by including a Proxy-
192 Authorization header field with the request. Both the Authorization
193 field value and the Proxy-Authorization field value consist of
194 credentials containing the authentication information of the client
195 for the realm of the resource being requested. The user agent MUST
196 choose to use one of the challenges with the strongest auth-scheme it
197 understands and request credentials from the user based upon that
200 credentials = auth-scheme #auth-param
202 Note that many browsers will only recognize Basic and will require
203 that it be the first auth-scheme presented. Servers should only
204 include Basic if it is minimally acceptable.
206 The protection space determines the domain over which credentials can
207 be automatically applied. If a prior request has been authorized, the
208 same credentials MAY be reused for all other requests within that
209 protection space for a period of time determined by the
210 authentication scheme, parameters, and/or user preference. Unless
211 otherwise defined by the authentication scheme, a single protection
212 space cannot extend outside the scope of its server.
214 If the origin server does not wish to accept the credentials sent
215 with a request, it SHOULD return a 401 (Unauthorized) response. The
216 response MUST include a WWW-Authenticate header field containing at
217 least one (possibly new) challenge applicable to the requested
218 resource. If a proxy does not accept the credentials sent with a
219 request, it SHOULD return a 407 (Proxy Authentication Required). The
220 response MUST include a Proxy-Authenticate header field containing a
224 Franks, et al. Standards Track [Page 4]
226 RFC 2617 HTTP Authentication June 1999
229 (possibly new) challenge applicable to the proxy for the requested
232 The HTTP protocol does not restrict applications to this simple
233 challenge-response mechanism for access authentication. Additional
234 mechanisms MAY be used, such as encryption at the transport level or
235 via message encapsulation, and with additional header fields
236 specifying authentication information. However, these additional
237 mechanisms are not defined by this specification.
239 Proxies MUST be completely transparent regarding user agent
240 authentication by origin servers. That is, they must forward the
241 WWW-Authenticate and Authorization headers untouched, and follow the
242 rules found in section 14.8 of [2]. Both the Proxy-Authenticate and
243 the Proxy-Authorization header fields are hop-by-hop headers (see
244 section 13.5.1 of [2]).
246 2 Basic Authentication Scheme
248 The "basic" authentication scheme is based on the model that the
249 client must authenticate itself with a user-ID and a password for
250 each realm. The realm value should be considered an opaque string
251 which can only be compared for equality with other realms on that
252 server. The server will service the request only if it can validate
253 the user-ID and password for the protection space of the Request-URI.
254 There are no optional authentication parameters.
256 For Basic, the framework above is utilized as follows:
258 challenge = "Basic" realm
259 credentials = "Basic" basic-credentials
261 Upon receipt of an unauthorized request for a URI within the
262 protection space, the origin server MAY respond with a challenge like
265 WWW-Authenticate: Basic realm="WallyWorld"
267 where "WallyWorld" is the string assigned by the server to identify
268 the protection space of the Request-URI. A proxy may respond with the
269 same challenge using the Proxy-Authenticate header field.
271 To receive authorization, the client sends the userid and password,
272 separated by a single colon (":") character, within a base64 [7]
273 encoded string in the credentials.
275 basic-credentials = base64-user-pass
276 base64-user-pass = <base64 [4] encoding of user-pass,
280 Franks, et al. Standards Track [Page 5]
282 RFC 2617 HTTP Authentication June 1999
285 except not limited to 76 char/line>
286 user-pass = userid ":" password
287 userid = *<TEXT excluding ":">
290 Userids might be case sensitive.
292 If the user agent wishes to send the userid "Aladdin" and password
293 "open sesame", it would use the following header field:
295 Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
297 A client SHOULD assume that all paths at or deeper than the depth of
298 the last symbolic element in the path field of the Request-URI also
299 are within the protection space specified by the Basic realm value of
300 the current challenge. A client MAY preemptively send the
301 corresponding Authorization header with requests for resources in
302 that space without receipt of another challenge from the server.
303 Similarly, when a client sends a request to a proxy, it may reuse a
304 userid and password in the Proxy-Authorization header field without
305 receiving another challenge from the proxy server. See section 4 for
306 security considerations associated with Basic authentication.
308 3 Digest Access Authentication Scheme
314 The protocol referred to as "HTTP/1.0" includes the specification for
315 a Basic Access Authentication scheme[1]. That scheme is not
316 considered to be a secure method of user authentication, as the user
317 name and password are passed over the network in an unencrypted form.
318 This section provides the specification for a scheme that does not
319 send the password in cleartext, referred to as "Digest Access
322 The Digest Access Authentication scheme is not intended to be a
323 complete answer to the need for security in the World Wide Web. This
324 scheme provides no encryption of message content. The intent is
325 simply to create an access authentication method that avoids the most
326 serious flaws of Basic authentication.
328 3.1.2 Overall Operation
330 Like Basic Access Authentication, the Digest scheme is based on a
331 simple challenge-response paradigm. The Digest scheme challenges
332 using a nonce value. A valid response contains a checksum (by
336 Franks, et al. Standards Track [Page 6]
338 RFC 2617 HTTP Authentication June 1999
341 default, the MD5 checksum) of the username, the password, the given
342 nonce value, the HTTP method, and the requested URI. In this way, the
343 password is never sent in the clear. Just as with the Basic scheme,
344 the username and password must be prearranged in some fashion not
345 addressed by this document.
347 3.1.3 Representation of digest values
349 An optional header allows the server to specify the algorithm used to
350 create the checksum or digest. By default the MD5 algorithm is used
351 and that is the only algorithm described in this document.
353 For the purposes of this document, an MD5 digest of 128 bits is
354 represented as 32 ASCII printable characters. The bits in the 128 bit
355 digest are converted from most significant to least significant bit,
356 four bits at a time to their ASCII presentation as follows. Each four
357 bits is represented by its familiar hexadecimal notation from the
358 characters 0123456789abcdef. That is, binary 0000 gets represented by
359 the character '0', 0001, by '1', and so on up to the representation
364 The Digest authentication scheme described in this document suffers
365 from many known limitations. It is intended as a replacement for
366 Basic authentication and nothing more. It is a password-based system
367 and (on the server side) suffers from all the same problems of any
368 password system. In particular, no provision is made in this protocol
369 for the initial secure arrangement between user and server to
370 establish the user's password.
372 Users and implementors should be aware that this protocol is not as
373 secure as Kerberos, and not as secure as any client-side private-key
374 scheme. Nevertheless it is better than nothing, better than what is
375 commonly used with telnet and ftp, and better than Basic
378 3.2 Specification of Digest Headers
380 The Digest Access Authentication scheme is conceptually similar to
381 the Basic scheme. The formats of the modified WWW-Authenticate header
382 line and the Authorization header line are specified below. In
383 addition, a new header, Authentication-Info, is specified.
392 Franks, et al. Standards Track [Page 7]
394 RFC 2617 HTTP Authentication June 1999
397 3.2.1 The WWW-Authenticate Response Header
399 If a server receives a request for an access-protected object, and an
400 acceptable Authorization header is not sent, the server responds with
401 a "401 Unauthorized" status code, and a WWW-Authenticate header as
402 per the framework defined above, which for the digest scheme is
405 challenge = "Digest" digest-challenge
407 digest-challenge = 1#( realm | [ domain ] | nonce |
408 [ opaque ] |[ stale ] | [ algorithm ] |
409 [ qop-options ] | [auth-param] )
412 domain = "domain" "=" <"> URI ( 1*SP URI ) <">
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" |
422 qop-options = "qop" "=" <"> 1#qop-value <">
423 qop-value = "auth" | "auth-int" | token
425 The meanings of the values of the directives used above are as
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".
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.
450 Franks, et al. Standards Track [Page 8]
452 RFC 2617 HTTP Authentication June 1999
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.
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.
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
470 time-stamp H(time-stamp ":" ETag ":" private-key)
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.)
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.
495 The nonce is opaque to the client.
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.
506 Franks, et al. Standards Track [Page 9]
508 RFC 2617 HTTP Authentication June 1999
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.
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).
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
536 For the "MD5" and "MD5-sess" algorithms
542 KD(secret, data) = H(concat(secret, ":", data))
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.
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
562 Franks, et al. Standards Track [Page 10]
564 RFC 2617 HTTP Authentication June 1999
567 descriptions below for calculating the response directive value for
568 the application of this choice. Unrecognized options MUST be
572 This directive allows for future extensions. Any unrecognized
573 directive MUST be ignored.
575 3.2.2 The Authorization Request Header
577 The client is expected to retry the request, passing an Authorization
578 header line, which is defined according to the framework above,
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] )
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
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"
603 The values of the opaque and algorithm fields must be those supplied
604 in the WWW-Authenticate response header for the entity being
608 A string of 32 hex digits computed as defined below, which proves
609 that the user knows a password
612 The user's name in the specified realm.
618 Franks, et al. Standards Track [Page 11]
620 RFC 2617 HTTP Authentication June 1999
624 The URI from Request-URI of the Request-Line; duplicated here
625 because proxies are allowed to change the Request-Line in transit.
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
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.
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.
663 This directive allows for future extensions. Any unrecognized
664 directive MUST be ignored.
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.
674 Franks, et al. Standards Track [Page 12]
676 RFC 2617 HTTP Authentication June 1999
679 The definition of request-digest above indicates the encoding for its
680 value. The following definitions show how the value is computed.
682 3.2.2.1 Request-Digest
684 If the "qop" value is "auth" or "auth-int":
686 request-digest = <"> < KD ( H(A1), unq(nonce-value)
688 ":" unq(cnonce-value)
693 If the "qop" directive is not present (this construction is for
694 compatibility with RFC 2069):
697 <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) >
700 See below for the definitions for A1 and A2.
704 If the "algorithm" directive's value is "MD5" or is unspecified, then
707 A1 = unq(username-value) ":" unq(realm-value) ":" passwd
711 passwd = < user's password >
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:
719 A1 = H( unq(username-value) ":" unq(realm-value)
721 ":" unq(nonce-value) ":" unq(cnonce-value)
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
730 Franks, et al. Standards Track [Page 13]
732 RFC 2617 HTTP Authentication June 1999
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
744 If the "qop" directive's value is "auth" or is unspecified, then A2
747 A2 = Method ":" digest-uri-value
749 If the "qop" value is "auth-int", then A2 is:
751 A2 = Method ":" digest-uri-value ":" H(entity-body)
753 3.2.2.4 Directive values and quoted-string
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
760 username="Mufasa", realm=myhost@testrealm.com
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.
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
771 Mufasa:myhost@testrealm.com:Circle Of Life
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.
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
786 Franks, et al. Standards Track [Page 14]
788 RFC 2617 HTTP Authentication June 1999
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.
795 3.2.2.5 Various considerations
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.
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.
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.
832 3.2.3 The Authentication-Info Header
834 The Authentication-Info header is used by the server to communicate
835 some information regarding the successful authentication in the
842 Franks, et al. Standards Track [Page 15]
844 RFC 2617 HTTP Authentication June 1999
847 AuthenticationInfo = "Authentication-Info" ":" auth-info
848 auth-info = 1#(nextnonce | [ message-qop ]
849 | [ response-auth ] | [ cnonce ]
851 nextnonce = "nextnonce" "=" nonce-value
852 response-auth = "rspauth" "=" response-digest
853 response-digest = <"> *LHEX <">
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".
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.
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.
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
890 A2 = ":" digest-uri-value
892 and if "qop=auth-int", then A2 is
894 A2 = ":" digest-uri-value ":" H(entity-body)
898 Franks, et al. Standards Track [Page 16]
900 RFC 2617 HTTP Authentication June 1999
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
910 The Authentication-Info header is allowed in the trailer of an HTTP
911 message transferred via chunked transfer-coding.
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.
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.
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.
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
954 Franks, et al. Standards Track [Page 17]
956 RFC 2617 HTTP Authentication June 1999
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
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
973 3.4 Security Protocol Negotiation
975 It is useful for a server to be able to know which security schemes a
976 client is capable of handling.
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.
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
992 The first time the client requests the document, no Authorization
993 header is sent, so the server responds with:
995 HTTP/1.1 401 Unauthorized
996 WWW-Authenticate: Digest
997 realm="testrealm@host.com",
999 nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
1000 opaque="5ccc069c403ebaf9f0171e9517f40e41"
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:
1010 Franks, et al. Standards Track [Page 18]
1012 RFC 2617 HTTP Authentication June 1999
1015 Authorization: Digest username="Mufasa",
1016 realm="testrealm@host.com",
1017 nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
1018 uri="/dir/index.html",
1022 response="6629fae49393a05397450978507c4ef1",
1023 opaque="5ccc069c403ebaf9f0171e9517f40e41"
1025 3.6 Proxy-Authentication and Proxy-Authorization
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.
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.
1045 On subsequent responses, the server sends Proxy-Authentication-Info
1046 with directives the same as those for the Authentication-Info header
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.
1052 4 Security Considerations
1054 4.1 Authentication of Clients using Basic Authentication
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.
1066 Franks, et al. Standards Track [Page 19]
1068 RFC 2617 HTTP Authentication June 1999
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.
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.
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.
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.
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.
1115 4.2 Authentication of Clients using Digest Authentication
1117 Digest Authentication does not provide a strong authentication
1118 mechanism, when compared to public key based mechanisms, for example.
1122 Franks, et al. Standards Track [Page 20]
1124 RFC 2617 HTTP Authentication June 1999
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.
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.
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.
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.
1151 4.3 Limited Use Nonce Values
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
1178 Franks, et al. Standards Track [Page 21]
1180 RFC 2617 HTTP Authentication June 1999
1183 4.4 Comparison of Digest with Basic Authentication
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.
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
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.
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
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.
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
1234 Franks, et al. Standards Track [Page 22]
1236 RFC 2617 HTTP Authentication June 1999
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.
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.
1253 4.6 Weakness Created by Multiple Authentication Schemes
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.
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.
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.
1271 4.7 Online dictionary attacks
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.
1279 The server can mitigate this attack by not allowing users to select
1280 passwords that are in a dictionary.
1290 Franks, et al. Standards Track [Page 23]
1292 RFC 2617 HTTP Authentication June 1999
1295 4.8 Man in the Middle
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.
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.
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
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.
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
1329 4.9 Chosen plaintext attacks
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].
1336 However, no way to analyze the MD5 one-way function used by Digest
1337 using chosen plaintext is currently known.
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.
1346 Franks, et al. Standards Track [Page 24]
1348 RFC 2617 HTTP Authentication June 1999
1351 4.10 Precomputed dictionary attacks
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.
1366 The countermeasure against this attack is to for clients to be
1367 configured to require the use of the optional "cnonce" directive.
1369 4.11 Batch brute force attacks
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.
1382 The countermeasure against this attack is to for clients to be
1383 configured to require the use of the optional "cnonce" directive.
1385 4.12 Spoofing by Counterfeit Servers
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.
1402 Franks, et al. Standards Track [Page 25]
1404 RFC 2617 HTTP Authentication June 1999
1407 4.13 Storing passwords
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
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).
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.
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.
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.
1458 Franks, et al. Standards Track [Page 26]
1460 RFC 2617 HTTP Authentication June 1999
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.
1467 5 Sample implementation
1469 [[ WARNING: DigestCalcHA1 IS WRONG ]]
1471 The following code implements the calculations of H(A1), H(A2),
1472 request-digest and response-digest, and a test program which computes
1473 the values used in the example of section 3.5. It uses the MD5
1474 implementation from RFC 1321.
1479 typedef char HASH[HASHLEN];
1480 #define HASHHEXLEN 32
1481 typedef char HASHHEX[HASHHEXLEN+1];
1485 /* calculate H(A1) as per HTTP Digest spec */
1488 IN char * pszUserName,
1490 IN char * pszPassword,
1492 IN char * pszCNonce,
1493 OUT HASHHEX SessionKey
1496 /* calculate request-digest/response-digest as per HTTP Digest spec */
1497 void DigestCalcResponse(
1498 IN HASHHEX HA1, /* H(A1) */
1499 IN char * pszNonce, /* nonce from server */
1500 IN char * pszNonceCount, /* 8 hex digits */
1501 IN char * pszCNonce, /* client nonce */
1502 IN char * pszQop, /* qop-value: "", "auth", "auth-int" */
1503 IN char * pszMethod, /* method from the request */
1504 IN char * pszDigestUri, /* requested URL */
1505 IN HASHHEX HEntity, /* H(entity body) if qop="auth-int" */
1506 OUT HASHHEX Response /* request-digest or response-digest */
1516 Franks, et al. Standards Track [Page 27]
1518 RFC 2617 HTTP Authentication June 1999
1522 #include "digcalc.h"
1532 for (i = 0; i < HASHLEN; i++) {
1533 j = (Bin[i] >> 4) & 0xf;
1535 Hex[i*2] = (j + '0');
1537 Hex[i*2] = (j + 'a' - 10);
1540 Hex[i*2+1] = (j + '0');
1542 Hex[i*2+1] = (j + 'a' - 10);
1544 Hex[HASHHEXLEN] = '\0';
1547 /* calculate H(A1) as per spec */
1550 IN char * pszUserName,
1552 IN char * pszPassword,
1554 IN char * pszCNonce,
1555 OUT HASHHEX SessionKey
1562 MD5Update(&Md5Ctx, pszUserName, strlen(pszUserName));
1563 MD5Update(&Md5Ctx, ":", 1);
1564 MD5Update(&Md5Ctx, pszRealm, strlen(pszRealm));
1565 MD5Update(&Md5Ctx, ":", 1);
1566 MD5Update(&Md5Ctx, pszPassword, strlen(pszPassword));
1567 MD5Final(HA1, &Md5Ctx);
1568 if (stricmp(pszAlg, "md5-sess") == 0) {
1572 Franks, et al. Standards Track [Page 28]
1574 RFC 2617 HTTP Authentication June 1999
1578 MD5Update(&Md5Ctx, HA1, HASHLEN);
1579 MD5Update(&Md5Ctx, ":", 1);
1580 MD5Update(&Md5Ctx, pszNonce, strlen(pszNonce));
1581 MD5Update(&Md5Ctx, ":", 1);
1582 MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
1583 MD5Final(HA1, &Md5Ctx);
1585 CvtHex(HA1, SessionKey);
1588 /* calculate request-digest/response-digest as per HTTP Digest spec */
1589 void DigestCalcResponse(
1590 IN HASHHEX HA1, /* H(A1) */
1591 IN char * pszNonce, /* nonce from server */
1592 IN char * pszNonceCount, /* 8 hex digits */
1593 IN char * pszCNonce, /* client nonce */
1594 IN char * pszQop, /* qop-value: "", "auth", "auth-int" */
1595 IN char * pszMethod, /* method from the request */
1596 IN char * pszDigestUri, /* requested URL */
1597 IN HASHHEX HEntity, /* H(entity body) if qop="auth-int" */
1598 OUT HASHHEX Response /* request-digest or response-digest */
1608 MD5Update(&Md5Ctx, pszMethod, strlen(pszMethod));
1609 MD5Update(&Md5Ctx, ":", 1);
1610 MD5Update(&Md5Ctx, pszDigestUri, strlen(pszDigestUri));
1611 if (stricmp(pszQop, "auth-int") == 0) {
1612 MD5Update(&Md5Ctx, ":", 1);
1613 MD5Update(&Md5Ctx, HEntity, HASHHEXLEN);
1615 MD5Final(HA2, &Md5Ctx);
1616 CvtHex(HA2, HA2Hex);
1618 // calculate response
1620 MD5Update(&Md5Ctx, HA1, HASHHEXLEN);
1621 MD5Update(&Md5Ctx, ":", 1);
1622 MD5Update(&Md5Ctx, pszNonce, strlen(pszNonce));
1623 MD5Update(&Md5Ctx, ":", 1);
1628 Franks, et al. Standards Track [Page 29]
1630 RFC 2617 HTTP Authentication June 1999
1633 MD5Update(&Md5Ctx, pszNonceCount, strlen(pszNonceCount));
1634 MD5Update(&Md5Ctx, ":", 1);
1635 MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
1636 MD5Update(&Md5Ctx, ":", 1);
1637 MD5Update(&Md5Ctx, pszQop, strlen(pszQop));
1638 MD5Update(&Md5Ctx, ":", 1);
1640 MD5Update(&Md5Ctx, HA2Hex, HASHHEXLEN);
1641 MD5Final(RespHash, &Md5Ctx);
1642 CvtHex(RespHash, Response);
1649 #include "digcalc.h"
1651 void main(int argc, char ** argv) {
1653 char * pszNonce = "dcd98b7102dd2f0e8b11d0f600bfb0c093";
1654 char * pszCNonce = "0a4f113b";
1655 char * pszUser = "Mufasa";
1656 char * pszRealm = "testrealm@host.com";
1657 char * pszPass = "Circle Of Life";
1658 char * pszAlg = "md5";
1659 char szNonceCount[9] = "00000001";
1660 char * pszMethod = "GET";
1661 char * pszQop = "auth";
1662 char * pszURI = "/dir/index.html";
1667 DigestCalcHA1(pszAlg, pszUser, pszRealm, pszPass, pszNonce,
1669 DigestCalcResponse(HA1, pszNonce, szNonceCount, pszCNonce, pszQop,
1670 pszMethod, pszURI, HA2, Response);
1671 printf("Response = %s\n", Response);
1684 Franks, et al. Standards Track [Page 30]
1686 RFC 2617 HTTP Authentication June 1999
1691 Eric W. Sink, of AbiSource, Inc., was one of the original authors
1692 before the specification underwent substantial revision.
1694 In addition to the authors, valuable discussion instrumental in
1695 creating this document has come from Peter J. Churchyard, Ned Freed,
1696 and David M. Kristol.
1698 Jim Gettys and Larry Masinter edited this document for update.
1702 [1] Berners-Lee, T., Fielding, R. and H. Frystyk, "Hypertext
1703 Transfer Protocol -- HTTP/1.0", RFC 1945, May 1996.
1705 [2] Fielding, R., Gettys, J., Mogul, J., Frysyk, H., Masinter, L.,
1706 Leach, P. and T. Berners-Lee, "Hypertext Transfer Protocol --
1707 HTTP/1.1", RFC 2616, June 1999.
1709 [3] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, April
1712 [4] Freed, N. and N. Borenstein. "Multipurpose Internet Mail
1713 Extensions (MIME) Part One: Format of Internet Message Bodies",
1714 RFC 2045, November 1996.
1716 [5] Dierks, T. and C. Allen "The TLS Protocol, Version 1.0", RFC
1719 [6] Franks, J., Hallam-Baker, P., Hostetler, J., Leach, P.,
1720 Luotonen, A., Sink, E. and L. Stewart, "An Extension to HTTP :
1721 Digest Access Authentication", RFC 2069, January 1997.
1723 [7] Berners Lee, T, Fielding, R. and L. Masinter, "Uniform Resource
1724 Identifiers (URI): Generic Syntax", RFC 2396, August 1998.
1726 [8] Kaliski, B.,Robshaw, M., "Message Authentication with MD5",
1727 CryptoBytes, Sping 1995, RSA Inc,
1728 (http://www.rsa.com/rsalabs/pubs/cryptobytes/spring95/md5.htm)
1730 [9] Klensin, J., Catoe, R. and P. Krumviede, "IMAP/POP AUTHorize
1731 Extension for Simple Challenge/Response", RFC 2195, September
1734 [10] Morgan, B., Alvestrand, H., Hodges, J., Wahl, M.,
1735 "Authentication Methods for LDAP", Work in Progress.
1740 Franks, et al. Standards Track [Page 31]
1742 RFC 2617 HTTP Authentication June 1999
1745 8 Authors' Addresses
1748 Professor of Mathematics
1749 Department of Mathematics
1750 Northwestern University
1751 Evanston, IL 60208-2730, USA
1753 EMail: john@math.nwu.edu
1756 Phillip M. Hallam-Baker
1757 Principal Consultant
1761 Wakefield MA 01880, USA
1763 EMail: pbaker@verisign.com
1766 Jeffery L. Hostetler
1772 EMail: jeff@AbiSource.com
1776 Agranat Systems, Inc.
1777 5 Clocktower Place, Suite 400
1778 Maynard, MA 01754, USA
1780 EMail: lawrence@agranat.com
1784 Microsoft Corporation
1786 Redmond, WA 98052, USA
1788 EMail: paulle@microsoft.com
1796 Franks, et al. Standards Track [Page 32]
1798 RFC 2617 HTTP Authentication June 1999
1802 Member of Technical Staff
1803 Netscape Communications Corporation
1804 501 East Middlefield Road
1805 Mountain View, CA 94043, USA
1811 Cambridge, MA 02142, USA
1813 EMail: stewart@OpenMarket.com
1852 Franks, et al. Standards Track [Page 33]
1854 RFC 2617 HTTP Authentication June 1999
1857 9. Full Copyright Statement
1859 Copyright (C) The Internet Society (1999). All Rights Reserved.
1861 This document and translations of it may be copied and furnished to
1862 others, and derivative works that comment on or otherwise explain it
1863 or assist in its implementation may be prepared, copied, published
1864 and distributed, in whole or in part, without restriction of any
1865 kind, provided that the above copyright notice and this paragraph are
1866 included on all such copies and derivative works. However, this
1867 document itself may not be modified in any way, such as by removing
1868 the copyright notice or references to the Internet Society or other
1869 Internet organizations, except as needed for the purpose of
1870 developing Internet standards in which case the procedures for
1871 copyrights defined in the Internet Standards process must be
1872 followed, or as required to translate it into languages other than
1875 The limited permissions granted above are perpetual and will not be
1876 revoked by the Internet Society or its successors or assigns.
1878 This document and the information contained herein is provided on an
1879 "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
1880 TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
1881 BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
1882 HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
1883 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
1887 Funding for the RFC Editor function is currently provided by the
1908 Franks, et al. Standards Track [Page 34]