Class: ForestLiana::UserSecretCreator

Inherits:
Object
  • Object
show all
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

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

#performObject



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