diff options
Diffstat (limited to 'fs/cifs/cifsencrypt.c')
-rw-r--r-- | fs/cifs/cifsencrypt.c | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c index 8bcb1da3270e..a89efaf78a26 100644 --- a/fs/cifs/cifsencrypt.c +++ b/fs/cifs/cifsencrypt.c | |||
@@ -212,7 +212,8 @@ int cifs_calculate_mac_key(char * key, const char * rn, const char * password) | |||
212 | return 0; | 212 | return 0; |
213 | } | 213 | } |
214 | 214 | ||
215 | int CalcNTLMv2_partial_mac_key(struct cifsSesInfo * ses, struct nls_table * nls_info) | 215 | int CalcNTLMv2_partial_mac_key(struct cifsSesInfo * ses, |
216 | const struct nls_table * nls_info) | ||
216 | { | 217 | { |
217 | char temp_hash[16]; | 218 | char temp_hash[16]; |
218 | struct HMACMD5Context ctx; | 219 | struct HMACMD5Context ctx; |
@@ -305,13 +306,15 @@ void calc_lanman_hash(struct cifsSesInfo * ses, char * lnm_session_key) | |||
305 | } | 306 | } |
306 | #endif /* CIFS_WEAK_PW_HASH */ | 307 | #endif /* CIFS_WEAK_PW_HASH */ |
307 | 308 | ||
308 | static int calc_ntlmv2_hash(const struct cifsSesInfo *ses, | 309 | static int calc_ntlmv2_hash(struct cifsSesInfo *ses, |
309 | char * ntv2_hash) | 310 | const struct nls_table * nls_cp) |
310 | { | 311 | { |
311 | int rc = 0; | 312 | int rc = 0; |
312 | int len; | 313 | int len; |
313 | char nt_hash[16]; | 314 | char nt_hash[16]; |
314 | struct HMACMD5Context * pctxt; | 315 | struct HMACMD5Context * pctxt; |
316 | wchar_t * user; | ||
317 | wchar_t * domain; | ||
315 | 318 | ||
316 | pctxt = kmalloc(sizeof(struct HMACMD5Context), GFP_KERNEL); | 319 | pctxt = kmalloc(sizeof(struct HMACMD5Context), GFP_KERNEL); |
317 | 320 | ||
@@ -321,26 +324,44 @@ static int calc_ntlmv2_hash(const struct cifsSesInfo *ses, | |||
321 | /* calculate md4 hash of password */ | 324 | /* calculate md4 hash of password */ |
322 | E_md4hash(ses->password, nt_hash); | 325 | E_md4hash(ses->password, nt_hash); |
323 | 326 | ||
324 | /* convERT Domainname to unicode and uppercase */ | 327 | /* convert Domainname to unicode and uppercase */ |
325 | hmac_md5_init_limK_to_64(nt_hash, 16, pctxt); | 328 | hmac_md5_init_limK_to_64(nt_hash, 16, pctxt); |
326 | 329 | ||
327 | /* convert ses->userName to unicode and uppercase */ | 330 | /* convert ses->userName to unicode and uppercase */ |
328 | 331 | len = strlen(ses->userName); | |
329 | /* len = ... */ /* BB FIXME BB */ | 332 | user = kmalloc(2 + (len * 2), GFP_KERNEL); |
330 | 333 | if(user == NULL) | |
331 | /* hmac_md5_update(user, len, pctxt); */ | 334 | goto calc_exit_2; |
335 | len = cifs_strtoUCS(user, ses->userName, len, nls_cp); | ||
336 | UniStrupr(user); | ||
337 | hmac_md5_update((char *)user, 2*len, pctxt); | ||
332 | 338 | ||
333 | /* convert ses->domainName to unicode and uppercase */ | 339 | /* convert ses->domainName to unicode and uppercase */ |
340 | if(ses->domainName) { | ||
341 | len = strlen(ses->domainName); | ||
334 | 342 | ||
335 | /* len = ... */ /* BB FIXME BB */ | 343 | domain = kmalloc(2 + (len * 2), GFP_KERNEL); |
336 | /* hmac_md5_update(domain, len, pctxt); */ | 344 | if(domain == NULL) |
345 | goto calc_exit_1; | ||
346 | len = cifs_strtoUCS(domain, ses->domainName, len, nls_cp); | ||
347 | UniStrupr(domain); | ||
337 | 348 | ||
338 | hmac_md5_final(ntv2_hash, pctxt); | 349 | hmac_md5_update((char *)domain, 2*len, pctxt); |
350 | |||
351 | kfree(domain); | ||
352 | } | ||
353 | calc_exit_1: | ||
354 | kfree(user); | ||
355 | calc_exit_2: | ||
356 | /* BB FIXME what about bytes 24 through 40 of the signing key? | ||
357 | compare with the NTLM example */ | ||
358 | hmac_md5_final(ses->server->mac_signing_key, pctxt); | ||
339 | 359 | ||
340 | return rc; | 360 | return rc; |
341 | } | 361 | } |
342 | 362 | ||
343 | void setup_ntlmv2_rsp(const struct cifsSesInfo * ses, char * resp_buf) | 363 | void setup_ntlmv2_rsp(struct cifsSesInfo * ses, char * resp_buf, |
364 | const struct nls_table * nls_cp) | ||
344 | { | 365 | { |
345 | int rc; | 366 | int rc; |
346 | struct ntlmv2_resp * buf = (struct ntlmv2_resp *)resp_buf; | 367 | struct ntlmv2_resp * buf = (struct ntlmv2_resp *)resp_buf; |
@@ -348,27 +369,28 @@ void setup_ntlmv2_rsp(const struct cifsSesInfo * ses, char * resp_buf) | |||
348 | buf->blob_signature = cpu_to_le32(0x00000101); | 369 | buf->blob_signature = cpu_to_le32(0x00000101); |
349 | buf->reserved = 0; | 370 | buf->reserved = 0; |
350 | buf->time = cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME)); | 371 | buf->time = cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME)); |
351 | get_random_bytes(&buf->client_chal, sizeof(buf->client_chal)); | 372 | get_random_bytes(&buf->client_chal, sizeof(buf->client_chal)); |
352 | buf->reserved2 = 0; | 373 | buf->reserved2 = 0; |
353 | buf->names[0].type = 0; | 374 | buf->names[0].type = 0; |
354 | buf->names[0].length = 0; | 375 | buf->names[0].length = 0; |
355 | 376 | ||
356 | /* calculate buf->ntlmv2_hash */ | 377 | /* calculate buf->ntlmv2_hash */ |
357 | rc = calc_ntlmv2_hash(ses,buf->ntlmv2_hash); | 378 | rc = calc_ntlmv2_hash(ses, nls_cp); |
358 | if(rc) | 379 | if(rc) |
359 | cERROR(1,("could not get v2 hash rc %d",rc)); | 380 | cERROR(1,("could not get v2 hash rc %d",rc)); |
381 | CalcNTLMv2_response(ses, resp_buf); | ||
360 | } | 382 | } |
361 | 383 | ||
362 | void CalcNTLMv2_response(const struct cifsSesInfo * ses,char * v2_session_response) | 384 | void CalcNTLMv2_response(const struct cifsSesInfo * ses, char * v2_session_response) |
363 | { | 385 | { |
364 | struct HMACMD5Context context; | 386 | struct HMACMD5Context context; |
387 | /* rest of v2 struct already generated */ | ||
365 | memcpy(v2_session_response + 8, ses->server->cryptKey,8); | 388 | memcpy(v2_session_response + 8, ses->server->cryptKey,8); |
366 | /* gen_blob(v2_session_response + 16); */ | ||
367 | hmac_md5_init_limK_to_64(ses->server->mac_signing_key, 16, &context); | 389 | hmac_md5_init_limK_to_64(ses->server->mac_signing_key, 16, &context); |
368 | 390 | ||
369 | hmac_md5_update(ses->server->cryptKey,8,&context); | 391 | hmac_md5_update(v2_session_response+8, |
370 | /* hmac_md5_update(v2_session_response+16)client thing,8,&context); */ /* BB fix */ | 392 | sizeof(struct ntlmv2_resp) - 8, &context); |
371 | 393 | ||
372 | hmac_md5_final(v2_session_response,&context); | 394 | hmac_md5_final(v2_session_response,&context); |
373 | cifs_dump_mem("v2_sess_rsp: ", v2_session_response, 32); /* BB removeme BB */ | 395 | /* cifs_dump_mem("v2_sess_rsp: ", v2_session_response, 32); */ |
374 | } | 396 | } |