net-http-digest_auth 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +4 -0
- data/.autotest +8 -0
- data/History.txt +5 -0
- data/Manifest.txt +7 -0
- data/README.txt +49 -0
- data/Rakefile +16 -0
- data/lib/net/http/digest_auth.rb +116 -0
- data/test/test_net_http_digest_auth.rb +72 -0
- metadata +131 -0
- metadata.gz.sig +1 -0
data.tar.gz.sig
ADDED
data/.autotest
ADDED
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= net-http-digest_auth
|
2
|
+
|
3
|
+
* http://github.com/drbrain/net-http-digest_auth
|
4
|
+
* http://seattlerb.rubyforge.org/net-http-digest_auth
|
5
|
+
* http://www.rfc-editor.org/rfc/rfc2617.txt
|
6
|
+
|
7
|
+
== DESCRIPTION:
|
8
|
+
|
9
|
+
An implementation of RFC 2617 - Digest Access Authentication. At this time
|
10
|
+
the gem does not fully integrate with Net::HTTP and can be used for with other
|
11
|
+
HTTP clients.
|
12
|
+
|
13
|
+
== FEATURES/PROBLEMS:
|
14
|
+
|
15
|
+
* Implements RFC 2617 for digest authentication
|
16
|
+
* Does not fully integrate with Net::HTTP
|
17
|
+
|
18
|
+
== SYNOPSIS:
|
19
|
+
|
20
|
+
See Net::HTTP::DigestAuth
|
21
|
+
|
22
|
+
== INSTALL:
|
23
|
+
|
24
|
+
gem install net-http-digest_auth
|
25
|
+
|
26
|
+
== LICENSE:
|
27
|
+
|
28
|
+
(The MIT License)
|
29
|
+
|
30
|
+
Copyright (c) 2010 Eric Hodel
|
31
|
+
|
32
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
33
|
+
a copy of this software and associated documentation files (the
|
34
|
+
'Software'), to deal in the Software without restriction, including
|
35
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
36
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
37
|
+
permit persons to whom the Software is furnished to do so, subject to
|
38
|
+
the following conditions:
|
39
|
+
|
40
|
+
The above copyright notice and this permission notice shall be
|
41
|
+
included in all copies or substantial portions of the Software.
|
42
|
+
|
43
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
44
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
45
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
46
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
47
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
48
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
49
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
|
6
|
+
Hoe.spec 'net-http-digest_auth' do
|
7
|
+
self.rubyforge_name = 'seattlerb'
|
8
|
+
developer 'Eric Hodel', 'drbrain@segment7.net'
|
9
|
+
|
10
|
+
self.testlib = :minitest
|
11
|
+
|
12
|
+
spec_extras['homepage'] =
|
13
|
+
'http://seattlerb.rubyforge.org/net-http-digest_auth'
|
14
|
+
end
|
15
|
+
|
16
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'digest'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
##
|
6
|
+
# An implementation of RFC 2617 Digest Access Authentication.
|
7
|
+
#
|
8
|
+
# http://www.rfc-editor.org/rfc/rfc2617.txt
|
9
|
+
#
|
10
|
+
# Here is a sample usage of DigestAuth on Net::HTTP:
|
11
|
+
#
|
12
|
+
# require 'uri'
|
13
|
+
# require 'net/http'
|
14
|
+
# require 'net/http/digest_auth'
|
15
|
+
#
|
16
|
+
# uri = URI.parse 'http://localhost:8000/'
|
17
|
+
# uri.user = 'username'
|
18
|
+
# uri.password = 'password'
|
19
|
+
#
|
20
|
+
# h = Net::HTTP.new uri.host, uri.port
|
21
|
+
#
|
22
|
+
# req = Net::HTTP::Get.new uri.request_uri
|
23
|
+
#
|
24
|
+
# res = h.request req
|
25
|
+
#
|
26
|
+
# digest_auth = Net::HTTP::DigestAuth.new
|
27
|
+
# auth = digest_auth.auth_header uri, res['www-authenticate'], 'GET'
|
28
|
+
#
|
29
|
+
# req = Net::HTTP::Get.new uri.request_uri
|
30
|
+
# req.add_field 'Authorization', auth
|
31
|
+
#
|
32
|
+
# res = h.request req
|
33
|
+
|
34
|
+
class Net::HTTP::DigestAuth
|
35
|
+
|
36
|
+
##
|
37
|
+
# Version of Net::HTTP::DigestAuth you are using
|
38
|
+
|
39
|
+
VERSION = '1.0'
|
40
|
+
|
41
|
+
##
|
42
|
+
# Creates a new DigestAuth header creator.
|
43
|
+
#
|
44
|
+
# +cnonce+ is the client nonce value. This should be an MD5 hexdigest of a
|
45
|
+
# secret value.
|
46
|
+
|
47
|
+
def initialize cnonce = make_cnonce
|
48
|
+
@nonce_count = -1
|
49
|
+
@cnonce = cnonce
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Creates a digest auth header for +uri+ from the +www_authenticate+ header
|
54
|
+
# for HTTP method +method+.
|
55
|
+
#
|
56
|
+
# The result of this method should be sent along with the HTTP request as
|
57
|
+
# the "Authorization" header. In Net::HTTP this will look like:
|
58
|
+
#
|
59
|
+
# request.add_field 'Authorization', digest_auth.auth_header # ...
|
60
|
+
#
|
61
|
+
# See Net::HTTP::DigestAuth for a complete example.
|
62
|
+
#
|
63
|
+
# IIS servers handle the "qop" parameter of digest authentication
|
64
|
+
# differently so you may need to set +iis+ to true for such servers.
|
65
|
+
|
66
|
+
def auth_header uri, www_authenticate, method, iis = false
|
67
|
+
@nonce_count += 1
|
68
|
+
|
69
|
+
user = CGI.unescape uri.user
|
70
|
+
password = CGI.unescape uri.password
|
71
|
+
|
72
|
+
www_authenticate =~ /^(\w+) (.*)/
|
73
|
+
|
74
|
+
params = {}
|
75
|
+
$2.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 }
|
76
|
+
|
77
|
+
a_1 = Digest::MD5.hexdigest "#{user}:#{params['realm']}:#{password}"
|
78
|
+
a_2 = Digest::MD5.hexdigest "#{method}:#{uri.request_uri}"
|
79
|
+
|
80
|
+
request_digest = [
|
81
|
+
a_1,
|
82
|
+
params['nonce'],
|
83
|
+
('%08x' % @nonce_count),
|
84
|
+
@cnonce,
|
85
|
+
params['qop'],
|
86
|
+
a_2
|
87
|
+
].join ':'
|
88
|
+
|
89
|
+
header = [
|
90
|
+
"Digest username=\"#{user}\"",
|
91
|
+
"realm=\"#{params['realm']}\"",
|
92
|
+
if iis then
|
93
|
+
"qop=\"#{params['qop']}\""
|
94
|
+
else
|
95
|
+
"qop=#{params['qop']}"
|
96
|
+
end,
|
97
|
+
"uri=\"#{uri.request_uri}\"",
|
98
|
+
"nonce=\"#{params['nonce']}\"",
|
99
|
+
"nc=#{'%08x' % @nonce_count}",
|
100
|
+
"cnonce=\"#{@cnonce}\"",
|
101
|
+
"response=\"#{Digest::MD5.hexdigest request_digest}\""
|
102
|
+
]
|
103
|
+
|
104
|
+
header.join ', '
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Creates a client nonce value that is used across all requests based on the
|
109
|
+
# current time.
|
110
|
+
|
111
|
+
def make_cnonce
|
112
|
+
Digest::MD5.hexdigest "%x" % (Time.now.to_i + rand(65535))
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'net/http/digest_auth'
|
3
|
+
|
4
|
+
class TestNetHttpDigestAuth < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@uri = URI.parse "http://www.example.com/"
|
8
|
+
@uri.user = 'user'
|
9
|
+
@uri.password = 'password'
|
10
|
+
|
11
|
+
@cnonce = '9ea5ff3bd34554a4165bbdc1df91dcff'
|
12
|
+
|
13
|
+
@header = [
|
14
|
+
'Digest qop="auth"',
|
15
|
+
'realm="www.example.com"',
|
16
|
+
'nonce="4107baa081a592a6021660200000cd6c5686ff5f579324402b374d83e2c9"'
|
17
|
+
].join ', '
|
18
|
+
|
19
|
+
@da = Net::HTTP::DigestAuth.new @cnonce
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_auth_header
|
23
|
+
expected = [
|
24
|
+
'Digest username="user"',
|
25
|
+
'realm="www.example.com"',
|
26
|
+
'qop=auth',
|
27
|
+
'uri="/"',
|
28
|
+
'nonce="4107baa081a592a6021660200000cd6c5686ff5f579324402b374d83e2c9"',
|
29
|
+
'nc=00000000',
|
30
|
+
'cnonce="9ea5ff3bd34554a4165bbdc1df91dcff"',
|
31
|
+
'response="67be92a5e7b38d08679957db04f5da04"'
|
32
|
+
].join ', '
|
33
|
+
|
34
|
+
assert_equal expected, @da.auth_header(@uri, @header, 'GET')
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_auth_header_iis
|
38
|
+
expected = [
|
39
|
+
'Digest username="user"',
|
40
|
+
'realm="www.example.com"',
|
41
|
+
'qop="auth"',
|
42
|
+
'uri="/"',
|
43
|
+
'nonce="4107baa081a592a6021660200000cd6c5686ff5f579324402b374d83e2c9"',
|
44
|
+
'nc=00000000',
|
45
|
+
'cnonce="9ea5ff3bd34554a4165bbdc1df91dcff"',
|
46
|
+
'response="67be92a5e7b38d08679957db04f5da04"'
|
47
|
+
].join ', '
|
48
|
+
|
49
|
+
assert_equal expected, @da.auth_header(@uri, @header, 'GET', true)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_auth_header_post
|
53
|
+
expected = [
|
54
|
+
'Digest username="user"',
|
55
|
+
'realm="www.example.com"',
|
56
|
+
'qop=auth',
|
57
|
+
'uri="/"',
|
58
|
+
'nonce="4107baa081a592a6021660200000cd6c5686ff5f579324402b374d83e2c9"',
|
59
|
+
'nc=00000000',
|
60
|
+
'cnonce="9ea5ff3bd34554a4165bbdc1df91dcff"',
|
61
|
+
'response="d82219e1e5430b136bbae1670fa51d48"'
|
62
|
+
].join ', '
|
63
|
+
|
64
|
+
assert_equal expected, @da.auth_header(@uri, @header, 'POST')
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_make_cnonce
|
68
|
+
assert_match %r%\A[a-f\d]{32}\z%, @da.make_cnonce
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: net-http-digest_auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: "1.0"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Eric Hodel
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain:
|
16
|
+
- |
|
17
|
+
-----BEGIN CERTIFICATE-----
|
18
|
+
MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
|
19
|
+
YWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZFgNu
|
20
|
+
ZXQwHhcNMDcxMjIxMDIwNDE0WhcNMDgxMjIwMDIwNDE0WjBBMRAwDgYDVQQDDAdk
|
21
|
+
cmJyYWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZ
|
22
|
+
FgNuZXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCbbgLrGLGIDE76
|
23
|
+
LV/cvxdEzCuYuS3oG9PrSZnuDweySUfdp/so0cDq+j8bqy6OzZSw07gdjwFMSd6J
|
24
|
+
U5ddZCVywn5nnAQ+Ui7jMW54CYt5/H6f2US6U0hQOjJR6cpfiymgxGdfyTiVcvTm
|
25
|
+
Gj/okWrQl0NjYOYBpDi+9PPmaH2RmLJu0dB/NylsDnW5j6yN1BEI8MfJRR+HRKZY
|
26
|
+
mUtgzBwF1V4KIZQ8EuL6I/nHVu07i6IkrpAgxpXUfdJQJi0oZAqXurAV3yTxkFwd
|
27
|
+
g62YrrW26mDe+pZBzR6bpLE+PmXCzz7UxUq3AE0gPHbiMXie3EFE0oxnsU3lIduh
|
28
|
+
sCANiQ8BAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
|
29
|
+
BBS5k4Z75VSpdM0AclG2UvzFA/VW5DANBgkqhkiG9w0BAQUFAAOCAQEAHagT4lfX
|
30
|
+
kP/hDaiwGct7XPuVGbrOsKRVD59FF5kETBxEc9UQ1clKWngf8JoVuEoKD774dW19
|
31
|
+
bU0GOVWO+J6FMmT/Cp7nuFJ79egMf/gy4gfUfQMuvfcr6DvZUPIs9P/TlK59iMYF
|
32
|
+
DIOQ3DxdF3rMzztNUCizN4taVscEsjCcgW6WkUJnGdqlu3OHWpQxZBJkBTjPCoc6
|
33
|
+
UW6on70SFPmAy/5Cq0OJNGEWBfgD9q7rrs/X8GGwUWqXb85RXnUVi/P8Up75E0ag
|
34
|
+
14jEc90kN+C7oI/AGCBN0j6JnEtYIEJZibjjDJTSMWlUKKkj30kq7hlUC2CepJ4v
|
35
|
+
x52qPcexcYZR7w==
|
36
|
+
-----END CERTIFICATE-----
|
37
|
+
|
38
|
+
date: 2010-09-10 00:00:00 -07:00
|
39
|
+
default_executable:
|
40
|
+
dependencies:
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubyforge
|
43
|
+
prerelease: false
|
44
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
hash: 7
|
50
|
+
segments:
|
51
|
+
- 2
|
52
|
+
- 0
|
53
|
+
- 4
|
54
|
+
version: 2.0.4
|
55
|
+
type: :development
|
56
|
+
version_requirements: *id001
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: hoe
|
59
|
+
prerelease: false
|
60
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 21
|
66
|
+
segments:
|
67
|
+
- 2
|
68
|
+
- 6
|
69
|
+
- 1
|
70
|
+
version: 2.6.1
|
71
|
+
type: :development
|
72
|
+
version_requirements: *id002
|
73
|
+
description: |-
|
74
|
+
An implementation of RFC 2617 - Digest Access Authentication. At this time
|
75
|
+
the gem does not fully integrate with Net::HTTP and can be used for with other
|
76
|
+
HTTP clients.
|
77
|
+
email:
|
78
|
+
- drbrain@segment7.net
|
79
|
+
executables: []
|
80
|
+
|
81
|
+
extensions: []
|
82
|
+
|
83
|
+
extra_rdoc_files:
|
84
|
+
- History.txt
|
85
|
+
- Manifest.txt
|
86
|
+
- README.txt
|
87
|
+
files:
|
88
|
+
- .autotest
|
89
|
+
- History.txt
|
90
|
+
- Manifest.txt
|
91
|
+
- README.txt
|
92
|
+
- Rakefile
|
93
|
+
- lib/net/http/digest_auth.rb
|
94
|
+
- test/test_net_http_digest_auth.rb
|
95
|
+
has_rdoc: true
|
96
|
+
homepage: http://seattlerb.rubyforge.org/net-http-digest_auth
|
97
|
+
licenses: []
|
98
|
+
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options:
|
101
|
+
- --main
|
102
|
+
- README.txt
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
hash: 3
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
version: "0"
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
version: "0"
|
123
|
+
requirements: []
|
124
|
+
|
125
|
+
rubyforge_project: seattlerb
|
126
|
+
rubygems_version: 1.3.7
|
127
|
+
signing_key:
|
128
|
+
specification_version: 3
|
129
|
+
summary: An implementation of RFC 2617 - Digest Access Authentication
|
130
|
+
test_files:
|
131
|
+
- test/test_net_http_digest_auth.rb
|
metadata.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
&��a����>�E]F��'�ؕ�A�Z��֗p��%#3�$ײ�����+�(��д~���B�_�i�p����]O@Z�h��_�?�~��P�����h���8��6���hڐ~H���s6�~3Ub�
|