From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/58183 Path: main.gmane.org!not-for-mail From: "Ted Zlatanov" Newsgroups: gmane.emacs.gnus.general Subject: Re: authinfo/netrc file encryption status -- GnuPG Date: 30 Jul 2004 12:52:45 -0400 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Sender: ding-owner@lists.math.uh.edu Message-ID: <4nk6wlzbc2.fsf@koz.bwh.harvard.edu> References: <4nwu0u8zht.fsf@lifelogs.com> <4noem1tmmp.fsf@lifelogs.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1091206757 11861 80.91.224.253 (30 Jul 2004 16:59:17 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 30 Jul 2004 16:59:17 +0000 (UTC) Original-X-From: ding-owner+M6724@lists.math.uh.edu Fri Jul 30 18:59:08 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 1Bqaiq-0001v3-00 for ; Fri, 30 Jul 2004 18:59:08 +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 1BqaeT-0002tB-00; Fri, 30 Jul 2004 11:54:37 -0500 Original-Received: from util2.math.uh.edu ([129.7.128.23]) by malifon.math.uh.edu with esmtp (Exim 3.20 #1) id 1BqaeM-0002t6-00 for ding@lists.math.uh.edu; Fri, 30 Jul 2004 11:54:30 -0500 Original-Received: from justine.libertine.org ([66.139.78.221] ident=postfix) by util2.math.uh.edu with esmtp (Exim 4.30) id 1BqaeM-0006FE-6Z for ding@lists.math.uh.edu; Fri, 30 Jul 2004 11:54:30 -0500 Original-Received: from mail.bwh.harvard.edu (sysblade0.bwh.harvard.edu [134.174.9.44]) by justine.libertine.org (Postfix) with ESMTP id 9B5DA3A003C for ; Fri, 30 Jul 2004 11:54:29 -0500 (CDT) Original-Received: (qmail 24951 invoked from network); 30 Jul 2004 16:46:54 -0000 Envelope-Sender: tzz@lifelogs.com Envelope-Recipients: ding@gnus.org, Original-Received: from koz.bwh.harvard.edu ([134.174.9.110]) (envelope-sender ) by mail.bwh.harvard.edu (qmail-ldap-1.03) with SMTP for ; 30 Jul 2004 16:46:53 -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 "Tue, 27 Jul 2004 11:12:23 -0700") User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (usg-unix-v) Precedence: bulk Xref: main.gmane.org gmane.emacs.gnus.general:58183 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:58183 --=-=-= On Tue, 27 Jul 2004, seh@panix.com wrote: > "Ted Zlatanov" writes: > >> 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. > > It's just that one function name swap: `make-temp-name' rather than > `make-temp-file'. I'm not sure how you'd prefer to make that > conditional. According to the Emacs docs you should use make-temp-file for safety, but I'll go with make-temp-name for simplicity because I don't expect the risk from it to be significant (I remove the temp file afterwards in any case). If anyone disagrees, let me know. >> I just wanted you to test the gnus-encrypt.el functions on their own >> and see if they work reliably for you. > > So far I've just tested them using gpg with AES, and the > encrypt/decrypt functions work mostly as expected. I'm not sure why > the "current buffer" can't be read-only when calling > `gnus-encrypt-write-file-contents', though: I've changed the code to do the right thing, I think (at the expense of passing around potentially large buffer substrings, but I expect this code to be used for small files). Can you test it again please? Once we're both OK with the code, I'll add the netrc.el hooks. Thanks 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) outdata) (insert-file-contents file) (cond ((eq method 'gpg) (setq outdata (gnus-encrypt-gpg-decode-buffer passphrase cipher))) ((eq method 'gnus-encrypt-xor) (setq outdata (gnus-encrypt-xor-decode-buffer passphrase cipher)))) (if outdata (progn (gnus-message 9 "%s was decrypted with %s (cipher %s)" file (symbol-name method) cipher) (delete-region (point-min) (point-max)) (goto-char (point-min)) (insert outdata)) (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))) outdata) (cond ((eq method 'gpg) (setq outdata (gnus-encrypt-gpg-encode-buffer passphrase cipher))) ((eq method 'gnus-encrypt-xor) (setq outdata (gnus-encrypt-xor-encode-buffer passphrase cipher)))) (if outdata (progn (gnus-message 9 "%s was encrypted with %s (cipher %s)" file (symbol-name method) cipher) (delete-region (point-min) (point-max)) (goto-char (point-min)) (insert outdata) ;; do not confirm overwrites (write-file file nil)) (gnus-error 5 "%s was NOT encrypted with %s (cipher %s)" file (symbol-name method) cipher)))) (defun gnus-encrypt-xor-encode-buffer (passphrase cipher) (gnus-encrypt-xor-process-buffer passphrase cipher t)) (defun gnus-encrypt-xor-decode-buffer (passphrase cipher) (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-substring-no-properties (point-min) (point-max))) ;; 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) (with-temp-buffer (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)))))) (buffer-substring-no-properties (point-min) (point-max))))) (defun gnus-encrypt-gpg-encode-buffer (passphrase cipher) (gnus-encrypt-gpg-process-buffer passphrase cipher t)) (defun gnus-encrypt-gpg-decode-buffer (passphrase cipher) (gnus-encrypt-gpg-process-buffer passphrase cipher nil)) (defun gnus-encrypt-gpg-process-buffer (passphrase=20 cipher=20 &optional encode) "With PASSPHRASE, use GPG to encode or decode the contents of the current= buffer." (let ((program gnus-encrypt-gpg-path) (input (buffer-substring-no-properties (point-min) (point-max))) (temp-file (make-temp-name 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 exit-data) (when encode (setq args=20 (append args '("--symmetric" "--armor")))) (if program (progn (with-temp-buffer (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))) (if (equal exit-status 0) (setq exit-data=20 (buffer-substring-no-properties (point-min) (point-max))) (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-data)) (provide 'gnus-encrypt) ;;; gnus-encrypt.el ends here --=-=-=--