Permalink
Browse files

Set nonce-count to "00000001" instead of "0"

  • Loading branch information...
1 parent bfe79b8 commit 5c5a86e38d9f4bce2fba36e8350be009ae52df22 @wok wok committed with May 24, 2012
Showing with 16 additions and 10 deletions.
  1. +14 −8 lib/httparty/net_digest_auth.rb
  2. +2 −2 spec/httparty/net_digest_auth_spec.rb
@@ -20,18 +20,24 @@ def initialize(username, password, method, path, response_header)
def authorization_header
@cnonce = md5(random)
- header = [%Q(Digest username="#{@username}"),
+ header = [
+ %Q(Digest username="#{@username}"),
%Q(realm="#{@response['realm']}"),
%Q(nonce="#{@response['nonce']}"),
%Q(uri="#{@path}"),
- %Q(response="#{request_digest}")]
-
- [%Q(cnonce="#{@cnonce}"),
- %Q(qop="#{@response['qop']}"),
- %Q(nc="0")].each { |field| header << field } if qop_present?
+ %Q(response="#{request_digest}"),
+ ]
+
+ if qop_present?
+ fields = [
+ %Q(cnonce="#{@cnonce}"),
+ %Q(qop="#{@response['qop']}"),
+ %Q(nc="00000001")
+ ]
+ fields.each { |field| header << field }
+ end
header << %Q(opaque="#{@response['opaque']}") if opaque_present?
-
header
end
@@ -58,7 +64,7 @@ def random
def request_digest
a = [md5(a1), @response['nonce'], md5(a2)]
- a.insert(2, "0", @cnonce, @response['qop']) if qop_present?
+ a.insert(2, "00000001", @cnonce, @response['qop']) if qop_present?
md5(a.join(":"))
end
@@ -66,11 +66,11 @@ def authorization_header
end
it "should set nonce-count" do
- authorization_header.should include(%Q(nc="0"))
+ authorization_header.should include(%Q(nc="00000001"))
end
it "should set response" do
- request_digest = "md5(md5(Mufasa:myhost@testrealm.com:Circle Of Life):NONCE:0:md5(deadbeef):auth:md5(GET:/dir/index.html))"
+ request_digest = "md5(md5(Mufasa:myhost@testrealm.com:Circle Of Life):NONCE:00000001:md5(deadbeef):auth:md5(GET:/dir/index.html))"
authorization_header.should include(%Q(response="#{request_digest}"))
end
end

0 comments on commit 5c5a86e

Please sign in to comment.