twilioauth 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +0 -2
- data/lib/twilioauth.rb +69 -1
- data/twilioauth.gemspec +1 -3
- metadata +1 -18
data/Gemfile.lock
CHANGED
data/lib/twilioauth.rb
CHANGED
@@ -27,9 +27,77 @@ module Twilioauth
|
|
27
27
|
|
28
28
|
def self.auth(number, options = {})
|
29
29
|
connection = Twilioauth::Connection.new(options[:account_sid], options[:auth_token])
|
30
|
-
newpin =
|
30
|
+
newpin = random_bytes(3).unpack("H*")[0]
|
31
31
|
connection.sms(newpin, number)
|
32
32
|
return newpin
|
33
33
|
end
|
34
34
|
|
35
|
+
def self.random_bytes(n=nil)
|
36
|
+
n ||= 16
|
37
|
+
|
38
|
+
unless defined? OpenSSL
|
39
|
+
begin
|
40
|
+
require 'openssl'
|
41
|
+
rescue LoadError
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
if defined? OpenSSL::Random
|
46
|
+
return OpenSSL::Random.random_bytes(n)
|
47
|
+
end
|
48
|
+
|
49
|
+
if !defined?(@has_urandom) || @has_urandom
|
50
|
+
flags = File::RDONLY
|
51
|
+
flags |= File::NONBLOCK if defined? File::NONBLOCK
|
52
|
+
flags |= File::NOCTTY if defined? File::NOCTTY
|
53
|
+
flags |= File::NOFOLLOW if defined? File::NOFOLLOW
|
54
|
+
begin
|
55
|
+
File.open("/dev/urandom", flags) {|f|
|
56
|
+
unless f.stat.chardev?
|
57
|
+
raise Errno::ENOENT
|
58
|
+
end
|
59
|
+
@has_urandom = true
|
60
|
+
ret = f.readpartial(n)
|
61
|
+
if ret.length != n
|
62
|
+
raise NotImplementedError, "Unexpected partial read from random device"
|
63
|
+
end
|
64
|
+
return ret
|
65
|
+
}
|
66
|
+
rescue Errno::ENOENT
|
67
|
+
@has_urandom = false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
if !defined?(@has_win32)
|
72
|
+
begin
|
73
|
+
require 'Win32API'
|
74
|
+
|
75
|
+
crypt_acquire_context = Win32API.new("advapi32", "CryptAcquireContext", 'PPPII', 'L')
|
76
|
+
@crypt_gen_random = Win32API.new("advapi32", "CryptGenRandom", 'LIP', 'L')
|
77
|
+
|
78
|
+
hProvStr = " " * 4
|
79
|
+
prov_rsa_full = 1
|
80
|
+
crypt_verifycontext = 0xF0000000
|
81
|
+
|
82
|
+
if crypt_acquire_context.call(hProvStr, nil, nil, prov_rsa_full, crypt_verifycontext) == 0
|
83
|
+
raise SystemCallError, "CryptAcquireContext failed: #{lastWin32ErrorMessage}"
|
84
|
+
end
|
85
|
+
@hProv, = hProvStr.unpack('L')
|
86
|
+
|
87
|
+
@has_win32 = true
|
88
|
+
rescue LoadError
|
89
|
+
@has_win32 = false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
if @has_win32
|
93
|
+
bytes = " " * n
|
94
|
+
if @crypt_gen_random.call(@hProv, bytes.size, bytes) == 0
|
95
|
+
raise SystemCallError, "CryptGenRandom failed: #{lastWin32ErrorMessage}"
|
96
|
+
end
|
97
|
+
return bytes
|
98
|
+
end
|
99
|
+
|
100
|
+
raise NotImplementedError, "No random device"
|
101
|
+
end
|
102
|
+
|
35
103
|
end
|
data/twilioauth.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.unshift lib unless $:.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'twilioauth'
|
6
|
-
s.version = '0.0.
|
6
|
+
s.version = '0.0.4'
|
7
7
|
s.date = '2012-08-08'
|
8
8
|
s.summary = "2 factor auth for twilio"
|
9
9
|
s.description = "2 factor auth for twilio"
|
@@ -17,10 +17,8 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.require_path = 'lib'
|
18
18
|
|
19
19
|
s.requirements << "twilio-ruby"
|
20
|
-
s.requirements << "activesupport"
|
21
20
|
|
22
21
|
s.add_dependency "twilio-ruby"
|
23
|
-
s.add_dependency "activesupport", ">= 3.0.0"
|
24
22
|
|
25
23
|
|
26
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twilioauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,22 +27,6 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: activesupport
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 3.0.0
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 3.0.0
|
46
30
|
description: 2 factor auth for twilio
|
47
31
|
email: kmahan@kmahan.com
|
48
32
|
executables: []
|
@@ -76,7 +60,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
60
|
version: '0'
|
77
61
|
requirements:
|
78
62
|
- twilio-ruby
|
79
|
-
- activesupport
|
80
63
|
rubyforge_project:
|
81
64
|
rubygems_version: 1.8.24
|
82
65
|
signing_key:
|