Class: MacAdmin::SaltedSHA1
- Inherits:
-
ShadowHash
- Object
- ShadowHash
- MacAdmin::SaltedSHA1
- Defined in:
- lib/macadmin/shadowhash.rb
Overview
Legacy ShadowHashs
-
password management for Mac OS X 10.6 and below
-
passwords are managed in separate files in /var/db/shadow/hash
Constant Summary collapse
- SHADOWHASH_STORE =
'/private/var/db/shadow/hash'
Instance Attribute Summary collapse
-
#hash ⇒ Object
Returns the value of attribute hash.
Attributes inherited from ShadowHash
Class Method Summary collapse
Instance Method Summary collapse
-
#data ⇒ Object
Return the ShadowHash as a Salted SHA1 String.
-
#initialize(string) ⇒ SaltedSHA1
constructor
Initializes a SaltedSHA512 ShadowHash object from string - string param should be a hex string, 24 bytes.
-
#password ⇒ Object
Return a String representation of the ShadowHash data.
-
#validate(string) ⇒ Object
Validates the string param - ensure the string param is hex string 24 bytes long.
Methods inherited from ShadowHash
create_from_user_record, read_shadowhashdata
Methods included from Password
#apropos, #convert_to_blob, #convert_to_hex, #salted_sha1, #salted_sha512, #salted_sha512_pbkdf2, salted_sha512_pbkdf2_from_string
Constructor Details
#initialize(string) ⇒ SaltedSHA1
Initializes a SaltedSHA512 ShadowHash object from string
-
string param should be a hex string, 24 bytes
76 77 78 |
# File 'lib/macadmin/shadowhash.rb', line 76 def initialize(string) @hash = validate(string) end |
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash.
54 55 56 |
# File 'lib/macadmin/shadowhash.rb', line 54 def hash @hash end |
Class Method Details
.create_from_shadowhash_file(guid) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/macadmin/shadowhash.rb', line 58 def create_from_shadowhash_file(guid) file = "#{SHADOWHASH_STORE}/#{guid}" if File.exists? file hash = read_from_shadowhash_file(file) return nil unless hash self.new(hash) end end |
.read_from_shadowhash_file(file) ⇒ Object
67 68 69 70 |
# File 'lib/macadmin/shadowhash.rb', line 67 def read_from_shadowhash_file(file) content = File.readlines(file).first content[168,48] end |
Instance Method Details
#data ⇒ Object
Return the ShadowHash as a Salted SHA1 String
94 95 96 |
# File 'lib/macadmin/shadowhash.rb', line 94 def data @data ||= @hash.to_s end |
#password ⇒ Object
Return a String representation of the ShadowHash data
89 90 91 |
# File 'lib/macadmin/shadowhash.rb', line 89 def password @hash.to_s end |
#validate(string) ⇒ Object
Validates the string param
-
ensure the string param is hex string 24 bytes long
82 83 84 85 86 |
# File 'lib/macadmin/shadowhash.rb', line 82 def validate(string) error = "Invalid: arg must be hexadecimal string (24 bytes)" raise ArgumentError.new(error) unless string =~ /([A-F0-9]{2}){24}/ string end |