Skip to content

Commit a1b5ca4

Browse files
authored
Merge pull request #474 from a-courteille/master
Fix PBKDF2 implementation to use Adapted Base64 encoding
2 parents 80ddb83 + 09d17b3 commit a1b5ca4

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/puppet/functions/openldap_password.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
return_type 'String'
3636
end
3737

38+
def ab64_encode(data)
39+
Base64.strict_encode64(data).tr('+', '.').delete('=')
40+
end
41+
3842
def generate_password(secret, scheme = 'SSHA', iterations = 60_000, hash_type = 'SHA512')
3943
case scheme[%r{([A-Z,0-9]+)}, 1]
4044
when 'PBKDF2'
@@ -55,13 +59,7 @@ def generate_password(secret, scheme = 'SSHA', iterations = 60_000, hash_type =
5559
config[:obj]
5660
)
5761

58-
value = [
59-
salt,
60-
iterations.to_s,
61-
derived_key
62-
].join('$')
63-
64-
password = "{PBKDF2-#{config[:name]}}#{Base64.strict_encode64(value)}"
62+
password = "{PBKDF2-#{config[:name]}}#{iterations}$#{ab64_encode(salt)}$#{ab64_encode(derived_key)}"
6563
when 'CRYPT'
6664
salt = call_function('fqdn_rand_string', 2)
6765
password = "{CRYPT}#{secret.crypt(salt)}"

0 commit comments

Comments
 (0)