commit 4f0ac189e627c531d9f4b648b158988c67ca6027
parent 2e869d2d3fd88be77b6292aba2382a3724b4b145
Author: Daniel Barlow <dan@telent.net>
Date: Fri, 13 Aug 2021 23:22:38 +0100
cache decrypted identity, to make `moss rebuild` usable
Diffstat:
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
@@ -116,7 +116,7 @@ I don't suggest you do this, at least until moss is a bit more mature. I am
only writing this down because I figured out how to
cd $HOME/.password-store
- for i in `find * -name \*.gpg` ;do ( gpg -d $i | ~/src/moss/moss.rb add "${i%.*}" );done
+ for i in `find * -name \*.gpg` ;do ( gpg -d $i | moss add "${i%.*}" );done
## Security considerations
@@ -161,6 +161,12 @@ security requirements, look elsewhere.
loggers, cameras pointing at your keyboard, virtual hosts with
compromised hypervisors, then moss won't help you
+* the first time an encrypted secret is needed (when writing a secet),
+ it is decrypted into memory and retained for the lifetime of the
+ process. If the app is paged out, maybe that data gets written to
+ swap. This is so that `moss rebuild` prompts only once for the
+ passphrase instead of once per secet
+
* `pass edit` uses Ruby's Tempfile class to write a temporary
plaintext file containing the secret. According to the Ruby
documentation the "filename picking method is both thread-safe and
diff --git a/moss.rb b/moss.rb
@@ -113,12 +113,24 @@ class Moss
end
end
+ def identity
+ unless @identity
+ @identity = encrypted?(identity_file) ?
+ capture_output([AGE, "-d", identity_file]) :
+ identity_file.read
+ end
+ @identity
+ end
+
+
def read_secret(name)
pathname = store.join("#{name}.age")
File.exist?(pathname) or raise MossError, "Can't open non-existent file #{pathname}"
- capture_output([AGE,
- "-i", identity_file,
- "-d", pathname])
+ IO.popen([AGE, "-i", "-", "-d", pathname.to_s], "r+") do |f|
+ f.write(identity)
+ f.close_write
+ f.read
+ end
end
def remove_secret(name)