Skip to content

Commit

Permalink
interpet and expose Secure Notes
Browse files Browse the repository at this point in the history
  • Loading branch information
saraid committed Oct 26, 2020
1 parent 4d9241a commit 4313409
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/lastpass.rb
Expand Up @@ -12,6 +12,7 @@
require "lastpass/exceptions"
require "lastpass/http"
require "lastpass/fetcher"
require "lastpass/note"
require "lastpass/parser"
require "lastpass/session"
require "lastpass/vault"
Expand Down
15 changes: 15 additions & 0 deletions lib/lastpass/note.rb
@@ -0,0 +1,15 @@
module LastPass
class Note
attr_reader :id,
:name,
:notes,
:group

def initialize id, name, notes, group
@id = id
@name = name
@notes = notes
@group = group
end
end
end
6 changes: 3 additions & 3 deletions lib/lastpass/parser.rb
Expand Up @@ -7,7 +7,7 @@ class Parser
RSA_PKCS1_OAEP_PADDING = 4

# Secure note types that contain account-like information
ALLOWED_SECURE_NOTE_TYPES = {
ACCOUNT_LIKE_SECURE_NOTE_TYPES = {
"Server" => true,
"Email Account" => true,
"Database" => true,
Expand Down Expand Up @@ -49,8 +49,8 @@ def self.parse_ACCT chunk, encryption_key
# Parse secure note
if secure_note == "1"
parsed = parse_secure_note_server notes
if !ALLOWED_SECURE_NOTE_TYPES.key? parsed[:type]
return nil
if !ACCOUNT_LIKE_SECURE_NOTE_TYPES.key? parsed[:type]
return Note.new id, name, notes, group
end

url = parsed[:url] if parsed.key? :url
Expand Down
16 changes: 12 additions & 4 deletions lib/lastpass/vault.rb
Expand Up @@ -3,7 +3,7 @@

module LastPass
class Vault
attr_reader :accounts
attr_reader :accounts, :notes

# Fetches a blob from the server and creates a vault
def self.open_remote username, password, multifactor_password = nil, client_id = nil
Expand Down Expand Up @@ -37,7 +37,11 @@ def initialize blob, encryption_key
private_key = Parser.parse_private_key blob.encrypted_private_key, encryption_key
end

@accounts = parse_accounts chunks, encryption_key, private_key
@accounts, @notes = parse_accounts chunks, encryption_key, private_key
end

def accounts_and_notes
@accounts_and_notes ||= @accounts + @notes
end

def complete? chunks
Expand All @@ -46,15 +50,19 @@ def complete? chunks

def parse_accounts 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
if account
case account
when Account
accounts << account
when Note
notes << account
end
when "SHAR"
raise "private_key must be provided" if !private_key
Expand All @@ -64,7 +72,7 @@ def parse_accounts chunks, encryption_key, private_key
end
end

accounts
[ accounts, notes ]
end
end
end

0 comments on commit 4313409

Please sign in to comment.