two_factor_authentication 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dec5112783c16117a3f498bed06abb05be9b2206
|
4
|
+
data.tar.gz: 6a637bc5a895b60da9b46360a799cd0a54d7da59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 796540a1cc3c572de0a121f90da0d1c1981689a53c7560e1b6cc2f2e192a9bdca46d9c2cdb6b34a625afbd5ce972959ae58244fb513f79278c122ae8bcb8f962
|
7
|
+
data.tar.gz: 53685bf09da5ed84bc2a1c8fb2bae730e4b2fb6438afdf871f8f3db0cd8a7e37351d6a581738ea9143bd61267ac9fa9943694443acc0c03776f6651060d04c34
|
data/README.md
CHANGED
@@ -175,14 +175,15 @@ To add them, generate a migration such as:
|
|
175
175
|
|
176
176
|
$ rails g migration AddTwoFactorFieldsToUsers direct_otp:string direct_otp_sent_at:datetime totp_timestamp:timestamp
|
177
177
|
|
178
|
-
The `otp_secret_key` is
|
178
|
+
The `otp_secret_key` is only required for users who use TOTP (Google Authenticator) codes,
|
179
179
|
so unless it has been shared with the user it should be set to `nil`. The
|
180
180
|
following pseudo-code is an example of how this might be done:
|
181
181
|
|
182
182
|
```ruby
|
183
183
|
User.find_each do |user| do
|
184
|
-
if !
|
184
|
+
if !uses_authenticator_app(user)
|
185
185
|
user.otp_secret_key = nil
|
186
|
+
user.save!
|
186
187
|
end
|
187
188
|
end
|
188
189
|
```
|
@@ -113,16 +113,16 @@ module Devise
|
|
113
113
|
|
114
114
|
module EncryptionInstanceMethods
|
115
115
|
def otp_secret_key
|
116
|
-
|
116
|
+
otp_decrypt(encrypted_otp_secret_key)
|
117
117
|
end
|
118
118
|
|
119
119
|
def otp_secret_key=(value)
|
120
|
-
self.encrypted_otp_secret_key =
|
120
|
+
self.encrypted_otp_secret_key = otp_encrypt(value)
|
121
121
|
end
|
122
122
|
|
123
123
|
private
|
124
124
|
|
125
|
-
def
|
125
|
+
def otp_decrypt(encrypted_value)
|
126
126
|
return encrypted_value if encrypted_value.blank?
|
127
127
|
|
128
128
|
encrypted_value = encrypted_value.unpack('m').first
|
@@ -137,7 +137,7 @@ module Devise
|
|
137
137
|
value
|
138
138
|
end
|
139
139
|
|
140
|
-
def
|
140
|
+
def otp_encrypt(value)
|
141
141
|
return value if value.blank?
|
142
142
|
|
143
143
|
value = value.to_s
|
@@ -162,7 +162,7 @@ module Devise
|
|
162
162
|
iv = encrypted_otp_secret_key_iv
|
163
163
|
|
164
164
|
if iv.nil?
|
165
|
-
algo = OpenSSL::Cipher
|
165
|
+
algo = OpenSSL::Cipher.new(algorithm)
|
166
166
|
iv = [algo.random_iv].pack('m')
|
167
167
|
self.encrypted_otp_secret_key_iv = iv
|
168
168
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: two_factor_authentication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitrii Golub
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|