ruby-openid 1.1.4 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/INSTALL +0 -9
- data/README +21 -22
- data/UPGRADE +117 -0
- data/admin/runtests.rb +36 -0
- data/examples/README +13 -21
- data/examples/active_record_openid_store/README +8 -3
- data/examples/active_record_openid_store/XXX_add_open_id_store_to_db.rb +4 -8
- data/examples/active_record_openid_store/XXX_upgrade_open_id_store.rb +26 -0
- data/examples/active_record_openid_store/lib/association.rb +2 -0
- data/examples/active_record_openid_store/lib/openid_ar_store.rb +22 -47
- data/examples/active_record_openid_store/test/store_test.rb +78 -48
- data/examples/discover +46 -0
- data/examples/{rails_server → rails_openid}/README +0 -0
- data/examples/{rails_server → rails_openid}/Rakefile +0 -0
- data/examples/{rails_server → rails_openid}/app/controllers/application.rb +0 -0
- data/examples/rails_openid/app/controllers/consumer_controller.rb +115 -0
- data/examples/{rails_server → rails_openid}/app/controllers/login_controller.rb +10 -2
- data/examples/rails_openid/app/controllers/server_controller.rb +265 -0
- data/examples/{rails_server → rails_openid}/app/helpers/application_helper.rb +0 -0
- data/examples/{rails_server → rails_openid}/app/helpers/login_helper.rb +0 -0
- data/examples/{rails_server → rails_openid}/app/helpers/server_helper.rb +0 -0
- data/examples/rails_openid/app/views/consumer/index.rhtml +81 -0
- data/examples/rails_openid/app/views/consumer/start.rhtml +8 -0
- data/examples/{rails_server → rails_openid}/app/views/layouts/server.rhtml +0 -0
- data/examples/{rails_server → rails_openid}/app/views/login/index.rhtml +1 -1
- data/examples/rails_openid/app/views/server/decide.rhtml +26 -0
- data/examples/{rails_server → rails_openid}/config/boot.rb +0 -0
- data/examples/{rails_server → rails_openid}/config/database.yml +0 -0
- data/examples/{rails_server → rails_openid}/config/environment.rb +0 -0
- data/examples/{rails_server → rails_openid}/config/environments/development.rb +0 -0
- data/examples/{rails_server → rails_openid}/config/environments/production.rb +0 -0
- data/examples/{rails_server → rails_openid}/config/environments/test.rb +0 -0
- data/examples/{rails_server → rails_openid}/config/routes.rb +2 -1
- data/examples/{rails_server → rails_openid}/doc/README_FOR_APP +0 -0
- data/examples/{rails_server → rails_openid}/public/404.html +0 -0
- data/examples/{rails_server → rails_openid}/public/500.html +0 -0
- data/examples/{rails_server → rails_openid}/public/dispatch.cgi +0 -0
- data/examples/{rails_server → rails_openid}/public/dispatch.fcgi +0 -0
- data/examples/{rails_server → rails_openid}/public/dispatch.rb +0 -0
- data/examples/{rails_server → rails_openid}/public/favicon.ico +0 -0
- data/examples/rails_openid/public/images/openid_login_bg.gif +0 -0
- data/examples/{rails_server → rails_openid}/public/javascripts/controls.js +0 -0
- data/examples/{rails_server → rails_openid}/public/javascripts/dragdrop.js +0 -0
- data/examples/{rails_server → rails_openid}/public/javascripts/effects.js +0 -0
- data/examples/{rails_server → rails_openid}/public/javascripts/prototype.js +0 -0
- data/examples/{rails_server → rails_openid}/public/robots.txt +0 -0
- data/examples/{rails_server → rails_openid}/script/about +0 -0
- data/examples/{rails_server → rails_openid}/script/breakpointer +0 -0
- data/examples/{rails_server → rails_openid}/script/console +0 -0
- data/examples/{rails_server → rails_openid}/script/destroy +0 -0
- data/examples/{rails_server → rails_openid}/script/generate +0 -0
- data/examples/{rails_server → rails_openid}/script/performance/benchmarker +0 -0
- data/examples/{rails_server → rails_openid}/script/performance/profiler +0 -0
- data/examples/{rails_server → rails_openid}/script/plugin +0 -0
- data/examples/{rails_server → rails_openid}/script/process/reaper +0 -0
- data/examples/{rails_server → rails_openid}/script/process/spawner +0 -0
- data/examples/{rails_server → rails_openid}/script/process/spinner +0 -0
- data/examples/{rails_server → rails_openid}/script/runner +0 -0
- data/examples/{rails_server → rails_openid}/script/server +0 -0
- data/examples/{rails_server → rails_openid}/test/functional/login_controller_test.rb +0 -0
- data/examples/{rails_server → rails_openid}/test/functional/server_controller_test.rb +0 -0
- data/examples/{rails_server → rails_openid}/test/test_helper.rb +0 -0
- data/lib/{hmac.rb → hmac/hmac.rb} +0 -0
- data/lib/{hmac-sha1.rb → hmac/sha1.rb} +1 -1
- data/lib/{hmac-sha2.rb → hmac/sha2.rb} +1 -1
- data/lib/openid/association.rb +213 -73
- data/lib/openid/consumer/associationmanager.rb +338 -0
- data/lib/openid/consumer/checkid_request.rb +175 -0
- data/lib/openid/consumer/discovery.rb +480 -0
- data/lib/openid/consumer/discovery_manager.rb +123 -0
- data/lib/openid/consumer/html_parse.rb +136 -0
- data/lib/openid/consumer/idres.rb +525 -0
- data/lib/openid/consumer/responses.rb +133 -0
- data/lib/openid/consumer.rb +280 -807
- data/lib/openid/cryptutil.rb +85 -0
- data/lib/openid/dh.rb +60 -23
- data/lib/openid/extension.rb +31 -0
- data/lib/openid/extensions/ax.rb +506 -0
- data/lib/openid/extensions/pape.rb +182 -0
- data/lib/openid/extensions/sreg.rb +275 -0
- data/lib/openid/extras.rb +11 -0
- data/lib/openid/fetchers.rb +132 -93
- data/lib/openid/kvform.rb +133 -0
- data/lib/openid/kvpost.rb +56 -0
- data/lib/openid/message.rb +534 -0
- data/lib/openid/protocolerror.rb +6 -0
- data/lib/openid/server.rb +1215 -666
- data/lib/openid/store/filesystem.rb +271 -0
- data/lib/openid/store/interface.rb +75 -0
- data/lib/openid/store/memory.rb +84 -0
- data/lib/openid/store/nonce.rb +68 -0
- data/lib/openid/trustroot.rb +314 -87
- data/lib/openid/urinorm.rb +37 -34
- data/lib/openid/util.rb +42 -220
- data/lib/openid/yadis/accept.rb +148 -0
- data/lib/openid/yadis/constants.rb +21 -0
- data/lib/openid/yadis/discovery.rb +153 -0
- data/lib/openid/yadis/filters.rb +205 -0
- data/lib/openid/{htmltokenizer.rb → yadis/htmltokenizer.rb} +1 -54
- data/lib/openid/yadis/parsehtml.rb +36 -0
- data/lib/openid/yadis/services.rb +42 -0
- data/lib/openid/yadis/xrds.rb +171 -0
- data/lib/openid/yadis/xri.rb +90 -0
- data/lib/openid/yadis/xrires.rb +106 -0
- data/lib/openid.rb +1 -4
- data/test/data/accept.txt +124 -0
- data/test/data/dh.txt +29 -0
- data/test/data/example-xrds.xml +14 -0
- data/test/data/linkparse.txt +587 -0
- data/test/data/n2b64 +650 -0
- data/test/data/test1-discover.txt +137 -0
- data/test/data/test1-parsehtml.txt +128 -0
- data/test/data/test_discover/openid.html +11 -0
- data/test/data/test_discover/openid2.html +11 -0
- data/test/data/test_discover/openid2_xrds.xml +12 -0
- data/test/data/test_discover/openid2_xrds_no_local_id.xml +11 -0
- data/test/data/test_discover/openid_1_and_2.html +11 -0
- data/test/data/test_discover/openid_1_and_2_xrds.xml +16 -0
- data/test/data/test_discover/openid_1_and_2_xrds_bad_delegate.xml +17 -0
- data/test/data/test_discover/openid_and_yadis.html +12 -0
- data/test/data/test_discover/openid_no_delegate.html +10 -0
- data/test/data/test_discover/yadis_0entries.xml +12 -0
- data/test/data/test_discover/yadis_2_bad_local_id.xml +15 -0
- data/test/data/test_discover/yadis_2entries_delegate.xml +22 -0
- data/test/data/test_discover/yadis_2entries_idp.xml +21 -0
- data/test/data/test_discover/yadis_another_delegate.xml +14 -0
- data/test/data/test_discover/yadis_idp.xml +12 -0
- data/test/data/test_discover/yadis_idp_delegate.xml +13 -0
- data/test/data/test_discover/yadis_no_delegate.xml +11 -0
- data/test/data/test_xrds/=j3h.2007.11.14.xrds +25 -0
- data/test/data/test_xrds/README +12 -0
- data/test/data/test_xrds/delegated-20060809-r1.xrds +34 -0
- data/test/data/test_xrds/delegated-20060809-r2.xrds +34 -0
- data/test/data/test_xrds/delegated-20060809.xrds +34 -0
- data/test/data/test_xrds/no-xrd.xml +7 -0
- data/test/data/test_xrds/not-xrds.xml +2 -0
- data/test/data/test_xrds/prefixsometimes.xrds +34 -0
- data/test/data/test_xrds/ref.xrds +109 -0
- data/test/data/test_xrds/sometimesprefix.xrds +34 -0
- data/test/data/test_xrds/spoof1.xrds +25 -0
- data/test/data/test_xrds/spoof2.xrds +25 -0
- data/test/data/test_xrds/spoof3.xrds +37 -0
- data/test/data/test_xrds/status222.xrds +9 -0
- data/test/data/test_xrds/valid-populated-xrds.xml +39 -0
- data/test/data/trustroot.txt +147 -0
- data/test/discoverdata.rb +131 -0
- data/test/test_accept.rb +170 -0
- data/test/test_association.rb +266 -0
- data/test/test_associationmanager.rb +899 -0
- data/test/test_ax.rb +587 -0
- data/test/test_checkid_request.rb +297 -0
- data/test/test_consumer.rb +257 -0
- data/test/test_cryptutil.rb +117 -0
- data/test/test_dh.rb +86 -0
- data/test/test_discover.rb +772 -0
- data/test/test_discovery_manager.rb +262 -0
- data/test/test_extras.rb +35 -0
- data/test/test_fetchers.rb +472 -0
- data/test/test_filters.rb +270 -0
- data/test/test_idres.rb +816 -0
- data/test/test_kvform.rb +165 -0
- data/test/test_kvpost.rb +65 -0
- data/test/test_linkparse.rb +101 -0
- data/test/test_message.rb +1058 -0
- data/test/test_nonce.rb +89 -0
- data/test/test_openid_yadis.rb +178 -0
- data/test/test_pape.rb +233 -0
- data/test/test_parsehtml.rb +80 -0
- data/test/test_responses.rb +63 -0
- data/test/test_server.rb +2270 -0
- data/test/test_sreg.rb +479 -0
- data/test/test_stores.rb +269 -0
- data/test/test_trustroot.rb +112 -0
- data/test/{urinorm.rb → test_urinorm.rb} +6 -3
- data/test/test_util.rb +144 -0
- data/test/test_xrds.rb +160 -0
- data/test/test_xri.rb +48 -0
- data/test/test_xrires.rb +63 -0
- data/test/test_yadis_discovery.rb +207 -0
- data/test/testutil.rb +116 -0
- data/test/util.rb +47 -50
- metadata +233 -143
- data/examples/consumer.rb +0 -290
- data/examples/rails_openid_login_generator/openid_login_generator-0.1.gem +0 -0
- data/examples/rails_server/app/controllers/server_controller.rb +0 -190
- data/examples/rails_server/app/views/server/decide.rhtml +0 -11
- data/examples/rails_server/public/images/rails.png +0 -0
- data/lib/hmac-md5.rb +0 -11
- data/lib/hmac-rmd160.rb +0 -11
- data/lib/openid/discovery.rb +0 -122
- data/lib/openid/filestore.rb +0 -315
- data/lib/openid/parse.rb +0 -23
- data/lib/openid/service.rb +0 -147
- data/lib/openid/stores.rb +0 -178
- data/test/assoc.rb +0 -38
- data/test/consumer.rb +0 -376
- data/test/data/brian.xrds +0 -16
- data/test/data/brianellin.mylid.xrds +0 -42
- data/test/dh.rb +0 -20
- data/test/extensions.rb +0 -30
- data/test/linkparse.rb +0 -305
- data/test/runtests.rb +0 -22
- data/test/server2.rb +0 -1053
- data/test/service.rb +0 -47
- data/test/storetestcase.rb +0 -172
- data/test/teststore.rb +0 -47
- data/test/trustroot.rb +0 -117
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require "openid/util"
|
|
2
|
+
require "digest/sha1"
|
|
3
|
+
require "digest/sha2"
|
|
4
|
+
require "hmac/sha1"
|
|
5
|
+
require "hmac/sha2"
|
|
6
|
+
|
|
7
|
+
module OpenID
|
|
8
|
+
# This module contains everything needed to perform low-level
|
|
9
|
+
# cryptograph and data manipulation tasks.
|
|
10
|
+
module CryptUtil
|
|
11
|
+
|
|
12
|
+
# Generate a random number, doing a little extra work to make it
|
|
13
|
+
# more likely that it's suitable for cryptography. If your system
|
|
14
|
+
# doesn't have /dev/urandom then this number is not
|
|
15
|
+
# cryptographically safe. See
|
|
16
|
+
# <http://www.cosine.org/2007/08/07/security-ruby-kernel-rand/>
|
|
17
|
+
# for more information. max is the largest possible value of such
|
|
18
|
+
# a random number, where the result will be less than max.
|
|
19
|
+
def CryptUtil.rand(max)
|
|
20
|
+
Kernel.srand()
|
|
21
|
+
return Kernel.rand(max)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def CryptUtil.sha1(text)
|
|
25
|
+
return Digest::SHA1.digest(text)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def CryptUtil.hmac_sha1(key, text)
|
|
29
|
+
return HMAC::SHA1.digest(key, text)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def CryptUtil.sha256(text)
|
|
33
|
+
return Digest::SHA256.digest(text)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def CryptUtil.hmac_sha256(key, text)
|
|
37
|
+
return HMAC::SHA256.digest(key, text)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Generate a random string of the given length, composed of the
|
|
41
|
+
# specified characters. If chars is nil, generate a string
|
|
42
|
+
# composed of characters in the range 0..255.
|
|
43
|
+
def CryptUtil.random_string(length, chars=nil)
|
|
44
|
+
s = ""
|
|
45
|
+
|
|
46
|
+
unless chars.nil?
|
|
47
|
+
length.times { s << chars[rand(chars.length)] }
|
|
48
|
+
else
|
|
49
|
+
length.times { s << rand(256).chr }
|
|
50
|
+
end
|
|
51
|
+
return s
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Convert a number to its binary representation; return a string
|
|
55
|
+
# of bytes.
|
|
56
|
+
def CryptUtil.num_to_binary(n)
|
|
57
|
+
bits = n.to_s(2)
|
|
58
|
+
prepend = (8 - bits.length % 8)
|
|
59
|
+
bits = ('0' * prepend) + bits
|
|
60
|
+
return [bits].pack('B*')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Convert a string of bytes into a number.
|
|
64
|
+
def CryptUtil.binary_to_num(s)
|
|
65
|
+
# taken from openid-ruby 0.0.1
|
|
66
|
+
s = "\000" * (4 - (s.length % 4)) + s
|
|
67
|
+
num = 0
|
|
68
|
+
s.unpack('N*').each do |x|
|
|
69
|
+
num <<= 32
|
|
70
|
+
num |= x
|
|
71
|
+
end
|
|
72
|
+
return num
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Encode a number as a base64-encoded byte string.
|
|
76
|
+
def CryptUtil.num_to_base64(l)
|
|
77
|
+
return OpenID::Util.to_base64(num_to_binary(l))
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Decode a base64 byte string to a number.
|
|
81
|
+
def CryptUtil.base64_to_num(s)
|
|
82
|
+
return binary_to_num(OpenID::Util.from_base64(s))
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
data/lib/openid/dh.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "openid/util"
|
|
2
|
+
require "openid/cryptutil"
|
|
2
3
|
|
|
3
4
|
module OpenID
|
|
4
5
|
|
|
@@ -7,40 +8,76 @@ module OpenID
|
|
|
7
8
|
#
|
|
8
9
|
# Read more about Diffie-Hellman on wikipedia:
|
|
9
10
|
# http://en.wikipedia.org/wiki/Diffie-Hellman
|
|
11
|
+
|
|
10
12
|
class DiffieHellman
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
@@
|
|
14
|
+
# From the OpenID specification
|
|
15
|
+
@@default_mod = 155172898181473697471232257763715539915724801966915404479707795314057629378541917580651227423698188993727816152646631438561595825688188889951272158842675419950341258706556549803580104870537681476726513255747040765857479291291572334510643245094715007229621094194349783925984760375594985848253359305585439638443
|
|
16
|
+
@@default_gen = 2
|
|
14
17
|
|
|
15
|
-
attr_reader :
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
unless g.nil?
|
|
22
|
-
g = OpenID::Util.base64_to_num(g)
|
|
23
|
-
end
|
|
24
|
-
DiffieHellman.new(p, g)
|
|
18
|
+
attr_reader :modulus, :generator, :public
|
|
19
|
+
|
|
20
|
+
# A new DiffieHellman object, using the modulus and generator from
|
|
21
|
+
# the OpenID specification
|
|
22
|
+
def DiffieHellman.from_defaults
|
|
23
|
+
DiffieHellman.new(@@default_mod, @@default_gen)
|
|
25
24
|
end
|
|
26
25
|
|
|
27
|
-
def initialize(
|
|
28
|
-
@
|
|
29
|
-
@
|
|
30
|
-
|
|
31
|
-
@private = OpenID::Util.rand(@p-2) + 1
|
|
32
|
-
@public = OpenID::Util.powermod(@g, @private, @p)
|
|
26
|
+
def initialize(modulus=nil, generator=nil, priv=nil)
|
|
27
|
+
@modulus = modulus.nil? ? @@default_mod : modulus
|
|
28
|
+
@generator = generator.nil? ? @@default_gen : generator
|
|
29
|
+
set_private(priv.nil? ? OpenID::CryptUtil.rand(@modulus-2) + 1 : priv)
|
|
33
30
|
end
|
|
34
31
|
|
|
35
32
|
def get_shared_secret(composite)
|
|
36
|
-
|
|
33
|
+
DiffieHellman.powermod(composite, @private, @modulus)
|
|
37
34
|
end
|
|
38
35
|
|
|
39
|
-
def
|
|
36
|
+
def xor_secret(algorithm, composite, secret)
|
|
40
37
|
dh_shared = get_shared_secret(composite)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return
|
|
38
|
+
packed_dh_shared = OpenID::CryptUtil.num_to_binary(dh_shared)
|
|
39
|
+
hashed_dh_shared = algorithm.call(packed_dh_shared)
|
|
40
|
+
return DiffieHellman.strxor(secret, hashed_dh_shared)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def using_default_values?
|
|
44
|
+
@generator == @@default_gen && @modulus == @@default_mod
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
def set_private(priv)
|
|
49
|
+
@private = priv
|
|
50
|
+
@public = DiffieHellman.powermod(@generator, @private, @modulus)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def DiffieHellman.strxor(s, t)
|
|
54
|
+
if s.length != t.length
|
|
55
|
+
raise ArgumentError, "strxor: lengths don't match. " +
|
|
56
|
+
"Inputs were #{s.inspect} and #{t.inspect}"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
indices = 0...(s.length)
|
|
60
|
+
chrs = indices.collect {|i| (s[i]^t[i]).chr}
|
|
61
|
+
chrs.join("")
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# This code is taken from this post:
|
|
65
|
+
# <http://blade.nagaokaut.ac.jp/cgi-bin/scat.\rb/ruby/ruby-talk/19098>
|
|
66
|
+
# by Eric Lee Green.
|
|
67
|
+
def DiffieHellman.powermod(x, n, q)
|
|
68
|
+
counter=0
|
|
69
|
+
n_p=n
|
|
70
|
+
y_p=1
|
|
71
|
+
z_p=x
|
|
72
|
+
while n_p != 0
|
|
73
|
+
if n_p[0]==1
|
|
74
|
+
y_p=(y_p*z_p) % q
|
|
75
|
+
end
|
|
76
|
+
n_p = n_p >> 1
|
|
77
|
+
z_p = (z_p * z_p) % q
|
|
78
|
+
counter += 1
|
|
79
|
+
end
|
|
80
|
+
return y_p
|
|
44
81
|
end
|
|
45
82
|
|
|
46
83
|
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'openid/message'
|
|
2
|
+
|
|
3
|
+
module OpenID
|
|
4
|
+
# An interface for OpenID extensions.
|
|
5
|
+
class Extension < Object
|
|
6
|
+
|
|
7
|
+
def initialize
|
|
8
|
+
@ns_uri = nil
|
|
9
|
+
@ns_alias = nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Get the string arguments that should be added to an OpenID
|
|
13
|
+
# message for this extension.
|
|
14
|
+
def get_extension_args
|
|
15
|
+
raise NotImplementedError
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Add the arguments from this extension to the provided
|
|
19
|
+
# message, or create a new message containing only those
|
|
20
|
+
# arguments. Returns the message with added extension args.
|
|
21
|
+
def to_message(message = nil)
|
|
22
|
+
message = Message.new if message.nil?
|
|
23
|
+
|
|
24
|
+
message.namespaces.add_alias(@ns_uri, @ns_alias)
|
|
25
|
+
# XXX python ignores keyerror if m.ns.getAlias(uri) == alias
|
|
26
|
+
|
|
27
|
+
message.update_args(@ns_uri, get_extension_args)
|
|
28
|
+
return message
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|