Sha256: ef87ad95860bf84b30ef03363dd3f3dc213fee04dfe1d540c8c7a3697fd96cb4

Contents?: true

Size: 992 Bytes

Versions: 89

Compression:

Stored size: 992 Bytes

Contents

require 'base32'

module ForestLiana
  # 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.
  class UserSecretCreator
    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

    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

    def hex_to_bin(hex_string)
      hex_string.scan(/../).map { |x| x.hex.chr }.join
    end
  end
end

Version data entries

89 entries across 89 versions & 1 rubygems

Version Path
forest_liana-5.1.0 app/services/forest_liana/user_secret_creator.rb
forest_liana-5.0.0 app/services/forest_liana/user_secret_creator.rb
forest_liana-5.0.0.pre.beta.0 app/services/forest_liana/user_secret_creator.rb
forest_liana-4.2.0 app/services/forest_liana/user_secret_creator.rb
forest_liana-4.1.3 app/services/forest_liana/user_secret_creator.rb
forest_liana-4.1.2 app/services/forest_liana/user_secret_creator.rb
forest_liana-4.1.1 app/services/forest_liana/user_secret_creator.rb
forest_liana-4.1.0 app/services/forest_liana/user_secret_creator.rb
forest_liana-4.0.2 app/services/forest_liana/user_secret_creator.rb
forest_liana-4.0.1 app/services/forest_liana/user_secret_creator.rb
forest_liana-4.0.0 app/services/forest_liana/user_secret_creator.rb
forest_liana-4.0.0.pre.beta.1 app/services/forest_liana/user_secret_creator.rb
forest_liana-3.3.0 app/services/forest_liana/user_secret_creator.rb
forest_liana-4.0.0.pre.beta.0 app/services/forest_liana/user_secret_creator.rb
forest_liana-3.2.0 app/services/forest_liana/user_secret_creator.rb
forest_liana-3.1.1 app/services/forest_liana/user_secret_creator.rb
forest_liana-3.1.0 app/services/forest_liana/user_secret_creator.rb
forest_liana-3.0.7 app/services/forest_liana/user_secret_creator.rb
forest_liana-3.0.6 app/services/forest_liana/user_secret_creator.rb
forest_liana-3.0.5 app/services/forest_liana/user_secret_creator.rb