From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/56331 Path: main.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.gnus.general Subject: Re: Crypto problems again Date: Mon, 09 Feb 2004 16:03:11 -0500 Organization: =?koi8-r?q?=F4=C5=CF=C4=CF=D2=20=FA=CC=C1=D4=C1=CE=CF=D7?= @ Cienfuegos Sender: ding-owner@lists.math.uh.edu Message-ID: <4nbro8aru8.fsf@collins.bwh.harvard.edu> References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1076360721 11733 80.91.224.253 (9 Feb 2004 21:05:21 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 9 Feb 2004 21:05:21 +0000 (UTC) Original-X-From: ding-owner+M4871@lists.math.uh.edu Mon Feb 09 22:05:15 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 1AqIag-0006xF-00 for ; Mon, 09 Feb 2004 22:05:14 +0100 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 1AqIaM-0000Hv-00; Mon, 09 Feb 2004 15:04:54 -0600 Original-Received: from justine.libertine.org ([66.139.78.221] ident=postfix) by malifon.math.uh.edu with esmtp (Exim 3.20 #1) id 1AqIaD-0000Hp-00 for ding@lists.math.uh.edu; Mon, 09 Feb 2004 15:04:45 -0600 Original-Received: from clifford.bwh.harvard.edu (clifford.bwh.harvard.edu [134.174.9.41]) by justine.libertine.org (Postfix) with ESMTP id 87D1B3A0260 for ; Mon, 9 Feb 2004 15:04:44 -0600 (CST) Original-Received: from collins.bwh.harvard.edu (collins [134.174.9.80]) by clifford.bwh.harvard.edu (8.10.2+Sun/8.11.0) with ESMTP id i19L3MU14578 for ; Mon, 9 Feb 2004 16:03:22 -0500 (EST) Original-Received: from collins.bwh.harvard.edu (localhost [127.0.0.1]) by collins.bwh.harvard.edu (8.12.9+Sun/8.11.0) with ESMTP id i19L3Bvl024269 for ; Mon, 9 Feb 2004 16:03:11 -0500 (EST) Original-Received: (from tzz@localhost) by collins.bwh.harvard.edu (8.12.9+Sun/8.12.9/Submit) id i19L3Brb024266; Mon, 9 Feb 2004 16:03:11 -0500 (EST) 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" Mail-Followup-To: ding@gnus.org In-Reply-To: (Jesper Harder's message of "Sat, 07 Feb 2004 00:58:48 +0100") User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (usg-unix-v) Precedence: bulk Xref: main.gmane.org gmane.emacs.gnus.general:56331 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:56331 --=-=-= I would appreciate any advice regarding gnus-encrypt.el, please. This is important because I have to remove the crypto wrapper code in netrc.el! gnus-encrypt.el works for me, I'm able to encrypt my .authinfo file and decrypt it. I haven't comitted the changes to CVS, because I need to know where to put the code and how to hook it into Gnus. The problem is that I want the gnus-encrypt package to be supported by Gnus, meaning that the user should just load gnus-encrypt and have support for gnus-encrypt-file-alist and all the other nice things in that package. But I'm not allowed to use most normal facilities in order to do this. What can I do? Thanks Ted p.s. including gnus-encrypt.el for those who missed it the first time... --=-=-= 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 ;; 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")) (eval-and-compile (autoload 'pgg-gpg-decrypt-region "pgg-gpg") (autoload 'pgg-gpg-encrypt-region "pgg-gpg")) (defgroup gnus-encrypt nil "Gnus encryption configuration.") (defcustom gnus-encrypt-file-alist nil "List of file names or regexes matched with encryptions. Format example: '((\"/home/tzz/alpha\" gpg \"AES\") ; GPG on single file ;; xor encryption on all files matching \"beta\" (\"beta\" 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) (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 --=-=-=--