Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LG-490 Use 32 byte salts for passwords #2372

Merged
merged 1 commit into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/services/encryption/password_verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def to_s
end

def self.digest(password)
salt = Devise.friendly_token[0, 20]
salt = SecureRandom.hex(32)
uak = UserAccessKey.new(password: password, salt: salt)
uak.build
PasswordDigest.new(
Expand Down
27 changes: 2 additions & 25 deletions spec/services/encryption/password_verifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
describe Encryption::PasswordVerifier do
describe '.digest' do
it 'creates a digest from the password' do
salt = '1' * 20
allow(Devise).to receive(:friendly_token).and_return(salt)
salt = '1' * 64 # 32 hex encoded bytes is 64 characters
allow(SecureRandom).to receive(:hex).once.with(32).and_return(salt)

digest = described_class.digest('saltypickles')

Expand Down Expand Up @@ -42,29 +42,6 @@
expect(result).to eq(false)
end

it 'allows verification of a password with a 32 byte salt' do
# Once all new password digests are 32 bytes, this test can be torn down
# as it will be covered by the tests above

password = 'saltypickles'
password_digest = {
encrypted_password: '8a5c5b165fd3a2fce81bc914d91a106b76dfdd9e8c2addf0e0f27424a32ca4cb',
encryption_key: 'VUl6QFRZeQZ5Xl9IUVsBZmRndkNkXHJDYgAFRX9nYVl8c3paUWhyX2p
oegBqaFgAeVpfWWpmcgRRXnJHfANAaFJdfQR/eHJbfXVASn0AYnx9dlRifAJ2BFF4dkFmdWZ
/Y3VASn0DfUlqZHp2aWdEAWZlWHRhWmZnY2dbAFMAfQFiW0hCVWNEAmFoan9TSnEEZUpcdmR
nanZ/dHZ/agJqR1VkWEd+XlgCUnRUXFFnYkdqXVQBZHRiUVMCantRAVRef3ZYZmNnW0JTdHJ
RfltYR353akVRAAV9VHZmAmUBZkBlXlxnZXVUe1RKWAJVXGp2Y1tqSmQBVFlnXWpiYkp6eWZ
dQEd/eFhHYWVYd2VKflhpA3lKZGZlSH5dal1+eHZJZWQACXlZR1lUd3ZeeVpfWVNnelhmewB
VZ2p7C3hqf3lhXV0XYDp0YmBnL0dlZQcKLQtUXA=='.gsub(/\s/, ''),
password_salt: '6bb7555423136772304b40c10afe11e459c4021a1a47dfd11fcc955e0a2161e2',
password_cost: '4000$8$4$',
}.to_json

result = described_class.verify(password: password, digest: password_digest)

expect(result).to eq(true)
end

it 'allows verification of a legacy password with a 20 byte salt' do
# Legacy passwords had 20 bytes salts, which were SHA256 digested to get
# to a 32 byte salt (64 char hexdigest). This test verifies that the
Expand Down