Michael-F-Bryan / adventures.michaelfbryan.com

A simple blog for documenting my thoughts and adventures
http://adventures.michaelfbryan.com/
15 stars 3 forks source link

Listing and retrieving attachments for secure notes in 'lpass' #28

Open whereisaaron opened 4 years ago

whereisaaron commented 4 years ago

Nice Rust article @Michael-F-Bryan. With regards to the original goal though, is this not that thing in the lpass client?

https://github.com/lastpass/lastpass-cli/commit/a4532a94c3b61f18e6cda5e4c56976e9a604203e

This change adds the ability to retrieve attachments for secure notes. The lpass show command now shows attachment ids and filenames if a secure note has attachments. The attachment id can then be passed to lpass show acct --attach=attachid which will either print the attachment (if non-binary) or offer the ability to save.

Michael-F-Bryan commented 4 years ago

My problem was there's no programmable way to find an attachment by name if you don't already know its attachment ID.

Sure, you can use lpass show but that's intended for humans and because it'll print things like the item's note inline, parsing the output by splitting on : isn't overly reliable. I want something I can trust to work all the time, not just most of the time.

$ lpass show "SSH Keys"
Group/SSH Keys [id: XXX]
URL: http://sn
att-XXX-YYY: id_rsa.pub.txt
att-XXX-YYY: id_rsa.txt
Reprompt: Yes
Notes: several lines
of text and random punctuation 
and maybe a 
https://url/or/two                  <---- Would be treated as the key-value pair "http" = "//url/or/two"

If you use the --json flag, it just plain doesn't show you what is attached to that item.

$ lpass show --json "SSH Keys"
[
  {
    "id": "XXXX",
    "name": "SSH Keys",
    "fullname": "Group/SSH Keys",
    "username": "",
    "password": "",
    "last_modified_gmt": "YYYY",
    "last_touch": "ZZZZ",
    "group": "Group",
    "url": "http://sn",
    "note": "..."
  }
]