rfc2831.Obsolete_Digest_AUTHentication_as_a_SASL_mech.txt 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  1. Network Working Group P. Leach
  2. Request for Comments: 2831 Microsoft
  3. Category: Standards Track C. Newman
  4. Innosoft
  5. May 2000
  6. Using Digest Authentication as a SASL Mechanism
  7. Status of this Memo
  8. This document specifies an Internet standards track protocol for the
  9. Internet community, and requests discussion and suggestions for
  10. improvements. Please refer to the current edition of the "Internet
  11. Official Protocol Standards" (STD 1) for the standardization state
  12. and status of this protocol. Distribution of this memo is unlimited.
  13. Copyright Notice
  14. Copyright (C) The Internet Society (2000). All Rights Reserved.
  15. Abstract
  16. This specification defines how HTTP Digest Authentication [Digest]
  17. can be used as a SASL [RFC 2222] mechanism for any protocol that has
  18. a SASL profile. It is intended both as an improvement over CRAM-MD5
  19. [RFC 2195] and as a convenient way to support a single authentication
  20. mechanism for web, mail, LDAP, and other protocols.
  21. Table of Contents
  22. 1 INTRODUCTION.....................................................2
  23. 1.1 CONVENTIONS AND NOTATION......................................2
  24. 1.2 REQUIREMENTS..................................................3
  25. 2 AUTHENTICATION...................................................3
  26. 2.1 INITIAL AUTHENTICATION........................................3
  27. 2.1.1 Step One...................................................3
  28. 2.1.2 Step Two...................................................6
  29. 2.1.3 Step Three................................................12
  30. 2.2 SUBSEQUENT AUTHENTICATION....................................12
  31. 2.2.1 Step one..................................................13
  32. 2.2.2 Step Two..................................................13
  33. 2.3 INTEGRITY PROTECTION.........................................13
  34. 2.4 CONFIDENTIALITY PROTECTION...................................14
  35. 3 SECURITY CONSIDERATIONS.........................................15
  36. 3.1 AUTHENTICATION OF CLIENTS USING DIGEST AUTHENTICATION........15
  37. 3.2 COMPARISON OF DIGEST WITH PLAINTEXT PASSWORDS................16
  38. 3.3 REPLAY ATTACKS...............................................16
  39. Leach & Newman Standards Track [Page 1]
  40. RFC 2831 Digest SASL Mechanism May 2000
  41. 3.4 ONLINE DICTIONARY ATTACKS....................................16
  42. 3.5 OFFLINE DICTIONARY ATTACKS...................................16
  43. 3.6 MAN IN THE MIDDLE............................................17
  44. 3.7 CHOSEN PLAINTEXT ATTACKS.....................................17
  45. 3.8 SPOOFING BY COUNTERFEIT SERVERS..............................17
  46. 3.9 STORING PASSWORDS............................................17
  47. 3.10 MULTIPLE REALMS.............................................18
  48. 3.11 SUMMARY.....................................................18
  49. 4 EXAMPLE.........................................................18
  50. 5 REFERENCES......................................................20
  51. 6 AUTHORS' ADDRESSES..............................................21
  52. 7 ABNF............................................................21
  53. 7.1 AUGMENTED BNF................................................21
  54. 7.2 BASIC RULES..................................................23
  55. 8 SAMPLE CODE.....................................................25
  56. 9 FULL COPYRIGHT STATEMENT........................................27
  57. 1 Introduction
  58. This specification describes the use of HTTP Digest Access
  59. Authentication as a SASL mechanism. The authentication type
  60. associated with the Digest SASL mechanism is "DIGEST-MD5".
  61. This specification is intended to be upward compatible with the
  62. "md5-sess" algorithm of HTTP/1.1 Digest Access Authentication
  63. specified in [Digest]. The only difference in the "md5-sess"
  64. algorithm is that some directives not needed in a SASL mechanism have
  65. had their values defaulted.
  66. There is one new feature for use as a SASL mechanism: integrity
  67. protection on application protocol messages after an authentication
  68. exchange.
  69. Also, compared to CRAM-MD5, DIGEST-MD5 prevents chosen plaintext
  70. attacks, and permits the use of third party authentication servers,
  71. mutual authentication, and optimized reauthentication if a client has
  72. recently authenticated to a server.
  73. 1.1 Conventions and Notation
  74. This specification uses the same ABNF notation and lexical
  75. conventions as HTTP/1.1 specification; see appendix A.
  76. Let { a, b, ... } be the concatenation of the octet strings a, b, ...
  77. Let H(s) be the 16 octet MD5 hash [RFC 1321] of the octet string s.
  78. Leach & Newman Standards Track [Page 2]
  79. RFC 2831 Digest SASL Mechanism May 2000
  80. Let KD(k, s) be H({k, ":", s}), i.e., the 16 octet hash of the string
  81. k, a colon and the string s.
  82. Let HEX(n) be the representation of the 16 octet MD5 hash n as a
  83. string of 32 hex digits (with alphabetic characters always in lower
  84. case, since MD5 is case sensitive).
  85. Let HMAC(k, s) be the 16 octet HMAC-MD5 [RFC 2104] of the octet
  86. string s using the octet string k as a key.
  87. The value of a quoted string constant as an octet string does not
  88. include any terminating null character.
  89. 1.2 Requirements
  90. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
  91. "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
  92. document are to be interpreted as described in RFC 2119 [RFC 2119].
  93. An implementation is not compliant if it fails to satisfy one or more
  94. of the MUST level requirements for the protocols it implements. An
  95. implementation that satisfies all the MUST level and all the SHOULD
  96. level requirements for its protocols is said to be "unconditionally
  97. compliant"; one that satisfies all the MUST level requirements but
  98. not all the SHOULD level requirements for its protocols is said to be
  99. "conditionally compliant."
  100. 2 Authentication
  101. The following sections describe how to use Digest as a SASL
  102. authentication mechanism.
  103. 2.1 Initial Authentication
  104. If the client has not recently authenticated to the server, then it
  105. must perform "initial authentication", as defined in this section. If
  106. it has recently authenticated, then a more efficient form is
  107. available, defined in the next section.
  108. 2.1.1 Step One
  109. The server starts by sending a challenge. The data encoded in the
  110. challenge contains a string formatted according to the rules for a
  111. "digest-challenge" defined as follows:
  112. Leach & Newman Standards Track [Page 3]
  113. RFC 2831 Digest SASL Mechanism May 2000
  114. digest-challenge =
  115. 1#( realm | nonce | qop-options | stale | maxbuf | charset
  116. algorithm | cipher-opts | auth-param )
  117. realm = "realm" "=" <"> realm-value <">
  118. realm-value = qdstr-val
  119. nonce = "nonce" "=" <"> nonce-value <">
  120. nonce-value = qdstr-val
  121. qop-options = "qop" "=" <"> qop-list <">
  122. qop-list = 1#qop-value
  123. qop-value = "auth" | "auth-int" | "auth-conf" |
  124. token
  125. stale = "stale" "=" "true"
  126. maxbuf = "maxbuf" "=" maxbuf-value
  127. maxbuf-value = 1*DIGIT
  128. charset = "charset" "=" "utf-8"
  129. algorithm = "algorithm" "=" "md5-sess"
  130. cipher-opts = "cipher" "=" <"> 1#cipher-value <">
  131. cipher-value = "3des" | "des" | "rc4-40" | "rc4" |
  132. "rc4-56" | token
  133. auth-param = token "=" ( token | quoted-string )
  134. The meanings of the values of the directives used above are as
  135. follows:
  136. realm
  137. Mechanistically, a string which can enable users to know which
  138. username and password to use, in case they might have different
  139. ones for different servers. Conceptually, it is the name of a
  140. collection of accounts that might include the user's account. This
  141. string should contain at least the name of the host performing the
  142. authentication and might additionally indicate the collection of
  143. users who might have access. An example might be
  144. "registered_users@gotham.news.example.com". This directive is
  145. optional; if not present, the client SHOULD solicit it from the
  146. user or be able to compute a default; a plausible default might be
  147. the realm supplied by the user when they logged in to the client
  148. system. Multiple realm directives are allowed, in which case the
  149. user or client must choose one as the realm for which to supply to
  150. username and password.
  151. nonce
  152. A server-specified data string which MUST be different each time a
  153. digest-challenge is sent as part of initial authentication. It is
  154. recommended that this string be base64 or hexadecimal data. Note
  155. that since the string is passed as a quoted string, the
  156. double-quote character is not allowed unless escaped (see section
  157. 7.2). The contents of the nonce are implementation dependent. The
  158. Leach & Newman Standards Track [Page 4]
  159. RFC 2831 Digest SASL Mechanism May 2000
  160. security of the implementation depends on a good choice. It is
  161. RECOMMENDED that it contain at least 64 bits of entropy. The nonce
  162. is opaque to the client. This directive is required and MUST
  163. appear exactly once; if not present, or if multiple instances are
  164. present, the client should abort the authentication exchange.
  165. qop-options
  166. A quoted string of one or more tokens indicating the "quality of
  167. protection" values supported by the server. The value "auth"
  168. indicates authentication; the value "auth-int" indicates
  169. authentication with integrity protection; the value "auth-conf"
  170. indicates authentication with integrity protection and encryption.
  171. This directive is optional; if not present it defaults to "auth".
  172. The client MUST ignore unrecognized options; if the client
  173. recognizes no option, it should abort the authentication exchange.
  174. stale
  175. The "stale" directive is not used in initial authentication. See
  176. the next section for its use in subsequent authentications. This
  177. directive may appear at most once; if multiple instances are
  178. present, the client should abort the authentication exchange.
  179. maxbuf
  180. A number indicating the size of the largest buffer the server is
  181. able to receive when using "auth-int" or "auth-conf". If this
  182. directive is missing, the default value is 65536. This directive
  183. may appear at most once; if multiple instances are present, the
  184. client should abort the authentication exchange.
  185. charset
  186. This directive, if present, specifies that the server supports
  187. UTF-8 encoding for the username and password. If not present, the
  188. username and password must be encoded in ISO 8859-1 (of which
  189. US-ASCII is a subset). The directive is needed for backwards
  190. compatibility with HTTP Digest, which only supports ISO 8859-1.
  191. This directive may appear at most once; if multiple instances are
  192. present, the client should abort the authentication exchange.
  193. algorithm
  194. This directive is required for backwards compatibility with HTTP
  195. Digest., which supports other algorithms. . This directive is
  196. required and MUST appear exactly once; if not present, or if
  197. multiple instances are present, the client should abort the
  198. authentication exchange.
  199. Leach & Newman Standards Track [Page 5]
  200. RFC 2831 Digest SASL Mechanism May 2000
  201. cipher-opts
  202. A list of ciphers that the server supports. This directive must be
  203. present exactly once if "auth-conf" is offered in the
  204. "qop-options" directive, in which case the "3des" and "des" modes
  205. are mandatory-to-implement. The client MUST ignore unrecognized
  206. options; if the client recognizes no option, it should abort the
  207. authentication exchange.
  208. des
  209. the Data Encryption Standard (DES) cipher [FIPS] in cipher
  210. block chaining (CBC) mode with a 56 bit key.
  211. 3des
  212. the "triple DES" cipher in CBC mode with EDE with the same key
  213. for each E stage (aka "two keys mode") for a total key length
  214. of 112 bits.
  215. rc4, rc4-40, rc4-56
  216. the RC4 cipher with a 128 bit, 40 bit, and 56 bit key,
  217. respectively.
  218. auth-param This construct allows for future extensions; it may appear
  219. more than once. The client MUST ignore any unrecognized
  220. directives.
  221. For use as a SASL mechanism, note that the following changes are made
  222. to "digest-challenge" from HTTP: the following Digest options (called
  223. "directives" in HTTP terminology) are unused (i.e., MUST NOT be sent,
  224. and MUST be ignored if received):
  225. opaque
  226. domain
  227. The size of a digest-challenge MUST be less than 2048 bytes.
  228. 2.1.2 Step Two
  229. The client makes note of the "digest-challenge" and then responds
  230. with a string formatted and computed according to the rules for a
  231. "digest-response" defined as follows:
  232. Leach & Newman Standards Track [Page 6]
  233. RFC 2831 Digest SASL Mechanism May 2000
  234. digest-response = 1#( username | realm | nonce | cnonce |
  235. nonce-count | qop | digest-uri | response |
  236. maxbuf | charset | cipher | authzid |
  237. auth-param )
  238. username = "username" "=" <"> username-value <">
  239. username-value = qdstr-val
  240. cnonce = "cnonce" "=" <"> cnonce-value <">
  241. cnonce-value = qdstr-val
  242. nonce-count = "nc" "=" nc-value
  243. nc-value = 8LHEX
  244. qop = "qop" "=" qop-value
  245. digest-uri = "digest-uri" "=" <"> digest-uri-value <">
  246. digest-uri-value = serv-type "/" host [ "/" serv-name ]
  247. serv-type = 1*ALPHA
  248. host = 1*( ALPHA | DIGIT | "-" | "." )
  249. serv-name = host
  250. response = "response" "=" response-value
  251. response-value = 32LHEX
  252. LHEX = "0" | "1" | "2" | "3" |
  253. "4" | "5" | "6" | "7" |
  254. "8" | "9" | "a" | "b" |
  255. "c" | "d" | "e" | "f"
  256. cipher = "cipher" "=" cipher-value
  257. authzid = "authzid" "=" <"> authzid-value <">
  258. authzid-value = qdstr-val
  259. username
  260. The user's name in the specified realm, encoded according to the
  261. value of the "charset" directive. This directive is required and
  262. MUST be present exactly once; otherwise, authentication fails.
  263. realm
  264. The realm containing the user's account. This directive is
  265. required if the server provided any realms in the
  266. "digest-challenge", in which case it may appear exactly once and
  267. its value SHOULD be one of those realms. If the directive is
  268. missing, "realm-value" will set to the empty string when computing
  269. A1 (see below for details).
  270. nonce
  271. The server-specified data string received in the preceding
  272. digest-challenge. This directive is required and MUST be present
  273. exactly once; otherwise, authentication fails.
  274. Leach & Newman Standards Track [Page 7]
  275. RFC 2831 Digest SASL Mechanism May 2000
  276. cnonce
  277. A client-specified data string which MUST be different each time a
  278. digest-response is sent as part of initial authentication. The
  279. cnonce-value is an opaque quoted string value provided by the
  280. client and used by both client and server to avoid chosen
  281. plaintext attacks, and to provide mutual authentication. The
  282. security of the implementation depends on a good choice. It is
  283. RECOMMENDED that it contain at least 64 bits of entropy. This
  284. directive is required and MUST be present exactly once; otherwise,
  285. authentication fails.
  286. nonce-count
  287. The nc-value is the hexadecimal count of the number of requests
  288. (including the current request) that the client has sent with the
  289. nonce value in this request. For example, in the first request
  290. sent in response to a given nonce value, the client sends
  291. "nc=00000001". The purpose of this directive is to allow the
  292. server to detect request replays by maintaining its own copy of
  293. this count - if the same nc-value is seen twice, then the request
  294. is a replay. See the description below of the construction of
  295. the response value. This directive may appear at most once; if
  296. multiple instances are present, the client should abort the
  297. authentication exchange.
  298. qop
  299. Indicates what "quality of protection" the client accepted. If
  300. present, it may appear exactly once and its value MUST be one of
  301. the alternatives in qop-options. If not present, it defaults to
  302. "auth". These values affect the computation of the response. Note
  303. that this is a single token, not a quoted list of alternatives.
  304. serv-type
  305. Indicates the type of service, such as "www" for web service,
  306. "ftp" for FTP service, "smtp" for mail delivery service, etc. The
  307. service name as defined in the SASL profile for the protocol see
  308. section 4 of [RFC 2222], registered in the IANA registry of
  309. "service" elements for the GSSAPI host-based service name form
  310. [RFC 2078].
  311. host
  312. The DNS host name or IP address for the service requested. The
  313. DNS host name must be the fully-qualified canonical name of the
  314. host. The DNS host name is the preferred form; see notes on server
  315. processing of the digest-uri.
  316. Leach & Newman Standards Track [Page 8]
  317. RFC 2831 Digest SASL Mechanism May 2000
  318. serv-name
  319. Indicates the name of the service if it is replicated. The service
  320. is considered to be replicated if the client's service-location
  321. process involves resolution using standard DNS lookup operations,
  322. and if these operations involve DNS records (such as SRV, or MX)
  323. which resolve one DNS name into a set of other DNS names. In this
  324. case, the initial name used by the client is the "serv-name", and
  325. the final name is the "host" component. For example, the incoming
  326. mail service for "example.com" may be replicated through the use
  327. of MX records stored in the DNS, one of which points at an SMTP
  328. server called "mail3.example.com"; it's "serv-name" would be
  329. "example.com", it's "host" would be "mail3.example.com". If the
  330. service is not replicated, or the serv-name is identical to the
  331. host, then the serv-name component MUST be omitted.
  332. digest-uri
  333. Indicates the principal name of the service with which the client
  334. wishes to connect, formed from the serv-type, host, and serv-name.
  335. For example, the FTP service on "ftp.example.com" would have a
  336. "digest-uri" value of "ftp/ftp.example.com"; the SMTP server from
  337. the example above would have a "digest-uri" value of
  338. "smtp/mail3.example.com/example.com".
  339. Servers SHOULD check that the supplied value is correct. This will
  340. detect accidental connection to the incorrect server. It is also so
  341. that clients will be trained to provide values that will work with
  342. implementations that use a shared back-end authentication service
  343. that can provide server authentication.
  344. The serv-type component should match the service being offered. The
  345. host component should match one of the host names of the host on
  346. which the service is running, or it's IP address. Servers SHOULD NOT
  347. normally support the IP address form, because server authentication
  348. by IP address is not very useful; they should only do so if the DNS
  349. is unavailable or unreliable. The serv-name component should match
  350. one of the service's configured service names.
  351. This directive may appear at most once; if multiple instances are
  352. present, the client should abort the authentication exchange.
  353. Note: In the HTTP use of Digest authentication, the digest-uri is the
  354. URI (usually a URL) of the resource requested -- hence the name of
  355. the directive.
  356. response
  357. A string of 32 hex digits computed as defined below, which proves
  358. that the user knows a password. This directive is required and
  359. MUST be present exactly once; otherwise, authentication fails.
  360. Leach & Newman Standards Track [Page 9]
  361. RFC 2831 Digest SASL Mechanism May 2000
  362. maxbuf
  363. A number indicating the size of the largest buffer the client is
  364. able to receive. If this directive is missing, the default value
  365. is 65536. This directive may appear at most once; if multiple
  366. instances are present, the server should abort the authentication
  367. exchange.
  368. charset
  369. This directive, if present, specifies that the client has used
  370. UTF-8 encoding for the username and password. If not present, the
  371. username and password must be encoded in ISO 8859-1 (of which
  372. US-ASCII is a subset). The client should send this directive only
  373. if the server has indicated it supports UTF-8. The directive is
  374. needed for backwards compatibility with HTTP Digest, which only
  375. supports ISO 8859-1.
  376. LHEX
  377. 32 hex digits, where the alphabetic characters MUST be lower case,
  378. because MD5 is not case insensitive.
  379. cipher
  380. The cipher chosen by the client. This directive MUST appear
  381. exactly once if "auth-conf" is negotiated; if required and not
  382. present, authentication fails.
  383. authzid
  384. The "authorization ID" as per RFC 2222, encoded in UTF-8. This
  385. directive is optional. If present, and the authenticating user has
  386. sufficient privilege, and the server supports it, then after
  387. authentication the server will use this identity for making all
  388. accesses and access checks. If the client specifies it, and the
  389. server does not support it, then the response-value will be
  390. incorrect, and authentication will fail.
  391. The size of a digest-response MUST be less than 4096 bytes.
  392. 2.1.2.1 Response-value
  393. The definition of "response-value" above indicates the encoding for
  394. its value -- 32 lower case hex characters. The following definitions
  395. show how the value is computed.
  396. Although qop-value and components of digest-uri-value may be
  397. case-insensitive, the case which the client supplies in step two is
  398. preserved for the purpose of computing and verifying the
  399. response-value.
  400. response-value =
  401. Leach & Newman Standards Track [Page 10]
  402. RFC 2831 Digest SASL Mechanism May 2000
  403. HEX( KD ( HEX(H(A1)),
  404. { nonce-value, ":" nc-value, ":",
  405. cnonce-value, ":", qop-value, ":", HEX(H(A2)) }))
  406. If authzid is specified, then A1 is
  407. A1 = { H( { username-value, ":", realm-value, ":", passwd } ),
  408. ":", nonce-value, ":", cnonce-value, ":", authzid-value }
  409. If authzid is not specified, then A1 is
  410. A1 = { H( { username-value, ":", realm-value, ":", passwd } ),
  411. ":", nonce-value, ":", cnonce-value }
  412. where
  413. passwd = *OCTET
  414. The "username-value", "realm-value" and "passwd" are encoded
  415. according to the value of the "charset" directive. If "charset=UTF-8"
  416. is present, and all the characters of either "username-value" or
  417. "passwd" are in the ISO 8859-1 character set, then it must be
  418. converted to ISO 8859-1 before being hashed. This is so that
  419. authentication databases that store the hashed username, realm and
  420. password (which is common) can be shared compatibly with HTTP, which
  421. specifies ISO 8859-1. A sample implementation of this conversion is
  422. in section 8.
  423. If the "qop" directive's value is "auth", then A2 is:
  424. A2 = { "AUTHENTICATE:", digest-uri-value }
  425. If the "qop" value is "auth-int" or "auth-conf" then A2 is:
  426. A2 = { "AUTHENTICATE:", digest-uri-value,
  427. ":00000000000000000000000000000000" }
  428. Note that "AUTHENTICATE:" must be in upper case, and the second
  429. string constant is a string with a colon followed by 32 zeros.
  430. These apparently strange values of A2 are for compatibility with
  431. HTTP; they were arrived at by setting "Method" to "AUTHENTICATE" and
  432. the hash of the entity body to zero in the HTTP digest calculation of
  433. A2.
  434. Also, in the HTTP usage of Digest, several directives in the
  435. Leach & Newman Standards Track [Page 11]
  436. RFC 2831 Digest SASL Mechanism May 2000
  437. "digest-challenge" sent by the server have to be returned by the
  438. client in the "digest-response". These are:
  439. opaque
  440. algorithm
  441. These directives are not needed when Digest is used as a SASL
  442. mechanism (i.e., MUST NOT be sent, and MUST be ignored if received).
  443. 2.1.3 Step Three
  444. The server receives and validates the "digest-response". The server
  445. checks that the nonce-count is "00000001". If it supports subsequent
  446. authentication (see section 2.2), it saves the value of the nonce and
  447. the nonce-count. It sends a message formatted as follows:
  448. response-auth = "rspauth" "=" response-value
  449. where response-value is calculated as above, using the values sent in
  450. step two, except that if qop is "auth", then A2 is
  451. A2 = { ":", digest-uri-value }
  452. And if qop is "auth-int" or "auth-conf" then A2 is
  453. A2 = { ":", digest-uri-value, ":00000000000000000000000000000000" }
  454. Compared to its use in HTTP, the following Digest directives in the
  455. "digest-response" are unused:
  456. nextnonce
  457. qop
  458. cnonce
  459. nonce-count
  460. 2.2 Subsequent Authentication
  461. If the client has previously authenticated to the server, and
  462. remembers the values of username, realm, nonce, nonce-count, cnonce,
  463. and qop that it used in that authentication, and the SASL profile for
  464. a protocol permits an initial client response, then it MAY perform
  465. "subsequent authentication", as defined in this section.
  466. Leach & Newman Standards Track [Page 12]
  467. RFC 2831 Digest SASL Mechanism May 2000
  468. 2.2.1 Step one
  469. The client uses the values from the previous authentication and sends
  470. an initial response with a string formatted and computed according to
  471. the rules for a "digest-response", as defined above, but with a
  472. nonce-count one greater than used in the last "digest-response".
  473. 2.2.2 Step Two
  474. The server receives the "digest-response". If the server does not
  475. support subsequent authentication, then it sends a
  476. "digest-challenge", and authentication proceeds as in initial
  477. authentication. If the server has no saved nonce and nonce-count from
  478. a previous authentication, then it sends a "digest-challenge", and
  479. authentication proceeds as in initial authentication. Otherwise, the
  480. server validates the "digest-response", checks that the nonce-count
  481. is one greater than that used in the previous authentication using
  482. that nonce, and saves the new value of nonce-count.
  483. If the response is invalid, then the server sends a
  484. "digest-challenge", and authentication proceeds as in initial
  485. authentication (and should be configurable to log an authentication
  486. failure in some sort of security audit log, since the failure may be
  487. a symptom of an attack). The nonce-count MUST NOT be incremented in
  488. this case: to do so would allow a denial of service attack by sending
  489. an out-of-order nonce-count.
  490. If the response is valid, the server MAY choose to deem that
  491. authentication has succeeded. However, if it has been too long since
  492. the previous authentication, or for any other reason, the server MAY
  493. send a new "digest-challenge" with a new value for nonce. The
  494. challenge MAY contain a "stale" directive with value "true", which
  495. says that the client may respond to the challenge using the password
  496. it used in the previous response; otherwise, the client must solicit
  497. the password anew from the user. This permits the server to make sure
  498. that the user has presented their password recently. (The directive
  499. name refers to the previous nonce being stale, not to the last use of
  500. the password.) Except for the handling of "stale", after sending the
  501. "digest-challenge" authentication proceeds as in the case of initial
  502. authentication.
  503. 2.3 Integrity Protection
  504. If the server offered "qop=auth-int" and the client responded
  505. "qop=auth-int", then subsequent messages, up to but not including the
  506. next subsequent authentication, between the client and the server
  507. Leach & Newman Standards Track [Page 13]
  508. RFC 2831 Digest SASL Mechanism May 2000
  509. MUST be integrity protected. Using as a base session key the value of
  510. H(A1) as defined above the client and server calculate a pair of
  511. message integrity keys as follows.
  512. The key for integrity protecting messages from client to server is:
  513. Kic = MD5({H(A1),
  514. "Digest session key to client-to-server signing key magic constant"})
  515. The key for integrity protecting messages from server to client is:
  516. Kis = MD5({H(A1),
  517. "Digest session key to server-to-client signing key magic constant"})
  518. where MD5 is as specified in [RFC 1321]. If message integrity is
  519. negotiated, a MAC block for each message is appended to the message.
  520. The MAC block is 16 bytes: the first 10 bytes of the HMAC-MD5 [RFC
  521. 2104] of the message, a 2-byte message type number in network byte
  522. order with value 1, and the 4-byte sequence number in network byte
  523. order. The message type is to allow for future extensions such as
  524. rekeying.
  525. MAC(Ki, SeqNum, msg) = (HMAC(Ki, {SeqNum, msg})[0..9], 0x0001,
  526. SeqNum)
  527. where Ki is Kic for messages sent by the client and Kis for those
  528. sent by the server. The sequence number is initialized to zero, and
  529. incremented by one for each message sent.
  530. Upon receipt, MAC(Ki, SeqNum, msg) is computed and compared with the
  531. received value; the message is discarded if they differ.
  532. 2.4 Confidentiality Protection
  533. If the server sent a "cipher-opts" directive and the client responded
  534. with a "cipher" directive, then subsequent messages between the
  535. client and the server MUST be confidentiality protected. Using as a
  536. base session key the value of H(A1) as defined above the client and
  537. server calculate a pair of message integrity keys as follows.
  538. The key for confidentiality protecting messages from client to server
  539. is:
  540. Kcc = MD5({H(A1)[0..n],
  541. "Digest H(A1) to client-to-server sealing key magic constant"})
  542. The key for confidentiality protecting messages from server to client
  543. is:
  544. Leach & Newman Standards Track [Page 14]
  545. RFC 2831 Digest SASL Mechanism May 2000
  546. Kcs = MD5({H(A1)[0..n],
  547. "Digest H(A1) to server-to-client sealing key magic constant"})
  548. where MD5 is as specified in [RFC 1321]. For cipher "rc4-40" n is 5;
  549. for "rc4-56" n is 7; for the rest n is 16. The key for the "rc-*"
  550. ciphers is all 16 bytes of Kcc or Kcs; the key for "des" is the first
  551. 7 bytes; the key for "3des" is the first 14 bytes. The IV for "des"
  552. and "3des" is the last 8 bytes of Kcc or Kcs.
  553. If message confidentiality is negotiated, each message is encrypted
  554. with the chosen cipher and a MAC block is appended to the message.
  555. The MAC block is a variable length padding prefix followed by 16
  556. bytes formatted as follows: the first 10 bytes of the HMAC-MD5 [RFC
  557. 2104] of the message, a 2-byte message type number in network byte
  558. order with value 1, and the 4-byte sequence number in network byte
  559. order. If the blocksize of the chosen cipher is not 1 byte, the
  560. padding prefix is one or more octets each containing the number of
  561. padding bytes, such that total length of the encrypted part of the
  562. message is a multiple of the blocksize. The padding and first 10
  563. bytes of the MAC block are encrypted along with the message.
  564. SEAL(Ki, Kc, SeqNum, msg) =
  565. {CIPHER(Kc, {msg, pad, HMAC(Ki, {SeqNum, msg})[0..9])}), 0x0001,
  566. SeqNum}
  567. where CIPHER is the chosen cipher, Ki and Kc are Kic and Kcc for
  568. messages sent by the client and Kis and Kcs for those sent by the
  569. server. The sequence number is initialized to zero, and incremented
  570. by one for each message sent.
  571. Upon receipt, the message is decrypted, HMAC(Ki, {SeqNum, msg}) is
  572. computed and compared with the received value; the message is
  573. discarded if they differ.
  574. 3 Security Considerations
  575. 3.1 Authentication of Clients using Digest Authentication
  576. Digest Authentication does not provide a strong authentication
  577. mechanism, when compared to public key based mechanisms, for example.
  578. However, since it prevents chosen plaintext attacks, it is stronger
  579. than (e.g.) CRAM-MD5, which has been proposed for use with LDAP [10],
  580. POP and IMAP (see RFC 2195 [9]). It is intended to replace the much
  581. weaker and even more dangerous use of plaintext passwords; however,
  582. since it is still a password based mechanism it avoids some of the
  583. potential deployabilty issues with public-key, OTP or similar
  584. mechanisms.
  585. Leach & Newman Standards Track [Page 15]
  586. RFC 2831 Digest SASL Mechanism May 2000
  587. Digest Authentication offers no confidentiality protection beyond
  588. protecting the actual password. All of the rest of the challenge and
  589. response are available to an eavesdropper, including the user's name
  590. and authentication realm.
  591. 3.2 Comparison of Digest with Plaintext Passwords
  592. The greatest threat to the type of transactions for which these
  593. protocols are used is network snooping. This kind of transaction
  594. might involve, for example, online access to a mail service whose use
  595. is restricted to paying subscribers. With plaintext password
  596. authentication an eavesdropper can obtain the password of the user.
  597. This not only permits him to access anything in the database, but,
  598. often worse, will permit access to anything else the user protects
  599. with the same password.
  600. 3.3 Replay Attacks
  601. Replay attacks are defeated if the client or the server chooses a
  602. fresh nonce for each authentication, as this specification requires.
  603. 3.4 Online dictionary attacks
  604. If the attacker can eavesdrop, then it can test any overheard
  605. nonce/response pairs against a (potentially very large) list of
  606. common words. Such a list is usually much smaller than the total
  607. number of possible passwords. The cost of computing the response for
  608. each password on the list is paid once for each challenge.
  609. The server can mitigate this attack by not allowing users to select
  610. passwords that are in a dictionary.
  611. 3.5 Offline dictionary attacks
  612. If the attacker can choose the challenge, then it can precompute the
  613. possible responses to that challenge for a list of common words. Such
  614. a list is usually much smaller than the total number of possible
  615. passwords. The cost of computing the response for each password on
  616. the list is paid just once.
  617. Offline dictionary attacks are defeated if the client chooses a fresh
  618. nonce for each authentication, as this specification requires.
  619. Leach & Newman Standards Track [Page 16]
  620. RFC 2831 Digest SASL Mechanism May 2000
  621. 3.6 Man in the Middle
  622. Digest authentication is vulnerable to "man in the middle" (MITM)
  623. attacks. Clearly, a MITM would present all the problems of
  624. eavesdropping. But it also offers some additional opportunities to
  625. the attacker.
  626. A possible man-in-the-middle attack would be to substitute a weaker
  627. qop scheme for the one(s) sent by the server; the server will not be
  628. able to detect this attack. For this reason, the client should always
  629. use the strongest scheme that it understands from the choices
  630. offered, and should never choose a scheme that does not meet its
  631. minimum requirements.
  632. 3.7 Chosen plaintext attacks
  633. A chosen plaintext attack is where a MITM or a malicious server can
  634. arbitrarily choose the challenge that the client will use to compute
  635. the response. The ability to choose the challenge is known to make
  636. cryptanalysis much easier [8].
  637. However, Digest does not permit the attack to choose the challenge as
  638. long as the client chooses a fresh nonce for each authentication, as
  639. this specification requires.
  640. 3.8 Spoofing by Counterfeit Servers
  641. If a user can be led to believe that she is connecting to a host
  642. containing information protected by a password she knows, when in
  643. fact she is connecting to a hostile server, then the hostile server
  644. can obtain challenge/response pairs where it was able to partly
  645. choose the challenge. There is no known way that this can be
  646. exploited.
  647. 3.9 Storing passwords
  648. Digest authentication requires that the authenticating agent (usually
  649. the server) store some data derived from the user's name and password
  650. in a "password file" associated with a given realm. Normally this
  651. might contain pairs consisting of username and H({ username-value,
  652. ":", realm-value, ":", passwd }), which is adequate to compute H(A1)
  653. as described above without directly exposing the user's password.
  654. The security implications of this are that if this password file is
  655. compromised, then an attacker gains immediate access to documents on
  656. the server using this realm. Unlike, say a standard UNIX password
  657. file, this information need not be decrypted in order to access
  658. documents in the server realm associated with this file. On the other
  659. Leach & Newman Standards Track [Page 17]
  660. RFC 2831 Digest SASL Mechanism May 2000
  661. hand, decryption, or more likely a brute force attack, would be
  662. necessary to obtain the user's password. This is the reason that the
  663. realm is part of the digested data stored in the password file. It
  664. means that if one Digest authentication password file is compromised,
  665. it does not automatically compromise others with the same username
  666. and password (though it does expose them to brute force attack).
  667. There are two important security consequences of this. First the
  668. password file must be protected as if it contained plaintext
  669. passwords, because for the purpose of accessing documents in its
  670. realm, it effectively does.
  671. A second consequence of this is that the realm string should be
  672. unique among all realms that any single user is likely to use. In
  673. particular a realm string should include the name of the host doing
  674. the authentication.
  675. 3.10 Multiple realms
  676. Use of multiple realms may mean both that compromise of a the
  677. security database for a single realm does not compromise all
  678. security, and that there are more things to protect in order to keep
  679. the whole system secure.
  680. 3.11 Summary
  681. By modern cryptographic standards Digest Authentication is weak,
  682. compared to (say) public key based mechanisms. But for a large range
  683. of purposes it is valuable as a replacement for plaintext passwords.
  684. Its strength may vary depending on the implementation.
  685. 4 Example
  686. This example shows the use of the Digest SASL mechanism with the
  687. IMAP4 AUTHENTICATE command [RFC 2060].
  688. In this example, "C:" and "S:" represent a line sent by the client or
  689. server respectively including a CRLF at the end. Linebreaks and
  690. indentation within a "C:" or "S:" are editorial and not part of the
  691. protocol. The password in this example was "secret". Note that the
  692. base64 encoding of the challenges and responses is part of the IMAP4
  693. AUTHENTICATE command, not part of the Digest specification itself.
  694. S: * OK elwood.innosoft.com PMDF IMAP4rev1 V6.0-9
  695. C: c CAPABILITY
  696. S: * CAPABILITY IMAP4 IMAP4rev1 ACL LITERAL+ NAMESPACE QUOTA
  697. UIDPLUS AUTH=CRAM-MD5 AUTH=DIGEST-MD5 AUTH=PLAIN
  698. S: c OK Completed
  699. Leach & Newman Standards Track [Page 18]
  700. RFC 2831 Digest SASL Mechanism May 2000
  701. C: a AUTHENTICATE DIGEST-MD5
  702. S: + cmVhbG09ImVsd29vZC5pbm5vc29mdC5jb20iLG5vbmNlPSJPQTZNRzl0
  703. RVFHbTJoaCIscW9wPSJhdXRoIixhbGdvcml0aG09bWQ1LXNlc3MsY2hh
  704. cnNldD11dGYtOA==
  705. C: Y2hhcnNldD11dGYtOCx1c2VybmFtZT0iY2hyaXMiLHJlYWxtPSJlbHdvb2
  706. QuaW5ub3NvZnQuY29tIixub25jZT0iT0E2TUc5dEVRR20yaGgiLG5jPTAw
  707. MDAwMDAxLGNub25jZT0iT0E2TUhYaDZWcVRyUmsiLGRpZ2VzdC11cmk9Im
  708. ltYXAvZWx3b29kLmlubm9zb2Z0LmNvbSIscmVzcG9uc2U9ZDM4OGRhZDkw
  709. ZDRiYmQ3NjBhMTUyMzIxZjIxNDNhZjcscW9wPWF1dGg=
  710. S: + cnNwYXV0aD1lYTQwZjYwMzM1YzQyN2I1NTI3Yjg0ZGJhYmNkZmZmZA==
  711. C:
  712. S: a OK User logged in
  713. ---
  714. The base64-decoded version of the SASL exchange is:
  715. S: realm="elwood.innosoft.com",nonce="OA6MG9tEQGm2hh",qop="auth",
  716. algorithm=md5-sess,charset=utf-8
  717. C: charset=utf-8,username="chris",realm="elwood.innosoft.com",
  718. nonce="OA6MG9tEQGm2hh",nc=00000001,cnonce="OA6MHXh6VqTrRk",
  719. digest-uri="imap/elwood.innosoft.com",
  720. response=d388dad90d4bbd760a152321f2143af7,qop=auth
  721. S: rspauth=ea40f60335c427b5527b84dbabcdfffd
  722. The password in this example was "secret".
  723. This example shows the use of the Digest SASL mechanism with the
  724. ACAP, using the same notational conventions and password as in the
  725. previous example. Note that ACAP does not base64 encode and uses
  726. fewer round trips that IMAP4.
  727. S: * ACAP (IMPLEMENTATION "Test ACAP server") (SASL "CRAM-MD5"
  728. "DIGEST-MD5" "PLAIN")
  729. C: a AUTHENTICATE "DIGEST-MD5"
  730. S: + {94}
  731. S: realm="elwood.innosoft.com",nonce="OA9BSXrbuRhWay",qop="auth",
  732. algorithm=md5-sess,charset=utf-8
  733. C: {206}
  734. C: charset=utf-8,username="chris",realm="elwood.innosoft.com",
  735. nonce="OA9BSXrbuRhWay",nc=00000001,cnonce="OA9BSuZWMSpW8m",
  736. digest-uri="acap/elwood.innosoft.com",
  737. response=6084c6db3fede7352c551284490fd0fc,qop=auth
  738. S: a OK (SASL {40}
  739. S: rspauth=2f0b3d7c3c2e486600ef710726aa2eae) "AUTHENTICATE
  740. Completed"
  741. ---
  742. Leach & Newman Standards Track [Page 19]
  743. RFC 2831 Digest SASL Mechanism May 2000
  744. The server uses the values of all the directives, plus knowledge of
  745. the users password (or the hash of the user's name, server's realm
  746. and the user's password) to verify the computations above. If they
  747. check, then the user has authenticated.
  748. 5 References
  749. [Digest] Franks, J., et al., "HTTP Authentication: Basic and Digest
  750. Access Authentication", RFC 2617, June 1999.
  751. [ISO-8859] ISO-8859. International Standard--Information Processing--
  752. 8-bit Single-Byte Coded Graphic Character Sets --
  753. Part 1: Latin alphabet No. 1, ISO-8859-1:1987.
  754. Part 2: Latin alphabet No. 2, ISO-8859-2, 1987.
  755. Part 3: Latin alphabet No. 3, ISO-8859-3, 1988.
  756. Part 4: Latin alphabet No. 4, ISO-8859-4, 1988.
  757. Part 5: Latin/Cyrillic alphabet, ISO-8859-5, 1988.
  758. Part 6: Latin/Arabic alphabet, ISO-8859-6, 1987.
  759. Part 7: Latin/Greek alphabet, ISO-8859-7, 1987.
  760. Part 8: Latin/Hebrew alphabet, ISO-8859-8, 1988.
  761. Part 9: Latin alphabet No. 5, ISO-8859-9, 1990.
  762. [RFC 822] Crocker, D., "Standard for The Format of ARPA Internet
  763. Text Messages," STD 11, RFC 822, August 1982.
  764. [RFC 1321] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321,
  765. April 1992.
  766. [RFC 2047] Moore, K., "MIME (Multipurpose Internet Mail Extensions)
  767. Part Three: Message Header Extensions for Non-ASCII Text",
  768. RFC 2047, November 1996.
  769. [RFC 2052] Gulbrandsen, A. and P. Vixie, "A DNS RR for specifying the
  770. location of services (DNS SRV)", RFC 2052, October 1996.
  771. [RFC 2060] Crispin, M., "Internet Message Access Protocol - Version
  772. 4rev1", RFC 2060, December 1996.
  773. [RFC 2104] Krawczyk, H., Bellare, M. and R. Canetti, "HMAC: Keyed-
  774. Hashing for Message Authentication", RFC 2104, February
  775. 1997.
  776. [RFC 2195] Klensin, J., Catoe, R. and P. Krumviede, "IMAP/POP
  777. AUTHorize Extension for Simple Challenge/Response", RFC
  778. 2195, September 1997.
  779. Leach & Newman Standards Track [Page 20]
  780. RFC 2831 Digest SASL Mechanism May 2000
  781. [RFC 2119] Bradner, S., "Key words for use in RFCs to Indicate
  782. Requirement Levels", BCP 14, RFC 2119, March 1997.
  783. [RFC 2222] Myers, J., "Simple Authentication and Security Layer
  784. (SASL)", RFC 2222, October 1997.
  785. [USASCII] US-ASCII. Coded Character Set - 7-Bit American Standard
  786. Code for Information Interchange. Standard ANSI X3.4-1986,
  787. ANSI, 1986.
  788. 6 Authors' Addresses
  789. Paul Leach
  790. Microsoft
  791. 1 Microsoft Way
  792. Redmond, WA 98052
  793. EMail: paulle@microsoft.com
  794. Chris Newman
  795. Innosoft International, Inc.
  796. 1050 Lakes Drive
  797. West Covina, CA 91790 USA
  798. EMail: chris.newman@innosoft.com
  799. 7 ABNF
  800. What follows is the definition of the notation as is used in the
  801. HTTP/1.1 specification (RFC 2616) and the HTTP authentication
  802. specification (RFC 2617); it is reproduced here for ease of
  803. reference. Since it is intended that a single Digest implementation
  804. can support both HTTP and SASL-based protocols, the same notation is
  805. used in both to facilitate comparison and prevention of unwanted
  806. differences. Since it is cut-and-paste from the HTTP specifications,
  807. not all productions may be used in this specification. It is also not
  808. quite legal ABNF; again, the errors were copied from the HTTP
  809. specifications.
  810. 7.1 Augmented BNF
  811. All of the mechanisms specified in this document are described in
  812. both prose and an augmented Backus-Naur Form (BNF) similar to that
  813. used by RFC 822 [RFC 822]. Implementers will need to be familiar with
  814. the notation in order to understand this specification.
  815. Leach & Newman Standards Track [Page 21]
  816. RFC 2831 Digest SASL Mechanism May 2000
  817. The augmented BNF includes the following constructs:
  818. name = definition
  819. The name of a rule is simply the name itself (without any
  820. enclosing "<" and ">") and is separated from its definition by the
  821. equal "=" character. White space is only significant in that
  822. indentation of continuation lines is used to indicate a rule
  823. definition that spans more than one line. Certain basic rules are
  824. in uppercase, such as SP, LWS, HT, CRLF, DIGIT, ALPHA, etc. Angle
  825. brackets are used within definitions whenever their presence will
  826. facilitate discerning the use of rule names.
  827. "literal"
  828. Quotation marks surround literal text. Unless stated otherwise,
  829. the text is case-insensitive.
  830. rule1 | rule2
  831. Elements separated by a bar ("|") are alternatives, e.g., "yes |
  832. no" will accept yes or no.
  833. (rule1 rule2)
  834. Elements enclosed in parentheses are treated as a single element.
  835. Thus, "(elem (foo | bar) elem)" allows the token sequences
  836. "elem foo elem" and "elem bar elem".
  837. *rule
  838. The character "*" preceding an element indicates repetition. The
  839. full form is "<n>*<m>element" indicating at least <n> and at most
  840. <m> occurrences of element. Default values are 0 and infinity so
  841. that "*(element)" allows any number, including zero; "1*element"
  842. requires at least one; and "1*2element" allows one or two.
  843. [rule]
  844. Square brackets enclose optional elements; "[foo bar]" is
  845. equivalent to "*1(foo bar)".
  846. N rule
  847. Specific repetition: "<n>(element)" is equivalent to
  848. "<n>*<n>(element)"; that is, exactly <n> occurrences of (element).
  849. Thus 2DIGIT is a 2-digit number, and 3ALPHA is a string of three
  850. alphabetic characters.
  851. #rule
  852. A construct "#" is defined, similar to "*", for defining lists of
  853. elements. The full form is "<n>#<m>element" indicating at least
  854. <n> and at most <m> elements, each separated by one or more commas
  855. (",") and OPTIONAL linear white space (LWS). This makes the usual
  856. form of lists very easy; a rule such as
  857. Leach & Newman Standards Track [Page 22]
  858. RFC 2831 Digest SASL Mechanism May 2000
  859. ( *LWS element *( *LWS "," *LWS element ))
  860. can be shown as
  861. 1#element
  862. Wherever this construct is used, null elements are allowed, but do
  863. not contribute to the count of elements present. That is,
  864. "(element), , (element) " is permitted, but counts as only two
  865. elements. Therefore, where at least one element is required, at
  866. least one non-null element MUST be present. Default values are 0
  867. and infinity so that "#element" allows any number, including zero;
  868. "1#element" requires at least one; and "1#2element" allows one or
  869. two.
  870. ; comment
  871. A semi-colon, set off some distance to the right of rule text,
  872. starts a comment that continues to the end of line. This is a
  873. simple way of including useful notes in parallel with the
  874. specifications.
  875. implied *LWS
  876. The grammar described by this specification is word-based. Except
  877. where noted otherwise, linear white space (LWS) can be included
  878. between any two adjacent words (token or quoted-string), and
  879. between adjacent words and separators, without changing the
  880. interpretation of a field. At least one delimiter (LWS and/or
  881. separators) MUST exist between any two tokens (for the definition
  882. of "token" below), since they would otherwise be interpreted as a
  883. single token.
  884. 7.2 Basic Rules
  885. The following rules are used throughout this specification to
  886. describe basic parsing constructs. The US-ASCII coded character set
  887. is defined by ANSI X3.4-1986 [USASCII].
  888. OCTET = <any 8-bit sequence of data>
  889. CHAR = <any US-ASCII character (octets 0 - 127)>
  890. UPALPHA = <any US-ASCII uppercase letter "A".."Z">
  891. LOALPHA = <any US-ASCII lowercase letter "a".."z">
  892. ALPHA = UPALPHA | LOALPHA
  893. DIGIT = <any US-ASCII digit "0".."9">
  894. CTL = <any US-ASCII control character
  895. (octets 0 - 31) and DEL (127)>
  896. CR = <US-ASCII CR, carriage return (13)>
  897. LF = <US-ASCII LF, linefeed (10)>
  898. SP = <US-ASCII SP, space (32)>
  899. HT = <US-ASCII HT, horizontal-tab (9)>
  900. <"> = <US-ASCII double-quote mark (34)>
  901. CRLF = CR LF
  902. Leach & Newman Standards Track [Page 23]
  903. RFC 2831 Digest SASL Mechanism May 2000
  904. All linear white space, including folding, has the same semantics as
  905. SP. A recipient MAY replace any linear white space with a single SP
  906. before interpreting the field value or forwarding the message
  907. downstream.
  908. LWS = [CRLF] 1*( SP | HT )
  909. The TEXT rule is only used for descriptive field contents and values
  910. that are not intended to be interpreted by the message parser. Words
  911. of *TEXT MAY contain characters from character sets other than
  912. ISO-8859-1 [ISO 8859] only when encoded according to the rules of RFC
  913. 2047 [RFC 2047].
  914. TEXT = <any OCTET except CTLs,
  915. but including LWS>
  916. A CRLF is allowed in the definition of TEXT only as part of a header
  917. field continuation. It is expected that the folding LWS will be
  918. replaced with a single SP before interpretation of the TEXT value.
  919. Hexadecimal numeric characters are used in several protocol elements.
  920. HEX = "A" | "B" | "C" | "D" | "E" | "F"
  921. | "a" | "b" | "c" | "d" | "e" | "f" | DIGIT
  922. Many HTTP/1.1 header field values consist of words separated by LWS
  923. or special characters. These special characters MUST be in a quoted
  924. string to be used within a parameter value.
  925. token = 1*<any CHAR except CTLs or separators>
  926. separators = "(" | ")" | "<" | ">" | "@"
  927. | "," | ";" | ":" | "\" | <">
  928. | "/" | "[" | "]" | "?" | "="
  929. | "{" | "}" | SP | HT
  930. A string of text is parsed as a single word if it is quoted using
  931. double-quote marks.
  932. quoted-string = ( <"> qdstr-val <"> )
  933. qdstr-val = *( qdtext | quoted-pair )
  934. qdtext = <any TEXT except <">>
  935. Note that LWS is NOT implicit between the double-quote marks (<">)
  936. surrounding a qdstr-val and the qdstr-val; any LWS will be considered
  937. part of the qdstr-val. This is also the case for quotation marks
  938. surrounding any other construct.
  939. Leach & Newman Standards Track [Page 24]
  940. RFC 2831 Digest SASL Mechanism May 2000
  941. The backslash character ("\") MAY be used as a single-character
  942. quoting mechanism only within qdstr-val and comment constructs.
  943. quoted-pair = "\" CHAR
  944. The value of this construct is CHAR. Note that an effect of this rule
  945. is that backslash must be quoted.
  946. 8 Sample Code
  947. The sample implementation in [Digest] also applies to DIGEST-MD5.
  948. The following code implements the conversion from UTF-8 to 8859-1 if
  949. necessary.
  950. /* if the string is entirely in the 8859-1 subset of UTF-8, then
  951. * translate to 8859-1 prior to MD5
  952. */
  953. void MD5_UTF8_8859_1(MD5_CTX *ctx, const unsigned char *base,
  954. int len)
  955. {
  956. const unsigned char *scan, *end;
  957. unsigned char cbuf;
  958. end = base + len;
  959. for (scan = base; scan < end; ++scan) {
  960. if (*scan > 0xC3) break; /* abort if outside 8859-1 */
  961. if (*scan >= 0xC0 && *scan <= 0xC3) {
  962. if (++scan == end || *scan < 0x80 || *scan > 0xBF)
  963. break;
  964. }
  965. }
  966. /* if we found a character outside 8859-1, don't alter string
  967. */
  968. if (scan < end) {
  969. MD5Update(ctx, base, len);
  970. return;
  971. }
  972. /* convert to 8859-1 prior to applying hash
  973. */
  974. do {
  975. for (scan = base; scan < end && *scan < 0xC0; ++scan)
  976. ;
  977. if (scan != base) MD5Update(ctx, base, scan - base);
  978. if (scan + 1 >= end) break;
  979. cbuf = ((scan[0] & 0x3) << 6) | (scan[1] & 0x3f);
  980. MD5Update(ctx, &cbuf, 1);
  981. Leach & Newman Standards Track [Page 25]
  982. RFC 2831 Digest SASL Mechanism May 2000
  983. base = scan + 2;
  984. } while (base < end);
  985. }
  986. Leach & Newman Standards Track [Page 26]
  987. RFC 2831 Digest SASL Mechanism May 2000
  988. 9 Full Copyright Statement
  989. Copyright (C) The Internet Society (2000). All Rights Reserved.
  990. This document and translations of it may be copied and furnished to
  991. others, and derivative works that comment on or otherwise explain it
  992. or assist in its implementation may be prepared, copied, published
  993. and distributed, in whole or in part, without restriction of any
  994. kind, provided that the above copyright notice and this paragraph are
  995. included on all such copies and derivative works. However, this
  996. document itself may not be modified in any way, such as by removing
  997. the copyright notice or references to the Internet Society or other
  998. Internet organizations, except as needed for the purpose of
  999. developing Internet standards in which case the procedures for
  1000. copyrights defined in the Internet Standards process must be
  1001. followed, or as required to translate it into languages other than
  1002. English.
  1003. The limited permissions granted above are perpetual and will not be
  1004. revoked by the Internet Society or its successors or assigns.
  1005. This document and the information contained herein is provided on an
  1006. "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
  1007. TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
  1008. BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
  1009. HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
  1010. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  1011. Acknowledgement
  1012. Funding for the RFC Editor function is currently provided by the
  1013. Internet Society.
  1014. Leach & Newman Standards Track [Page 27]