istox 0.3.2 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +34 -31
- data/istox.gemspec +1 -1
- data/lib/istox/helpers/redis_manager.rb +8 -0
- data/lib/istox/helpers/vault.rb +97 -64
- data/lib/istox/version.rb +1 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a816c1acd21c9c847f00150866adf15bcad08e32b103cb17ad118c27a4fea411
|
4
|
+
data.tar.gz: 16fe87ea30c68dbb52fae11bd78413d61f8fd5d253bd91e242c5f8d52fbbab46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c850d92ad43f68126a1d92d7a5ac6d8978535b106741f6412074d3e7c5ecf50703ca8aff85b3b1fc9e891c57c1a4e17a9c158dd04d57b90ba1c1b9d277d51061
|
7
|
+
data.tar.gz: c47a08f6087e1a0e596c84d6b33e429db75c285b266561ce2c548ca83fda1db199a62606d140f24d86c34a1c7d98986e1094d87070ba8dfa9c05b65113319db2
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
istox (0.
|
4
|
+
istox (0.3.3)
|
5
5
|
amazing_print
|
6
6
|
awesome_print
|
7
7
|
aws-sdk-sns (~> 1)
|
@@ -17,7 +17,6 @@ PATH
|
|
17
17
|
redis (>= 2.0.0)
|
18
18
|
redis-namespace (>= 1.0.0)
|
19
19
|
redis-rails (~> 5.0.2)
|
20
|
-
vault (~> 0.1)
|
21
20
|
|
22
21
|
GEM
|
23
22
|
remote: https://rubygems.org/
|
@@ -63,7 +62,7 @@ GEM
|
|
63
62
|
i18n (>= 0.7, < 2)
|
64
63
|
minitest (~> 5.1)
|
65
64
|
tzinfo (~> 1.1)
|
66
|
-
amazing_print (1.
|
65
|
+
amazing_print (1.4.0)
|
67
66
|
amq-protocol (2.3.2)
|
68
67
|
arel (9.0.0)
|
69
68
|
awesome_print (1.9.2)
|
@@ -112,43 +111,49 @@ GEM
|
|
112
111
|
i18n (~> 0.5)
|
113
112
|
fakeredis (0.7.0)
|
114
113
|
redis (>= 3.2, < 5.0)
|
115
|
-
faraday (1.
|
114
|
+
faraday (1.9.3)
|
116
115
|
faraday-em_http (~> 1.0)
|
117
116
|
faraday-em_synchrony (~> 1.0)
|
118
117
|
faraday-excon (~> 1.1)
|
119
|
-
faraday-httpclient (~> 1.0
|
118
|
+
faraday-httpclient (~> 1.0)
|
119
|
+
faraday-multipart (~> 1.0)
|
120
120
|
faraday-net_http (~> 1.0)
|
121
|
-
faraday-net_http_persistent (~> 1.
|
121
|
+
faraday-net_http_persistent (~> 1.0)
|
122
122
|
faraday-patron (~> 1.0)
|
123
|
-
|
123
|
+
faraday-rack (~> 1.0)
|
124
|
+
faraday-retry (~> 1.0)
|
124
125
|
ruby2_keywords (>= 0.0.4)
|
125
126
|
faraday-em_http (1.0.0)
|
126
127
|
faraday-em_synchrony (1.0.0)
|
127
128
|
faraday-excon (1.1.0)
|
128
129
|
faraday-httpclient (1.0.1)
|
130
|
+
faraday-multipart (1.0.3)
|
131
|
+
multipart-post (>= 1.2, < 3)
|
129
132
|
faraday-net_http (1.0.1)
|
130
133
|
faraday-net_http_persistent (1.2.0)
|
131
134
|
faraday-patron (1.0.0)
|
132
|
-
|
135
|
+
faraday-rack (1.0.0)
|
136
|
+
faraday-retry (1.0.3)
|
137
|
+
faraday_middleware (1.2.0)
|
133
138
|
faraday (~> 1.0)
|
134
|
-
ffi (1.15.
|
139
|
+
ffi (1.15.5)
|
135
140
|
globalid (0.4.2)
|
136
141
|
activesupport (>= 4.2.0)
|
137
|
-
google-protobuf (3.
|
138
|
-
googleapis-common-protos-types (1.
|
142
|
+
google-protobuf (3.19.4-x86_64-darwin)
|
143
|
+
googleapis-common-protos-types (1.3.0)
|
139
144
|
google-protobuf (~> 3.14)
|
140
145
|
graphlient (0.5.0)
|
141
146
|
faraday (>= 1.0)
|
142
147
|
faraday_middleware
|
143
148
|
graphql-client
|
144
|
-
graphql (1.
|
145
|
-
graphql-client (0.
|
149
|
+
graphql (1.13.6)
|
150
|
+
graphql-client (0.17.0)
|
146
151
|
activesupport (>= 3.0)
|
147
|
-
graphql (~> 1.
|
148
|
-
grpc (1.
|
149
|
-
google-protobuf (~> 3.
|
152
|
+
graphql (~> 1.10)
|
153
|
+
grpc (1.43.1-universal-darwin)
|
154
|
+
google-protobuf (~> 3.18)
|
150
155
|
googleapis-common-protos-types (~> 1.0)
|
151
|
-
grpc-tools (1.
|
156
|
+
grpc-tools (1.43.1)
|
152
157
|
hashie (3.5.7)
|
153
158
|
i18n (0.9.5)
|
154
159
|
concurrent-ruby (~> 1.0)
|
@@ -178,11 +183,11 @@ GEM
|
|
178
183
|
nokogiri (1.11.7)
|
179
184
|
mini_portile2 (~> 2.5.0)
|
180
185
|
racc (~> 1.4)
|
181
|
-
oj (3.
|
186
|
+
oj (3.13.11)
|
182
187
|
ougai (2.0.0)
|
183
188
|
oj (~> 3.10)
|
184
|
-
paranoia (2.
|
185
|
-
activerecord (>=
|
189
|
+
paranoia (2.6.0)
|
190
|
+
activerecord (>= 5.1, < 7.1)
|
186
191
|
pry (0.12.2)
|
187
192
|
coderay (~> 1.1.0)
|
188
193
|
method_source (~> 0.9.0)
|
@@ -220,28 +225,28 @@ GEM
|
|
220
225
|
rake (>= 0.8.7)
|
221
226
|
thor (>= 0.19.0, < 2.0)
|
222
227
|
rake (10.5.0)
|
223
|
-
rb-fsevent (0.11.
|
228
|
+
rb-fsevent (0.11.1)
|
224
229
|
rb-inotify (0.10.1)
|
225
230
|
ffi (~> 1.0)
|
226
|
-
rbtree (0.4.
|
231
|
+
rbtree (0.4.5)
|
227
232
|
redis (4.3.1)
|
228
|
-
redis-actionpack (5.
|
229
|
-
actionpack (>= 5, <
|
233
|
+
redis-actionpack (5.3.0)
|
234
|
+
actionpack (>= 5, < 8)
|
230
235
|
redis-rack (>= 2.1.0, < 3)
|
231
236
|
redis-store (>= 1.1.0, < 2)
|
232
|
-
redis-activesupport (5.
|
233
|
-
activesupport (>= 3, <
|
237
|
+
redis-activesupport (5.3.0)
|
238
|
+
activesupport (>= 3, < 8)
|
234
239
|
redis-store (>= 1.3, < 2)
|
235
240
|
redis-namespace (1.8.1)
|
236
241
|
redis (>= 3.0.4)
|
237
|
-
redis-rack (2.1.
|
242
|
+
redis-rack (2.1.4)
|
238
243
|
rack (>= 2.0.8, < 3)
|
239
244
|
redis-store (>= 1.2, < 2)
|
240
245
|
redis-rails (5.0.2)
|
241
246
|
redis-actionpack (>= 5.0, < 6)
|
242
247
|
redis-activesupport (>= 5.0, < 6)
|
243
248
|
redis-store (>= 1.2, < 2)
|
244
|
-
redis-store (1.9.
|
249
|
+
redis-store (1.9.1)
|
245
250
|
redis (>= 4, < 5)
|
246
251
|
rspec (3.8.0)
|
247
252
|
rspec-core (~> 3.8.0)
|
@@ -265,7 +270,7 @@ GEM
|
|
265
270
|
rspec-support (~> 3.8.0)
|
266
271
|
rspec-support (3.8.0)
|
267
272
|
ruby2_keywords (0.0.5)
|
268
|
-
set (1.0.
|
273
|
+
set (1.0.2)
|
269
274
|
slop (4.9.1)
|
270
275
|
sorted_set (1.0.3)
|
271
276
|
rbtree
|
@@ -284,8 +289,6 @@ GEM
|
|
284
289
|
tzinfo (1.2.9)
|
285
290
|
thread_safe (~> 0.1)
|
286
291
|
uniform_notifier (1.11.0)
|
287
|
-
vault (0.16.0)
|
288
|
-
aws-sigv4
|
289
292
|
websocket-driver (0.7.5)
|
290
293
|
websocket-extensions (>= 0.1.0)
|
291
294
|
websocket-extensions (0.1.5)
|
data/istox.gemspec
CHANGED
@@ -45,7 +45,7 @@ Gem::Specification.new do |spec|
|
|
45
45
|
spec.add_dependency 'redis', '>= 2.0.0'
|
46
46
|
spec.add_dependency 'redis-namespace', '>= 1.0.0'
|
47
47
|
spec.add_dependency 'redis-rails', '~> 5.0.2'
|
48
|
-
spec.add_dependency 'vault', '~> 0.1'
|
48
|
+
# spec.add_dependency 'vault', '~> 0.1'
|
49
49
|
spec.add_development_dependency 'aws-xray-sdk'
|
50
50
|
spec.add_development_dependency 'bullet', '~> 5.7.5'
|
51
51
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
data/lib/istox/helpers/vault.rb
CHANGED
@@ -1,85 +1,118 @@
|
|
1
1
|
require 'istox/helpers/logger'
|
2
|
-
require 'vault'
|
2
|
+
# require 'vault'
|
3
3
|
|
4
4
|
module Istox
|
5
5
|
module Vault
|
6
|
-
module TOTP
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
6
|
+
# module TOTP
|
7
|
+
# class << self
|
8
|
+
# # def create(sid, host)
|
9
|
+
# # log.debug { "Generate vault TOTP for key #{totp_key(sid).inspect}" }
|
10
|
+
|
11
|
+
# # write_data(totp_key(sid),
|
12
|
+
# # generate: true,
|
13
|
+
# # issuer: host,
|
14
|
+
# # account_name: sid,
|
15
|
+
# # period: 300,
|
16
|
+
# # qr_size: 300)
|
17
|
+
# # end
|
18
|
+
|
19
|
+
# # def generate_code(sid)
|
20
|
+
# # log.debug { "Generate 6-digit OTP code: key #{totp_code_key(sid)}" }
|
21
|
+
# # read_data(totp_code_key(sid)).data[:code]
|
22
|
+
# # end
|
23
|
+
|
24
|
+
# # def validate?(sid, code)
|
25
|
+
# # log.debug { "Validate TOTP code: key #{totp_code_key(sid)}, code: #{code}" }
|
26
|
+
# # result = write_data(totp_code_key(sid), code: code).data[:valid]
|
27
|
+
|
28
|
+
# # unless result
|
29
|
+
# # code = read_data(totp_code_key(sid)).data[:code]
|
30
|
+
# # log.debug { "Code is not valid, it should be #{code}" }
|
31
|
+
# # end
|
32
|
+
|
33
|
+
# # result
|
34
|
+
# # end
|
35
|
+
|
36
|
+
# # private
|
37
|
+
|
38
|
+
# # def read_data(key)
|
39
|
+
# # ::Vault.logical.read(key)
|
40
|
+
# # end
|
41
|
+
|
42
|
+
# # def write_data(key, params)
|
43
|
+
# # ::Vault.logical.write(key, params)
|
44
|
+
# # end
|
45
|
+
|
46
|
+
# # def totp_key(sid)
|
47
|
+
# # "totp/keys/#{sid}"
|
48
|
+
# # end
|
49
|
+
|
50
|
+
# # def totp_code_key(sid)
|
51
|
+
# # "totp/code/#{sid}"
|
52
|
+
# # end
|
53
|
+
# # end
|
54
|
+
# end
|
32
55
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
56
|
+
class << self
|
57
|
+
# def logical
|
58
|
+
# ::Vault.logical
|
59
|
+
# end
|
60
|
+
|
61
|
+
# def initialize(secret_key, file_location)
|
62
|
+
# ::Vault.configure do |config|
|
63
|
+
# config.address = secret_key
|
64
|
+
|
65
|
+
# if File.exist?(file_location)
|
66
|
+
# token = File.read(file_location).strip
|
67
|
+
# config.token = token
|
68
|
+
# config.ssl_verify = false
|
69
|
+
# config.timeout = 60
|
70
|
+
# else
|
71
|
+
# log.info 'Vault token not found, OTP will not be able to use'
|
72
|
+
# end
|
73
|
+
# end
|
74
|
+
# end
|
75
|
+
|
76
|
+
def get_otp(sid, _host, expired_seconds: 600)
|
77
|
+
# ::Istox::Vault::TOTP.create(sid, host)
|
78
|
+
# Istox::Vault::TOTP.generate_code(sid)
|
79
|
+
|
80
|
+
otp = 6.times.map { rand(10) }.join
|
81
|
+
|
82
|
+
otp_redis.set(sid, otp, nx: false, ex: expired_seconds.seconds)
|
83
|
+
otp_redis.del(sid + '_tries')
|
84
|
+
|
85
|
+
otp
|
86
|
+
end
|
37
87
|
|
38
|
-
|
39
|
-
|
40
|
-
end
|
88
|
+
def validate_otp(sid, otp)
|
89
|
+
# ::Istox::Vault::TOTP.validate?(sid, otp)
|
41
90
|
|
42
|
-
|
43
|
-
::Vault.logical.write(key, params)
|
44
|
-
end
|
91
|
+
stored_otp = otp_redis.get(sid)
|
45
92
|
|
46
|
-
|
47
|
-
|
48
|
-
end
|
93
|
+
return false if stored_otp.blank?
|
94
|
+
return false if otp.blank?
|
49
95
|
|
50
|
-
|
51
|
-
"totp/code/#{sid}"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
96
|
+
result = otp.to_s == stored_otp.to_s
|
55
97
|
|
56
|
-
|
57
|
-
def logical
|
58
|
-
::Vault.logical
|
59
|
-
end
|
98
|
+
otp_redis.del(sid) if result == true
|
60
99
|
|
61
|
-
|
62
|
-
|
63
|
-
config.address = secret_key
|
100
|
+
if result == false
|
101
|
+
current_tries = (otp_redis.get(sid + '_tries') || 0).to_s.to_i
|
64
102
|
|
65
|
-
if
|
66
|
-
|
67
|
-
|
68
|
-
config.ssl_verify = false
|
69
|
-
config.timeout = 60
|
103
|
+
if current_tries > 4
|
104
|
+
otp_redis.del(sid)
|
105
|
+
otp_redis.del(sid + '_tries')
|
70
106
|
else
|
71
|
-
|
107
|
+
otp_redis.set(sid + '_tries', current_tries + 1)
|
72
108
|
end
|
73
109
|
end
|
74
|
-
end
|
75
110
|
|
76
|
-
|
77
|
-
::Istox::Vault::TOTP.create(sid, host)
|
78
|
-
Istox::Vault::TOTP.generate_code(sid)
|
111
|
+
result
|
79
112
|
end
|
80
113
|
|
81
|
-
def
|
82
|
-
::Istox::
|
114
|
+
def otp_redis
|
115
|
+
@otp_redis ||= ::Istox::RedisManager.otp_redis
|
83
116
|
end
|
84
117
|
end
|
85
118
|
end
|
data/lib/istox/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: istox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Siong Leng
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amazing_print
|
@@ -220,20 +220,6 @@ dependencies:
|
|
220
220
|
- - "~>"
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: 5.0.2
|
223
|
-
- !ruby/object:Gem::Dependency
|
224
|
-
name: vault
|
225
|
-
requirement: !ruby/object:Gem::Requirement
|
226
|
-
requirements:
|
227
|
-
- - "~>"
|
228
|
-
- !ruby/object:Gem::Version
|
229
|
-
version: '0.1'
|
230
|
-
type: :runtime
|
231
|
-
prerelease: false
|
232
|
-
version_requirements: !ruby/object:Gem::Requirement
|
233
|
-
requirements:
|
234
|
-
- - "~>"
|
235
|
-
- !ruby/object:Gem::Version
|
236
|
-
version: '0.1'
|
237
223
|
- !ruby/object:Gem::Dependency
|
238
224
|
name: aws-xray-sdk
|
239
225
|
requirement: !ruby/object:Gem::Requirement
|