Class: ForestLiana::UserSecretCreator
- Inherits:
-
Object
- Object
- ForestLiana::UserSecretCreator
- Defined in:
- app/services/forest_liana/user_secret_creator.rb
Overview
NOTICE: This service combines the 2FA secret stored on the forest server to the local secret
salt. This guarantees that only the owner of the server and the concerned end user can
know the final key.
This is done by using a bitwise exclusive or operation, which guarantees the key to stay
unique, so it is impossible for two users to have the same key.
Instance Method Summary collapse
- #hex_to_bin(hex_string) ⇒ Object
-
#initialize(two_factor_authentication_secret, two_factor_secret_salt) ⇒ UserSecretCreator
constructor
A new instance of UserSecretCreator.
- #perform ⇒ Object
Constructor Details
#initialize(two_factor_authentication_secret, two_factor_secret_salt) ⇒ UserSecretCreator
Returns a new instance of UserSecretCreator.
10 11 12 13 |
# File 'app/services/forest_liana/user_secret_creator.rb', line 10 def initialize(two_factor_authentication_secret, two_factor_secret_salt) @two_factor_authentication_secret = two_factor_authentication_secret @two_factor_secret_salt = two_factor_secret_salt end |
Instance Method Details
#hex_to_bin(hex_string) ⇒ Object
22 23 24 |
# File 'app/services/forest_liana/user_secret_creator.rb', line 22 def hex_to_bin(hex_string) hex_string.scan(/../).map { |x| x.hex.chr }.join end |
#perform ⇒ Object
15 16 17 18 19 20 |
# File 'app/services/forest_liana/user_secret_creator.rb', line 15 def perform hash = (@two_factor_authentication_secret.to_i(16) ^ @two_factor_secret_salt.to_i(16)).to_s(16) bin_hash = hex_to_bin(hash) Base32.encode(bin_hash).tr('=', '') end |