@@ -310,12 +310,18 @@ def basic_auth_header(username,password)
310
310
auth_str = "Basic " + Rex ::Text . encode_base64 ( auth_str )
311
311
end
312
312
313
+
314
+ def make_cnonce
315
+ Digest ::MD5 . hexdigest "%x" % ( Time . now . to_i + rand ( 65535 ) )
316
+ end
317
+
313
318
# Send a series of requests to complete Digest Authentication
314
319
#
315
320
# @param opts [Hash] the options used to build an HTTP request
316
321
# @return [Response] the last valid HTTP response we received
317
322
def digest_auth ( opts = { } )
318
- @nonce_count = 0
323
+ cnonce = make_cnonce
324
+ nonce_count = 0
319
325
320
326
to = opts [ 'timeout' ] || 20
321
327
@@ -330,7 +336,7 @@ def digest_auth(opts={})
330
336
end
331
337
332
338
begin
333
- @ nonce_count += 1
339
+ nonce_count += 1
334
340
335
341
resp = opts [ 'response' ]
336
342
@@ -387,7 +393,7 @@ def digest_auth(opts={})
387
393
[
388
394
algorithm . hexdigest ( "#{ digest_user } :#{ parameters [ 'realm' ] } :#{ digest_password } " ) ,
389
395
parameters [ 'nonce' ] ,
390
- @ cnonce
396
+ cnonce
391
397
] . join ':'
392
398
else
393
399
"#{ digest_user } :#{ parameters [ 'realm' ] } :#{ digest_password } "
@@ -397,7 +403,7 @@ def digest_auth(opts={})
397
403
ha2 = algorithm . hexdigest ( "#{ method } :#{ path } " )
398
404
399
405
request_digest = [ ha1 , parameters [ 'nonce' ] ]
400
- request_digest . push ( ( '%08x' % @ nonce_count) , @ cnonce, qop ) if qop
406
+ request_digest . push ( ( '%08x' % nonce_count ) , cnonce , qop ) if qop
401
407
request_digest << ha2
402
408
request_digest = request_digest . join ':'
403
409
@@ -407,8 +413,8 @@ def digest_auth(opts={})
407
413
"realm=\" #{ parameters [ 'realm' ] } \" " ,
408
414
"nonce=\" #{ parameters [ 'nonce' ] } \" " ,
409
415
"uri=\" #{ path } \" " ,
410
- "cnonce=\" #{ @ cnonce} \" " ,
411
- "nc=#{ '%08x' % @ nonce_count} " ,
416
+ "cnonce=\" #{ cnonce } \" " ,
417
+ "nc=#{ '%08x' % nonce_count } " ,
412
418
"algorithm=#{ algstr } " ,
413
419
"response=\" #{ algorithm . hexdigest ( request_digest ) [ 0 , 32 ] } \" " ,
414
420
# The spec says the qop value shouldn't be enclosed in quotes, but
0 commit comments