Class: KStor::Model::KeychainItem

Inherits:
Base
  • Object
show all
Defined in:
lib/kstor/model.rb

Overview

An item in a user keychain: associates a group and it’s private key, encrypted with the user’s key pair.

Initially encrypted, the #privk property will be nil until #unlocked.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#clean, #dirty?, #initialize, property, property?

Constructor Details

This class inherits a constructor from KStor::Model::Base

Instance Attribute Details

#encrypted_privkObject

Returns value of property encrypted_privk

Returns:

  • returns value of property encrypted_privk



106
# File 'lib/kstor/model.rb', line 106

property :encrypted_privk

#group_idObject

Returns value of property group_id

Returns:

  • returns value of property group_id



102
# File 'lib/kstor/model.rb', line 102

property :group_id

#group_pubkObject

Returns value of property group_pubk

Returns:

  • returns value of property group_pubk



104
# File 'lib/kstor/model.rb', line 104

property :group_pubk

#privkObject

Returns value of property privk

Returns:

  • returns value of property privk



108
# File 'lib/kstor/model.rb', line 108

property :privk

Instance Method Details

#encrypt(user_pubk) ⇒ Object

Re-encrypt group private key.

Calling this will overwrite the #encrypted_privk property.

Parameters:



128
129
130
131
132
# File 'lib/kstor/model.rb', line 128

def encrypt(user_pubk)
  self.encrypted_privk = Crypto.encrypt_group_privk(
    user_pubk, privk, privk
  )
end

#lockObject

Forget about decrypted group private key.

This will unset #privk property.



137
138
139
# File 'lib/kstor/model.rb', line 137

def lock
  self.privk = nil
end

#locked?Boolean

Check if group private key was decrypted.

Returns:

  • (Boolean)

    false if decrypted



144
145
146
# File 'lib/kstor/model.rb', line 144

def locked?
  privk.nil?
end

#to_hObject

Dump properties except #encrypted_privk.



156
157
158
159
160
# File 'lib/kstor/model.rb', line 156

def to_h
  h = super
  h.delete('encrypted_privk')
  h
end

#unlock(group_pubk, user_privk) ⇒ Object

Decrypt group private key.

Calling this method will set the #privk property.

Parameters:

  • group_pubk (PublicKey)

    public key to verify ciphertext signature

  • user_privk (PrivateKey)

    private key of owner of keychain item



116
117
118
119
120
# File 'lib/kstor/model.rb', line 116

def unlock(group_pubk, user_privk)
  self.privk = Crypto.decrypt_group_privk(
    group_pubk, user_privk, encrypted_privk
  )
end

#unlocked?Boolean

Check if group private key was decrypted.

Returns:

  • (Boolean)

    true if decrypted



151
152
153
# File 'lib/kstor/model.rb', line 151

def unlocked?
  !locked?
end