Class: LastPass::Vault
- Inherits:
-
Object
- Object
- LastPass::Vault
- Defined in:
- lib/lastpass/vault.rb
Instance Attribute Summary collapse
-
#accounts ⇒ Object
readonly
Returns the value of attribute accounts.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
Class Method Summary collapse
-
.fetch_blob(username, password, multifactor_password = nil, client_id = nil) ⇒ Object
Just fetches the blob, could be used to store it locally.
-
.open(blob, username, password) ⇒ Object
Creates a vault from a blob object.
-
.open_remote(username, password, multifactor_password = nil, client_id = nil) ⇒ Object
Fetches a blob from the server and creates a vault.
Instance Method Summary collapse
- #accounts_and_notes ⇒ Object
- #complete?(chunks) ⇒ Boolean
-
#initialize(blob, encryption_key) ⇒ Vault
constructor
This more of an internal method, use one of the static constructors instead.
- #parse_accounts_and_notes(chunks, encryption_key, private_key) ⇒ Object
Constructor Details
#initialize(blob, encryption_key) ⇒ Vault
This more of an internal method, use one of the static constructors instead
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lastpass/vault.rb', line 29 def initialize blob, encryption_key chunks = Parser.extract_chunks blob if !complete? chunks raise InvalidResponseError, "Blob is truncated" end private_key = nil if blob.encrypted_private_key private_key = Parser.parse_private_key blob.encrypted_private_key, encryption_key end @accounts, @notes = parse_accounts_and_notes chunks, encryption_key, private_key end |
Instance Attribute Details
#accounts ⇒ Object (readonly)
Returns the value of attribute accounts.
6 7 8 |
# File 'lib/lastpass/vault.rb', line 6 def accounts @accounts end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
6 7 8 |
# File 'lib/lastpass/vault.rb', line 6 def notes @notes end |
Class Method Details
.fetch_blob(username, password, multifactor_password = nil, client_id = nil) ⇒ Object
Just fetches the blob, could be used to store it locally
20 21 22 23 24 25 26 |
# File 'lib/lastpass/vault.rb', line 20 def self.fetch_blob username, password, multifactor_password = nil, client_id = nil session = Fetcher.login username, password, multifactor_password, client_id blob = Fetcher.fetch session Fetcher.logout session blob end |
.open(blob, username, password) ⇒ Object
Creates a vault from a blob object
15 16 17 |
# File 'lib/lastpass/vault.rb', line 15 def self.open blob, username, password new blob, blob.encryption_key(username, password) end |
.open_remote(username, password, multifactor_password = nil, client_id = nil) ⇒ Object
Fetches a blob from the server and creates a vault
9 10 11 12 |
# File 'lib/lastpass/vault.rb', line 9 def self.open_remote username, password, multifactor_password = nil, client_id = nil blob = Vault.fetch_blob username, password, multifactor_password, client_id open blob, username, password end |
Instance Method Details
#accounts_and_notes ⇒ Object
43 44 45 |
# File 'lib/lastpass/vault.rb', line 43 def accounts_and_notes @accounts_and_notes ||= @accounts + @notes end |
#complete?(chunks) ⇒ Boolean
47 48 49 |
# File 'lib/lastpass/vault.rb', line 47 def complete? chunks !chunks.empty? && chunks.last.id == "ENDM" && chunks.last.payload == "OK" end |
#parse_accounts_and_notes(chunks, encryption_key, private_key) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/lastpass/vault.rb', line 51 def parse_accounts_and_notes chunks, encryption_key, private_key accounts = [] notes = [] key = encryption_key chunks.each do |i| case i.id when "ACCT" # TODO: Put shared folder name as group in the account account = Parser.parse_ACCT i, key case account when Account accounts << account when Note notes << account end when "SHAR" raise "private_key must be provided" if !private_key # After SHAR chunk all the folliwing accounts are enrypted with a new key key = Parser.parse_SHAR(i, encryption_key, private_key)[:encryption_key] end end [accounts, notes] end |