Skip to content

Commit

Permalink
fixes #9551 - checking the encryption format so osx doesn't fail
Browse files Browse the repository at this point in the history
  • Loading branch information
unorthodoxgeek committed Feb 26, 2015
1 parent 8647e5e commit c8c0617
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/models/concerns/host_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,18 @@ def crypt_root_pass
end

if unencrypted_pass.present?
self.root_pass = !!(unencrypted_pass.match('^\$\d+\$.+\$.+')) ? unencrypted_pass :
(operatingsystem.nil? ? PasswordCrypt.passw_crypt(unencrypted_pass) : PasswordCrypt.passw_crypt(unencrypted_pass, operatingsystem.password_hash))
self.grub_pass = !!(unencrypted_pass.match('^\$\d+\$.+\$.+')) ? unencrypted_pass : PasswordCrypt.grub2_passw_crypt(unencrypted_pass)
is_actually_encrypted = if PasswordCrypt.nix?
unencrypted_pass.match('^\$\d+\$.+\$.+')
else
unencrypted_pass.starts_with?("$")
end

if is_actually_encrypted
self.root_pass = self.grub_pass = unencrypted_pass
else
self.root_pass = operatingsystem.nil? ? PasswordCrypt.passw_crypt(unencrypted_pass) : PasswordCrypt.passw_crypt(unencrypted_pass, operatingsystem.password_hash)
self.grub_pass = PasswordCrypt.grub2_passw_crypt(unencrypted_pass)
end
end
end

Expand Down
4 changes: 4 additions & 0 deletions app/services/password_crypt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ def self.passw_crypt(passwd, hash_alg = 'MD5')
def self.grub2_passw_crypt(passw)
self.passw_crypt(passw, 'MD5')
end

def self.nix?
@nix ||= passw_crypt("test_this").match('^\$\d+\$.+\$.+')
end
end

0 comments on commit c8c0617

Please sign in to comment.