ledger-mode icon indicating copy to clipboard operation
ledger-mode copied to clipboard

[FEATURE] Full file crypt encrypt/decrypt support

Open wakatara opened this issue 4 years ago • 6 comments

Org-journal released a shockingly useful feature recently of transparent full-file encryption via org-crypt. Basically, the org file is saved and unsaved as a gpg file on the fly so it is always stored at rest encrypted though unlocked via emacs with gpg integration.

This is done magically through org-crypt (I believe - I also have a setup where :crypt: tagged headers can be encrypted but the transparent full-file encryption is the bomb. Is there any possibility to have ledger-mode support the same in-mode? The beauty of it is that the file is encrypted but transparently usable by a person in emacs mode. Would be super handy for ledger files considering how secure some of this stuff is business and personally.

thanks! Daryl. PS> (sorry for bothering you with all the feature requests - I obviously have more time on my hands during lockdown here in SG... =p ).

wakatara avatar Apr 19 '20 06:04 wakatara

Well I guess ledger-mode will already "work" for the most part with Emacs' transparent decryption support, but there will be cases where ledger will get executed under the covers on the "at rest" file, and then it will fail. Additionally, you'd presumably want to be sure that no temp files are ever created containing the decrypted contents, and that's a very hard thing to ensure in general. As soon as you use flycheck or similar, there will be temp files in the mix. A further thing is that if you include one file from another using ledger's directives, it would become impractical to ever run ledger on a buffer's contents. It's worth noting that the inside of Emacs isn't a particularly secure environment anyway: given that, a potentially superior approach might be to keep your ledger files in a separate encrypted file system volume and then just mount it when necessary.

purcell avatar Apr 20 '20 05:04 purcell

Yes, you are correct in what you say, but in particular I was thinking this case was of particular note where you are using your ledger file at rest with cloud storage. I already have the local OS and linux file system encrypted, and temp files and backups are local rather than cloud based, so the particular use case for this is where you are saving the end ledger file in Dropbox, iCloud, Goog or similar.

Few of those have the capability to vault things though a few do, though those tend to have poor third party API support for doing other interesting things.

I was thinking of lifting the feature entirely from org-journal and just having it in ledger-mode basically. It didn't seem to be a lot of work (and they just added a reencrypting to another key feature which was a previous friction.).

Thoughts?

wakatara avatar Apr 21 '20 17:04 wakatara

Still, I think the key issue is that we use ledger a lot on underlying files, and those files can inherently refer to each other, so I suspect it is unfeasible to make everything "just work" without a lot of additional complexity. Having a single ledger file is a special case we should be careful to avoid assuming.

purcell avatar Apr 21 '20 23:04 purcell

These are very good points. I might mess around extracting the feature from org-journal and see what happens (for example, both my budget file (not so important to encrypt) and portfolio (would like encrypted) and a price file (not so important) are included in the master file but feels like it could be interesting. I like the full file encrpyption since it seems less error prone and open to disaster than using :crypt: tags in org-mode.

Lemme see what the implications of cascading encryption/decryption would be (though imagine at least all encrypted files would need to be open in buffer. Hmmm... Will poke around after I'm done with this other thing I am prepping for release, and swing back around on it.

thanks for entertaining the feature request and discussion. I'll see what sort of mischief I can handle with this (though my guess is encrypting a main file but not others would be easy enough to do, no?... cascadig/referred to failed not so much. (also, obviously running the ledger command on the encrypted files would not be very useful... =p

wakatara avatar Apr 24 '20 12:04 wakatara

@wakatara you can add the necessary decryption to the ledger-reports variable.

(setq ledger-reports '(("bal" "gpg -d -q %(ledger-file) | %(binary) -f - bal")
                       ("reg" "gpg -d -q %(ledger-file) | %(binary) -f - reg")
                       ("payee" "gpg -d -q %(ledger-file) | %(binary) -f - reg @%(payee)")
                       ("account" "gpg -d -q %(ledger-file) | %(binary) -f - reg %(account)")))

cvdub avatar Oct 22 '21 01:10 cvdub

@cvdub Thanks for the snips. Got the final piece of the puzzle 😄

ThangaAyyanar avatar Oct 22 '21 14:10 ThangaAyyanar