lib/lastpass/vault.rb in lastpass-1.0.1 vs lib/lastpass/vault.rb in lastpass-1.1.0
- old
+ new
@@ -4,12 +4,12 @@
module LastPass
class Vault
attr_reader :accounts
# Fetches a blob from the server and creates a vault
- def self.open_remote username, password
- open Vault.fetch_blob(username, password), username, password
+ def self.open_remote username, password, multifactor_password = nil
+ open Vault.fetch_blob(username, password, multifactor_password), username, password
end
# Creates a vault from a locally stored blob
def self.open_local blob_filename, username, password
# TODO: read the blob here
@@ -19,16 +19,31 @@
def self.open blob, username, password
new blob, blob.encryption_key(username, password)
end
# Just fetches the blob, could be used to store it locally
- def self.fetch_blob username, password
- Fetcher.fetch Fetcher.login username, password
+ def self.fetch_blob username, password, multifactor_password = nil
+ Fetcher.fetch Fetcher.login username, password, multifactor_password
end
# This more of an internal method, use one of the static constructors instead
def initialize blob, encryption_key
- chunks = Parser.extract_chunks blob
- @accounts = (chunks["ACCT"] || []).map { |i| Parser.parse_account i, encryption_key }
+ @accounts = []
+
+ key = encryption_key
+ rsa_private_key = nil
+
+ Parser.extract_chunks(blob).each do |i|
+ case i.id
+ when "ACCT"
+ # TODO: Put shared folder name as group in the account
+ @accounts.push Parser.parse_ACCT i, key
+ when "PRIK"
+ rsa_private_key = Parser.parse_PRIK i, encryption_key
+ when "SHAR"
+ # After SHAR chunk all the folliwing accounts are enrypted with a new key
+ key = Parser.parse_SHAR(i, encryption_key, rsa_private_key)[:encryption_key]
+ end
+ end
end
end
end