Bump versions.
[gsasl.git] / doc / specification / draft-ietf-sasl-rfc2831bis-00.txt
blob8c8514c91c74e78d9aec08312dfcd2c4378a6b34
7 INTERNET-DRAFT                                                  P. Leach
8 Obsoletes: 2831                                                Microsoft
9 Intended category: Standards track                             C. Newman
10                                                                 Innosoft
11                                                              A. Melnikov
12                                                          MessagingDirect
13                                                            February 2003
15             Using Digest Authentication as a SASL Mechanism
16                    draft-ietf-sasl-rfc2831bis-00.txt
18 Status of this Memo
20    This document is an Internet-Draft and is in full conformance with
21    all provisions of Section 10 of RFC 2026.
23    Internet-Drafts are working documents of the Internet Engineering
24    Task Force (IETF), its areas, and its working groups. Note that other
25    groups may also distribute working documents as Internet-Drafts.
27    Internet-Drafts are draft documents valid for a maximum of six months
28    and may be updated, replaced, or obsoleted by other documents at any
29    time. It is inappropriate to use Internet-Drafts as reference
30    material or to cite them other than as "work in progress."
32    The list of current Internet-Drafts can be accessed at
33    http://www.ietf.org/ietf/1id-abstracts.txt
35    The list of Internet-Draft Shadow Directories can be accessed at
36    http://www.ietf.org/shadow.html.
38 Copyright Notice
40    Copyright (C) The Internet Society (2003).  All Rights Reserved.
42 Abstract
44    This specification defines how HTTP Digest Authentication [Digest]
45    can be used as a SASL [RFC 2222] mechanism for any protocol that has
46    a SASL profile. It is intended both as an improvement over CRAM-MD5
47    [RFC 2195] and as a convenient way to support a single authentication
48    mechanism for web, mail, LDAP, and other protocols.
58 Leach & Newman            Expires: August 2003                  [Page 1]
64 INTERNET DRAFT            Digest SASL Mechanism            February 2003
67 Table of Contents
69    1 INTRODUCTION.....................................................3
70     1.1 CONVENTIONS AND NOTATION......................................3
71     1.2 REQUIREMENTS..................................................4
72    2 AUTHENTICATION...................................................5
73     2.1 INITIAL AUTHENTICATION........................................5
74      2.1.1 Step One...................................................5
75      2.1.2 Step Two...................................................9
76      2.1.3 Step Three................................................15
77     2.2 SUBSEQUENT AUTHENTICATION....................................16
78      2.2.1 Step one..................................................16
79      2.2.2 Step Two..................................................16
80     2.3 INTEGRITY PROTECTION.........................................17
81     2.4 CONFIDENTIALITY PROTECTION...................................17
82    3 SECURITY CONSIDERATIONS.........................................19
83     3.1 AUTHENTICATION OF CLIENTS USING DIGEST AUTHENTICATION........19
84     3.2 COMPARISON OF DIGEST WITH PLAINTEXT PASSWORDS................19
85     3.3 REPLAY ATTACKS...............................................19
86     3.4 ONLINE DICTIONARY ATTACKS....................................19
87     3.5 OFFLINE DICTIONARY ATTACKS...................................20
88     3.6 MAN IN THE MIDDLE............................................20
89     3.7 CHOSEN PLAINTEXT ATTACKS.....................................20
90     3.8 SPOOFING BY COUNTERFEIT SERVERS..............................21
91     3.9 STORING PASSWORDS............................................21
92     3.10 MULTIPLE REALMS.............................................21
93     3.11 SUMMARY.....................................................22
94    4 EXAMPLE.........................................................22
95    5 REFERENCES......................................................24
96     5.1 NORMATIVE REFERENCES.........................................24
97     5.2 INFORMATIVE REFERENCES.......................................25
98    6 AUTHORS' ADDRESSES..............................................26
99    7 ABNF............................................................27
100     7.1 AUGMENTED BNF................................................27
101     7.2 BASIC RULES..................................................29
102    8 SAMPLE CODE.....................................................31
103    9 INTEROPERABILITY CONSIDERATIONS.................................32
104     9.1 Implementing DES cipher in CBC mode..........................32
105    10  ACKNOWLEDGEMENTS..............................................32
106    11 FULL COPYRIGHT STATEMENT.......................................33
107    Appendix A: Changes from 2831.....................................34
108    Appendix B: Open Issues...........................................34
118 Leach & Newman            Expires: August 2003                  [Page 2]
124 INTERNET DRAFT            Digest SASL Mechanism            February 2003
127 1  Introduction
129    This specification describes the use of HTTP Digest Access
130    Authentication as a SASL mechanism. The authentication type
131    associated with the Digest SASL mechanism is "DIGEST-MD5".
133    This specification is intended to be upward compatible with the
134    "md5-sess" algorithm of HTTP/1.1 Digest Access Authentication
135    specified in [Digest]. The only difference in the "md5-sess"
136    algorithm is that some directives not needed in a SASL mechanism have
137    had their values defaulted.
139    There is one new feature for use as a SASL mechanism: integrity
140    protection on application protocol messages after an authentication
141    exchange.
143    Also, compared to CRAM-MD5, DIGEST-MD5 prevents chosen plaintext
144    attacks, and permits the use of third party authentication servers,
145    mutual authentication, and optimized reauthentication if a client has
146    recently authenticated to a server.
148 1.1  Conventions and Notation
150    This specification uses the same ABNF notation and lexical
151    conventions as HTTP/1.1 specification; see section 7.
153    Let { a, b, ... } be the concatenation of the octet strings a, b, ...
155    Let ** denote the power operation.
157    Let H(s) be the 16 octet MD5 hash [RFC 1321] of the octet string s.
159    Let KD(k, s) be H({k, ":", s}), i.e., the 16 octet hash of the string
160    k, a colon and the string s.
162    Let HEX(n) be the representation of the 16 octet MD5 hash n as a
163    string of 32 hex digits (with alphabetic characters always in lower
164    case, since MD5 is case sensitive).
166    Let HMAC(k, s) be the 16 octet HMAC-MD5 [RFC 2104] of the octet
167    string s using the octet string k as a key.
178 Leach & Newman            Expires: August 2003                  [Page 3]
184 INTERNET DRAFT            Digest SASL Mechanism            February 2003
187    Let unq(X) be the value of the quoted-string X without the
188    surrounding quotes and with all escape characters "\\" removed. For
189    example for the quoted-string "Babylon" the value of unq("Babylon")
190    is Babylon; for the quoted string "ABC\"123\\" the value of
191    unq("ABC\"123\\") is ABC"123\.
193    The value of a quoted string constant as an octet string does not
194    include any terminating null character.
196 1.2  Requirements
198    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
199    "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
200    document are to be interpreted as described in RFC 2119 [RFC 2119].
202    An implementation is not compliant if it fails to satisfy one or more
203    of the MUST level requirements for the protocols it implements. An
204    implementation that satisfies all the MUST level and all the SHOULD
205    level requirements for its protocols is said to be "unconditionally
206    compliant"; one that satisfies all the MUST level requirements but
207    not all the SHOULD level requirements for its protocols is said to be
208    "conditionally compliant."
238 Leach & Newman            Expires: August 2003                  [Page 4]
244 INTERNET DRAFT            Digest SASL Mechanism            February 2003
247 2  Authentication
249    The following sections describe how to use Digest as a SASL
250    authentication mechanism.
252 2.1  Initial Authentication
254    If the client has not recently authenticated to the server, then it
255    must perform "initial authentication", as defined in this section. If
256    it has recently authenticated, then a more efficient form is
257    available, defined in the next section.
259 2.1.1  Step One
261    The server starts by sending a challenge. The data encoded in the
262    challenge contains a string formatted according to the rules for a
263    "digest-challenge" defined as follows:
298 Leach & Newman            Expires: August 2003                  [Page 5]
304 INTERNET DRAFT            Digest SASL Mechanism            February 2003
307    digest-challenge  =
308          1#( realm | nonce | qop-options | stale | maxbuf | charset
309                algorithm | cipher-opts | auth-param )
311         realm             = "realm" "=" <"> realm-value <">
312         realm-value       = qdstr-val
313         nonce             = "nonce" "=" <"> nonce-value <">
314         nonce-value       = *qdtext
315         qop-options       = "qop" "=" <"> qop-list <">
316         qop-list          = 1#qop-value
317         qop-value         = "auth" | "auth-int" | "auth-conf" |
318                              token
319         stale             = "stale" "=" "true"
320         maxbuf            = "maxbuf" "=" maxbuf-value
321         maxbuf-value      = 1*DIGIT
322         charset           = "charset" "=" "utf-8"
323         algorithm         = "algorithm" "=" "md5-sess"
324         cipher-opts       = "cipher" "=" <"> 1#cipher-value <">
325         cipher-value      = "3des" | "des" | "rc4-40" | "rc4" |
326                             "rc4-56" | token
327         auth-param        = token "=" ( token | quoted-string )
329    The meanings of the values of the directives used above are as
330    follows:
332    realm
333       Mechanistically, a string which can enable users to know which
334       username and password to use, in case they might have different
335       ones for different servers. Conceptually, it is the name of a
336       collection of accounts that might include the user's account. This
337       string should contain at least the name of the host performing the
338       authentication and might additionally indicate the collection of
339       users who might have access. An example might be
340       "registered_users@gotham.news.example.com".  This directive is
341       optional; if not present, the client SHOULD solicit it from the
342       user or be able to compute a default; a plausible default might be
343       the realm supplied by the user when they logged in to the client
344       system.  Multiple realm directives are allowed, in which case the
345       user or client must choose one as the realm for which to supply to
346       username and password.
348    nonce
349       A server-specified data string which MUST be different each time a
350       digest-challenge is sent as part of initial authentication.  It is
351       recommended that this string be base64 or hexadecimal data. Note
352       that since the string is passed as a quoted string, the
353       double-quote character is not allowed unless escaped (see section
354       7.2). The contents of the nonce are implementation dependent. The
358 Leach & Newman            Expires: August 2003                  [Page 6]
364 INTERNET DRAFT            Digest SASL Mechanism            February 2003
367       security of the implementation depends on a good choice. It is
368       RECOMMENDED that it contain at least 64 bits of entropy. The nonce
369       is opaque to the client. This directive is required and MUST
370       appear exactly once; if not present, or if multiple instances are
371       present, the client should abort the authentication exchange.
373    qop-options
374       A quoted string of one or more tokens indicating the "quality of
375       protection" values supported by the server.  The value "auth"
376       indicates authentication; the value "auth-int" indicates
377       authentication with integrity protection; the value "auth-conf"
378       indicates authentication with integrity protection and encryption.
379       This directive is optional; if not present it defaults to "auth".
380       The client MUST ignore unrecognized options; if the client
381       recognizes no option, it should abort the authentication exchange.
383    stale
384       The "stale" directive is not used in initial authentication. See
385       the next section for its use in subsequent authentications. This
386       directive may appear at most once; if multiple instances are
387       present, the client should abort the authentication exchange.
389    maxbuf ("maximal ciphertext buffer size")
390       A number indicating the size of the largest buffer the server is
391       able to receive when using "auth-int" or "auth-conf". The value
392       MUST be bigger than 16 and smaller or equal to 16777215 (i.e.
393       2**24-1). If this directive is missing, the default value is
394       65536. This directive may appear at most once; if multiple
395       instances are present, the client should abort the authentication
396       exchange.
398       Let call "maximal cleartext buffer size" (or "maximal sender
399       size") the maximal size of a cleartext buffer that, after being
400       transformed by integrity (section 2.3) or confidentiality (section
401       2.4) protection function, will produce a SASL block of the maxbuf
402       size. The "maximal sender size" for the client can be calculated
403       by subtracting 16 from the maxbuf value.  As it should be clear
404       from the name, the sender MUST never pass a block of data bigger
405       than the "maximal sender size" through the selected protection
406       function.  This will guaranty that the receiver will never get a
407       block bigger than the maxbuf.
409    charset
410       This directive, if present, specifies that the server supports
411       UTF-8 [UTF-8] encoding for the username, realm and password. If
412       present, the username, realm and password MUST be in Unicode
413       Normalization Form KC [UNICODE-NORMALIZATION] (without NUL
414       character) encoded as UTF-8 [UTF-8]. If not present, the username,
418 Leach & Newman            Expires: August 2003                  [Page 7]
424 INTERNET DRAFT            Digest SASL Mechanism            February 2003
427       realm and password must be encoded in ISO 8859-1 [ISO-8859] (of
428       which US-ASCII [USASCII] is a subset). The directive is needed for
429       backwards compatibility with HTTP Digest, which only supports ISO
430       8859-1. This directive may appear at most once; if multiple
431       instances are present, the client should abort the authentication
432       exchange.
434       Note, that this directive doesn't affect authorization id
435       ("authzid") which is always in UTF-8.
437    algorithm
438       This directive is required for backwards compatibility with HTTP
439       Digest, which supports other algorithms. This directive is
440       required and MUST appear exactly once; if not present, or if
441       multiple instances are present, the client should abort the
442       authentication exchange.
444    cipher-opts
445       A list of ciphers that the server supports. This directive must be
446       present exactly once if "auth-conf" is offered in the
447       "qop-options" directive, in which case the "3des" cipher is
448       mandatory-to-implement. The client MUST ignore unrecognized
449       options; if the client recognizes no option, it should abort the
450       authentication exchange.
452       des
453          the Data Encryption Standard (DES) cipher [FIPS] in cipher
454          block chaining (CBC) mode with a 56 bit key.
456       3des
457          the "triple DES" cipher in CBC mode with EDE with the same key
458          for each E stage (aka "two keys mode") for a total key length
459          of 112 bits.
461       rc4, rc4-40, rc4-56
462          the RC4 cipher with a 128 bit, 40 bit, and 56 bit key,
463          respectively.
465    auth-param This construct allows for future extensions; it may appear
466       more than once. The client MUST ignore any unrecognized
467       directives.
469    For use as a SASL mechanism, note that the following changes are made
470    to "digest-challenge" from HTTP: the following Digest options (called
471    "directives" in HTTP terminology) are unused (i.e., MUST NOT be sent,
472    and MUST be ignored if received):
474     opaque
478 Leach & Newman            Expires: August 2003                  [Page 8]
484 INTERNET DRAFT            Digest SASL Mechanism            February 2003
487     domain
489    The size of a digest-challenge MUST be less than 2048 bytes.
491 2.1.2  Step Two
493    The client makes note of the "digest-challenge" and then responds
494    with a string formatted and computed according to the rules for a
495    "digest-response" defined as follows:
497    digest-response  = 1#( username | realm | nonce | cnonce |
498                           nonce-count | qop | digest-uri | response |
499                           maxbuf | charset | cipher | authzid |
500                           auth-param )
502        username         = "username" "=" <"> username-value <">
503        username-value   = qdstr-val
504        cnonce           = "cnonce" "=" <"> cnonce-value <">
505        cnonce-value     = *qdtext
506        nonce-count      = "nc" "=" nc-value
507        nc-value         = 8LHEX
508        qop              = "qop" "=" qop-value
509        digest-uri       = "digest-uri" "=" <"> digest-uri-value <">
510        digest-uri-value  = serv-type "/" host [ "/" serv-name ]
511        serv-type        = 1*ALPHA
512        serv-name        = host
513        response         = "response" "=" response-value
514        response-value   = 32LHEX
515        LHEX             = "0" | "1" | "2" | "3" |
516                           "4" | "5" | "6" | "7" |
517                           "8" | "9" | "a" | "b" |
518                           "c" | "d" | "e" | "f"
519        cipher           = "cipher" "=" cipher-value
520        authzid          = "authzid" "=" <"> authzid-value <">
521        authzid-value    = qdstr-val
523    The 'host' non-terminal is defined in [RFC 2732] as
525        host          = hostname | IPv4address | IPv6reference
526        ipv6reference = "[" IPv6address "]"
528    where IPv6address and IPv4address are defined in [RFC 2373]
529    and 'hostname' is defined in [RFC 2396].
531    username
532       The user's name in the specified realm, encoded according to the
533       value of the "charset" directive. This directive is required and
534       MUST be present exactly once; otherwise, authentication fails.
538 Leach & Newman            Expires: August 2003                  [Page 9]
544 INTERNET DRAFT            Digest SASL Mechanism            February 2003
547    realm
548       The realm containing the user's account, encoded according to the
549       value of the "charset" directive. This directive is required if
550       the server provided any realms in the
551       "digest-challenge", in which case it may appear exactly once and
552       its value SHOULD be one of those realms. If the directive is
553       missing, "realm-value" will set to the empty string when computing
554       A1 (see below for details).
556    nonce
557       The server-specified data string received in the preceding digest-
558       challenge.  This directive is required and MUST be present exactly
559       once; otherwise, authentication fails.
598 Leach & Newman            Expires: August 2003                 [Page 10]
604 INTERNET DRAFT            Digest SASL Mechanism            February 2003
607    cnonce
608       A client-specified data string which MUST be different each time a
609       digest-response is sent as part of initial authentication. The
610       cnonce-value is an opaque quoted string value provided by the
611       client and used by both client and server to avoid chosen
612       plaintext attacks, and to provide mutual authentication. The
613       security of the implementation depends on a good choice. It is
614       RECOMMENDED that it contain at least 64 bits of entropy. This
615       directive is required and MUST be present exactly once; otherwise,
616       authentication fails.
618    nonce-count
619       The nc-value is the hexadecimal count of the number of requests
620       (including the current request) that the client has sent with the
621       nonce value in this request.  For example, in the first request
622       sent in response to a given nonce value, the client sends
623       "nc=00000001".  The purpose of this directive is to allow the
624       server to detect request replays by maintaining its own copy of
625       this count - if the same nc-value is seen twice, then the request
626       is a replay. See the description below of the construction of the
627       response value. This directive is required and MUST be present
628       exactly once; otherwise, authentication fails.
630    qop
631       Indicates what "quality of protection" the client accepted. If
632       present, it may appear exactly once and  its value MUST be one of
633       the alternatives in qop-options. If not present, it defaults to
634       "auth".  These values affect the computation of the response. Note
635       that this is a single token, not a quoted list of alternatives.
637    serv-type
638       Indicates the type of service, such as "http" for web service,
639       "ftp" for FTP service, "smtp" for mail delivery service, etc. The
640       service name as defined in the SASL profile for the protocol see
641       section 4 of [RFC 2222], registered in the IANA registry of
642       "service" elements for the GSSAPI host-based service name form
643       [RFC 2078].
645    host
646       The DNS host name or IP (IPv4 or IPv6) address for the service
647       requested.  The DNS host name must be the fully-qualified
648       canonical name of the host.  The DNS host name is the preferred
649       form; see notes on server processing of the digest-uri.
658 Leach & Newman            Expires: August 2003                 [Page 11]
664 INTERNET DRAFT            Digest SASL Mechanism            February 2003
667    serv-name
668       Indicates the name of the service if it is replicated. The service
669       is considered to be replicated if the client's service-location
670       process involves resolution using standard DNS lookup operations,
671       and if these operations involve DNS records (such as SRV [RFC
672       2052], or MX) which resolve one DNS name into a set of other DNS
673       names. In this case, the initial name used by the client is the
674       "serv-name", and the final name is the "host" component. For
675       example, the incoming mail service for "example.com" may be
676       replicated through the use of MX records stored in the DNS, one of
677       which points at an SMTP server called "mail3.example.com"; it's
678       "serv-name" would be "example.com", it's "host" would be
679       "mail3.example.com". If the service is not replicated, or the
680       serv-name is identical to the host, then the serv-name component
681       MUST be omitted.
683    digest-uri
684       Indicates the principal name of the service with which the client
685       wishes to connect, formed from the serv-type, host, and serv-name.
686       For example, the FTP service on "ftp.example.com" would have a
687       "digest-uri" value of "ftp/ftp.example.com"; the SMTP server from
688       the example above would have a "digest-uri" value of
689       "SMTP/mail3.example.com/example.com".
691    Servers SHOULD check that the supplied value is correct. This will
692    detect accidental connection to the incorrect server, as well as some
693    redirection attacks. It is also so that clients will be trained to
694    provide values that will work with implementations that use a shared
695    back-end authentication service that can provide server
696    authentication.
698    The serv-type component should match the service being offered. The
699    host component should match one of the host names of the host on
700    which the service is running, or it's IP address. Servers SHOULD NOT
701    normally support the IP address form, because server authentication
702    by IP address is not very useful; they should only do so if the DNS
703    is unavailable or unreliable. The serv-name component should match
704    one of the service's configured service names.
706    This directive may appear at most once; if multiple instances are
707    present, the client should abort the authentication exchange.
709    Note: In the HTTP use of Digest authentication, the digest-uri is the
710    URI (usually a URL) of the resource requested -- hence the name of
711    the directive.
718 Leach & Newman            Expires: August 2003                 [Page 12]
724 INTERNET DRAFT            Digest SASL Mechanism            February 2003
727    response
728       A string of 32 hex digits computed as defined below, which proves
729       that the user knows a password. This directive is required and
730       MUST be present exactly once; otherwise, authentication fails.
732    maxbuf
733       A number indicating the size of the largest buffer the client is
734       able to receive. If this directive is missing, the default value
735       is 65536.  This directive may appear at most once; if multiple
736       instances are present, the server should abort the authentication
737       exchange.
739    charset
740       This directive, if present, specifies that the client has used
741       UTF-8 [UTF-8] encoding for the username, realm and password. If
742       present, the username, realm and password MUST be in Unicode
743       Normalization Form KC [UNICODE-NORMALIZATION] (without NUL
744       character) encoded as UTF-8 [UTF-8]. If not present, the username
745       and password must be encoded in ISO 8859-1 [ISO-8859] (of which
746       US-ASCII [USASCII] is a subset). The client should send this
747       directive only if the server has indicated it supports UTF-8
748       [UTF-8]. The directive is needed for backwards compatibility with
749       HTTP Digest, which only supports ISO 8859-1.
751       Note, that this directive doesn't affect authorization id
752       ("authzid") which is always in UTF-8.
754    LHEX
755       32 hex digits, where the alphabetic characters MUST be lower case,
756       because MD5 is not case insensitive.
758    cipher
759       The cipher chosen by the client. This directive MUST appear
760       exactly once if "auth-conf" is negotiated; if required and not
761       present, authentication fails.
763    authzid
764       The "authorization ID" in Unicode Normalization Form KC [UNICODE-
765       NORMALIZATION] without NUL character, encoded in UTF-8 [UTF-8].
766       This directive is optional. If present, and the authenticating
767       user has sufficient privilege, and the server supports it, then
768       after authentication the server will use this identity for making
769       all accesses and access checks. If the client specifies it, and
770       the server does not support it, then the response-value calculated
771       on the server will not match the one calculated on the client and
772       authentication will fail.
774    The size of a digest-response MUST be less than 4096 bytes.
778 Leach & Newman            Expires: August 2003                 [Page 13]
784 INTERNET DRAFT            Digest SASL Mechanism            February 2003
787 2.1.2.1   Response-value
789    The definition of "response-value" above indicates the encoding for
790    its value -- 32 lower case hex characters. The following definitions
791    show how the value is computed.
793    Although qop-value and components of digest-uri-value may be
794    case-insensitive, the case which the client supplies in step two is
795    preserved for the purpose of computing and verifying the
796    response-value.
798       response-value  =
799          HEX( KD ( HEX(H(A1)),
800                  { nonce-value, ":" nc-value, ":",
801                    cnonce-value, ":", qop-value, ":", HEX(H(A2)) }))
803    If authzid is specified, then A1 is
806       A1 = { H( { unq(username-value), ":", unq(realm-value), ":", passwd } ),
807            ":", nonce-value, ":", cnonce-value, ":", unq(authzid-value) }
809    If authzid is not specified, then A1 is
812       A1 = { H( { unq(username-value), ":", unq(realm-value), ":", passwd } ),
813            ":", nonce-value, ":", cnonce-value }
815    where
817          passwd   = *OCTET
819    The "username-value", "realm-value" and "passwd" are encoded
820    according to the value of the "charset" directive. If "charset=UTF-8"
821    is present, and all the characters of "username-value" are, after
822    converting to Unicode Normalization Form KC [UNICODE-NORMALIZATION],
823    in the ISO 8859-1 character set, then it must be converted to ISO
824    8859-1 before being hashed. The same transformation has to be done
825    for "realm-value" and "passwd". This is so that authentication
826    databases that store the hashed username, realm and password (which
827    is common) can be shared compatibly with HTTP, which specifies ISO
828    8859-1. A sample implementation of this conversion is in section 8.
830    If the "qop" directive's value is "auth", then A2 is:
832       A2       = { "AUTHENTICATE:", digest-uri-value }
838 Leach & Newman            Expires: August 2003                 [Page 14]
844 INTERNET DRAFT            Digest SASL Mechanism            February 2003
847    If the "qop" value is "auth-int" or "auth-conf" then A2 is:
849       A2       = { "AUTHENTICATE:", digest-uri-value,
850                ":00000000000000000000000000000000" }
852    Note that "AUTHENTICATE:" must be in upper case, and the second
853    string constant is a string with a colon followed by 32 zeros.
855    These apparently strange values of A2 are for compatibility with
856    HTTP; they were arrived at by setting "Method" to "AUTHENTICATE" and
857    the hash of the entity body to zero in the HTTP digest calculation of
858    A2.
860    Also, in the HTTP usage of Digest, several directives in the
861    "digest-challenge" sent by the server have to be returned by the
862    client in the "digest-response". These are:
864     opaque
865     algorithm
867    These directives are not needed when Digest is used as a SASL
868    mechanism (i.e., MUST NOT be sent, and MUST be ignored if received).
870 2.1.3  Step Three
872    The server receives and validates the "digest-response". The server
873    checks that the nonce-count is "00000001". If it supports subsequent
874    authentication (see section 2.2), it saves the value of the nonce and
875    the nonce-count. It sends a message formatted as follows:
877     response-auth = "rspauth" "=" response-value
879    where response-value is calculated as above, using the values sent in
880    step two, except that if qop is "auth", then A2 is
882        A2 = { ":", digest-uri-value }
884    And if qop is "auth-int" or "auth-conf" then A2 is
886        A2 = { ":", digest-uri-value, ":00000000000000000000000000000000" }
888    Compared to its use in HTTP, the following Digest directives in the
889    "digest-response" are unused:
891        nextnonce
892        qop
893        cnonce
894        nonce-count
898 Leach & Newman            Expires: August 2003                 [Page 15]
904 INTERNET DRAFT            Digest SASL Mechanism            February 2003
907 2.2  Subsequent Authentication
909    If the client has previously authenticated to the server, and
910    remembers the values of username, realm, nonce, nonce-count, cnonce,
911    and qop that it used in that authentication, and the SASL profile for
912    a protocol permits an initial client response, then it MAY perform
913    "subsequent authentication", as defined in this section.
915 2.2.1  Step one
917    The client uses the values from the previous authentication and sends
918    an initial response with a string formatted and computed according to
919    the rules for a "digest-response", as defined above, but with a
920    nonce-count one greater than used in the last "digest-response".
922 2.2.2  Step Two
924    The server receives the "digest-response". If the server does not
925    support subsequent authentication, then it sends a
926    "digest-challenge", and authentication proceeds as in initial
927    authentication. If the server has no saved nonce and nonce-count from
928    a previous authentication, then it sends a "digest-challenge", and
929    authentication proceeds as in initial authentication. Otherwise, the
930    server validates the "digest-response", checks that the nonce-count
931    is one greater than that used in the previous authentication using
932    that nonce, and saves the new value of nonce-count.
934    If the response is invalid, then the server sends a
935    "digest-challenge", and authentication proceeds as in initial
936    authentication (and should be configurable to log an authentication
937    failure in some sort of security audit log, since the failure may be
938    a symptom of an attack). The nonce-count MUST NOT be incremented in
939    this case: to do so would allow a denial of service attack by sending
940    an out-of-order nonce-count.
942    If the response is valid, the server MAY choose to deem that
943    authentication has succeeded. However, if it has been too long since
944    the previous authentication, or for any other reason, the server MAY
945    send a new "digest-challenge" with a new value for nonce. The
946    challenge MAY contain a "stale" directive with value "true", which
947    says that the client may respond to the challenge using the password
948    it used in the previous response; otherwise, the client must solicit
949    the password anew from the user. This permits the server to make sure
950    that the user has presented their password recently. (The directive
951    name refers to the previous nonce being stale, not to the last use of
952    the password.) Except for the handling of "stale", after sending the
953    "digest-challenge" authentication proceeds as in the case of initial
954    authentication.
958 Leach & Newman            Expires: August 2003                 [Page 16]
964 INTERNET DRAFT            Digest SASL Mechanism            February 2003
967 2.3   Integrity Protection
969    If the server offered "qop=auth-int" and the client responded
970    "qop=auth-int", then subsequent messages, up to but not including the
971    next subsequent authentication, between the client and the server
972    MUST be integrity protected. Using as a base session key the value of
973    H(A1) as defined above the client and server calculate a pair of
974    message integrity keys as follows.
976    The key for integrity protecting messages from client to server is:
978    Kic = MD5({H(A1),
979    "Digest session key to client-to-server signing key magic constant"})
981    The key for integrity protecting messages from server to client is:
983    Kis = MD5({H(A1),
984    "Digest session key to server-to-client signing key magic constant"})
986    where MD5 is as specified in [RFC 1321]. If message integrity is
987    negotiated, a MAC block for each message is appended to the message.
988    The MAC block is 16 bytes: the first 10 bytes of the HMAC-MD5 [RFC
989    2104] of the message, a 2-byte message type number in network byte
990    order with value 1, and the 4-byte sequence number in network byte
991    order. The message type is to allow for future extensions such as
992    rekeying.
994    MAC(Ki, SeqNum, msg) = (HMAC(Ki, {SeqNum, msg})[0..9], 0x0001,
995    SeqNum)
997    where Ki is Kic for messages sent by the client and Kis for those
998    sent by the server. The sequence number is an unsigned number
999    initialized to zero after initial or subsequent authentication, and
1000    incremented by one for each message sent/successfully verified.
1001    (Note, that there are two independent counters for sending and
1002    receiving.) The sequence number wraps around to 0 after 2**32-1.
1004    Upon receipt, MAC(Ki, SeqNum, msg) is computed and compared with the
1005    received value; the message is discarded if they differ. The
1006    receiver's sequence counter is incremented if they match.
1009 2.4   Confidentiality Protection
1011    If the server sent a "cipher-opts" directive and the client responded
1012    with a "cipher" directive, then subsequent messages between the
1013    client and the server MUST be confidentiality protected. Using as a
1014    base session key the value of H(A1) as defined above the client and
1018 Leach & Newman            Expires: August 2003                 [Page 17]
1024 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1027    server calculate a pair of message integrity keys as follows.
1029    The key for confidentiality protecting messages from client to server
1030    is:
1032    Kcc = MD5({H(A1)[0..n-1],
1033    "Digest H(A1) to client-to-server sealing key magic constant"})
1035    The key for confidentiality protecting messages from server to client
1036    is:
1038    Kcs = MD5({H(A1)[0..n-1],
1039    "Digest H(A1) to server-to-client sealing key magic constant"})
1041    where MD5 is as specified in [RFC 1321]. For cipher "rc4-40" n is 5;
1042    for "rc4-56" n is 7; for the rest n is 16. The key for the "rc4-*"
1043    ciphers is all 16 bytes of Kcc or Kcs; the key for "des" is the first
1044    7 bytes; the key for "3des" is the first 14 bytes. The IV for "des"
1045    and "3des" is the last 8 bytes of Kcc or Kcs.
1047    The MAC block is a variable length padding prefix followed by 16
1048    bytes formatted as follows: the first 10 bytes of the HMAC-MD5 [RFC
1049    2104] of the message, a 2-byte message type number in network byte
1050    order with value 1, and the 4-byte sequence number in network byte
1051    order. If the blocksize of the chosen cipher is not 1 byte, the
1052    padding prefix is one or more octets each containing the number of
1053    padding bytes, such that total length of the encrypted part of the
1054    message is a multiple of the blocksize. The padding and first 10
1055    bytes of the MAC block are encrypted with the chosen cipher along
1056    with the message.
1058    SEAL(Ki, Kc, SeqNum, msg) =
1059          {CIPHER(Kc, {msg, pad, HMAC(Ki, {SeqNum, msg})[0..9]}), 0x0001,
1060           SeqNum}
1062    where CIPHER is the chosen cipher, Ki and Kc are Kic and Kcc for
1063    messages sent by the client and Kis and Kcs for those sent by the
1064    server. The sequence number is an unsigned number initialized to zero
1065    after initial or subsequent authentication, and incremented by one
1066    for each message sent/successfully verified. (Note, that there are
1067    two independent counters for sending and receiving.) The sequence
1068    number wraps around to 0 after 2**32-1.
1070    Upon receipt, the message is decrypted, HMAC(Ki, {SeqNum, msg}) is
1071    computed and compared with the received value; the message is
1072    discarded if they differ. The receiver's sequence counter is
1073    incremented if they match.
1078 Leach & Newman            Expires: August 2003                 [Page 18]
1084 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1087 3  Security Considerations
1089 3.1   Authentication of Clients using Digest Authentication
1091    Digest Authentication does not provide a strong authentication
1092    mechanism, when compared to public key based mechanisms, for example.
1093    However, since it prevents chosen plaintext attacks, it is stronger
1094    than (e.g.) CRAM-MD5, which has been proposed for use with ACAP [RFC
1095    2244], POP and IMAP [RFC 2195]. It is intended to replace the much
1096    weaker and even more dangerous use of plaintext passwords; however,
1097    since it is still a password based mechanism it avoids some of the
1098    potential deployabilty issues with public-key, OTP or similar
1099    mechanisms.
1101    Digest Authentication offers no confidentiality protection beyond
1102    protecting the actual password. All of the rest of the challenge and
1103    response are available to an eavesdropper, including the user's name
1104    and authentication realm.
1106 3.2   Comparison of Digest with Plaintext Passwords
1108    The greatest threat to the type of transactions for which these
1109    protocols are used is network snooping. This kind of transaction
1110    might involve, for example, online access to a mail service whose use
1111    is restricted to paying subscribers. With plaintext password
1112    authentication an eavesdropper can obtain the password of the user.
1113    This not only permits him to access anything in the database, but,
1114    often worse, will permit access to anything else the user protects
1115    with the same password.
1117 3.3   Replay Attacks
1119    Replay attacks are defeated if the client or the server chooses a
1120    fresh nonce for each authentication, as this specification requires.
1122    As a security precaution, the server, when verifying a response from
1123    the client, must use the original server nonce ("nonce") it sent, not
1124    the one returned by the client in the response, as it might have been
1125    modified by an attacker.
1127    To prevent some redirection attacks it is recommended that the server
1128    verifies that the "serv-type" part of the "digest-uri" matches the
1129    service name and that the hostname/IP address belongs to the server.
1131 3.4  Online dictionary attacks
1133    If the attacker can eavesdrop, then it can test any overheard
1134    nonce/response pairs against a (potentially very large) list of
1138 Leach & Newman            Expires: August 2003                 [Page 19]
1144 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1147    common words. Such a list is usually much smaller than the total
1148    number of possible passwords. The cost of computing the response for
1149    each password on the list is paid once for each challenge.
1151    The server can mitigate this attack by not allowing users to select
1152    passwords that are in a dictionary.
1154 3.5  Offline dictionary attacks
1156    If the attacker can choose the challenge, then it can precompute the
1157    possible responses to that challenge for a list of common words. Such
1158    a list is usually much smaller than the total number of possible
1159    passwords. The cost of computing the response for each password on
1160    the list is paid just once.
1162    Offline dictionary attacks are defeated if the client chooses a fresh
1163    nonce for each authentication, as this specification requires.
1165 3.6  Man in the Middle
1167    Digest authentication is vulnerable to "man in the middle" (MITM)
1168    attacks. Clearly, a MITM would present all the problems of
1169    eavesdropping. But it also offers some additional opportunities to
1170    the attacker.
1172    A possible man-in-the-middle attack would be to substitute a weaker
1173    qop scheme for the one(s) sent by the server; the server will not be
1174    able to detect this attack. For this reason, the client should always
1175    use the strongest scheme that it understands from the choices
1176    offered, and should never choose a scheme that does not meet its
1177    minimum requirements.
1179    A man-in-the-middle attack may also make the client and the server
1180    that agreed to use confidentiality protection to use different (and
1181    possibly weaker) cipher's. This is because the chosen cipher is not
1182    used in the shared secret calculation.
1184 3.7  Chosen plaintext attacks
1186    A chosen plaintext attack is where a MITM or a malicious server can
1187    arbitrarily choose the challenge that the client will use to compute
1188    the response. The ability to choose the challenge is known to make
1189    cryptanalysis much easier [MD5].
1191    However, Digest does not permit the attack to choose the challenge as
1192    long as the client chooses a fresh nonce for each authentication, as
1193    this specification requires.
1198 Leach & Newman            Expires: August 2003                 [Page 20]
1204 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1207 3.8  Spoofing by Counterfeit Servers
1209    If a user can be led to believe that she is connecting to a host
1210    containing information protected by a password she knows, when in
1211    fact she is connecting to a hostile server, then the hostile server
1212    can obtain challenge/response pairs where it was able to partly
1213    choose the challenge. There is no known way that this can be
1214    exploited.
1216 3.9  Storing passwords
1218    Digest authentication requires that the authenticating agent (usually
1219    the server) store some data derived from the user's name and password
1220    in a "password file" associated with a given realm. Normally this
1221    might contain pairs consisting of username and H({ username-value,
1222    ":", realm-value, ":", passwd }), which is adequate to compute H(A1)
1223    as described above without directly exposing the user's password.
1225    The security implications of this are that if this password file is
1226    compromised, then an attacker gains immediate access to documents on
1227    the server using this realm. Unlike, say a standard UNIX password
1228    file, this information need not be decrypted in order to access
1229    documents in the server realm associated with this file. On the other
1230    hand, decryption, or more likely a brute force attack, would be
1231    necessary to obtain the user's password. This is the reason that the
1232    realm is part of the digested data stored in the password file. It
1233    means that if one Digest authentication password file is compromised,
1234    it does not automatically compromise others with the same username
1235    and password (though it does expose them to brute force attack).
1237    There are two important security consequences of this. First the
1238    password file must be protected as if it contained plaintext
1239    passwords, because for the purpose of accessing documents in its
1240    realm, it effectively does.
1242    A second consequence of this is that the realm string should be
1243    unique among all realms that any single user is likely to use. In
1244    particular a realm string should include the name of the host doing
1245    the authentication.
1247 3.10  Multiple realms
1249    Use of multiple realms may mean both that compromise of a the
1250    security database for a single realm does not compromise all
1251    security, and that there are more things to protect in order to keep
1252    the whole system secure.
1258 Leach & Newman            Expires: August 2003                 [Page 21]
1264 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1267 3.11  Summary
1269    By modern cryptographic standards Digest Authentication is weak,
1270    compared to (say) public key based mechanisms. But for a large range
1271    of purposes it is valuable as a replacement for plaintext passwords.
1272    Its strength may vary depending on the implementation.
1275 4  Example
1277    This example shows the use of the Digest SASL mechanism with the
1278    IMAP4 AUTHENTICATE command [RFC 2060].
1280    In this example, "C:" and "S:" represent a line sent by the client or
1281    server respectively including a CRLF at the end.  Linebreaks and
1282    indentation within a "C:" or "S:" are editorial and not part of the
1283    protocol. The password in this example was "secret".  Note that the
1284    base64 encoding of the challenges and responses is part of the IMAP4
1285    AUTHENTICATE command, not part of the Digest specification itself.
1287     S: * OK elwood.innosoft.com PMDF IMAP4rev1 V6.0-9
1288     C: c CAPABILITY
1289     S: * CAPABILITY IMAP4 IMAP4rev1 ACL LITERAL+ NAMESPACE QUOTA
1290                 UIDPLUS AUTH=CRAM-MD5 AUTH=DIGEST-MD5 AUTH=PLAIN
1291     S: c OK Completed
1292     C: a AUTHENTICATE DIGEST-MD5
1293     S: + cmVhbG09ImVsd29vZC5pbm5vc29mdC5jb20iLG5vbmNlPSJPQTZNRzl0
1294          RVFHbTJoaCIscW9wPSJhdXRoIixhbGdvcml0aG09bWQ1LXNlc3MsY2hh
1295          cnNldD11dGYtOA==
1296     C: Y2hhcnNldD11dGYtOCx1c2VybmFtZT0iY2hyaXMiLHJlYWxtPSJlbHdvb2
1297        QuaW5ub3NvZnQuY29tIixub25jZT0iT0E2TUc5dEVRR20yaGgiLG5jPTAw
1298        MDAwMDAxLGNub25jZT0iT0E2TUhYaDZWcVRyUmsiLGRpZ2VzdC11cmk9Im
1299        ltYXAvZWx3b29kLmlubm9zb2Z0LmNvbSIscmVzcG9uc2U9ZDM4OGRhZDkw
1300        ZDRiYmQ3NjBhMTUyMzIxZjIxNDNhZjcscW9wPWF1dGg=
1301     S: + cnNwYXV0aD1lYTQwZjYwMzM1YzQyN2I1NTI3Yjg0ZGJhYmNkZmZmZA==
1302     C:
1303     S: a OK User logged in
1304     ---
1306     The base64-decoded version of the SASL exchange is:
1308     S: realm="elwood.innosoft.com",nonce="OA6MG9tEQGm2hh",qop="auth",
1309        algorithm=md5-sess,charset=utf-8
1310     C: charset=utf-8,username="chris",realm="elwood.innosoft.com",
1311        nonce="OA6MG9tEQGm2hh",nc=00000001,cnonce="OA6MHXh6VqTrRk",
1312        digest-uri="imap/elwood.innosoft.com",
1313        response=d388dad90d4bbd760a152321f2143af7,qop=auth
1314     S: rspauth=ea40f60335c427b5527b84dbabcdfffd
1318 Leach & Newman            Expires: August 2003                 [Page 22]
1324 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1327     The password in this example was "secret".
1329    This example shows the use of the Digest SASL mechanism with the
1330    ACAP, using the same notational conventions and password as in the
1331    previous example. Note that ACAP does not base64 encode and uses
1332    fewer round trips that IMAP4.
1334     S: * ACAP (IMPLEMENTATION "Test ACAP server") (SASL "CRAM-MD5"
1335                "DIGEST-MD5" "PLAIN")
1336     C: a AUTHENTICATE "DIGEST-MD5"
1337     S: + {94}
1338     S: realm="elwood.innosoft.com",nonce="OA9BSXrbuRhWay",qop="auth",
1339        algorithm=md5-sess,charset=utf-8
1340     C: {206}
1341     C: charset=utf-8,username="chris",realm="elwood.innosoft.com",
1342        nonce="OA9BSXrbuRhWay",nc=00000001,cnonce="OA9BSuZWMSpW8m",
1343        digest-uri="acap/elwood.innosoft.com",
1344        response=6084c6db3fede7352c551284490fd0fc,qop=auth
1345     S: a OK (SASL {40}
1346     S: rspauth=2f0b3d7c3c2e486600ef710726aa2eae) "AUTHENTICATE
1347     Completed"
1348     ---
1350    The server uses the values of all the directives, plus knowledge of
1351    the users password (or the hash of the user's name, server's realm
1352    and the user's password) to verify the computations above. If they
1353    check, then the user has authenticated.
1378 Leach & Newman            Expires: August 2003                 [Page 23]
1384 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1387 5   References
1389 5.1   Normative references
1391    [Digest]   Franks, J., et al., "HTTP Authentication: Basic and Digest
1392               Access Authentication", RFC 2617, June 1999.
1394    [ISO-8859] ISO-8859. International Standard--Information Processing--
1395               8-bit Single-Byte Coded Graphic Character Sets --
1396               Part 1: Latin alphabet No. 1, ISO-8859-1:1987.
1397               Part 2: Latin alphabet No. 2, ISO-8859-2, 1987.
1398               Part 3: Latin alphabet No. 3, ISO-8859-3, 1988.
1399               Part 4: Latin alphabet No. 4, ISO-8859-4, 1988.
1400               Part 5: Latin/Cyrillic alphabet, ISO-8859-5, 1988.
1401               Part 6: Latin/Arabic alphabet, ISO-8859-6, 1987.
1402               Part 7: Latin/Greek alphabet, ISO-8859-7, 1987.
1403               Part 8: Latin/Hebrew alphabet, ISO-8859-8, 1988.
1404               Part 9: Latin alphabet No. 5, ISO-8859-9, 1990.
1406    [RFC 822]  Crocker, D., "Standard for The Format of ARPA Internet
1407               Text Messages," STD 11, RFC 822, August 1982.
1409    [RFC 1321] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321,
1410               April 1992.
1412    [RFC 2052] Gulbrandsen, A. and P. Vixie, "A DNS RR for specifying the
1413               location of services (DNS SRV)", RFC 2052, October 1996.
1415    [RFC 2104] Krawczyk, H., Bellare, M. and R. Canetti, "HMAC: Keyed-
1416               Hashing for  Message Authentication", RFC 2104, February
1417               1997.
1438 Leach & Newman            Expires: August 2003                 [Page 24]
1444 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1447    [RFC 2119] Bradner, S., "Key words for use in RFCs to Indicate
1448               Requirement Levels", BCP 14, RFC 2119, March 1997.
1450    [RFC 2222] Myers, J., "Simple Authentication and Security Layer
1451               (SASL)", RFC 2222, October 1997.
1453    [UNICODE-NORMALIZATION] Davis, Durst, "Unicode Standard Annex #15:
1454               Unicode Normalization Forms",
1455               http://www.unicode.org/unicode/reports/tr15/, March 2001.
1457    [UTF-8] Yergeau, "UTF-8, a transformation format of ISO 10646", RFC
1458               2279, Janyary 1998.
1460    [USASCII]  US-ASCII. Coded Character Set - 7-Bit American Standard
1461               Code for Information Interchange. Standard ANSI X3.4-1986,
1462               ANSI, 1986.
1464    [RFC 2732]  Hinden, R., Carpenter, B., Masinter, L., "Format for
1465               Literal IPv6 Addresses in URL's", RFC 2732, December 1999.
1467    [RFC 2373] Hinden, R., Deering, S., "IP Version 6 Addressing
1468               Architecture", RFC 2373, July 1998.
1470    [RFC 2396] Berners-Lee, T., Fielding, R., Masinter, L., "Uniform
1471               Resource Identifiers (URI): Generic Syntax", RFC 2396,
1472               August 1998.
1475 5.2   Informative references
1477    [RFC 2195] Klensin, J., Catoe, R. and P. Krumviede, "IMAP/POP
1478               AUTHorize Extension for Simple Challenge/Response", RFC
1479               2195, September 1997.
1481    [MD5]  Kaliski, B.,Robshaw, M., "Message Authentication with MD5",
1482               CryptoBytes, Sping 1995, RSA Inc,
1483               (http://www.rsa.com/rsalabs/pubs/cryptobytes/spring95/md5.htm)
1485    [RFC 2078] Linn, J., "Generic Security Service Application Program
1486               Interface, Version 2", RFC 2078, January 1997.
1488    [RFC 2060] Crispin, M., "Internet Message Access Protocol - Version
1489               4rev1", RFC 2060, December 1996.
1491    [RFC 2244] Newman, C., Myers, J., "ACAP -- Application Configuration
1492               Access Protocol", RFC 2244, November 1997.
1498 Leach & Newman            Expires: August 2003                 [Page 25]
1504 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1507    [RFC 2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H.,
1508               Masinter, L., Leach, P., Berners-Lee, T., "Hypertext
1509               Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999.
1512 6  Authors' Addresses
1514    Paul Leach
1515    Microsoft
1516    1 Microsoft Way
1517    Redmond, WA  98052
1519    EMail: paulle@microsoft.com
1522    Chris Newman
1523    Innosoft International, Inc.
1524    1050 Lakes Drive
1525    West Covina, CA 91790 USA
1527    EMail: chris.newman@innosoft.com
1530    Alexey Melnikov
1531    ACI WorldWide/MessagingDirect
1532    59 Clarendon Road, Watford, Hertfordshire, WD17 1FQ, UK
1534    Email: mel@messagingdirect.com
1558 Leach & Newman            Expires: August 2003                 [Page 26]
1564 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1567 7  ABNF
1569    What follows is the definition of the notation as is used in the
1570    HTTP/1.1 specification [RFC 2616] and the HTTP authentication
1571    specification [Digest]; it is reproduced here for ease of reference.
1572    Since it is intended that a single Digest implementation can support
1573    both HTTP and SASL-based protocols, the same notation is used in both
1574    to facilitate comparison and prevention of unwanted differences.
1575    Since it is cut-and-paste from the HTTP specifications, not all
1576    productions may be used in this specification. It is also not quite
1577    legal ABNF; again, the errors were copied from the HTTP
1578    specifications.
1580 7.1   Augmented BNF
1582    All of the mechanisms specified in this document are described in
1583    both prose and an augmented Backus-Naur Form (BNF) similar to that
1584    used by RFC 822 [RFC 822]. Implementers will need to be familiar with
1585    the notation in order to understand this specification.
1587    The augmented BNF includes the following constructs:
1589    name = definition
1590       The name of a rule is simply the name itself (without any
1591       enclosing "<" and ">") and is separated from its definition by the
1592       equal "=" character. White space is only significant in that
1593       indentation of continuation lines is used to indicate a rule
1594       definition that spans more than one line. Certain basic rules are
1595       in uppercase, such as SP, LWS, HT, CRLF, DIGIT, ALPHA, etc. Angle
1596       brackets are used within definitions whenever their presence will
1597       facilitate discerning the use of rule names.
1599    "literal"
1600       Quotation marks surround literal text. Unless stated otherwise,
1601       the text is case-insensitive.
1603    rule1 | rule2
1604       Elements separated by a bar ("|") are alternatives, e.g., "yes |
1605       no" will accept yes or no.
1607    (rule1 rule2)
1608       Elements enclosed in parentheses are treated as a single element.
1609       Thus, "(elem (foo | bar) elem)" allows the token sequences
1610       "elem foo elem" and "elem bar elem".
1612    *rule
1613       The character "*" preceding an element indicates repetition. The
1614       full form is "<n>*<m>element" indicating at least <n> and at most
1618 Leach & Newman            Expires: August 2003                 [Page 27]
1624 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1627       <m> occurrences of element. Default values are 0 and infinity so
1628       that "*(element)" allows any number, including zero; "1*element"
1629       requires at least one; and "1*2element" allows one or two.
1631    [rule]
1632       Square brackets enclose optional elements; "[foo bar]" is
1633       equivalent to "*1(foo bar)".
1635    N rule
1636       Specific repetition: "<n>(element)" is equivalent to
1637       "<n>*<n>(element)"; that is, exactly <n> occurrences of (element).
1638       Thus 2DIGIT is a 2-digit number, and 3ALPHA is a string of three
1639       alphabetic characters.
1641    #rule
1642       A construct "#" is defined, similar to "*", for defining lists of
1643       elements. The full form is "<n>#<m>element" indicating at least
1644       <n> and at most <m> elements, each separated by one or more commas
1645       (",") and OPTIONAL linear white space (LWS). This makes the usual
1646       form of lists very easy; a rule such as
1647         ( *LWS element *( *LWS "," *LWS element ))
1648       can be shown as
1649         1#element
1650       Wherever this construct is used, null elements are allowed, but do
1651       not contribute to the count of elements present. That is,
1652       "(element), , (element) " is permitted, but counts as only two
1653       elements.  Therefore, where at least one element is required, at
1654       least one non-null element MUST be present. Default values are 0
1655       and infinity so that "#element" allows any number, including zero;
1656       "1#element" requires at least one; and "1#2element" allows one or
1657       two.
1659    ; comment
1660       A semi-colon, set off some distance to the right of rule text,
1661       starts a comment that continues to the end of line. This is a
1662       simple way of including useful notes in parallel with the
1663       specifications.
1665    implied *LWS
1666       The grammar described by this specification is word-based. Except
1667       where noted otherwise, linear white space (LWS) can be included
1668       between any two adjacent words (token or quoted-string), and
1669       between adjacent words and separators, without changing the
1670       interpretation of a field. At least one delimiter (LWS and/or
1671       separators) MUST exist between any two tokens (for the definition
1672       of "token" below), since they would otherwise be interpreted as a
1673       single token.
1678 Leach & Newman            Expires: August 2003                 [Page 28]
1684 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1687 7.2   Basic Rules
1689    The following rules are used throughout this specification to
1690    describe basic parsing constructs. The US-ASCII coded character set
1691    is defined by ANSI X3.4-1986 [USASCII].
1693        OCTET          = <any 8-bit character>
1694        CHAR           = <any US-ASCII character (octets 0 - 127)>
1695        UPALPHA        = <any US-ASCII uppercase letter "A".."Z">
1696        LOALPHA        = <any US-ASCII lowercase letter "a".."z">
1697        ALPHA          = UPALPHA | LOALPHA
1698        DIGIT          = <any US-ASCII digit "0".."9">
1699        CTL            = <any US-ASCII control character
1700                         (octets 0 - 31) and DEL (127)>
1701        CR             = <US-ASCII CR, carriage return (13)>
1702        LF             = <US-ASCII LF, linefeed (10)>
1703        SP             = <US-ASCII SP, space (32)>
1704        HT             = <US-ASCII HT, horizontal-tab (9)>
1705        <">            = <US-ASCII double-quote mark (34)>
1706        TEXTCHAR       = <any OCTET except CTLs, but including HT>
1707        CRLF           = CR LF
1709    All linear white space, including folding, has the same semantics as
1710    SP.  A recipient MAY replace any linear white space with a single SP
1711    before interpreting the field value or forwarding the message
1712    downstream.
1714        LWS            = [CRLF] 1*( SP | HT )
1716    The TEXT rule is only used for descriptive field contents and values
1717    that are not intended to be interpreted by the message parser. Words
1718    of TEXT contains characters either from ISO-8859-1 [ISO-8859]
1719    character set or UTF-8 [UTF-8].
1721        TEXT           = <any *OCTET except CTLs,
1722                         but including LWS>
1724    A CRLF is allowed in the definition of TEXT only as part of a header
1725    field continuation. It is expected that the folding LWS will be
1726    replaced with a single SP before interpretation of the TEXT value.
1728    Hexadecimal numeric characters are used in several protocol elements.
1730        HEX            = "A" | "B" | "C" | "D" | "E" | "F"
1731                       | "a" | "b" | "c" | "d" | "e" | "f" | DIGIT
1733    Many HTTP/1.1 header field values consist of words separated by LWS
1734    or special characters. These special characters MUST be in a quoted
1738 Leach & Newman            Expires: August 2003                 [Page 29]
1744 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1747    string to be used within a parameter value.
1749        token          = 1*TOKENCHAR
1750        separators     = "(" | ")" | "<" | ">" | "@"
1751                       | "," | ";" | ":" | "\" | <">
1752                       | "/" | "[" | "]" | "?" | "="
1753                       | "{" | "}" | SP | HT
1754        TOKENCHAR      = <any CHAR except CTLs or separators>
1756    A string of text is parsed as a single word if it is quoted using
1757    double-quote marks.
1759        quoted-string  = ( <"> qdstr-val <"> )
1760        qdstr-val      = *( qdtext | quoted-pair )
1761        qdtext         = <any TEXTCHAR except <"> and "\">
1763    Note that LWS is NOT implicit between the double-quote marks (<">)
1764    surrounding a qdstr-val and the qdstr-val; any LWS will be considered
1765    part of the qdstr-val.  This is also the case for quotation marks
1766    surrounding any other construct.
1768    The backslash character ("\") MAY be used as a single-character
1769    quoting mechanism only within qdstr-val and comment constructs.
1771        quoted-pair    = "\" CHAR
1773    The value of this construct is CHAR. Note that an effect of this rule
1774    is that backslash itself MUST be quoted.
1798 Leach & Newman            Expires: August 2003                 [Page 30]
1804 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1807 8  Sample Code
1809    The sample implementation in [Digest] also applies to DIGEST-MD5.
1811    The following code implements the conversion from UTF-8 to 8859-1 if
1812    necessary.
1814     /* if the string is entirely in the 8859-1 subset of UTF-8, then
1815      * translate to 8859-1 prior to MD5
1816      */
1817     void MD5_UTF8_8859_1(MD5_CTX *ctx, const unsigned char *base,
1818         int len)
1819     {
1820         const unsigned char *scan, *end;
1821         unsigned char cbuf;
1823         end = base + len;
1824         for (scan = base; scan < end; ++scan) {
1825             if (*scan > 0xC3) break; /* abort if outside 8859-1 */
1826             if (*scan >= 0xC0 && *scan <= 0xC3) {
1827                 if (++scan == end || *scan < 0x80 || *scan > 0xBF)
1828                     break;
1829             }
1830         }
1831         /* if we found a character outside 8859-1, don't alter string
1832          */
1833         if (scan < end) {
1834             MD5Update(ctx, base, len);
1835             return;
1836         }
1838         /* convert to 8859-1 prior to applying hash
1839          */
1840         do {
1841             for (scan = base; scan < end && *scan < 0xC0; ++scan)
1842                 ;
1843             if (scan != base) MD5Update(ctx, base, scan - base);
1844             if (scan + 1 >= end) break;
1845             cbuf = ((scan[0] & 0x3) << 6) | (scan[1] & 0x3f);
1846             MD5Update(ctx, &cbuf, 1);
1847             base = scan + 2;
1848         } while (base < end);
1849     }
1858 Leach & Newman            Expires: August 2003                 [Page 31]
1864 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1867 9   Interoperability considerations
1869    9.1 Implementing DES cipher in CBC mode
1871    Several cryptographic libraries (Ebones, OpenSSL) provide a convenience
1872    function des_cbc_encrypt for implementing DES cipher in CBC mode.
1873    There is a documented bug in this function: the function doesn't update
1874    IV before returning. If an implementation uses this function to implement
1875    DES cipher in CBC mode, it MUST update IV by copying the last 8 bytes of
1876    the des_cbc_encrypt's output to the IV buffer.
1878    Note that the function des_ede2_cbc_encrypt that may be used to implement
1879    3DES (in "two keys mode") in CBC mode works as expected.
1882 10  Acknowledgements
1884    The following people had substantial contributions to the development
1885    and refinement of this document:
1887    Lawrence Greenfield
1888    John Gardiner Myers
1889    Simon Josefsson
1890    "RL 'Bob' Morgan"
1891    Jeff Hodges
1892    Claus Assmann
1893    Tony Hansen
1895    as well as other members of SASL mailing list.
1918 Leach & Newman            Expires: August 2003                 [Page 32]
1924 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1927 11  Full Copyright Statement
1929    Copyright (C) The Internet Society (2003).  All Rights Reserved.
1931    This document and translations of it may be copied and furnished to
1932    others, and derivative works that comment on or otherwise explain it
1933    or assist in its implementation may be prepared, copied, published
1934    and distributed, in whole or in part, without restriction of any
1935    kind, provided that the above copyright notice and this paragraph are
1936    included on all such copies and derivative works.  However, this
1937    document itself may not be modified in any way, such as by removing
1938    the copyright notice or references to the Internet Society or other
1939    Internet organizations, except as needed for the purpose of
1940    developing Internet standards in which case the procedures for
1941    copyrights defined in the Internet Standards process must be
1942    followed, or as required to translate it into languages other than
1943    English.
1945    The limited permissions granted above are perpetual and will not be
1946    revoked by the Internet Society or its successors or assigns.
1948    This document and the information contained herein is provided on an
1949    "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
1950    TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
1951    BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
1952    HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
1953    MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
1955 Acknowledgement
1957    Funding for the RFC Editor function is currently provided by the
1958    Internet Society.
1978 Leach & Newman            Expires: August 2003                 [Page 33]
1984 INTERNET DRAFT            Digest SASL Mechanism            February 2003
1987 Appendix A: Changes from 2831
1989    1). Fixed various typos in formulas.
1991    2). Dropped DES as mandatory to implement cipher (3DES is mandatory
1992    to implement).
1994    3). Tighten ABNF. Fixed some bugs.
1996    4). Clarified nc-value verification and which side is aborting
1997    exchange.
1999    5). Added text saying that for interoperability username/password
2000    MUST be normalized according to Normalization form KC.
2002    6). Clarified that unquoted version of the username, etc. used in A1
2003    calculation.
2005    7). Various cleanup to References section. Split all references to
2006    Normative and Informative.
2008    8). Added minimal and maximal limits on maxbuf. Clarified how to
2009    calculate max sender size.
2011    9). Change ABNF for host to allow for IPv6 addresses. ABNF now
2012    references RFC 2373 and RFC 2396.
2014    10). Added DES cipher interoperability section.
2016    11). Added man-in-the-middle considerations for ciphers.
2018    12). Clarified how sequence counters are modified.
2020    13). Addition warnings about preventing reply/redirection attacks.
2022    14). Specified that "charset" directive affects "realm" and doesn't
2023    affect
2024         "authzid".
2026    15). Minor text clarifications.
2028 Appendix B: Open Issues
2030    1). The latest revision prohibits escaped characters in nonce/cnonce.
2031    Any objections?
2033    2). What to do about CBC mode attack that affects TLS document and
2034    DIGEST-MD5 as well?
2038 Leach & Newman            Expires: August 2003                 [Page 34]
2044 INTERNET DRAFT            Digest SASL Mechanism            February 2003
2047    One of the proposals is to drop DES/3DES ciphers and define a new one
2048    (e.g. AES) in such a way that is not susceptible to this kind of
2049    attack.
2051    3). Merge DIGEST-MD5 AES cipher with this document?
2053    4). Normative vs. Informative references must be carefully rechecked.
2098 Leach & Newman            Expires: August 2003                 [Page 35]