ntlmv2/ntlmssp authentication code
Subsystems (2)
PATCH 6/8 ntlmv2/ntlmssp authentication code
From: Shirish Pargaonkar <[email protected]>
To calculate ntlmv2 response we need ti/av pair blob.
For sec mech like ntlmssp, the blob is plucked from type 2 response from the server. From this blob, netbios name of the domain is retrieved, if user has not already provided.
For sec mech like ntlmv2, create a minimal, two av pair blob.
The allocated blob is freed in case of error. In case there is no error, this blob is used in calculating ntlmv2 response (in CalcNTLMv2_response) and is also copied on the response to the server, and then freed.
The type 3 ntlmssp response is prepared on a buffer,
5 * sizeof of struct _AUTHENTICATE_MESSAGE, an empirical value large enough to hold _AUTHENTICATE_MESSAGE plus a blob with max possible 10 values as part of ntlmv2 response and lmv2 keys and domain, user, workstation names etc.
--- fs/cifs/cifsencrypt.c | 47 +++++++++++++++++++++---- fs/cifs/cifsglob.h | 2 +- fs/cifs/cifsproto.h | 4 +- fs/cifs/sess.c | 92 ++++++++++++++++++++++++++++++++++-------------- fs/cifs/transport.c | 6 ++-- 5 files changed, 110 insertions(+), 41 deletions(-)
fs/cifs/cifsencrypt.c +39 -8
@@ -80,7 +80,7 @@ int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, server->sequence_number++;spin_unlock (&GlobalMid_Lock); - rc =cifs_calculate_signature (cifs_pdu, &server->mac_signing_key, + rc =cifs_calculate_signature (cifs_pdu, &server->session_key, smb_signature);if (rc)memset (cifs_pdu->Signature.SecuritySignature,0 ,8 );
@@ -147,7 +147,7 @@ int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, server->sequence_number++;spin_unlock (&GlobalMid_Lock); - rc =cifs_calc_signature2 (iov, n_vec, &server->mac_signing_key, + rc =cifs_calc_signature2 (iov, n_vec, &server->session_key, smb_signature);if (rc)memset (cifs_pdu->Signature.SecuritySignature,0 ,8 );
@@ -211,7 +211,7 @@ int cifs_verify_signature(struct smb_hdr *cifs_pdu, }/* We fill in key by putting in 40 byte array which was allocated by caller */ -int cifs_calculate_mac_key (struct session_key *key,const char *rn, +int cifs_calculate_session_key (struct session_key *key,const char *rn,const char *password) {char temp_key[16 ];
@@ -395,7 +395,8 @@ calc_exit_2:return rc; } -void setup_ntlmv2_rsp (struct cifsSesInfo *ses,char *resp_buf, +int +setup_ntlmv2_rsp (struct cifsSesInfo *ses,char *resp_buf,const struct nls_table *nls_cp) {int rc;
@@ -408,20 +409,46 @@ void setup_ntlmv2_rsp(struct cifsSesInfo *ses, char *resp_buf,get_random_bytes (&buf->client_chal,sizeof (buf->client_chal)); buf->reserved2 =0 ; +if (ses->server->secType == RawNTLMSSP) { +if (!ses->domainName) { + rc =find_domain_name (ses); +if (rc) { +cERROR (1 ,"error %d finding domain name" , rc); + goto setup_ntlmv2_rsp_ret; + } + } + }else { + rc =build_avpair_blob (ses); +if (rc) { +cERROR (1 ,"error %d building av pair blob" , rc); +return rc; + } + } +/* calculate buf->ntlmv2_hash */ rc =calc_ntlmv2_hash (ses, nls_cp); -if (rc) +if (rc) {cERROR (1 ,"could not get v2 hash rc %d" , rc); + goto setup_ntlmv2_rsp_ret; + }CalcNTLMv2_response (ses, resp_buf);/* now calculate the MAC key for NTLMv2 */ hmac_md5_init_limK_to_64 (ses->server->ntlmv2_hash,16 , &context);hmac_md5_update (resp_buf,16 , &context); -hmac_md5_final (ses->server->mac_signing_key.data.ntlmv2.key, &context); +hmac_md5_final (ses->server->session_key.data.ntlmv2.key, &context); -memcpy (&ses->server->mac_signing_key.data.ntlmv2.resp, resp_buf, +memcpy (&ses->server->session_key.data.ntlmv2.resp, resp_buf,sizeof (struct ntlmv2_resp )); - ses->server->mac_signing_key.len =16 +sizeof (struct ntlmv2_resp ); + ses->server->session_key.len =16 +sizeof (struct ntlmv2_resp ); + +return 0 ; + +setup_ntlmv2_rsp_ret: +kfree (ses->tiblob); + ses->tilen =0 ; + +return rc; } void CalcNTLMv2_response(const struct cifsSesInfo *ses,
@@ -435,6 +462,10 @@ void CalcNTLMv2_response(const struct cifsSesInfo *ses,hmac_md5_update (v2_session_response+8 ,sizeof (struct ntlmv2_resp ) -8 , &context); +if (ses->tilen) +hmac_md5_update (ses->tiblob, + ses->tilen, &context); +hmac_md5_final (v2_session_response, &context);/* cifs_dump_mem("v2_sess_rsp: ", v2_session_response, 32); */ }
fs/cifs/cifsglob.h +1 -1
@@ -207,7 +207,7 @@ struct TCP_Server_Info {/* 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 */ -struct session_key mac_signing_key; +struct session_key session_key;char ntlmv2_hash[16 ];unsigned long lstrp;/* when we got last response from this server */ u16 dialect;/* dialect index that server chose */
fs/cifs/cifsproto.h +2 -2
@@ -363,10 +363,10 @@ extern int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *,extern int cifs_verify_signature (struct smb_hdr *,const struct session_key *session_key,__u32 expected_sequence_number); -extern int cifs_calculate_mac_key (struct session_key *key,const char *rn, +extern int cifs_calculate_session_key (struct session_key *key,const char *rn,const char *pass);extern void CalcNTLMv2_response (const struct cifsSesInfo *,char *); -extern void setup_ntlmv2_rsp (struct cifsSesInfo *,char *, +extern int setup_ntlmv2_rsp (struct cifsSesInfo *,char *,const struct nls_table *);extern int cifs_crypto_shash_allocate (struct TCP_Server_Info *);extern void cifs_crypto_shash_release (struct TCP_Server_Info *);
fs/cifs/sess.c +65 -27
196 lines not on this page · raw message
fs/cifs/transport.c +3 -3
@@ -543,7 +543,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses, (ses->server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))) { rc =cifs_verify_signature (midQ->resp_buf, - &ses->server->mac_signing_key, + &ses->server->session_key, midQ->sequence_number+1 );if (rc) {cERROR (1 ,"Unexpected SMB signature" );
@@ -731,7 +731,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses, (ses->server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))) { rc =cifs_verify_signature (out_buf, - &ses->server->mac_signing_key, + &ses->server->session_key, midQ->sequence_number+1 );if (rc) {cERROR (1 ,"Unexpected SMB signature" );
@@ -981,7 +981,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon, (ses->server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))) { rc =cifs_verify_signature (out_buf, - &ses->server->mac_signing_key, + &ses->server->session_key, midQ->sequence_number+1 );if (rc) {cERROR (1 ,"Unexpected SMB signature" );
Signature · 1 line
1.6.0.2