Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support opaque

  • Loading branch information...
commit 81642f84c5d86057a4ce296baecebc919a5862a4 1 parent 78d0f64
@drbrain authored
View
5 History.txt
@@ -1,3 +1,8 @@
+=== 1.0.1
+
+* Bug fixes
+ * Support opaque per RFC 2617 3.2.1
+
=== 1.0 / 2010-09-10
* Major enhancements
View
15 lib/net/http/digest_auth.rb
@@ -74,16 +74,16 @@ def auth_header uri, www_authenticate, method, iis = false
params = {}
$2.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 }
- a_1 = Digest::MD5.hexdigest "#{user}:#{params['realm']}:#{password}"
- a_2 = Digest::MD5.hexdigest "#{method}:#{uri.request_uri}"
+ ha1 = Digest::MD5.hexdigest "#{user}:#{params['realm']}:#{password}"
+ ha2 = Digest::MD5.hexdigest "#{method}:#{uri.request_uri}"
request_digest = [
- a_1,
+ ha1,
params['nonce'],
('%08x' % @nonce_count),
@cnonce,
params['qop'],
- a_2
+ ha2
].join ':'
header = [
@@ -98,8 +98,11 @@ def auth_header uri, www_authenticate, method, iis = false
"nonce=\"#{params['nonce']}\"",
"nc=#{'%08x' % @nonce_count}",
"cnonce=\"#{@cnonce}\"",
- "response=\"#{Digest::MD5.hexdigest request_digest}\""
- ]
+ "response=\"#{Digest::MD5.hexdigest request_digest}\"",
+ if params.key? 'opaque' then
+ "opaque=\"#{params['opaque']}\""
+ end
+ ].compact
header.join ', '
end
View
18 test/test_net_http_digest_auth.rb
@@ -49,6 +49,24 @@ def test_auth_header_iis
assert_equal expected, @da.auth_header(@uri, @header, 'GET', true)
end
+ def test_auth_header_opaque
+ expected = [
+ 'Digest username="user"',
+ 'realm="www.example.com"',
+ 'qop=auth',
+ 'uri="/"',
+ 'nonce="4107baa081a592a6021660200000cd6c5686ff5f579324402b374d83e2c9"',
+ 'nc=00000000',
+ 'cnonce="9ea5ff3bd34554a4165bbdc1df91dcff"',
+ 'response="67be92a5e7b38d08679957db04f5da04"',
+ 'opaque="5ccc069c403ebaf9f0171e9517f40e41"',
+ ].join ', '
+
+ @header << 'opaque="5ccc069c403ebaf9f0171e9517f40e41"'
+
+ assert_equal expected, @da.auth_header(@uri, @header, 'GET')
+ end
+
def test_auth_header_post
expected = [
'Digest username="user"',
Please sign in to comment.
Something went wrong with that request. Please try again.