Class: Puppet::Util::MongodbScram
- Inherits:
-
Object
- Object
- Puppet::Util::MongodbScram
- Defined in:
- lib/puppet/util/mongodb_scram.rb
Constant Summary collapse
- CLIENT_KEY =
'Client Key'
- SERVER_KEY =
'Server Key'
Instance Attribute Summary collapse
-
#iterations ⇒ Object
readonly
Returns the value of attribute iterations.
-
#password_hash ⇒ Object
readonly
Returns the value of attribute password_hash.
-
#salt ⇒ Object
readonly
Returns the value of attribute salt.
Instance Method Summary collapse
- #client_key ⇒ Object
- #digest ⇒ Object
- #hash(string) ⇒ Object
- #hmac(data, key) ⇒ Object
-
#initialize(password_hash, salt, iterations) ⇒ MongodbScram
constructor
A new instance of MongodbScram.
- #salted_password ⇒ Object
- #server_key ⇒ Object
- #stored_key ⇒ Object
Constructor Details
#initialize(password_hash, salt, iterations) ⇒ MongodbScram
Returns a new instance of MongodbScram.
14 15 16 17 18 |
# File 'lib/puppet/util/mongodb_scram.rb', line 14 def initialize(password_hash, salt, iterations) @password_hash = password_hash @salt = salt @iterations = iterations end |
Instance Attribute Details
#iterations ⇒ Object (readonly)
Returns the value of attribute iterations.
12 13 14 |
# File 'lib/puppet/util/mongodb_scram.rb', line 12 def iterations @iterations end |
#password_hash ⇒ Object (readonly)
Returns the value of attribute password_hash.
12 13 14 |
# File 'lib/puppet/util/mongodb_scram.rb', line 12 def password_hash @password_hash end |
#salt ⇒ Object (readonly)
Returns the value of attribute salt.
12 13 14 |
# File 'lib/puppet/util/mongodb_scram.rb', line 12 def salt @salt end |
Instance Method Details
#client_key ⇒ Object
41 42 43 |
# File 'lib/puppet/util/mongodb_scram.rb', line 41 def client_key hmac(salted_password, CLIENT_KEY) end |
#digest ⇒ Object
20 21 22 |
# File 'lib/puppet/util/mongodb_scram.rb', line 20 def digest @digest ||= OpenSSL::Digest.new('SHA1').freeze end |
#hash(string) ⇒ Object
24 25 26 |
# File 'lib/puppet/util/mongodb_scram.rb', line 24 def hash(string) digest.digest(string) end |
#hmac(data, key) ⇒ Object
28 29 30 |
# File 'lib/puppet/util/mongodb_scram.rb', line 28 def hmac(data, key) OpenSSL::HMAC.digest(digest, data, key) end |
#salted_password ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/puppet/util/mongodb_scram.rb', line 32 def salted_password OpenSSL::PKCS5.pbkdf2_hmac_sha1( @password_hash, Base64.strict_decode64(@salt), @iterations, digest.size ) end |
#server_key ⇒ Object
49 50 51 |
# File 'lib/puppet/util/mongodb_scram.rb', line 49 def server_key Base64.strict_encode64(hmac(salted_password, SERVER_KEY)) end |
#stored_key ⇒ Object
45 46 47 |
# File 'lib/puppet/util/mongodb_scram.rb', line 45 def stored_key Base64.strict_encode64(hash(client_key)) end |