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



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

property :encrypted_privk

#group_idObject

Returns value of property group_id

Returns:

  • returns value of property group_id



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

property :group_id

#group_pubkObject

Returns value of property group_pubk

Returns:

  • returns value of property group_pubk



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

property :group_pubk

#privkObject

Returns value of property privk

Returns:

  • returns value of property privk



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

property :privk

Instance Method Details

#encrypt(user_pubk) ⇒ Object

Re-encrypt group private key.

Calling this will overwrite the #encrypted_privk property.

Parameters:



125
126
127
128
129
# File 'lib/kstor/model.rb', line 125

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.



134
135
136
# File 'lib/kstor/model.rb', line 134

def lock
  self.privk = nil
end

#locked?Boolean

Check if group private key was decrypted.

Returns:

  • (Boolean)

    false if decrypted



141
142
143
# File 'lib/kstor/model.rb', line 141

def locked?
  privk.nil?
end

#to_hObject

Dump properties except #encrypted_privk.



153
154
155
# File 'lib/kstor/model.rb', line 153

def to_h
  super.except('encrypted_privk')
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



113
114
115
116
117
# File 'lib/kstor/model.rb', line 113

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



148
149
150
# File 'lib/kstor/model.rb', line 148

def unlocked?
  !locked?
end