From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/58168 Path: main.gmane.org!not-for-mail From: "Ted Zlatanov" Newsgroups: gmane.emacs.gnus.general Subject: Re: authinfo/netrc file encryption status -- GnuPG Date: 27 Jul 2004 12:56:14 -0400 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Sender: ding-owner@lists.math.uh.edu Message-ID: <4noem1tmmp.fsf@lifelogs.com> References: <4nwu0u8zht.fsf@lifelogs.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1090948624 20790 80.91.224.253 (27 Jul 2004 17:17:04 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 27 Jul 2004 17:17:04 +0000 (UTC) Original-X-From: ding-owner+M6709@lists.math.uh.edu Tue Jul 27 19:16:57 2004 Return-path: Original-Received: from malifon.math.uh.edu ([129.7.128.13]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BpVZQ-0004iM-00 for ; Tue, 27 Jul 2004 19:16:57 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by malifon.math.uh.edu with smtp (Exim 3.20 #1) id 1BpVZE-0003N0-00; Tue, 27 Jul 2004 12:16:44 -0500 Original-Received: from util2.math.uh.edu ([129.7.128.23]) by malifon.math.uh.edu with esmtp (Exim 3.20 #1) id 1BpVZ8-0003Mv-00 for ding@lists.math.uh.edu; Tue, 27 Jul 2004 12:16:38 -0500 Original-Received: from justine.libertine.org ([66.139.78.221] ident=postfix) by util2.math.uh.edu with esmtp (Exim 4.30) id 1BpVZ7-0002tb-Pg for ding@lists.math.uh.edu; Tue, 27 Jul 2004 12:16:37 -0500 Original-Received: from mail.bwh.harvard.edu (sysblade0.bwh.harvard.edu [134.174.9.44]) by justine.libertine.org (Postfix) with ESMTP id 72EF53A0036 for ; Tue, 27 Jul 2004 12:16:37 -0500 (CDT) Original-Received: (qmail 24551 invoked from network); 27 Jul 2004 17:09:08 -0000 Envelope-Sender: tzz@lifelogs.com Envelope-Recipients: ding@gnus.org, Original-Received: from asimov.bwh.harvard.edu (HELO asimov) ([134.174.9.63]) (envelope-sender ) by mail.bwh.harvard.edu (qmail-ldap-1.03) with SMTP for ; 27 Jul 2004 17:09:07 -0000 Mail-Followup-To: ding@gnus.org Original-To: ding@gnus.org X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6;d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" In-Reply-To: (Steven E. Harris's message of "Fri, 23 Jul 2004 14:39:24 -0700") User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux) Precedence: bulk Xref: main.gmane.org gmane.emacs.gnus.general:58168 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:58168 --=-=-= On Fri, 23 Jul 2004, seh@panix.com wrote: > So far, I noticed that `make-temp-file' (used in > gnus-encrypt-gpg-process-buffer) does not exist in XEmacs. I used > `make-temp-name' instead. I don't use XEmacs, so thanks for catching that. Can I get your changes as a patch? If it's trivial don't worry about it. >> Just call the functions gnus-encrypt-insert-file-contents and >> gnus-encrypt-write-file-contents directly after customizing >> gnus-encrypt-file-alist. > > I don't understand. Is this encryption stuff not hooked into Gnus in > any way? That might explain my experience with it so far. No. netrc.el has temporary encryption support right now, but don't use it. I just wanted you to test the gnus-encrypt.el functions on their own and see if they work reliably for you. > I encrypted my .authinfo file using gnus-encrypt-write-file-contents > (gpg, AES), but when I then fire up Gnus I don't get prompted for a > password, and Gnus can't read the file. > > I used the Customize interface to add an entry to > gnus-encrypt-file-alist, which wound up looking like this: > > (("/home/sharris/.authinfo" (gpg "AES"))) > > Note that the gpg and cipher specification are in a nested list, which > differs from the example alist: > > '(("/home/tzz/alpha" gpg "AES") ; GPG on single file > ;; xor encryption on all files matching "beta" > ("beta" gnus-encrypt-xor "Semi-Secret")) See attached new version, I think that's OK now. So test the internal gnus-encrypt.el functions again, and if they work OK for you I'll add them to netrc.el so they're used automatically (based on the gnus-encrupt-file-alist contents). Ted --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=gnus-encrypt.el Content-Transfer-Encoding: quoted-printable ;;; gnus-encrypt.el --- file encryption routines for Gnus ;; Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. ;; Author: Teodor Zlatanov ;; Created: 2003/01/24 ;; Keywords: files ;; This file is part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;;; This module addresses data encryption under Gnus. Page breaks are ;;; used for grouping declarations and documentation relating to each ;;; particular aspect. ;;; Code: ;; autoload password (eval-and-compile (autoload 'password-read "password")) (defgroup gnus-encrypt nil "Gnus encryption configuration.") (defcustom gnus-encrypt-password-cache-expiry 20 "Gnus encryption password timeout. When set, directly sets password-cache-expiry" :type 'integer :group 'gnus-encrypt) (defcustom gnus-encrypt-file-alist nil "List of file names or regexes matched with encryptions. Format example: '((\"beta\" (gpg \"AES\")) (\"/home/tzz/alpha\" (gnus-encrypt-xor \"Semi-Secret\")))" :type '(repeat (list :tag "Encryption entry" (radio :tag "What to encrypt" (file :tag "Filename") (regexp :tag "Regular expression match")) (radio :tag "How to encrypt it" (list :tag "GPG Encryption" (const :tag "GPG Program" gpg) (radio :tag "Choose a cipher" (const :tag "3DES Encryption" "3DES") (const :tag "CAST5 Encryption" "CAST5") (const :tag "Blowfish Encryption" "BLOWFISH") (const :tag "AES Encryption" "AES") (const :tag "AES192 Encryption" "AES192") (const :tag "AES256 Encryption" "AES256") (const :tag "Twofish Encryption" "TWOFISH") (string :tag "Cipher Name"))) (list :tag "Built-in simple XOR" (const :tag "XOR Encryption" gnus-encrypt-xor) (string :tag "XOR Cipher Value (seed value)"))))) :group 'gnus-encrypt) ;; TODO: now, load gencrypt.el and if successful, modify the ;; custom-type of gnus-encrypt-file-alist to add the gencrypt.el options ;; (plist-get (symbol-plist 'gnus-encrypt-file-alist) 'custom-type) ;; then use plist-put (defcustom gnus-encrypt-gpg-path (executable-find "gpg") "Path to the GPG program." :type '(radio (file :tag "Location of the GPG executable") (const :tag "GPG is not installed" nil)) :group 'gnus-encrypt) (defvar gnus-encrypt-temp-prefix "gnus-encrypt" "Prefix for temporary filenames") (defun gnus-encrypt-find-model (filename) "Given a filename, find a gnus-encrypt-file-alist entry" (dolist (entry gnus-encrypt-file-alist) (let ((match (nth 0 entry)) (model (nth 1 entry))) (when (or (eq match filename) (string-match match filename)) (return model))))) (defun gnus-encrypt-insert-file-contents (file) "Decrypt FILE into the current buffer." (interactive "fFile to insert: ") (let* ((model (gnus-encrypt-find-model file)) (method (nth 0 model)) (cipher (nth 1 model)) (passphrase (password-read (format "%s password for cipher %s? " (symbol-name method) cipher) (format "gnus-encrypt-password-%s-%s" (symbol-name method) cipher))) (buffer-file-coding-system 'binary) (coding-system-for-read 'binary) status-ok) (insert-file-contents file) (cond ((eq method 'gpg) (setq status-ok (gnus-encrypt-gpg-decode-buffer passphrase cipher t))) ((eq method 'gnus-encrypt-xor) (setq status-ok (gnus-encrypt-xor-decode-buffer passphrase cipher t))= )) (if status-ok (gnus-message 9 "%s was decrypted with %s (cipher %s)" file (symbol-name method) cipher) (gnus-error 5 "%s was NOT decrypted with %s (cipher %s)" file (symbol-name method) cipher)))) (defun gnus-encrypt-write-file-contents (file) "Encrypt the current buffer to FILE, then continue normally." (interactive "fFile to write: ") (let* ((model (gnus-encrypt-find-model file)) (method (nth 0 model)) (cipher (nth 1 model)) (contents (buffer-string)) (passphrase (password-read (format "%s password for cipher %s? " (symbol-name method) cipher) (format "gnus-encrypt-password-%s-%s" (symbol-name method) cipher))) status-ok) (cond ((eq method 'gpg) (setq status-ok (gnus-encrypt-gpg-encode-buffer passphrase cipher t))) ((eq method 'gnus-encrypt-xor) (setq status-ok (gnus-encrypt-xor-encode-buffer passphrase cipher t))= )) (if status-ok (gnus-message 9 "%s was encrypted with %s (cipher %s)" file (symbol-name method) cipher) (gnus-error 5 "%s was NOT encrypted with %s (cipher %s)" file (symbol-name method) cipher)) ;; do not confirm overwrites (write-file file nil))) ;; undo-if-error is ignored (defun gnus-encrypt-xor-encode-buffer (passphrase cipher undo-if-error) (gnus-encrypt-xor-process-buffer passphrase cipher t)) ;; undo-if-error is ignored (defun gnus-encrypt-xor-decode-buffer (passphrase cipher undo-if-error) (gnus-encrypt-xor-process-buffer passphrase cipher nil)) (defun gnus-encrypt-xor-process-buffer (passphrase cipher &optional encode) "Given PASSPHRASE, xor-encode or decode the contents of the current buffe= r." (let* ((bs (buffer-string)) ;; passphrase-sum is a simple additive checksum of the ;; passphrase and the cipher (passphrase-sum (when (stringp passphrase) (apply '+ (append cipher passphrase nil)))) new-list) (delete-region (point-min) (point-max)) (goto-char (point-min)) (if encode (progn (dolist (x (append bs nil)) (setq new-list (cons (logxor x passphrase-sum) new-list))) (dolist (x new-list) (insert (format "%d " x)))) (progn (setq new-list (reverse (split-string bs))) (dolist (x new-list) (setq x (string-to-int x)) (insert (format "%c" (logxor x passphrase-sum)))))) t)) (defun gnus-encrypt-gpg-encode-buffer (passphrase cipher undo-if-error) (gnus-encrypt-gpg-process-buffer passphrase cipher t undo-if-error)) (defun gnus-encrypt-gpg-decode-buffer (passphrase cipher undo-if-error) (gnus-encrypt-gpg-process-buffer passphrase cipher nil undo-if-error)) (defun gnus-encrypt-gpg-process-buffer (passphrase=20 cipher=20 &optional encode undo-if-error) "With PASSPHRASE, use GPG to encode or decode the contents of the current= buffer." (let ((program gnus-encrypt-gpg-path) (old-buffer-string (buffer-string)) (input (buffer-substring-no-properties (point-min) (point-max))) (temp-file (make-temp-file gnus-encrypt-temp-prefix)) (default-enable-multibyte-characters nil) (args `("--cipher-algo" ,cipher "--status-fd" "2" "--logger-fd" "2" "--passphrase-fd" "0" "--no-tty")) exit-status) (when encode (setq args=20 (append args '("--symmetric" "--armor")))) (if program (progn (delete-region (point-min) (point-max)) (goto-char (point-min)) (when passphrase (insert passphrase "\n")) (insert input) (setq exit-status (apply #'call-process-region (point-min) (point-max) program t `(t ,temp-file) nil args)) (unless (equal exit-status 0) (setq exit-status nil) (when undo-if-error (delete-region (point-min) (point-max)) (goto-char (point-min)) (insert old-buffer-string)) (with-temp-buffer (when (file-exists-p temp-file) (insert-file-contents temp-file) (delete-file temp-file)) (gnus-error 5 (format "%s exited abnormally: '%s' [%s]" program exit-status (buffer-string)))))) (gnus-error 5 "GPG is not installed.")) exit-status)) (provide 'gnus-encrypt) ;;; gnus-encrypt.el ends here --=-=-=--