Class: OmniAuth::Strategies::Onetime

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/omniauth/strategies/onetime.rb

Overview

An omniauth strategy using secure onetime passwords

Constant Summary collapse

AdversarySingleDevice =

these options are a means of modeling a theoretical adversary and ensuring some minimum level of security against that adversary the default is roughly a cluster of 100 GPU’s, this is not inexpensive keep this in mind: xkcd.com/538/ cost = bcrypt cost speed = hashes per second per device at cost devices = number of devices

{ cost: 12, speed: 300, devices: 1 }
AdversaryMultiDevice =
{ cost: 12, speed: 300, devices: 128 }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, *args, &block) ⇒ Onetime

Returns a new instance of Onetime.



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/omniauth/strategies/onetime.rb', line 49

def initialize(app, *args, &block)
  super

  if options[:password_cache].nil? && defined?(Rails)
    options[:password_cache] = Rails.cache
  end

  if options[:password_cache].nil?
    raise 'omniauth-onetime must be configured with a password cache.'
  end
end

Class Method Details

.adversary_adjustObject

factor to adjust bcrypt costs



69
70
71
72
# File 'lib/omniauth/strategies/onetime.rb', line 69

def self.adversary_adjust
  2**(default_options[:adversary][:cost] -
      default_options[:password_cost])
end

.adversary_chanceObject

percentage chance of the adversary cracking the password



88
89
90
# File 'lib/omniauth/strategies/onetime.rb', line 88

def self.adversary_chance
  100 / adversary_ratio
end

.adversary_ratioObject

ratio of hashes per second needed to brute-force to the theoretical adversary, <= 1 means the adversary can crack within the time alloted higher is more secure, chance of cracking = 1 in adversary_ratio



83
84
85
# File 'lib/omniauth/strategies/onetime.rb', line 83

def self.adversary_ratio
  Rational(difficulty, adversary_speed)
end

.adversary_speedObject

hashes per second (total) at password_cost



75
76
77
78
# File 'lib/omniauth/strategies/onetime.rb', line 75

def self.adversary_speed
  default_options[:adversary][:speed] *
    default_options[:adversary][:devices] * adversary_adjust
end

.difficultyObject

hashes per second needed for 100% complete brute force higher is more secure



63
64
65
66
# File 'lib/omniauth/strategies/onetime.rb', line 63

def self.difficulty
  (26**default_options[:password_length]) /
    default_options[:password_time]
end