home *** CD-ROM | disk | FTP | other *** search
/ ftp.microsoft.com / 2002-07-02_ftp.microsoft.com.zip / developr / drg / CIFS / CIFS-Auth-Spec.txt < prev    next >
Text File  |  1997-03-25  |  19KB  |  558 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.               CIFS Authentication Protocols Specification
  9.  
  10.                              Paul J. Leach
  11.  
  12.                                Microsoft
  13.  
  14.                     Preliminary Draft - do not cite
  15.  
  16.                            Author's draft: 4
  17.  
  18. This is a preliminary draft of a specification of a proposed new version
  19. of the CIFS authentication protocol. It is supplied here as a standalone
  20. document for ease of review; if accepted and implemented, it may be
  21. incorporated into a future release of the CIFS specification. (This
  22. specification may change without notice, and should not be construed as
  23. a product commitment from Microsoft Corporation.)
  24.  
  25. There are two sections: one about the authentication protocols
  26. themselves; and one about how the protocol to use is negotiated and the
  27. protocol messages transported in CIFS requests and responses.
  28.  
  29.  
  30. 1. CIFS Authentication Protocols
  31.  
  32. This section defines the CIFS session and message authentication
  33. protocols. Session authentication is done via a challenge response
  34. protocol based upon the shared knowledge of the user's password. Message
  35. authentication is done by attaching a message authentication code (MAC)
  36. to each message.
  37.  
  38.  
  39. 1.1 Overview
  40.  
  41. There are several variations on one basic session authentication scheme:
  42. To gain authenticated access to server resources, the server sends a
  43. "challenge" to the client, which the client responds to in a way that
  44. proves it knows the client's password: a "response" is created from  the
  45. challenge by  encrypting it (and possibly a nonce of the client's
  46. choice) with a 168 bit "session key" computed from the user's password.
  47. The response, or a subset of it, and client nonce are then returned to
  48. the server, which can validate the response by performing the same
  49. computation. The client and server negotiate which variation to use by a
  50. mechanism described in the next section (being careful to not permit a
  51. downgrade attack).
  52.  
  53. We describe the session authentication protocol as if the CIFS server
  54. keeps a clientÆs password, but an implementation might actually store
  55. the passwords on a key distribution server (KDS) and have servers use a
  56. protocol outside the scope of this specification  to enable them to
  57. perform the steps required by this protocol.
  58.  
  59. Once the session is authenticated, subsequent messages may be
  60. authenticated by computing a MAC for each message and attaching it to
  61. the message. The MAC used is a keyed MD5 construction similar to that
  62. used in IPSec [RFC 1828], using a "MAC key" computed from the session
  63. key, and the response to the server's challenge. The MAC is over both
  64. the message text and an implicit sequence number, to prevent replay.
  65.  
  66.  
  67. Paul Leach                 Page 1                   03/25/97
  68.  
  69.  
  70. Preliminary         CIFS AuthenticationMay  change without notice
  71.  
  72.  
  73. 1.2 Definitions
  74.  
  75. Let
  76.  
  77. E(K, D)
  78.   denote the DES block mode encryption function [FIPS 81] , which
  79.   accepts a seven byte key (K) and an eight byte data block (D) and
  80.   produces an eight byte encrypted data block as its value.
  81.  
  82. Ex(K,D)
  83.   denote the extension of DES to longer keys and data blocks. If the
  84.   data to be encrypted is longer than eight bytes, the encryption
  85.   function is applied to each block of eight bytes in sequence and the
  86.   results are concatenated together.  If the key is longer than seven
  87.   bytes, each 8 byte block of data is first completely encrypted using
  88.   the first seven bytes of the key, then the second seven bytes, etc.,
  89.   appending the results each time.  For example, to encrypt the 16 byte
  90.   quantity D0D1 with the 14 byte key K0K1,
  91.  
  92.      Ex(K0K1,D0D1) = concat(E(K0,D0),E(K0,D1),E(K1,D0),E(K1,D1))
  93.  
  94. concat(A, B, à, Z)
  95.   is the result of concatenating the byte strings A, B, à Z
  96.  
  97. head(S, N)
  98.   denote the first N bytes of the byte string S.
  99.  
  100. swab(S)
  101.   denote the byte string obtained by reversing the order of the bits in
  102.   each byte of S, i.e., if S is byte string of length one, with the
  103.   value 0x37 then swab(S) is 0xEC.
  104.  
  105. zeros(N)
  106.   denote a  byte string of length N whose bytes all have value 0
  107.   (zero).
  108.  
  109. ones(N)
  110.   denote a  byte string of length N whose bytes all have value 255.
  111.  
  112. xor(A, B)
  113.   denote a byte string formed by the bytewise logical "xor" of each of
  114.   the bytes in A and B.
  115.  
  116. and(A, B)
  117.   denote a byte string formed by the bytewise logical "and" of each of
  118.   the bytes in A and B.
  119.  
  120. substr(S, A, B)
  121.   denote a byte string of length N obtained by taking N bytes of S
  122.   starting at byte A. The first byte is numbered zero. I.e., if S is
  123.   the string "NONCE" then substr(S, 0, 2) is "NO".
  124.  
  125.  
  126.  
  127.  
  128. Paul Leach                 Page 2                   03/25/97
  129.  
  130.  
  131. Preliminary         CIFS AuthenticationMay  change without notice
  132.  
  133.  
  134. 1.3 Session Keys
  135.  
  136. The session authentication protocol is the same for all dialects, but
  137. the computation of the session keys is different depending on the
  138. dialect and the authentication negotiation described below.
  139.  
  140.  
  141. 1.3.1     NT Session Key
  142.  
  143. The session key  S21 and partial MAC key S16 are computed as
  144.  
  145.   S16 = MD4(U(PN))
  146.   S21 = concat(S16, zeros(5))
  147.  
  148. where
  149.  
  150.      o PN is a string containing the userÆs password in clear text,
  151.        case sensitive, no maximum length
  152.  
  153.      o U(x) of an ASCII string "x" is that string converted to Unicode
  154.  
  155.      o MD4(x) of an byte string "x" is the 16 byte MD4 message digest
  156.        [RFC 1320] of that string
  157.  
  158.  
  159. 1.3.2     LM Session Key
  160.  
  161. The session key  S21 and partial MAC key S16 are computed as
  162.  
  163.   S   16X = Ex(swab(P14),N8)
  164.   S   21 = concat(S16X, zeros(5))
  165.   S   16 = concat(head(S16X, 8), zeros(8))
  166.    
  167. where
  168.  
  169.      o P14 is a 14 byte string containing the userÆs password in clear
  170.        text, upper cased, padded with spaces
  171.  
  172.      o N8 is an 8 byte string whose value is available from Microsoft
  173.        upon request.
  174.  
  175.  
  176. 1.4 Session Authentication Protocol
  177.  
  178. The session authentication protocol has the following steps:
  179.  
  180. o The server chooses a unique 8 byte challenge C8 (a "nonce" that has
  181.   never been used before and will not be reused) and sends it to the
  182.   client
  183.  
  184. o The client computes
  185.  
  186.   R   N = Ex(S21,C8)
  187.    
  188.  
  189. Paul Leach                 Page 3                   03/25/97
  190.  
  191.  
  192. Preliminary         CIFS AuthenticationMay  change without notice
  193.  
  194.  
  195. o The client sends the 24 byte response RN to the server
  196.  
  197. o The server computes RN as above and compares the received response
  198.   with its computed value for RN; if equal, the client has
  199.   authenticated.
  200.  
  201.  
  202. 1.6 Message authentication code
  203.  
  204. The MAC is the keyed MD5 construction:
  205.  
  206.   M   AC(K, text) = head(MD5(concat(K, text)), 8)
  207.    
  208. Where:
  209.  
  210.   MD5
  211.   is the MD5 hash function; see RFC 1321
  212.  
  213.   K
  214.   is the key
  215.  
  216.   text
  217.   is the message whose MAC is being computed
  218.  
  219. See RFC 1828 for an example of Keyed-MD5 applied to IP security. If not
  220. used properly, keyed MD5 may have weaknesses as a MAC. Iterative hashes
  221. such as MD5 may be subject to message extension attacks and to
  222. cryptanalysis [Kal 95]. This construction is not subject to the problems
  223. identified there, because the text contains an explicit length, which
  224. prevents message extension attacks; and because there are always two
  225. iterations of the compression function, and only 64 bits of the hash are
  226. output, which prevents known cryptanalysis techniques.
  227.  
  228.  
  229. 1.7 MAC key
  230.  
  231. The MAC key is computed as follows:
  232.  
  233.   K    = concat(S16, RN)
  234.    
  235. Where S16 and RN are as above. K is either 40 or 44 bytes long,
  236. depending on the length of RN.
  237.  
  238.  
  239. 1.8 Message Authentication Protocol
  240.  
  241. Once the session has been authenticated, each message can be
  242. authenticated as well. This will prevent MITM attacks, replay attacks,
  243. and active message modification attacks. (See Security Considerations,
  244. below.)
  245.  
  246. Let
  247.  
  248.   SN
  249.  
  250. Paul Leach                 Page 4                   03/25/97
  251.  
  252.  
  253. Preliminary         CIFS AuthenticationMay  change without notice
  254.  
  255.  
  256.   be a request sequence number, initially set to 0. Both client and
  257.   server have one SN for each connection between them.
  258.  
  259.   RSN
  260.   is the sequence number expected on the response to a request.
  261.  
  262.   req_msg
  263.   be a request message
  264.  
  265.   rsp_msg
  266.   be a response message
  267.  
  268. The SN is logically contained in each message, as defined below in the
  269. section on authenticated message transport, and participates in the
  270. computation of the MAC, as defined in that section.
  271.  
  272. Then for or each message sent in the session the following procedure is
  273. followed:
  274.  
  275. ╖ Client computes MAC(req_msg) using SN, and sends it to the server in
  276.   the request message. If there are multiple messages in the request,
  277.   each uses the same SN. If there are multiple requests in the message
  278.   (using the "AndX" facility) , then the MAC is calculated as if it
  279.   were a single large request.
  280.  
  281. ╖ Client increments its SN and saves it as RSN
  282.  
  283. ╖ Client increments its SN - this is the SN it will use in its next
  284.   request
  285.  
  286. ╖ Server receives each req_msg, validates MAC(req_msg) using SN, and
  287.   responds ACCESS_DENIED if invalid
  288.  
  289. ╖ Server increments its SN and saves it as RSN
  290.  
  291. ╖ Server increments its SN - this is the SN it will expect in the next
  292.   request
  293.  
  294. ╖ For each response message for this request, computes MAC(rsp_msg)
  295.   using RSN, and sends it  to client in the response message. If there
  296.   are multiple responses in the message (using the "AndX" facility) ,
  297.   then the MAC is calculated as if it were a single large response.
  298.  
  299. ╖ Client receives each rsp_msg, validates MAC(rsp_msg) using RSN, and
  300.   discards the response message if invalid
  301.  
  302.  
  303. 2. Security Level and Authentication Protocol Negotiation
  304.  
  305. The SMB_COM_NEGPROT response from a server has the following bits in its
  306. SecurityMode field:
  307.  
  308.   #define NEGOTIATE_SECURITY_USER_LEVEL               0x01
  309.   #define NEGOTIATE_SECURITY_CHALLENGE_RESPONSE       0x02
  310.  
  311.  
  312. Paul Leach                 Page 5                   03/25/97
  313.  
  314.  
  315. Preliminary         CIFS AuthenticationMay  change without notice
  316.  
  317.  
  318.   #define NEGOTIATE_SECURITY_SIGNATURES_ENABLED       0x04
  319.   #define NEGOTIATE_SECURITY_SIGNATURES_REQUIRED      0x08
  320.  
  321. If NEGOTIATE_SECURITY_USER_LEVEL is set, then "user level" security is
  322. in effect for all the shares on the server. This means that the client
  323. MUST establish a session (with SMB_COM_SESSION_SETUP_ANX) to
  324. authenticate the user before connecting to a share, and the password to
  325. use in the authentication protocol described above is the user's
  326. password. If NEGOTIATE_SECURITY_USER_LEVEL is clear, then "share level"
  327. security is in effect for all the shares in the server. This means that
  328. a session need not be established, and the password to use in the
  329. authentication protocol is a password for the share.
  330.  
  331. If NEGOTIATE_SECURITY_CHALLENGE_RESPONSE is clear, then the server is
  332. requesting plaintext passwords. Clients MUST be able to be configured to
  333. refuse requests for plaintext passwords (in order to prevent downgrade
  334. attacks by rogue or spoofing servers); this SHOULD be the default.
  335. Servers MUST be able to be configured to refuse plaintext passwords (in
  336. order to make password guessing attacks harder).
  337.  
  338. If NEGOTIATE_SECURITY_CHALLENGE_RESPONSE is set, then the server
  339. supports the challenge/response session authentication protocol
  340. described above, and clients SHOULD use it. Servers MAY refuse
  341. connections that do not use it, and MUST be able to be configured to do
  342. so.
  343.  
  344. If the dialect is earlier than "NTLM 0.12" then the client computes the
  345. response using the "LM session key". If the dialect is "NTLM 0.12" then
  346. the client MAY compute the response either using the "LM session key",
  347. or the "NT session key", or both. The server MAY choose to refuse
  348. responses computed using the "LM session key", and MUST be able to be
  349. configured to do so (in order to protect against downgrade attacks).
  350.  
  351. If NEGOTIATE_SECURITY_SIGNATURES_ENABLED is set, then the server
  352. supports the message authentication protocol described above, and the
  353. client MAY use it. This bit may only be set if
  354. NEGOTIATE_SECURITY_CHALLENGE_RESPONSE is set. Clients that support
  355. security signatures MUST be configurable to refuse to connect to servers
  356. that do not have NEGOTIATE_SECURITY_SIGNATURES_ENABLED set. Clients that
  357. are so configured MUST refuse to connect to servers that have
  358. NEGOTIATE_SECURITY_CHALLENGE_RESPONSE  set and do not have
  359. NEGOTIATE_SECURITY_USER_LEVEL set (i.e., they must not use
  360. challenge/response authentication to a server using "share-level"
  361. security).
  362.  
  363. If NEGOTIATE_SECURITY_SIGNATURES_REQUIRED is set, then the server
  364. requires the use of the message authentication protocol described above,
  365. and the client MUST use it. This bit may only be set if
  366. NEGOTIATE_SECURITY_SIGNATURES_ENABLED is set. This bit MUST NOT be set.
  367. if NEGOTIATE_SECURITY_USER_LEVEL is clear (i.e., for servers using
  368. "share level" security).
  369.  
  370. The SMB_COM_SESSION_SETUP_ANDX request has the following bit in the
  371. Flags2 field:
  372.  
  373. Paul Leach                 Page 6                   03/25/97
  374.  
  375.  
  376. Preliminary         CIFS AuthenticationMay  change without notice
  377.  
  378.  
  379. #define SMB_FLAGS2_SMB_SECURITY_SIGNATURE 0x0004
  380.  
  381. To use  message authentication, the client sets
  382. SMB_FLAGS2_SMB_SECURITY_SIGNATURE in a SMB_COM_SESSION_SETUP_ANDX
  383. request to the server, and includes a MAC calculated as described above.
  384. If the  resulting session is non-null and non-guest, then the
  385. SMB_COM_SESSION_SETUP_ANDX response and all subsequent SMB requests and
  386. responses MUST include a MAC calculated as described above. The first
  387. non-null, non-guest session determines the key to be used for the MAC
  388. for all subsequent sessions.
  389.  
  390. Message authentication may only be requested when the "NTML 0.12"
  391. dialect has been negotiated. If message authentication is used, raw mode
  392. MUST not be used (because some raw mode messages have no headers in
  393. which to carry the MAC).
  394.  
  395. No matter which authentication protocol is negotiated, servers MUST be
  396. able to be configured to "lock out" accounts that make too many failed
  397. authentication attempts, in order to foil brute force attacks on the
  398. protocol.
  399.  
  400.  
  401. 2.1 Plaintext password transport
  402.  
  403. If plaintext password authentication was negotiated, clients send the
  404. plaintext password in the first SMB_COM_TREE_CONNECT,
  405. SMB_COM_TREE_CONNECT_ANDX, and/or SMB_COM_SESSION_SETUP_ANDX request
  406. which follows the SMB_COM_NEGPROT message exchange.  The SMB field used
  407. to contain the response depends upon the request:
  408.  
  409.   ╖ Password in SMB_COM_TREE_CONNECT
  410.  
  411.   ╖ Password in SMB_COM_TREE_CONNECT_ANDX
  412.  
  413.   ╖ AccountPassword in SMB_COM_SESSION_SETUP_ANDX in dialects prior to
  414.      "NTLM 0.12"
  415.  
  416.   ╖ CaseInsensitivePassword in SMB_COM_SESSION_SETUP_ANDX in the "NTLM
  417.      0.12" dialect
  418.  
  419.   ╖ CaseSensitivePassword in SMB_COM_SESSION_SETUP_ANDX  in the "NTLM
  420.      0.12" dialect
  421.  
  422.  
  423. 2.2 Challenge/response transport
  424.  
  425. The challenge C8 from the server to the client is contained in the
  426. EncryptionKey field in the SMB_COM_NEGPROT response.  (Note: the name
  427. "EncryptionKey" is historical -- it doesn't actually hold an encryption
  428. key.)
  429.  
  430. Clients send the cleartext password, or the response to the challenge,
  431. in the first SMB_COM_TREE_CONNECT, SMB_COM_TREE_CONNECT_ANDX, and/or
  432. SMB_COM_SESSION_SETUP_ANDX request which follows the SMB_COM_NEGPROT
  433.  
  434. Paul Leach                 Page 7                   03/25/97
  435.  
  436.  
  437. Preliminary         CIFS AuthenticationMay  change without notice
  438.  
  439.  
  440. message exchange.  The SMB field used to contain the response depends
  441. upon the request:
  442.  
  443.   ╖ Password in SMB_COM_TREE_CONNECT
  444.  
  445.   ╖ Password in SMB_COM_TREE_CONNECT_ANDX
  446.  
  447.   ╖ AccountPassword in SMB_COM_SESSION_SETUP_ANDX in dialects prior to
  448.      "NTLM 0.12"
  449.  
  450.   ╖ CaseInsensitivePassword in SMB_COM_SESSION_SETUP_ANDX for a
  451.      response computed using the "LM session key" in the "NTLM 0.12"
  452.      dialect
  453.  
  454.   ╖ CaseSensitivePassword in SMB_COM_SESSION_SETUP_ANDX for a response
  455.      computed using the "NT session key" in the "NTLM 0.12" dialect
  456.  
  457.  (Note: again, the names are historical, and do not reflect this usage.)
  458.  
  459.  
  460. 2.3 MAC transport
  461.  
  462. In each message that contains a MAC, the following bit is set in the
  463. flags2 field:
  464.  
  465. #define SMB_FLAGS2_SMB_SECURITY_SIGNATURES 0x0004
  466.  
  467. The SMB header has been modified to include a place for the MAC:
  468.  
  469. typedef struct _SMB_HEADER {
  470.     UCHAR Protocol[4];              // Contains 0xFF,'SMB'
  471.     UCHAR Command;                      // Command code
  472.     UCHAR ErrorClass;               // Error class
  473.     UCHAR Reserved;                 // Reserved for future use
  474.     USHORT Error ;                  // Error code
  475.     UCHAR Flags;                    // Flags
  476.     USHORT Flags2 ;                 // More flags
  477.     union {
  478.         USHORT Reserved2[6];        // Reserved for future use
  479.         struct {
  480.             USHORT PidHigh;        // High part of PID
  481.                     // Client must send the correct Signature
  482.                // for this SMB to be accepted.
  483.             UCHAR SecuritySignature[8];
  484.         };
  485.     };
  486.    ....
  487. } SMB_HEADER;
  488.  
  489. The sender of a message inserts the sequence number SSN into the message
  490. by putting it into the first 4 bytes of the SecuritySignature field and
  491. zeroing the last 4 bytes, computes the MAC over the entire message, then
  492. puts the MAC in the field. The receiver of a message validates the MAC
  493. by extracting the value of the SecuritySignature field, putting its ESN
  494.  
  495. Paul Leach                 Page 8                   03/25/97
  496.  
  497.  
  498. Preliminary         CIFS AuthenticationMay  change without notice
  499.  
  500.  
  501. into the first 4 bytes of the SecuritySignature field and zeroing the
  502. last 4 bytes, computing the MAC, and comparing it to the extracted
  503. value.
  504.  
  505. Oplock break messages from the server to the client may not use message
  506. authentication, even if it has been negotiated.
  507.  
  508.  
  509. 3. Security considerations
  510.  
  511. (These are already in the main CIFS spec, of which this will eventually
  512. become a part.) Relevant additions:
  513.  
  514. Clients  that require the use of message authentication will be
  515. protected against man-in-the-middle attacks and downgrade attacks by
  516. rogue or counterfeit servers. Servers that require the use of message
  517. authentication will be protected against man-in-the-middle attacks and
  518. downgrade attacks by rogue clients.
  519.  
  520.  
  521. 4. References
  522.  
  523. [FIPS 81] DES, FIPS PUB xxx
  524.  
  525. [RFC 1320] RFC 1320, R. Rivest, The MD4 Message-Digest Algorithm
  526.  
  527. [RFC 1321] RFC 1321, R. Rivest, The MD5 Message-Digest Algorithm
  528.  
  529. [RFC 1828] RFC 1828, P. Metzger, W. Simpson, "IP Authentication using
  530. Keyed MD5", August 1995
  531.  
  532. {Kal 95] B. Kaliski, M.Robshaw,  "Message Authentication with MD5",
  533. CryptoBytes, Sping 1995, RSA Inc,
  534. (http://www.rsa.com/rsalabs/pubs/cryptobytes/spring95/md5.htm)
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558. Paul Leach                 Page 9                   03/25/97