Module: Keychain

Defined in:
lib/keychain.rb,
lib/keychain/version.rb,
lib/keychain/keychain.rb

Overview

top level constant for this library

Defined Under Namespace

Modules: Protocols Classes: AuthFailedError, DuplicateItemError, Error, Item, Keychain, NoSuchKeychainError, Scope, UserCancelledError

Constant Summary collapse

VERSION =

The current version string

'0.1.0'

Class Method Summary collapse

Class Method Details

.create(path, password) ⇒ Keychain::Keychain

creates a new keychain file and adds it to the keychain search path ( SecKeychainCreate )

See developer.apple.com/library/mac/documentation/security/Reference/keychainservices/Reference/reference.html#//apple_ref/c/func/SecKeychainCreate

Parameters:

  • path (String)

    The path to the keychain file to create If it is not absolute it is interpreted relative to ~/Library/Keychains

  • password (String)

    The password to use for the keychain

Returns:



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/keychain.rb', line 20

def create(path, password)
  password = password.encode(Encoding::UTF_8)
  path = path.encode(Encoding::UTF_8)

  out_buffer = FFI::MemoryPointer.new(:pointer)
  status = Sec.SecKeychainCreate(path, password.bytesize, FFI::MemoryPointer.from_string(password), 0,
                                      nil, out_buffer)

  Sec.check_osstatus(status)
  Keychain.new(out_buffer.read_pointer).release_on_gc
end

.defaultKeychain::Keychain

Returns:



36
37
38
39
40
41
42
# File 'lib/keychain.rb', line 36

def default
  out_buffer = FFI::MemoryPointer.new(:pointer)
  status = Sec.SecKeychainCopyDefault(out_buffer);
  Sec.check_osstatus(status)

  Keychain.new(out_buffer.read_pointer).release_on_gc
end

.generic_passwordsKeychain::Scope

Returns a scope for generic passwords in all keychains

Returns:



68
69
70
# File 'lib/keychain.rb', line 68

def generic_passwords
  Scope.new(Sec::Classes::GENERIC)
end

.internet_passwordsKeychain::Scope

Returns a scope for internet passwords contained in all keychains

Returns:



61
62
63
# File 'lib/keychain.rb', line 61

def internet_passwords
  Scope.new(Sec::Classes::INTERNET)
end

.open(path) ⇒ Keychain::Keychain

Opens the keychain file at the specified path and adds it to the keychain search path ( SecKeychainOpen )

Will succeed even if the file doesn’t exists (however most operations on the keychain will then fail)

See developer.apple.com/library/mac/documentation/security/Reference/keychainservices/Reference/reference.html#//apple_ref/c/func/SecKeychainCopyDefault

Parameters:

  • path (String)

    Path to the keychain file

Returns:



51
52
53
54
55
56
# File 'lib/keychain.rb', line 51

def open(path)
  out_buffer = FFI::MemoryPointer.new(:pointer)
  status = Sec.SecKeychainOpen(path,out_buffer);
  Sec.check_osstatus(status)
  Keychain.new(out_buffer.read_pointer).release_on_gc
end