Class: Keychain::Identity

Inherits:
Sec::Base
  • Object
show all
Defined in:
lib/keychain/identity.rb

Constant Summary collapse

ATTR_MAP =
Keychain::Certificate::ATTR_MAP.merge(Keychain::Key::ATTR_MAP)
INVERSE_ATTR_MAP =
ATTR_MAP.invert

Instance Attribute Summary

Attributes inherited from Sec::Base

#attributes

Instance Method Summary collapse

Methods inherited from Sec::Base

define_attributes, #initialize, #keychain, #load_attributes, register_type, #update_self_from_dictionary

Constructor Details

This class inherits a constructor from Sec::Base

Instance Method Details

#certificateObject



23
24
25
26
27
28
29
# File 'lib/keychain/identity.rb', line 23

def certificate
  certificate_ref = FFI::MemoryPointer.new(:pointer)
  status = Sec.SecIdentityCopyCertificate(self, certificate_ref)
  Sec.check_osstatus(status)

  Keychain::Certificate.new(certificate_ref.read_pointer)
end

#klassObject



19
20
21
# File 'lib/keychain/identity.rb', line 19

def klass
  Sec::Classes::IDENTITY.to_ruby
end

#pkcs12(passphrase = '') ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/keychain/identity.rb', line 39

def pkcs12(passphrase='')
  flags = Sec::SecItemImportExportKeyParameters.new
  flags[:version] = Sec::SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION
  flags[:passphrase] = CF::String.from_string(passphrase).to_ptr

  data_ptr = FFI::MemoryPointer.new(:pointer)
  status = Sec.SecItemExport(self, :kSecFormatPKCS12, 0, flags, data_ptr)
  Sec.check_osstatus(status)

  data = CF::Data.new(data_ptr.read_pointer)
  result = OpenSSL::PKCS12.new(data.to_s)
  data.release
  result
end

#private_keyObject



31
32
33
34
35
36
37
# File 'lib/keychain/identity.rb', line 31

def private_key
  key_ref = FFI::MemoryPointer.new(:pointer)
  status = Sec.SecIdentityCopyPrivateKey(self, key_ref)
  Sec.check_osstatus(status)

  Keychain::Key.new(key_ref.read_pointer)
end