NTLM auth and sign - Use appropriate server challenge
Subsystems (2)
PATCH 1/1 NTLM auth and sign - Use appropriate server challenge
From: Shirish Pargaonkar <[email protected]>
Need to have cryptKey or server challenge in smb connection (struct TCP_Server_Info) for ntlm and ntlmv2 auth types for which cryptKey (Encryption Key) is supplied just once in Negotiate Protocol response during an smb connection setup for all the smb sessions over that smb connection.
For ntlmssp, cryptKey or server challenge is provided for every smb session in type 2 packet of ntlmssp negotiation, the cryptKey provided during Negotiation Protocol response before smb connection does not count.
--- fs/cifs/cifsencrypt.c | 10 +++++++--- fs/cifs/cifsglob.h | 3 ++- fs/cifs/cifssmb.c | 4 ++-- fs/cifs/connect.c | 4 ++-- fs/cifs/sess.c | 10 +++++++--- 5 files changed, 20 insertions(+), 11 deletions(-)
fs/cifs/cifsencrypt.c +7 -3
@@ -249,7 +249,7 @@ int setup_ntlm_response(struct cifsSesInfo *ses) } ses->auth_key.len = temp_len; -SMBNTencrypt (ses->password, ses->cryptKey, +SMBNTencrypt (ses->password, ses->server->cryptKey, ses->auth_key.response +CIFS_SESS_KEY_SIZE );E_md4hash (ses->password, temp_key);
@@ -537,8 +537,12 @@ CalcNTLMv2_response(const struct cifsSesInfo *ses)return rc; } -memcpy (ses->auth_key.response + offset, - ses->cryptKey,CIFS_SERVER_CHALLENGE_SIZE ); +if (ses->server->secType == RawNTLMSSP) +memcpy (ses->auth_key.response + offset, + ses->cryptKey,CIFS_SERVER_CHALLENGE_SIZE ); +else +memcpy (ses->auth_key.response + offset, + ses->server->cryptKey,CIFS_SERVER_CHALLENGE_SIZE );crypto_shash_update (&ses->server->secmech.sdeschmacmd5->shash, ses->auth_key.response + offset, ses->auth_key.len - offset);
fs/cifs/cifsglob.h +2 -1
@@ -196,6 +196,7 @@ struct TCP_Server_Info {int capabilities;/* allow selective disabling of caps by smb sess */ int timeAdj;/* Adjust for difference in server time zone in sec */ __u16 CurrentMid;/* multiplex id - rotating counter */ +char cryptKey[CIFS_CRYPTO_KEY_SIZE ];/* used by ntlm, ntlmv2 etc */ /* 16th byte of RFC1001 workstation name is always null */ char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL ];__u32 sequence_number;/* needed for CIFS PDU signature */
@@ -240,7 +241,7 @@ struct cifsSesInfo {char userName[MAX_USERNAME_SIZE +1 ];char *domainName;char *password; -char cryptKey[CIFS_CRYPTO_KEY_SIZE ]; +char cryptKey[CIFS_CRYPTO_KEY_SIZE ];/* used by ntlmssp */ struct session_key auth_key;char ntlmv2_hash[16 ];unsigned int tilen;/* length of the target info blob */
fs/cifs/cifssmb.c +2 -2
@@ -503,7 +503,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)if (rsp->EncryptionKeyLength ==cpu_to_le16 (CIFS_CRYPTO_KEY_SIZE )) { -memcpy (ses->cryptKey, rsp->EncryptionKey, +memcpy (ses->server->cryptKey, rsp->EncryptionKey,CIFS_CRYPTO_KEY_SIZE ); }else if (server->secMode &SECMODE_PW_ENCRYPT ) { rc = -EIO ;/* need cryptkey unless plain text */
@@ -574,7 +574,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) server->timeAdj = (int )(__s16 )le16_to_cpu (pSMBr->ServerTimeZone); server->timeAdj *=60 ;if (pSMBr->EncryptionKeyLength ==CIFS_CRYPTO_KEY_SIZE ) { -memcpy (ses->cryptKey, pSMBr->u.EncryptionKey, +memcpy (ses->server->cryptKey, pSMBr->u.EncryptionKey,CIFS_CRYPTO_KEY_SIZE ); }else if ((pSMBr->hdr.Flags2 &SMBFLG2_EXT_SEC ) && (pSMBr->EncryptionKeyLength ==0 )) {
fs/cifs/connect.c +2 -2
@@ -3002,13 +3002,13 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,#ifdef CONFIG_CIFS_WEAK_PW_HASH if ((global_secflags &CIFSSEC_MAY_LANMAN ) && (ses->server->secType ==LANMAN )) -calc_lanman_hash (tcon->password, ses->cryptKey, +calc_lanman_hash (tcon->password, ses->server->cryptKey, ses->server->secMode &SECMODE_PW_ENCRYPT ? true : false, bcc_ptr); else#endif /* CIFS_WEAK_PW_HASH */ -SMBNTencrypt (tcon->password, ses->cryptKey, bcc_ptr); +SMBNTencrypt (tcon->password, ses->server->cryptKey, bcc_ptr); bcc_ptr +=CIFS_SESS_KEY_SIZE ;if (ses->capabilities &CAP_UNICODE ) {
fs/cifs/sess.c +7 -3
@@ -667,10 +667,14 @@ ssetup_ntlmssp_authenticate:/* no capabilities flags in old lanman negotiation */ pSMB->old_req.PasswordLength =cpu_to_le16 (CIFS_SESS_KEY_SIZE ); -/* BB calculate hash with password */ -/* and copy into bcc */ -calc_lanman_hash (ses->password, ses->cryptKey, +/* Calculate hash with password and copy into bcc_ptr. +* Encryption Key (stored as in cryptKey) gets used if the +* security mode bit in Negottiate Protocol response states +* to use challenge/response method (i.e. Password bit is 1). +*/ + +calc_lanman_hash (ses->password, ses->server->cryptKey, ses->server->secMode &SECMODE_PW_ENCRYPT ? true : false, lnm_session_key);
Signature · 1 line
1.6.0.2
A message that is not in the archive (sent off-list or not yet received): 1288197518-9117-1-git-send-email-shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 23 lines · On Wed, 27 Oct 2010 11:38:38 -0500 shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@pub…
From: Shirish Pargaonkar <[email protected]>
Need to have cryptKey or server challenge in smb connection (struct
TCP_Server_Info) for ntlm and ntlmv2 auth types for which cryptKey (Encryption Key) is supplied just once in Negotiate Protocol response during an smb connection setup for all the smb sessions over that smb connection.For ntlmssp, cryptKey or server challenge is provided for every smb session in type 2 packet of ntlmssp negotiation, the cryptKey provided during Negotiation Protocol response before smb connection does not count.
Signed-off-by Shirish Pargaonkar <[email protected]>--- fs/cifs/cifsencrypt.c | 10 +++++++--- fs/cifs/cifsglob.h | 3 ++- fs/cifs/cifssmb.c | 4 ++-- fs/cifs/connect.c | 4 ++-- fs/cifs/sess.c | 10 +++++++--- 5 files changed, 20 insertions(+), 11 deletions(-)
[...]
fs/cifs/cifsglob.h struct TCP_Server_Info { · line 199
Quoted 9 lines
fs/cifs/cifsglob.h +1
-0@@ -196,6 +196,7 @@ struct TCP_Server_Info {int capabilities;/* allow selective disabling of caps by smb sess */ int timeAdj;/* Adjust for difference in server time zone in sec */ __u16 CurrentMid;/* multiplex id - rotating counter */ +char cryptKey[CIFS_CRYPTO_KEY_SIZE ];/* used by ntlm, ntlmv2 etc */
^^^^^^^^^^ Please, no camel-case on new fields.
fs/cifs/cifsglob.h struct cifsSesInfo { · line 244
Quoted 9 lines
fs/cifs/cifsglob.h +1
-1/* 16th byte of RFC1001 workstation name is always null */ char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL ];__u32 sequence_number;/* needed for CIFS PDU signature */ @@ -240,7 +241,7 @@ struct cifsSesInfo {char userName[MAX_USERNAME_SIZE +1 ];char *domainName;char *password; -char cryptKey[CIFS_CRYPTO_KEY_SIZE ]; +char cryptKey[CIFS_CRYPTO_KEY_SIZE ];/* used by ntlmssp */
^^^^^ And it wouldn't hurt to fix this one while you're in here.
Quoted 3 lines
fs/cifs/cifsglob.h +0
-0struct session_key auth_key;char ntlmv2_hash[16 ];unsigned int tilen;/* length of the target info blob */
Signature · 1 line
Jeff Layton <[email protected]>