4 Digest Authentication as a SASL Mechanism September 1998
7 Network Working Group Paul J. Leach, Microsoft
8 INTERNET-DRAFT Chris Newman, Innosoft
9 draft-leach-digest-sasl-02.txt
10 Category: Standards Track
11 Expires August 26, 1999 February 26, 1999
15 Using Digest Authentication as a SASL Mechanism
26 This document is an Internet-Draft and is in full conformance with all
27 provisions of Section 10 of RFC2026.
29 THIS IS A PRELIMINARY DRAFT OF AN INTERNET-DRAFT. IT DOES NOT REPRESENT
30 THE CONSENSUS OF ANY WORKING GROUP.
32 Internet-Drafts are working documents of the Internet Engineering Task
33 Force (IETF), its areas, and its working groups. Note that other groups
34 may also distribute working documents as Internet-Drafts.
36 Internet-Drafts are draft documents valid for a maximum of six months
37 and may be updated, replaced, or obsoleted by other documents at any
38 time. It is inappropriate to use Internet- Drafts as reference material
39 or to cite them other than as "work in progress."
41 The list of current Internet-Drafts can be accessed at
42 http://www.ietf.org/ietf/1id-abstracts.txt
44 The list of Internet-Draft Shadow Directories can be accessed at
45 http://www.ietf.org/shadow.html.
47 Distribution of this document is unlimited. Please send comments to the
48 authors or the SASL mailing list, ietf-sasl@imc.org.
50 Copyright Notice: Copyright (C) The Internet Society (1998). All Rights
51 Reserved. See section 8 for the full copyright notice.
56 This specification defines how HTTP Digest Authentication [Digest] can
57 be used as a SASL [RFC 2222] mechanism for any protocol that has a SASL
58 profile. It is intended both as an improvement over CRAM-MD5 [RFC2195]
59 and as a convenient way to support a single authentication mechanism for
60 web, mail, LDAP, and other protocols.
62 Leach, Newman Standards Track [Page 1]
\f
66 Digest Authentication as a SASL Mechanism September 1998
72 1 INTRODUCTION........................................................2
74 1.1 CONVENTIONS AND NOTATION.........................................2
76 1.2 REQUIREMENTS.....................................................2
79 2 AUTHENTICATION......................................................3
81 2.1 INITIAL AUTHENTICATION...........................................3
83 2.1.1Step One......................................................3
85 2.1.2Step Two......................................................5
87 2.1.3Step Three....................................................9
89 2.2 SUBSEQUENT AUTHENTICATION........................................9
91 2.2.1Step one......................................................9
93 2.2.2Step Two......................................................9
95 2.3 INTEGRITY PROTECTION............................................10
98 3 SECURITY CONSIDERATIONS............................................12
100 3.1 AUTHENTICATION OF CLIENTS USING DIGEST AUTHENTICATION...........12
102 3.2 COMPARISON OF DIGEST WITH PLAINTEXT PASSWORDS...................12
104 3.3 REPLAY ATTACKS..................................................12
106 3.4 ONLINE DICTIONARY ATTACKS.......................................12
108 3.5 OFFLINE DICTIONARY ATTACKS......................................13
110 3.6 MAN IN THE MIDDLE...............................................13
112 3.7 CHOSEN PLAINTEXT ATTACKS........................................13
114 3.8 SPOOFING BY COUNTERFEIT SERVERS.................................13
116 3.9 STORING PASSWORDS...............................................13
118 3.10SUMMARY.........................................................14
121 4 EXAMPLE............................................................14
123 5 REFERENCES.........................................................15
125 6 AUTHORS' ADDRESSES.................................................16
128 Leach, Newman Standards Track [Page 2]
\f
132 Digest Authentication as a SASL Mechanism September 1998
135 7 ABNF...............................................................16
137 7.1 AUGMENTED BNF...................................................16
139 7.2 BASIC RULES.....................................................18
142 8 SAMPLE CODE........................................................19
144 9 FULL COPYRIGHT STATEMENT...........................................20
151 This specification describes the use of HTTP Digest Access
152 Authentication as a SASL mechanism. The authentication type associated
153 with the Digest SASL mechanism is "DIGEST-MD5".
155 This specification is intended to be upward compatible with the "md5-
156 sess" algorithm of HTTP/1.1 Digest Access Authentication specified in
157 [Digest]. The only difference in the "md5-sess" algorithm is that some
158 directives not needed in a SASL mechanism have had their values
161 There is one new feature for use as a SASL mechanism: integrity
162 protection on application protocol messages after an authentication
165 Also, compared to CRAM-MD5, DIGEST-MD5 prevents chosen plaintext
166 attacks, and permits the use of third party authentication servers,
167 mutual authentication, and optimized reauthentication if a client has
168 recently authenticated to a server.
171 1.1 Conventions and Notation
173 This specification uses the same ABNF notation and lexical conventions
174 as HTTP/1.1 specification; see appendix A.
176 Let { a, b, ... } be the concatenation of the strings a, b, à
178 Let H(s) be the 16 octet MD5 hash of the string s.
180 Let KD(k, s) be the 16 octet MD5 hash of the concatenation of the string
181 k, ":" (a 1 character long string consisting of a colon), and the string
184 Let HEX(n) be the representation of the 16 octet MD5 hash n as a string
185 of 32 hex digits (with alphabetic characters always in lower case),
186 since MD5 is case sensitive.
193 Leach, Newman Standards Track [Page 3]
\f
197 Digest Authentication as a SASL Mechanism September 1998
203 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
204 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
205 document are to be interpreted as described in RFC 2119 [RFC 2119].
207 An implementation is not compliant if it fails to satisfy one or more of
208 the MUST level requirements for the protocols it implements. An
209 implementation that satisfies all the MUST level and all the SHOULD
210 level requirements for its protocols is said to be "unconditionally
211 compliant"; one that satisfies all the MUST level requirements but not
212 all the SHOULD level requirements for its protocols is said to be
213 "conditionally compliant."
218 The following sections describe how to use Digest as a SASL
219 authentication mechanism.
222 2.1 Initial Authentication
224 If the client has not recently authenticated to the server, then it must
225 perform "initial authentication", as defined in this section. If it has
226 recently authenticated, then a more efficient form is available, defined
232 The server starts by sending a challenge. The data encoded in the
233 challenge contains a string formatted according to the rules for a
234 "digest-challenge" defined as follows:
236 digest-challenge = 1#( realm | nonce | qop-options | stale |
237 maxbuf | charset | cipher-opts | auth-
241 realm = "realm" "=" <"> realm-value <">
242 realm-value = qdstr-val
243 nonce = "nonce" "=" <"> nonce-value <">
244 nonce-value = qdstr-val
245 qop-options = "qop" "=" <"> qop-list <">
246 qop-list = 1#qop-value
247 qop-value = "auth" | "auth-int" | "auth-conf" |
249 stale = "stale" "=" "true"
250 maxbuf = "maxbuf" "=" maxbuf-value
251 maxbuf-value = 1*DIGIT
252 charset = "charset" "=" "utf-8"
253 algorithm = "algorithm" "=" "md5-sess"
254 cipher-opts = "cipher" "=" 1#cipher-value
255 cipher-value = "3des" | "des" | "rc4-40" | "rc4" | "rc4-56" |
258 Leach, Newman Standards Track [Page 4]
\f
262 Digest Authentication as a SASL Mechanism September 1998
265 auth-param = token "=" ( token | quoted-string )
267 The meanings of the values of the directives used above are as follows:
271 A string to be displayed to users so they know which username and
272 password to use. This string should contain at least the name of the
273 host performing the authentication and might additionally indicate
274 the collection of users who might have access. An example might be
275 "registered_users@gotham.news.com". This directive is optional; if
276 not present, it defaults to the realm used by the user to login to
277 the client system. Multiple realm directives are allowed.
281 A server-specified data string which MUST be different each time a
282 digest-challenge is sent as part of initial authentication. It is
283 recommended that this string be base64 or hexadecimal data. Note that
284 since the string is passed as a quoted string, the double-quote
285 character is not allowed. The contents of the nonce are
286 implementation dependent. The security of the implementation depends
287 on a good choice. It is RECOMMENDED that it contain at least 64 bits
288 of entropy. The nonce is opaque to the client. This directive is
289 required and may appear exactly once; if not present, or if multiple
290 instances are present, the client should abort the authentication
295 A quoted string of one or more tokens indicating the "quality of
296 protection" values supported by the server. The value "auth"
297 indicates authentication; the value "auth-int" indicates
298 authentication with integrity protection; the value "auth-conf"
299 indicates authentication with integrity protection and encryption.
300 The client MUST ignore unrecognized options; if the client recognizes
301 no option, it should abort the authentication exchange.
305 The "stale" directive is not used in initial authentication. See the
306 next section for its use in subsequent authentications.
310 A number indicating the size of the largest buffer the server is able
311 to receive when using "auth-int" or "auth-conf". If this directive is
312 missing, the default value is 65536. This directive may appear at
313 most once; if multiple instances are present, the client should abort
314 the authentication exchange.
318 This directive, if present, specifies that the server supports UTF-8
319 encoding for the username and password. If not present, the username
320 and password must be encoded in ISO 8859-1 (of which US-ASCII is a
321 subset). The directive is needed for backwards compatibility with
322 HTTP Digest, which only supports ISO 8859-1.
325 Leach, Newman Standards Track [Page 5]
\f
329 Digest Authentication as a SASL Mechanism September 1998
333 This directive is required for backwards compatibility with HTTP
334 Digest., which supports other algorithms.
338 A list of ciphers that the server supports. The "3des" and "des"
339 modes are mandatory-to-implement. This directive must be present
340 exactly once if "auth-conf" is offered.
344 the Data Encryption Standard (DES) cipher [FIPS] in cipher block
345 chaining (CBC) mode with a 56 bit key.
349 the "triple DES" cipher in CBC mode with EDE with the same key for
350 each E stage (aka "two keys mode") for a total key length of 112
355 the RC4 cipher with a 128 bit, 40 bit, and 56 bit key, respectively.
359 This directive allows for future extensions. The client MUST ignore
360 any unrecognized directive.
362 For use as a SASL mechanism, note that the following changes are made to
363 "digest-challenge" from HTTP: the following Digest options (called
364 "directives" in HTTP terminology) are unused (i.e., MUST NOT be sent,
365 and MUST be ignored if received):
371 The size of a digest-challenge MUST be less than 2048 bytes.
376 The client makes note of the "digest-challenge" and then responds with a
377 string formatted and computed according to the rules for a "digest-
378 response" defined as follows:
380 digest-response = 1#( username | realm | nonce | cnonce |
381 nonce-count | qop | digest-uri | response |
382 maxbuf | charset | cipher | auth-param )
384 username = "username" "=" <"> username-value <">
385 username-value = qdstr-val
386 cnonce = "cnonce" "=" <"> cnonce-value <">
387 cnonce-value = qdstr-val
388 nonce-count = "nc" "=" nc-value
390 qop = "qop" "=" qop-value
393 Leach, Newman Standards Track [Page 6]
\f
397 Digest Authentication as a SASL Mechanism September 1998
400 digest-uri = "digest-uri" "=" digest-uri-value
401 digest-uri-value = serv-type "/" host [ "/" serv-name ]
403 host = 1*( ALPHA | DIGIT | "-" | "." )
405 response = "response" "=" <"> response-value <">
406 response-value = 32LHEX
407 LHEX = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
408 "8" | "9" | "a" | "b" | "c" | "d" | "e" | "f"
409 cipher = "cipher" "=" cipher-value
415 The user's name in the specified realm, encoded as UTF-8. This
416 directive is required; if not present, authentication fails.
420 The realm containing the user's account. It MUST be one of the realms
421 from the "digest-challenge", if any were provided. This directive is
422 required unless the server did not provide any realms; otherwise, if
423 not present, or not one of the ones in the "digest-challenge",
424 authentication fails.
428 The server-specified data string received in the preceding digest-
433 A client-specified data string which MUST be different each time a
434 digest-response is sent as part of initial authentication. The
435 cnonce-value is an opaque quoted string value provided by the client
436 and used by both client and server to avoid chosen plaintext attacks,
437 and to provide mutual authentication. The security of the
438 implementation depends on a good choice. It is RECOMMENDED that it
439 contain at least 64 bits of entropy. This directive is required; if
440 not present, authentication fails.
444 The nc-value is the hexadecimal count of the number of requests
445 (including the current request) that the client has sent with the
446 nonce value in this request. For example, in the first request sent
447 in response to a given nonce value, the client sends "nc=00000001".
448 The purpose of this directive is to allow the server to detect
449 request replays by maintaining its own copy of this count - if the
450 same nc-value is seen twice, then the request is a replay. See the
451 description below of the construction of the response value.
455 Indicates what "quality of protection" the client accepted. If
456 present, its value MUST be one of the alternatives the server
457 indicated it supports in digest-challenge. If not present, it
460 Leach, Newman Standards Track [Page 7]
\f
464 Digest Authentication as a SASL Mechanism September 1998
467 defaults to "auth". These values affect the computation of the
468 response. Note that this is a single token, not a quoted list of
473 Indicates the type of service, such as "www" for web service, "ftp"
474 for FTP service, "SMTP" for mail delivery service, etc..
478 Indicates the DNS host name for the service requested.
482 Indicates the name of the service if it is replicated. If the
483 client's service-location process involves resolution using standard
484 (i.e., insecure) DNS lookup operations, and these operations involve
485 DNS records such as CNAME, SRV, or MX, which resolve one DNS name
486 into another, the initial name used by the client is the "serv-name",
487 and the final name is the "host" component. For example, the incoming
488 mail service for "example.com" may be replicated through the use of
489 MX records stored in the DNS, one of which points at an SMTP server
490 called "mail3.example.com"; it's "serv-name" would be "example.com",
491 it's "host" would be "mail3.example.com".
495 Indicates the principal name of the service with which the client
496 wishes to connect, formed from the serv-type, host, and serv-name.
497 For example, the FTP service on "ftp.xyz.com" would have a "digest-
498 uri" value of "ftp/ftp.xyz.com"; the SMTP server from the example
499 above would have a "digest-uri" value of "smtp/mail3.xyz.com/xyz.com"
503 A string of 32 hex digits computed as defined below, which proves
504 that the user knows a password. This directive is required; if not
505 present, authentication fails.
509 A number indicating the size of the largest buffer the client is able
510 to receive. If this directive is missing, the default value is 65536.
511 This directive may appear at most once; if multiple instances are
512 present, the server should abort the authentication exchange.
516 This directive, if present, specifies that the client has used UTF-8
517 encoding for the username and password. If not present, the username
518 and password must be encoded in ISO 8859-1 (of which US-ASCII is a
519 subset). The client should send this directive only if the server has
520 indicated it supports UTF-8. The directive is needed for backwards
521 compatibility with HTTP Digest, which only supports ISO 8859-1.
525 32 hex digits, where the alphabetic characters MUST be lower case,
526 because MD5 is not case insensitive.
528 Leach, Newman Standards Track [Page 8]
\f
532 Digest Authentication as a SASL Mechanism September 1998
536 The cipher chosen by the client. This directive MUST appear exactly
537 once if "auth-conf" is negotiated; if required and not present,
538 authentication fails.
540 The size of a digest-response MUST be less than 2048 bytes.
543 2.1.2.1 Response-value
545 The definition of "response-value" above indicates the encoding for its
546 value -- 32 lower case hex characters. The following definitions show
547 how the value is computed.
550 HEX( KD ( HEX(H(A1)),
551 { nonce-value, ":" nc-value, ":",
552 cnonce-value, ":", qop-value, ":", HEX(H(A2))
558 A1 = { H( { username-value, ":", realm-value, ":", passwd } ),
559 ":", nonce-value, ":", cnonce-value }
565 The "username-value", "realm-value" and "passwd" are encoded according
566 to the value of the "charset" directive. If "charset=UTF-8" is present,
567 and all the characters of either "username-value" or "passwd" are in the
568 ISO 8859-1 character set, then it must be converted to ISO 8859-1 before
569 being hashed. A sample implementation of this conversion is in section
572 If the "qop" directive's value is "auth", then A2 is:
574 A2 = { "AUTHENTICATE:", digest-uri-value }
576 If the "qop" value is "auth-int" or "auth-conf" then A2 is:
578 A2 = { "AUTHENTICATE:", digest-uri-value,
579 ":00000000000000000000000000000000" }
581 Note that "AUTHENTICATE:" must be in upper case, and the second string
582 constant is a string with a colon followed by 32 zeros.
584 These apparently strange values of A2 are for compatibility with HTTP;
585 they were arrived at by setting "Method" to "AUTHENTICATE" and the hash
586 of the entity body to zero in the HTTP digest calculation of A2.
590 Leach, Newman Standards Track [Page 9]
\f
594 Digest Authentication as a SASL Mechanism September 1998
597 Also, in the HTTP usage of Digest, several directives in the "digest-
598 challenge" sent by the server have to be returned by the client in the
599 "digest-response". These are:
605 These directives are not needed when Digest is used as a SASL mechanism
606 (i.e., MUST NOT be sent, and MUST be ignored if received).
611 The server receives and validates the "digest-response". The server
612 checks that the nonce-count is "00000001". If it supports subsequent
613 authentication (see section 2.2), it saves the value of the nonce and
614 the nonce-count. It sends a message formatted as follows:
617 response-auth = "rspauth" "=" response-value
619 where response-value is calculated as above, using the values sent in
620 step two, except that if qop is "auth", then A2 is
623 A2 = { ":", digest-uri-value }
625 And if qop is "auth-int" or "auth-conf" then A2 is
628 A2 = { ":", digest-uri-value, ":00000000000000000000000000000000"
631 Compared to its use in HTTP, the following Digest directives in the
632 "digest-response" are unused:
640 2.2 Subsequent Authentication
642 If the client has previously authenticated to the server, and remembers
643 the values of username, realm, nonce, nonce-count, cnonce, and qop that
644 it used in that authentication, and the SASL profile for a protocol
645 permits an initial client response, then it MAY perform "subsequent
646 authentication", as defined in this section.
651 The client uses the values from the previous authentication and sends an
652 initial response with a string formatted and computed according to the
653 rules for a "digest-response", as defined above, but with a nonce-count
654 one greater than used in the last "digest-response".
659 Leach, Newman Standards Track [Page 10]
\f
663 Digest Authentication as a SASL Mechanism September 1998
669 The server receives the "digest-response". If the server does not
670 support subsequent authentication, then it sends a "digest-challenge",
671 and authentication proceeds as in initial authentication. If the server
672 has no saved nonce and nonce-count from a previous authentication, then
673 it sends a "digest-challenge", and authentication proceeds as in initial
674 authentication. Otherwise, the server validates the "digest-response",
675 checks that the nonce-count is one greater than that used in the
676 previous authentication using that nonce, and saves the new value of
679 If the response is invalid, then the server sends a "digest-challenge",
680 and authentication proceeds as in initial authentication (and should be
681 configurable to log an authentication failure in some sort of security
682 audit log, since the failure may be a symptom of an attack). The nonce-
683 count MUST NOT be incremented in this case: to do so would allow a
684 denial of service attack by sending an out-of-order nonce-count.
686 If the response is valid, the server MAY choose to deem that
687 authentication has succeeded. However, if it has been too long since the
688 previous authentication, or for any other reason, the server MAY send a
689 new "digest-challenge" with a new value for nonce. The challenge MAY
690 contain a "stale" directive with value "true", which says that the
691 client may respond to the challenge using the password it used in the
692 previous response; otherwise, the client must solicit a new password
693 from the user. Except for the handling of "stale", after sending the
694 "digest-challenge" authentication proceeds as in the case of initial
698 2.3 Integrity Protection
700 If the server offered "qop=auth-int" and the client responded "qop=auth-
701 int", then subsequent messages, up to but not including the next
702 subsequent authentication, between the client and the server MUST be
703 integrity protected. Using as a base session key the value of H(A1) as
704 defined above the client and server calculate a pair of message
705 integrity keys as follows.
707 The key for integrity protecting messages from client to server is:
710 "Digest session key to client-to-server signing key magic
713 The key for integrity protecting messages from client to server is:
716 "Digest session key to server-to-client signing key magic
719 where MD5 is as specified in [RFC 1321]. If message integrity is
720 negotiated, a MAC for each message is appended to the message. The MAC
723 Leach, Newman Standards Track [Page 11]
\f
727 Digest Authentication as a SASL Mechanism September 1998
730 is 16 bytes: a 4-byte version number with value 1, the first 8 bytes of
731 the HMAC-MD5 [RFC 2104] of the message and the sequence number.
733 MAC(Ki, SeqNum, msg) = (0x00000001, HMAC(Ki, (SeqNum, msg))[0..7],
736 where Ki is Kic for messages sent by the client and Kis for those sent
737 by the server. The sequence number is initialized to zero, and
738 incremented by one for each message sent.
740 Upon receipt, MAC(Ki, SeqNum, msg) is computed and compared with the
741 received value; the message is discarded if they differ.
744 2.4 Confidentiality Protection
746 If the server sent a "cipher-opts" directive and the client responded
747 with a "cipher" directive, then subsequent messages between the client
748 and the server MUST be confidentiality protected. Using as a base
749 session key the value of H(A1) as defined above the client and server
750 calculate a pair of message integrity keys as follows.
752 The key for confidentiality protecting messages from client to server
755 Kcc = MD5(H(A1)[0..n],
756 "Digest H(A1) to client-to-server sealing key magic constant")
758 The key for confidentiality protecting messages from server to client
761 Kcs = MD5(H(A1)[0..n],
762 "Digest H(A1) to server-to-client sealing key magic constant")
764 where MD5 is as specified in [RFC 1321]. For cipher "rc4-40" n is 5; for
765 "rc4-56" n is 7; for the rest n is 16. The key for the "rc-*" ciphers is
766 all 16 bytes of Kcc or Kcs; the key for "des" is the first 7 bytes; the
767 key for "3des" is the first 14 bytes. The IV for "des" and "3des" is the
768 last 8 bytes of Kcc or Kcs.
770 If message confidentiality is negotiated, each message is encrypted
771 with the chosen cipher and a MAC is appended to the message.
773 The MAC is a variable length padding prefix followed by 16 bytes
774 formatted as follows: a 4-byte version number with value 1, the first 8
775 bytes of the HMAC-MD5 [RFC 2104] of the message and the sequence number.
776 If the blocksize of the chosen cipher is not 1 byte, the padding prefix
777 is one or more octets each containing the number of padding bytes such
778 that length of the message plus the length of the padding prefix is a
779 multiple of the blocksize.
781 SEAL(Ki, Ke, SeqNum, msg) = CIPHER(Ke, { msg, pad}), CMAC(Ki, Ke,
783 CMAC(Ki, Ke, SeqNum, msg) =
784 { 0x00000001, CIPHER(Ke, HMAC(Ki, (SeqNum, msg))[0..7]), SeqNum }
786 Leach, Newman Standards Track [Page 12]
\f
790 Digest Authentication as a SASL Mechanism September 1998
794 where CIPHER is the chosen cipher, Ki and Ke are Kic and Kcc for
795 messages sent by the client and Kis and Kcs for those sent by the
796 server. The sequence number is initialized to zero, and incremented by
797 one for each message sent.
799 Upon receipt, the message is decrypted, CMAC(Ki, Ke, SeqNum, msg) is
800 computed and compared with the received value; the message is discarded
804 3 Security Considerations
807 3.1 Authentication of Clients using Digest Authentication
809 Digest Authentication does not provide a strong authentication
810 mechanism, when compared to public key based mechanisms, for example.
811 However, since it prevents chosen plaintext attacks, it is stronger than
812 (e.g.) CRAM-MD5, which has been proposed for use with LDAP [10], POP and
813 IMAP (see RFC 2195 [9]). It is intended to replace the much weaker and
814 even more dangerous use of plaintext passwords; however, since it is
815 still a password based mechanism it avoids some of the potential
816 deployabilty issues with public-key, OTP or similar mechanisms.
818 Digest Authentication offers no confidentiality protection beyond
819 protecting the actual password. All of the rest of the challenge
820 and response are available to an eavesdropper, including the
821 user's name and authentication realm.
824 3.2 Comparison of Digest with Plaintext Passwords
826 The greatest threat to the type of transactions for which these
827 protocols are used is network snooping. This kind of transaction
828 might involve, for example, online access to a mail service whose
829 use is restricted to paying subscribers. With plaintext password
830 authentication an eavesdropper can obtain the password of the
831 user. This not only permits him to access anything in the
832 database, but, often worse, will permit access to anything else
833 the user protects with the same password.
838 Replay attacks are defeated if the client or the server chooses a
839 fresh nonce for each authentication, as this specification
843 3.4 Online dictionary attacks
845 I f the attacker can eavesdrop, then it can test any overheard
846 nonce/response pairs against a (potentially very large) list of common
847 words. Such a list is usually much smaller than the total number of
848 possible passwords. The cost of computing the response for each password
849 on the list is paid once for each challenge.
852 Leach, Newman Standards Track [Page 13]
\f
856 Digest Authentication as a SASL Mechanism September 1998
859 The server can mitigate this attack by not allowing users to select
860 passwords that are in a dictionary.
863 3.5 Offline dictionary attacks
865 If the attacker can choose the challenge, then it can precompute the
866 possible responses to that challenge for a list of common words. Such a
867 list is usually much smaller than the total number of possible
868 passwords. The cost of computing the response for each password on the
869 list is paid just once.
871 Offline dictionary attacks are defeated if the client chooses a fresh
872 nonce for each authentication, as this specification requires.
875 3.6 Man in the Middle
877 Digest authentication is vulnerable to "man in the middle" (MITM)
878 attacks. Clearly, a MITM would present all the problems of
879 eavesdropping. But it also offers some additional opportunities to the
882 A possible man-in-the-middle attack would be to substitute a weaker qop
883 scheme for the one(s) sent by the server; the server will not be able to
884 detect this attack. For this reason, the client should always use the
885 strongest scheme that it understands from the choices offered, and
886 should never choose a scheme that does not meet its minimum
890 3.7 Chosen plaintext attacks
892 A chosen plaintext attack is where a MITM or a malicious server can
893 arbitrarily choose the challenge that the client will use to compute the
894 response. The ability to choose the challenge is known to make
895 cryptanalysis much easier [8].
897 However, Digest does not permit the attack to choose the challenge as
898 long as the client chooses a fresh nonce for each authentication, as
899 this specification requires.
902 3.8 Spoofing by Counterfeit Servers
904 If a user can be led to believe that she is connecting to a host
905 containing information protected by a password she knows, when in fact
906 she is connecting to a hostile server, then the hostile server can
907 obtain challenge/response pairs where it was able to partly choose the
908 challenge. There is no known way that this can be exploited.
911 3.9 Storing passwords
913 Digest authentication requires that the authenticating agent (usually
914 the server) store some data derived from the user's name and password in
915 a "password file" associated with a given realm. Normally this might
916 contain pairs consisting of username and H(A1), where H(A1) is the
917 digested value of the username, realm, and password as described above.
919 Leach, Newman Standards Track [Page 14]
\f
923 Digest Authentication as a SASL Mechanism September 1998
926 The security implications of this are that if this password file is
927 compromised, then an attacker gains immediate access to documents on the
928 server using this realm. Unlike, say a standard UNIX password file, this
929 information need not be decrypted in order to access documents in the
930 server realm associated with this file. On the other hand, decryption,
931 or more likely a brute force attack, would be necessary to obtain the
932 user's password. This is the reason that the realm is part of the
933 digested data stored in the password file. It means that if one Digest
934 authentication password file is compromised, it does not automatically
935 compromise others with the same username and password (though it does
936 expose them to brute force attack).
938 There are two important security consequences of this. First the
939 password file must be protected as if it contained plaintext passwords,
940 because for the purpose of accessing documents in its realm, it
943 A second consequence of this is that the realm string should be unique
944 among all realms that any single user is likely to use. In particular a
945 realm string should include the name of the host doing the
951 Use of multiple realms may mean both that compromise of a the security
952 database for a single realm does not compromise all security, and that
953 there are more things to protect in order to keep the whole system
959 By modern cryptographic standards Digest Authentication is weak,
960 compared to (say) public key based mechanisms. But for a large range of
961 purposes it is valuable as a replacement for plaintext passwords. Its
962 strength may vary depending on the implementation.
967 This example shows the use of the Digest SASL mechanism with the IMAP4
968 AUTHENTICATE command [RFC 2060]. The base64 encoding of the challenges
969 and responses is part of the IMAP4 AUTHENTICATE command, not part of the
970 Digest specification itself. (Note: linebreaks added for editorial
971 clarity are not part of the mechanism):
983 Leach, Newman Standards Track [Page 15]
\f
987 Digest Authentication as a SASL Mechanism September 1998
991 * OK elwood.innosoft.com IMAP4 Server PMDF5.3-1 at Mon, 28 Sep 1998
994 * CAPABILITY IMAP4 IMAP4REV1 NAMESPACE STARTTLS AUTH=CRAM-MD5
995 AUTH=DIGEST-MD5 AUTH=LOGIN AUTH=PLAIN
996 c OK CAPABILITY completed
997 a AUTHENTICATE DIGEST-MD5
998 + cmVhbG09ImVsd29vZC5pbm5vc29mdC5jb20iLG5vbmNlPSJENlBpNXVvT2xp
999 RzI4WFZidVRYQ0l3Iixxb3A9ImF1dGgi
1000 dXNlcm5hbWU9ImNocmlzIixyZWFsbT0iZWx3b29kLmlubm9zb2Z0LmNvbSIsbm
1001 9uY2U9IkQ2UGk1dW9PbGlHMjhYVmJ1VFhDSXciLG5jPTAwMDAwMDAxLGNub25j
1002 ZT0iZS9nWG5wRW94ODNzVzNERXU3b1FoZyIscmVzcG9uc2U9IjRmNjA2NTBhYW
1003 FmNDQxNzkyOWViNjg3Zjc2NmNlOTMyIixxb3A9ImF1dGgi
1004 a OK AUTHENTICATE completed
1007 Decoding the base64, gets:
1009 realm="elwood.innosoft.com",nonce="D6Pi5uoOliG28XVbuTXCIw",qop="auth
1014 username="chris",realm="elwood.innosoft.com",nonce="D6Pi5uoOliG28XVb
1016 nc=00000001,cnonce="e/gXnpEox83sW3DEu7oQhg",
1017 response="4f60650aaaf4417929eb687f766ce932",qop="auth"
1019 The password was "secret".
1021 The server uses the values of all the directives, plus knowledge of the
1022 users password (or the hash of the userÆs name, serverÆs realm and the
1023 userÆs password) to verify the computations above. If they check, then
1024 the user has authenticated.
1030 [Digest] Franks, J., et. al., "HTTP Authentication: Basic and Digest
1031 Access Authentication", <draft-ietf-http-authentication-03>, Work in
1032 Progress of the HTTP Working Group, August, 1998
1035 [ISO-8859] ISO-8859. International Standard -- Information Processing --
1036 8-bit Single-Byte Coded Graphic Character Sets --
1037 Part 1: Latin alphabet No. 1, ISO-8859-1:1987.
1038 Part 2: Latin alphabet No. 2, ISO-8859-2, 1987.
1039 Part 3: Latin alphabet No. 3, ISO-8859-3, 1988.
1040 Part 4: Latin alphabet No. 4, ISO-8859-4, 1988.
1041 Part 5: Latin/Cyrillic alphabet, ISO-8859-5, 1988.
1042 Part 6: Latin/Arabic alphabet, ISO-8859-6, 1987.
1043 Part 7: Latin/Greek alphabet, ISO-8859-7, 1987.
1044 Part 8: Latin/Hebrew alphabet, ISO-8859-8, 1988.
1045 Part 9: Latin alphabet No. 5, ISO-8859-9, 1990.
1048 Leach, Newman Standards Track [Page 16]
\f
1052 Digest Authentication as a SASL Mechanism September 1998
1055 [RFC 822] D. H. Crocker, "Standard for The Format of ARPA Internet Text
1056 Messages," STD 11, RFC 822, UDEL, August 1982.
1059 [RFC 1321] R. Rivest, "The MD5 Message-Digest Algorithm", RFC 1321,
1063 [RFC 2047] Moore, K., "MIME (Multipurpose Internet Mail Extensions) Part
1064 Three: Message Header Extensions for Non-ASCII Text", RFC 2047,
1065 University of Tennessee, November 1996.
1068 [RFC 2060] Crispin, "Internet Message Access Protocol - Version 4rev1",
1069 RFC 2060, University of Washington, December 1996.
1072 [RFC 2104] H. Krawczyk, M. Bellare, R. Canetti, "HMAC: Keyed-Hashing
1073 for Message Authentication", RFC 2104, 02/05/1997
1076 [RFC2195] Klensin, J., et. al., "IMAP/POP AUTHorize Extension for Simple
1077 Challenge/Response", RFC 2195, September, 1997.
1080 [RFC 2119] Bradner, S., "Key words for use in RFCs to Indicate
1081 Requirement Levels," RFC 2119, Harvard University, March 1997.
1084 [USASCII] US-ASCII. Coded Character Set - 7-Bit American Standard Code
1085 for Information Interchange. Standard ANSI X3.4-1986, ANSI, 1986.
1088 6 Authors' Addresses
1094 paulle@microsoft.com
1097 Innosoft International, Inc.
1099 West Covina, CA 91790 USA
1100 chris.newman@innosoft.com
1108 All of the mechanisms specified in this document are described in both
1109 prose and an augmented Backus-Naur Form (BNF) similar to that used by
1110 RFC 822 [RFC 822]. Implementors will need to be familiar with the
1111 notation in order to understand this specification. The augmented BNF
1112 includes the following constructs:
1116 Leach, Newman Standards Track [Page 17]
\f
1120 Digest Authentication as a SASL Mechanism September 1998
1124 The name of a rule is simply the name itself (without any enclosing
1125 "<" and ">") and is separated from its definition by the equal "="
1126 character. White space is only significant in that indentation of
1127 continuation lines is used to indicate a rule definition that spans
1128 more than one line. Certain basic rules are in uppercase, such as SP,
1129 LWS, HT, CRLF, DIGIT, ALPHA, etc. Angle brackets are used within
1130 definitions whenever their presence will facilitate discerning the
1135 Quotation marks surround literal text. Unless stated otherwise, the
1136 text is case-insensitive.
1140 Elements separated by a bar ("|") are alternatives, e.g., "yes | no"
1141 will accept yes or no.
1145 Elements enclosed in parentheses are treated as a single element.
1146 Thus, "(elem (foo | bar) elem)" allows the token sequences
1147 "elem foo elem" and "elem bar elem".
1151 The character "*" preceding an element indicates repetition. The full
1152 form is "<n>*<m>element" indicating at least <n> and at most <m>
1153 occurrences of element. Default values are 0 and infinity so that
1154 "*(element)" allows any number, including zero; "1*element" requires
1155 at least one; and "1*2element" allows one or two.
1159 Square brackets enclose optional elements; "[foo bar]" is equivalent
1164 Specific repetition: "<n>(element)" is equivalent to
1165 "<n>*<n>(element)"; that is, exactly <n> occurrences of (element).
1166 Thus 2DIGIT is a 2-digit number, and 3ALPHA is a string of three
1167 alphabetic characters.
1171 A construct "#" is defined, similar to "*", for defining lists of
1172 elements. The full form is "<n>#<m>element" indicating at least <n>
1173 and at most <m> elements, each separated by one or more commas (",")
1174 and OPTIONAL linear white space (LWS). This makes the usual form of
1175 lists very easy; a rule such as
1176 ( *LWS element *( *LWS "," *LWS element ))
1179 Wherever this construct is used, null elements are allowed, but do
1180 not contribute to the count of elements present. That is, "(element),
1181 , (element) " is permitted, but counts as only two elements.
1184 Leach, Newman Standards Track [Page 18]
\f
1188 Digest Authentication as a SASL Mechanism September 1998
1191 Therefore, where at least one element is required, at least one non-
1192 null element MUST be present. Default values are 0 and infinity so
1193 that "#element" allows any number, including zero; "1#element"
1194 requires at least one; and "1#2element" allows one or two.
1198 A semi-colon, set off some distance to the right of rule text, starts
1199 a comment that continues to the end of line. This is a simple way of
1200 including useful notes in parallel with the specifications.
1204 Except where noted otherwise, linear white space ("LWS") can be
1205 included between any adjacent "token", "quoted-string", or
1206 "separators" constructs, as these are defined in the basic rules
1207 below; such LWS is ignored.
1212 The following rules are used throughout this specification to describe
1213 basic parsing constructs. The US-ASCII coded character set is defined by
1214 ANSI X3.4-1986 [USASCII].
1216 OCTET = <any 8-bit sequence of data>
1217 CHAR = <any US-ASCII character (octets 0 - 127)>
1218 UPALPHA = <any US-ASCII uppercase letter "A".."Z">
1219 LOALPHA = <any US-ASCII lowercase letter "a".."z">
1220 ALPHA = UPALPHA | LOALPHA
1221 DIGIT = <any US-ASCII digit "0".."9">
1222 CTL = <any US-ASCII control character
1223 (octets 0 - 31) and DEL (127)>
1224 CR = <US-ASCII CR, carriage return (13)>
1225 LF = <US-ASCII LF, linefeed (10)>
1226 SP = <US-ASCII SP, space (32)>
1227 HT = <US-ASCII HT, horizontal-tab (9)>
1228 <"> = <US-ASCII double-quote mark (34)>
1230 All linear white space, including folding, has the same semantics as SP.
1231 A recipient MAY replace any linear white space with a single SP before
1232 interpreting the field value or forwarding the message downstream.
1234 LWS = [CRLF] 1*( SP | HT )
1236 The TEXT rule is only used for descriptive field contents and values
1237 that are not intended to be interpreted by the message parser. Words of
1238 *TEXT MAY contain characters from character sets other than ISO-8859-1
1239 [ISO 8859] only when encoded according to the rules of RFC 2047 [RFC
1242 TEXT = <any OCTET except CTLs,
1249 Leach, Newman Standards Track [Page 19]
\f
1253 Digest Authentication as a SASL Mechanism September 1998
1256 A CRLF is allowed in the definition of TEXT only as part of a header
1257 field continuation. It is expected that the folding LWS will be replaced
1258 with a single SP before interpretation of the TEXT value.
1260 Hexadecimal numeric characters are used in several protocol elements.
1262 HEX = "A" | "B" | "C" | "D" | "E" | "F"
1263 | "a" | "b" | "c" | "d" | "e" | "f" | DIGIT
1265 Many HTTP/1.1 header field values consist of words separated by LWS or
1266 special characters. These special characters MUST be in a quoted string
1267 to be used within a parameter value.
1269 token = 1*<any CHAR except CTLs or separators>
1270 separators = "(" | ")" | "<" | ">" | "@"
1271 | "," | ";" | ":" | "\" | <">
1272 | "/" | "[" | "]" | "?" | "="
1273 | "{" | "}" | SP | HT
1275 A string of text is parsed as a single word if it is quoted using
1278 quoted-string = ( <"> qdstr-val <"> )
1279 qdstr-val = *(qdtext | quoted-pair )
1280 qdtext = <any TEXT except <">>
1282 The backslash character ("\") MAY be used as a single-character quoting
1283 mechanism only within qdstr-val and comment constructs.
1285 quoted-pair = "\" CHAR
1287 The value of this construct is CHAR. Note that an effect of this rule is
1288 that backslash must be quoted.
1293 The sample implementation in [Digest] also applies to DIGEST-MD5.
1295 The following code implements the conversion from UTF-8 to 8859-1 if
1311 Leach, Newman Standards Track [Page 20]
\f
1315 Digest Authentication as a SASL Mechanism September 1998
1319 /* if the string is entirely in the 8859-1 subset of UTF-8, then
1321 * to 8859-1 prior to MD5
1323 void MD5_UTF8_8859_1(MD5_CTX *ctx, const unsigned char *base, int
1326 const unsigned char *scan, *end;
1330 for (scan = base; scan < end; ++scan) {
1331 if (*scan > 0xC3) break; /* abort if outside 8859-1 */
1332 if (*scan >= 0xC0 && *scan <= 0xC3) {
1333 if (++scan == end || *scan < 0x80 || *scan > 0xBF)
1337 /* if we found a character outside 8859-1, don't alter string
1340 MD5Update(ctx, base, len);
1344 /* convert to 8859-1 prior to applying hash
1347 for (scan = base; scan < end && *scan < 0xC0; ++scan)
1349 if (scan != base) MD5Update(ctx, base, scan - base);
1350 if (scan + 1 >= end) break;
1351 cbuf = ((scan[0] & 0x3) << 6) | (scan[1] & 0x3f);
1352 MD5Update(ctx, &cbuf, 1);
1354 } while (base < end);
1358 9 Full Copyright Statement
1360 Copyright (C) The Internet Society (1998). All Rights Reserved.
1362 This document and translations of it may be copied and furnished to
1363 others, and derivative works that comment on or otherwise explain it or
1364 assist in its implmentation may be prepared, copied, published and
1365 distributed, in whole or in part, without restriction of any kind,
1366 provided that the above copyright notice and this paragraph are included
1367 on all such copies and derivative works. However, this document itself
1368 may not be modified in any way, such as by removing the copyright notice
1369 or references to the Internet Society or other Internet organizations,
1370 except as needed for the purpose of developing Internet standards in
1371 which case the procedures for copyrights defined in the Internet
1374 Leach, Newman Standards Track [Page 21]
\f
1378 Digest Authentication as a SASL Mechanism September 1998
1381 Standards process must be followed, or as required to translate it into
1382 languages other than English.
1384 The limited permissions granted above are perpetual and will not be
1385 revoked by the Internet Society or its successors or assigns.
1387 This document and the information contained herein is provided on an "AS
1388 IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK
1389 FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
1390 LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT
1391 INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR
1392 FITNESS FOR A PARTICULAR PURPOSE.
1436 Leach, Newman Standards Track [Page 22]
\f