Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for age encryption via age.el #442

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

fapdash
Copy link

@fapdash fapdash commented Aug 25, 2024

  • require age.el if the package is installed https://github.com/anticomputer/age.el
  • add new customizable variable org-journal-encryption-extension to control the file extension appended to the file name to trigger transparent encryption
  • recognize .age files as journal files
  • generate encrypted files based on chosen file extension instead of hard coding .gpg
  • support .age files in org-journal-re-encrypt-journals - only re-encrypt files for the currently chosen encryption extension - functional change: don't edit/re-save files that aren't encrypted. I assume that they where handled by this function in the past was an oversight and not intended. - allow multiple recipients for age encryption

closes #441


age encyrption works with this change.
TODOs from age encrypted journal files get added to the agenda. (org-journal-enable-agenda-integration)

I wasn't sure how to do optional dependencies for Emacs packages.
If someone tries to set age as extension the org-journal-re-encrypt-journals
function will fail because of missing functions, of course.

org-journal-re-encrypt-journals works for me if age-default-recipient and age-default-identity are set,
but things got a bit weird when I hadn't set those.
I might be missing some settings, but at some point age encryption wasn't working at all and I had to restart Emacs.

Theoretically org-journal would work with any encryption that implements transparent, as long as the org-journal--list-files and org-journal--dir-and-file-format->pattern would get consider the value of org-journal-encryption-extension in their regexes. If we don't want to implement this then it's probably better to make org-journal-encryption-extension of :type '(choice (const :tag "age" age) (const :tag "gpg" gpg)) instead of 'string.

Instructions for testing

Create age keys:

age-keygen -o key.txt
age-keygen -y key.txt > key.pub

Example age.el configuration for testing:

(use-package age
  :ensure t
  :demand t
  :custom
  (age-program "age")
  (age-default-identity "~/.age/key.txt")
  (age-default-recipient '("~/.age/key.pub"))
  :config
  (age-file-enable))

Activate age encrption for org-journal:

(setq 
  org-journal-encrypt-journal t
  org-journal-encryption-extension "age")

- require age.el if the package is installed
  https://github.com/anticomputer/age.el
- add new customizable variable `org-journal-encryption-extension` to
  control the file extension appended to the file name to trigger
  transparent encryption
- recognize `.age` files as journal files
- generate encrypted files based on chosen file extension instead of
  hard coding `.gpg`
- support `.age` files in `org-journal-re-encrypt-journals`
    - only re-encrypt files for the currently chosen encryption
      extension
    - functional change: don't edit/re-save files that aren't
      encrypted. I assume that they where handled by this function in
      the past was an oversight and not intended.
    - allow multiple recipients for `age` encryption

closes bastibe#441
@fapdash
Copy link
Author

fapdash commented Aug 25, 2024

@rosstimson Can you please test if this is working for you?

@rosstimson
Copy link

@fapdash Thanks for your work here. I don't think it is encrypting the file properly.

My relevant config looks like:

(use-package age
    :mode ("\\.age\\'" . age-encryption-mode)
    :custom
    (age-default-identity (expand-file-name ".age/rosstimson.txt" (getenv "HOME")))
    ;; My public age key
    (age-default-recipient "age17ll5hultu5gpye40nlj7z7ktcxl8ne9xvtd6udzugkmwlmt83uns82smww")
    :config
    (age-file-enable))

(use-package org-journal
    :after org
    :bind ("C-c j" . org-journal-new-entry)
    :custom
    (org-journal-file-type 'monthly)
    (org-journal-date-format "%A, %d %B %Y")
    (org-journal-encrypt-journal t)
    (org-journal-encryption-extension "age")
    (org-journal-dir (concat (concat org-directory "/journal/") (format-time-string "%Y"))))

If I create a test file of foo.age and save some text then check it in terminal with less I can see that it is age encrypted and it automatically decrypts when I open it within emacs.

I then shifted my existing gpg encrypted journal files into a backup dir and used org-journal-new-entry to create a new journal entry, when I check the file in the terminal it shows as plain text rather than encrypted, it does indeed have have the .age extension though.

I've rebuilt the org-journal package with your branch and restarted emacs of course, if I enter the customize stuff I can see your newly added org-journal-encryption-extension when I search for it, I saw no errors with my init config.

@fapdash
Copy link
Author

fapdash commented Aug 28, 2024

@rosstimson Mh, I can't reproduce this.. 🤷
org-journal doesn't really change anything about age.el, the only change you're hitting is that the file extension is changed to .age, which you've confirmed is working.

Can you please check if age-encryption-mode is active in the buffer for your journal .age file after you've created it via org-journal-new-entry?
I don't expect it to make a difference, but can you try without the :mode ("\\.age\\'" . age-encryption-mode) line? (mode activation is already handled by age-file-enable)

@rosstimson
Copy link

@fapdash Not sure why it was a problem but you were correct, simply removing the line :mode ("\\.age\\'" . age-encryption-mode) has fixed it. So exact same config as I posted above minus that link.

I can now confirm that this works as expected. Thanks again for your work here. 🎉

This way the function `org-journal-re-encrypt-journal`
will work with `age` even if `age` has been installed after
`org-journal` has been loaded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for age encryption
2 participants