lib/chef/provider/user/dscl.rb
#
# Prepares the password shadow info based on the platform version.
#
Prepares the password shadow info based on the platform version.
Prepares the password shadow info based on the platform version .
def prepare_password_shadow_info
          shadow_info = { }
          entropy = nil
          salt = nil
          iterations = nil
          if mac_osx_version_10_7?
            hash_value = if salted_sha512?(@new_resource.password)
              @new_resource.password
            else
              salt = OpenSSL::Random.random_bytes(4)
              encoded_password = OpenSSL::Digest::SHA512.hexdigest(salt + @new_resource.password)
              hash_value = salt.unpack('H*').first + encoded_password
            end
            shadow_info["SALTED-SHA512"] = StringIO.new
            shadow_info["SALTED-SHA512"].string = convert_to_binary(hash_value)
            shadow_info
          else
            if salted_sha512_pbkdf2?(@new_resource.password)
              entropy = convert_to_binary(@new_resource.password)
              salt = convert_to_binary(@new_resource.salt)
              iterations = @new_resource.iterations
            else
              salt = OpenSSL::Random.random_bytes(32)
              iterations = @new_resource.iterations 
              entropy = OpenSSL::PKCS5::pbkdf2_hmac(
                @new_resource.password,
                salt,
                iterations,
                128,
                OpenSSL::Digest::SHA512.new
              )
            end
            pbkdf_info = { }
            pbkdf_info["entropy"] = StringIO.new
            pbkdf_info["entropy"].string = entropy
            pbkdf_info["salt"] = StringIO.new
            pbkdf_info["salt"].string = salt
            pbkdf_info["iterations"] = iterations
            shadow_info["SALTED-SHA512-PBKDF2"] = pbkdf_info
          end
          shadow_info
        end
def prepare_password_shadow_info shadow_info = { } entropy = nil salt = nil iterations = nil if mac_osx_version_10_7? hash_value = if salted_sha512? ( @new_resource . password ) @new_resource . password else salt = OpenSSL :: Random . random_bytes ( 4 ) encoded_password = OpenSSL :: Digest :: SHA512 . hexdigest ( salt + @new_resource . password ) hash_value = salt . unpack ( 'H*' ) . first + encoded_password end shadow_info [ "SALTED-SHA512" ] = StringIO . new shadow_info [ "SALTED-SHA512" ] . string = convert_to_binary ( hash_value ) shadow_info else if salted_sha512_pbkdf2? ( @new_resource . password ) entropy = convert_to_binary ( @new_resource . password ) salt = convert_to_binary ( @new_resource . salt ) iterations = @new_resource . iterations else salt = OpenSSL :: Random . random_bytes ( 32 ) iterations = @new_resource . iterations entropy = OpenSSL :: PKCS5 :: pbkdf2_hmac ( @new_resource . password , salt , iterations , 128 , OpenSSL :: Digest :: SHA512 . new ) end pbkdf_info = { } pbkdf_info [ "entropy" ] = StringIO . new pbkdf_info [ "entropy" ] . string = entropy pbkdf_info [ "salt" ] = StringIO . new pbkdf_info [ "salt" ] . string = salt pbkdf_info [ "iterations" ] = iterations shadow_info [ "SALTED-SHA512-PBKDF2" ] = pbkdf_info end shadow_info end
Prepares the password shadow info based on the platform version.
Prepares the password shadow info based on the platform version .
# Create a random 4 byte salt # Use the default if not specified by the user