Class: MagicKeyAuth::SSL

Inherits:
Object
  • Object
show all
Defined in:
lib/magic_key_auth/SSL.rb

Class Method Summary collapse

Class Method Details

.authenticate(opts = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/magic_key_auth/SSL.rb', line 12

def authenticate(opts = {})
  opts = {:digest => "", :message => Time.now.to_i.to_s}.merge(opts)
  raise MagicKeyAuth::InvalidKeyDir, "key directory doesn't exist!" unless File.exists?(key_location)
  Dir.new(key_location).entries.each do |key|
    next unless key =~ /\.pem/
    return key.gsub(/\.pem/, '') if 
      (EzCrypto::Verifier.from_file(File.join(key_location, key)).verify(opts[:digest], opts[:message]) rescue false)
  end
  nil
end

.key_locationObject



8
9
10
# File 'lib/magic_key_auth/SSL.rb', line 8

def key_location
  @key_location || "keys"
end

.key_location=(dir) ⇒ Object



4
5
6
# File 'lib/magic_key_auth/SSL.rb', line 4

def key_location=(dir)
  @key_location = dir
end