class RIMS::Password::HashSource
Public Class Methods
build_from_conf(config)
click to toggle source
# File lib/rims/passwd.rb, line 234 def self.build_from_conf(config) hash_src = self.new for user_entry in config hash_src.add(user_entry['user'], parse_entry(user_entry['hash'])) end hash_src end
make_entry(digest_factory, stretch_count, salt, password)
click to toggle source
# File lib/rims/passwd.rb, line 179 def self.make_entry(digest_factory, stretch_count, salt, password) hash = Entry.encode(digest_factory.new, stretch_count, salt, password) Entry.new(digest_factory, stretch_count, salt, hash) end
make_salt_generator(octets)
click to toggle source
# File lib/rims/passwd.rb, line 175 def self.make_salt_generator(octets) proc{ SecureRandom.random_bytes(octets) } end
new()
click to toggle source
# File lib/rims/passwd.rb, line 196 def initialize @passwd = {} end
parse_entry(password_hash)
click to toggle source
hash password format:
[hash type]:[stretch count]:[base64 encoded salt]:[password hash hex digest]
example:
SHA256:1000:2tImt4kLqLM=:756f633bf70613555aa93a5be1e5d93adfe87160e794abc6294c3b58a18f93aa
# File lib/rims/passwd.rb, line 188 def self.parse_entry(password_hash) hash_type, stretch_count, salt_base64, hash = password_hash.split(':', 4) digest_factory = search_digest_factory(hash_type) stretch_count = stretch_count.to_i salt = Protocol.decode_base64(salt_base64) Entry.new(digest_factory, stretch_count, salt, hash) end
search_digest_factory(hash_type)
click to toggle source
# File lib/rims/passwd.rb, line 166 def self.search_digest_factory(hash_type) if (digest_factory = Digest.const_get(hash_type)) then if (digest_factory < Digest::Base) then return digest_factory end end raise TypeError, "not a digest factory: #{hash_type}" end
Public Instance Methods
add(username, entry)
click to toggle source
# File lib/rims/passwd.rb, line 219 def add(username, entry) @passwd[username] = entry self end
compare_password(username, password)
click to toggle source
# File lib/rims/passwd.rb, line 228 def compare_password(username, password) if (entry = @passwd[username]) then entry.compare(password) end end
raw_password?()
click to toggle source
# File lib/rims/passwd.rb, line 215 def raw_password? false end
start()
click to toggle source
# File lib/rims/passwd.rb, line 200 def start if (@logger.debug?) then for name, entry in @passwd @logger.debug("user name: #{name}") @logger.debug("password hash: #{entry}") end end nil end
stop()
click to toggle source
# File lib/rims/passwd.rb, line 210 def stop @passwd.clear nil end
user?(username)
click to toggle source
# File lib/rims/passwd.rb, line 224 def user?(username) @passwd.key? username end