Skip to content

Commit 1792608

Browse files
Merge pull request #303 from ICIJ/master
Use Base64.strict_encode64 and SSHA256
2 parents 58b4a85 + 2eeab2b commit 1792608

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Diff for: lib/net/ldap/password.rb

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- ruby encoding: utf-8 -*-
22
require 'digest/sha1'
3+
require 'digest/sha2'
34
require 'digest/md5'
45
require 'base64'
56
require 'securerandom'
@@ -28,6 +29,9 @@ def generate(type, str)
2829
when :ssha
2930
salt = SecureRandom.random_bytes(16)
3031
'{SSHA}' + Base64.strict_encode64(Digest::SHA1.digest(str + salt) + salt)
32+
when :ssha256
33+
salt = SecureRandom.random_bytes(16)
34+
'{SSHA256}' + Base64.strict_encode64(Digest::SHA256.digest(str + salt) + salt)
3135
else
3236
raise Net::LDAP::HashTypeUnsupportedError, "Unsupported password-hash type (#{type})"
3337
end

Diff for: test/test_password.rb

+5
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ def test_psw
77
assert_equal("{MD5}xq8jwrcfibi0sZdZYNkSng==", Net::LDAP::Password.generate(:md5, "cashflow"))
88
assert_equal("{SHA}YE4eGkN4BvwNN1f5R7CZz0kFn14=", Net::LDAP::Password.generate(:sha, "cashflow"))
99
end
10+
11+
def test_psw_with_ssha256_should_not_contain_linefeed
12+
flexmock(SecureRandom).should_receive(:random_bytes).and_return('\xE5\x8A\x99\xF8\xCB\x15GW\xE8\xEA\xAD\x0F\xBF\x95\xB0\xDC')
13+
assert_equal("{SSHA256}Cc7MXboTyUP5PnPAeJeCrgMy8+7Gus0sw7kBJuTrmf1ceEU1XHg4QVx4OTlceEY4XHhDQlx4MTVHV1x4RThceEVBXHhBRFx4MEZceEJGXHg5NVx4QjBceERD", Net::LDAP::Password.generate( :ssha256, "cashflow" ))
14+
end
1015
end

0 commit comments

Comments
 (0)