ruby-srp 0.0.2
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/.gitmodules +3 -0
- data/Readme.md +5 -0
- data/example/config.ru +5 -0
- data/example/http-srp.rb +73 -0
- data/example/models/log.rb +31 -0
- data/example/models/user.rb +42 -0
- data/example/public/bootstrap-responsive.min.css +9 -0
- data/example/public/bootstrap.min.css +9 -0
- data/example/public/example.css +25 -0
- data/example/public/glyphicons-halflings.png +0 -0
- data/example/public/jquery.min.js +4 -0
- data/example/public/srp.js +26 -0
- data/example/public/ui.js +0 -0
- data/example/views/index.erb +79 -0
- data/example/views/layout.erb +39 -0
- data/example/views/login.erb +20 -0
- data/example/views/signup.erb +22 -0
- data/example/views/verify.erb +7 -0
- data/lib/ruby-srp.rb +15 -0
- data/lib/srp/authentication.rb +59 -0
- data/lib/srp/client.rb +50 -0
- data/lib/srp/util.rb +77 -0
- data/ruby-srp.gemspec +26 -0
- data/test/auth_test.rb +47 -0
- data/test/test_helper.rb +3 -0
- metadata +92 -0
data/lib/srp/util.rb
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
require 'digest'
|
|
2
|
+
require 'openssl'
|
|
3
|
+
|
|
4
|
+
module SRP
|
|
5
|
+
module Util
|
|
6
|
+
|
|
7
|
+
# constants both sides know
|
|
8
|
+
# in this case taken from srp-js
|
|
9
|
+
PRIME_N = <<-EOS.split.join.hex
|
|
10
|
+
115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3
|
|
11
|
+
EOS
|
|
12
|
+
|
|
13
|
+
BIG_PRIME_N = <<-EOS # 1024 bits modulus (N)
|
|
14
|
+
eeaf0ab9adb38dd69c33f80afa8fc5e86072618775ff3c0b9ea2314c9c25657
|
|
15
|
+
6d674df7496ea81d3383b4813d692c6e0e0d5d8e250b98be48e495c1d6089da
|
|
16
|
+
d15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e5
|
|
17
|
+
7ec68edbc3c05726cc02fd4cbf4976eaa9afd5138fe8376435b9fc61d2fc0eb
|
|
18
|
+
06e3
|
|
19
|
+
EOS
|
|
20
|
+
GENERATOR = 2 # g
|
|
21
|
+
|
|
22
|
+
# a^n (mod m)
|
|
23
|
+
def modpow(a, n, m)
|
|
24
|
+
r = 1
|
|
25
|
+
while true
|
|
26
|
+
r = r * a % m if n[0] == 1
|
|
27
|
+
n >>= 1
|
|
28
|
+
return r if n == 0
|
|
29
|
+
a = a * a % m
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def sha256_hex(h)
|
|
34
|
+
Digest::SHA2.hexdigest([h].pack('H*'))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def sha256_str(s)
|
|
38
|
+
Digest::SHA2.hexdigest(s)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def bigrand(bytes)
|
|
42
|
+
OpenSSL::Random.random_bytes(bytes).unpack("H*")[0]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def multiplier
|
|
46
|
+
return "c46d46600d87fef149bd79b81119842f3c20241fda67d06ef412d8f6d9479c58".hex % PRIME_N
|
|
47
|
+
@k ||= calculate_multiplier
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
protected
|
|
51
|
+
|
|
52
|
+
def calculate_multiplier
|
|
53
|
+
n = PRIME_N
|
|
54
|
+
g = GENERATOR
|
|
55
|
+
nhex = '%x' % [n]
|
|
56
|
+
nlen = nhex.length + (nhex.length.odd? ? 1 : 0 )
|
|
57
|
+
ghex = '%x' % [g]
|
|
58
|
+
hashin = '0' * (nlen - nhex.length) + nhex \
|
|
59
|
+
+ '0' * (nlen - ghex.length) + ghex
|
|
60
|
+
sha256_hex(hashin).hex % n
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def calculate_m(aa, bb, s)
|
|
64
|
+
hashin = '%x%x%x' % [aa, bb, s]
|
|
65
|
+
sha256_str(hashin).hex
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def calculate_u(aa, bb, n)
|
|
69
|
+
nlen = 2 * ((('%x' % [n]).length * 4 + 7) >> 3)
|
|
70
|
+
aahex = '%x' % [aa]
|
|
71
|
+
bbhex = '%x' % [bb]
|
|
72
|
+
return sha256_str("%x%x" % [aa, bb]).hex
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
data/ruby-srp.gemspec
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = "ruby-srp"
|
|
3
|
+
s.version = "0.0.2"
|
|
4
|
+
s.platform = Gem::Platform::RUBY
|
|
5
|
+
s.authors = ["Azul"]
|
|
6
|
+
s.email = ["azul@leap.se"]
|
|
7
|
+
s.homepage = "http://github.com/leapdev/ruby.srp"
|
|
8
|
+
s.summary = "Secure remote password library for ruby"
|
|
9
|
+
s.description = "SRP client and server based on version 6 of the standard"
|
|
10
|
+
|
|
11
|
+
s.required_rubygems_version = ">= 1.3.6"
|
|
12
|
+
|
|
13
|
+
# If you have runtime dependencies, add them here
|
|
14
|
+
# s.add_runtime_dependency "other", "~> 1.2"
|
|
15
|
+
|
|
16
|
+
# If you have development dependencies, add them here
|
|
17
|
+
# s.add_development_dependency "another", "= 0.9"
|
|
18
|
+
|
|
19
|
+
# The list of files to be contained in the gem
|
|
20
|
+
s.files = `git ls-files`.split("\n")
|
|
21
|
+
# s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
|
22
|
+
# s.extensions = `git ls-files ext/extconf.rb`.split("\n")
|
|
23
|
+
|
|
24
|
+
s.require_path = 'lib'
|
|
25
|
+
|
|
26
|
+
end
|
data/test/auth_test.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
|
2
|
+
|
|
3
|
+
class User
|
|
4
|
+
|
|
5
|
+
include SRP::Authentication
|
|
6
|
+
|
|
7
|
+
attr_accessor :salt, :verifier
|
|
8
|
+
|
|
9
|
+
def initialize(salt, verifier)
|
|
10
|
+
@salt = salt
|
|
11
|
+
@verifier = verifier
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def handshake(login, aa)
|
|
15
|
+
@session = initialize_auth(aa)
|
|
16
|
+
return @session.bb
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def validate(m)
|
|
20
|
+
authenticate(m, @session)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class AuthTest < Test::Unit::TestCase
|
|
26
|
+
|
|
27
|
+
def setup
|
|
28
|
+
@username = 'user'
|
|
29
|
+
@password = 'opensesami'
|
|
30
|
+
@client = SRP::Client.new(@username, @password)
|
|
31
|
+
@server = User.new(@client.salt, @client.verifier)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_successful_auth
|
|
35
|
+
assert @client.authenticate(@server, @username, @password)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_wrong_password
|
|
39
|
+
assert !@client.authenticate(@server, @username, "wrong password")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_wrong_username
|
|
43
|
+
assert !@client.authenticate(@server, "wrong username", @password)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
|
data/test/test_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ruby-srp
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 27
|
|
5
|
+
prerelease:
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 2
|
|
10
|
+
version: 0.0.2
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Azul
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2012-08-06 00:00:00 Z
|
|
19
|
+
dependencies: []
|
|
20
|
+
|
|
21
|
+
description: SRP client and server based on version 6 of the standard
|
|
22
|
+
email:
|
|
23
|
+
- azul@leap.se
|
|
24
|
+
executables: []
|
|
25
|
+
|
|
26
|
+
extensions: []
|
|
27
|
+
|
|
28
|
+
extra_rdoc_files: []
|
|
29
|
+
|
|
30
|
+
files:
|
|
31
|
+
- .gitmodules
|
|
32
|
+
- Readme.md
|
|
33
|
+
- example/config.ru
|
|
34
|
+
- example/http-srp.rb
|
|
35
|
+
- example/models/log.rb
|
|
36
|
+
- example/models/user.rb
|
|
37
|
+
- example/public/bootstrap-responsive.min.css
|
|
38
|
+
- example/public/bootstrap.min.css
|
|
39
|
+
- example/public/example.css
|
|
40
|
+
- example/public/glyphicons-halflings.png
|
|
41
|
+
- example/public/jquery.min.js
|
|
42
|
+
- example/public/srp.js
|
|
43
|
+
- example/public/ui.js
|
|
44
|
+
- example/views/index.erb
|
|
45
|
+
- example/views/layout.erb
|
|
46
|
+
- example/views/login.erb
|
|
47
|
+
- example/views/signup.erb
|
|
48
|
+
- example/views/verify.erb
|
|
49
|
+
- lib/ruby-srp.rb
|
|
50
|
+
- lib/srp/authentication.rb
|
|
51
|
+
- lib/srp/client.rb
|
|
52
|
+
- lib/srp/util.rb
|
|
53
|
+
- ruby-srp.gemspec
|
|
54
|
+
- test/auth_test.rb
|
|
55
|
+
- test/test_helper.rb
|
|
56
|
+
homepage: http://github.com/leapdev/ruby.srp
|
|
57
|
+
licenses: []
|
|
58
|
+
|
|
59
|
+
post_install_message:
|
|
60
|
+
rdoc_options: []
|
|
61
|
+
|
|
62
|
+
require_paths:
|
|
63
|
+
- lib
|
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
hash: 3
|
|
70
|
+
segments:
|
|
71
|
+
- 0
|
|
72
|
+
version: "0"
|
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
|
+
none: false
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
hash: 23
|
|
79
|
+
segments:
|
|
80
|
+
- 1
|
|
81
|
+
- 3
|
|
82
|
+
- 6
|
|
83
|
+
version: 1.3.6
|
|
84
|
+
requirements: []
|
|
85
|
+
|
|
86
|
+
rubyforge_project:
|
|
87
|
+
rubygems_version: 1.8.15
|
|
88
|
+
signing_key:
|
|
89
|
+
specification_version: 3
|
|
90
|
+
summary: Secure remote password library for ruby
|
|
91
|
+
test_files: []
|
|
92
|
+
|