Guest User

Untitled

a guest
Oct 21st, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Keys generated using:
  4. #
  5. # fingerprint=$(echo -n "${imap_password}" | gpg2 --batch --passphrase-fd 0 --quick-gen-key "Mail encryption key <${imap_user}>" ed25519 2>&1 | fgrep 'revocation certificate stored as' | sed -e 's/.*///' -e 's/..*//')
  6. # echo -n "${imap_password}" | gpg2 --batch --passphrase-fd 0 --quick-add-key "${fingerprint}" cv25519
  7. #
  8. # Call this from dovecot with:
  9. #
  10. # plugin {
  11. # mail_filter = mail-filter read %u %{userdb:pass}
  12. # mail_filter_out = mail-filter-out write %u
  13. # }
  14. #
  15. # And configure dovecot to pass the un-encrypted mail password through:
  16. #
  17. # passdb {
  18. # driver = passwd-file
  19. # args = scheme=CRYPT username_format=%u /etc/dovecot/users
  20. # override_fields = userdb_pass=%w
  21. # }
  22.  
  23. export GNUPGHOME="/srv/mail/.gnupg"
  24. imap_user="$2"
  25.  
  26. tempfile=$(mktemp)
  27. cat > "$tempfile"
  28.  
  29. if [ "$1" == "write" ]; then
  30. gpg2 --armor --batch --encrypt -r "${imap_user}" < "$tempfile"
  31. elif [ "$1" == "read" ]; then
  32. imap_password="$3"
  33. echo -n "${imap_password}" | gpg2 --quiet --batch --passphrase-fd 0 --decrypt "$tempfile"
  34. fi
  35.  
  36. rm -f "$tempfile"
Add Comment
Please, Sign In to add comment