aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2007-12-02 18:58:23 +0000
committerGlenn Morris2007-12-02 18:58:23 +0000
commitceabaeb3be461197bfc1c479f19c2163e78fa984 (patch)
tree858bb88ac2716339d2a91e83c2e3a5323e694f7c
parentcb11d61498063c1bc42bf76e8dd78de18feeca40 (diff)
downloademacs-ceabaeb3be461197bfc1c479f19c2163e78fa984.tar.gz
emacs-ceabaeb3be461197bfc1c479f19c2163e78fa984.zip
Remove file.
-rw-r--r--lisp/gnus/ChangeLog2
-rw-r--r--lisp/gnus/encrypt.el295
2 files changed, 2 insertions, 295 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog
index c923594d570..a0f69e99e44 100644
--- a/lisp/gnus/ChangeLog
+++ b/lisp/gnus/ChangeLog
@@ -2,6 +2,8 @@
2 2
3 * binhex.el, uudecode.el: Move to ../mail. 3 * binhex.el, uudecode.el: Move to ../mail.
4 4
5 * encrypt.el: Remove file.
6
52007-12-01 Glenn Morris <rgm@gnu.org> 72007-12-01 Glenn Morris <rgm@gnu.org>
6 8
7 * dig.el, dns.el: Move to ../net. 9 * dig.el, dns.el: Move to ../net.
diff --git a/lisp/gnus/encrypt.el b/lisp/gnus/encrypt.el
deleted file mode 100644
index 5f65417e5fc..00000000000
--- a/lisp/gnus/encrypt.el
+++ /dev/null
@@ -1,295 +0,0 @@
1;;; encrypt.el --- file encryption routines
2
3;; Copyright (C) 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
4
5;; Author: Teodor Zlatanov <tzz@lifelogs.com>
6;; Created: 2003/01/24
7;; Keywords: files
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation; either version 3, or (at your option)
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to the
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
25
26;;; Commentary:
27
28;;; This module addresses data encryption. Page breaks are used for
29;;; grouping declarations and documentation relating to each
30;;; particular aspect.
31
32;;; Use in Gnus like this:
33;;; (setq
34;;; nnimap-authinfo-file "~/.authinfo.enc"
35;;; nntp-authinfo-file "~/.authinfo.enc"
36;;; smtpmail-auth-credentials "~/.authinfo.enc"
37;;; ;; using the AES256 cipher, feel free to use your own favorite
38;;; encrypt-file-alist (quote (("~/.authinfo.enc" (gpg "AES256"))))
39;;; password-cache-expiry 600)
40
41;;; Then write ~/.authinfo.enc:
42
43;;; 1) open the old authinfo
44;;; C-x C-f ~/.authinfo
45
46;;; 2) write the new authinfo.enc
47;;; M-x encrypt-write-file-contents RET ~/.authinfo.enc
48
49;;; 3) verify the new authinfo is correct (this will show the contents in the minibuffer)
50;;; M-: (encrypt-get-file-contents "~/.authinfo.enc")
51
52
53;;; Code:
54
55(require 'password)
56
57(defgroup encrypt '((password-cache custom-variable)
58 (password-cache-expiry custom-variable))
59 "File encryption configuration."
60 :group 'applications)
61
62(defcustom encrypt-file-alist nil
63 "List of file names or regexes matched with encryptions.
64Format example:
65 '((\"beta\"
66 (gpg \"AES\"))
67 (\"/home/tzz/alpha\"
68 (encrypt-xor \"Semi-Secret\")))"
69
70 :type '(repeat
71 (list :tag "Encryption entry"
72 (radio :tag "What to encrypt"
73 (file :tag "Filename")
74 (regexp :tag "Regular expression match"))
75 (radio :tag "How to encrypt it"
76 (list
77 :tag "GPG Encryption"
78 (const :tag "GPG Program" gpg)
79 (radio :tag "Choose a cipher"
80 (const :tag "3DES Encryption" "3DES")
81 (const :tag "CAST5 Encryption" "CAST5")
82 (const :tag "Blowfish Encryption" "BLOWFISH")
83 (const :tag "AES Encryption" "AES")
84 (const :tag "AES192 Encryption" "AES192")
85 (const :tag "AES256 Encryption" "AES256")
86 (const :tag "Twofish Encryption" "TWOFISH")
87 (string :tag "Cipher Name")))
88 (list
89 :tag "Built-in simple XOR"
90 (const :tag "XOR Encryption" encrypt-xor)
91 (string :tag "XOR Cipher Value (seed value)")))))
92 :group 'encrypt)
93
94;; TODO: now, load gencrypt.el and if successful, modify the
95;; custom-type of encrypt-file-alist to add the gencrypt.el options
96
97;; (plist-get (symbol-plist 'encrypt-file-alist) 'custom-type)
98;; then use plist-put
99
100(defcustom encrypt-gpg-path (executable-find "gpg")
101 "Path to the GPG program."
102 :type '(radio
103 (file :tag "Location of the GPG executable")
104 (const :tag "GPG is not installed" nil))
105 :group 'encrypt)
106
107(defvar encrypt-temp-prefix "encrypt"
108 "Prefix for temporary filenames")
109
110;;;###autoload
111(defun encrypt-find-model (filename)
112 "Given a filename, find a encrypt-file-alist entry"
113 (dolist (entry encrypt-file-alist)
114 (let ((match (nth 0 entry))
115 (model (nth 1 entry)))
116 (when (or (eq match filename)
117 (string-match match filename))
118 (return model)))))
119
120;;;###autoload
121(defun encrypt-insert-file-contents (file &optional model)
122 "Decrypt FILE into the current buffer."
123 (interactive "fFile to insert: ")
124 (let* ((model (or model (encrypt-find-model file)))
125 (method (nth 0 model))
126 (cipher (nth 1 model))
127 (password-key (format "encrypt-password-%s-%s %s"
128 (symbol-name method) cipher file))
129 (passphrase
130 (password-read-and-add
131 (format "%s password for cipher %s (file %s)? "
132 file (symbol-name method) cipher)
133 password-key))
134 (buffer-file-coding-system 'binary)
135 (coding-system-for-read 'binary)
136 outdata)
137
138 ;; note we only insert-file-contents if the method is known to be valid
139 (cond
140 ((eq method 'gpg)
141 (insert-file-contents file)
142 (setq outdata (encrypt-gpg-decode-buffer passphrase cipher)))
143 ((eq method 'encrypt-xor)
144 (insert-file-contents file)
145 (setq outdata (encrypt-xor-decode-buffer passphrase cipher))))
146
147 (if outdata
148 (progn
149 (message "%s was decrypted with %s (cipher %s)"
150 file (symbol-name method) cipher)
151 (delete-region (point-min) (point-max))
152 (goto-char (point-min))
153 (insert outdata))
154 ;; the decryption failed, alas
155 (password-cache-remove password-key)
156 (gnus-error 5 "%s was NOT decrypted with %s (cipher %s)"
157 file (symbol-name method) cipher))))
158
159(defun encrypt-get-file-contents (file &optional model)
160 "Decrypt FILE and return the contents."
161 (interactive "fFile to decrypt: ")
162 (with-temp-buffer
163 (encrypt-insert-file-contents file model)
164 (buffer-string)))
165
166(defun encrypt-put-file-contents (file data &optional model)
167 "Encrypt the DATA to FILE, then continue normally."
168 (with-temp-buffer
169 (insert data)
170 (encrypt-write-file-contents file model)))
171
172(defun encrypt-write-file-contents (file &optional model)
173 "Encrypt the current buffer to FILE, then continue normally."
174 (interactive "sFile to write: ")
175 (setq model (or model (encrypt-find-model file)))
176 (if model
177 (let* ((method (nth 0 model))
178 (cipher (nth 1 model))
179 (password-key (format "encrypt-password-%s-%s %s"
180 (symbol-name method) cipher file))
181 (passphrase
182 (password-read
183 (format "%s password for cipher %s? "
184 (symbol-name method) cipher)
185 password-key))
186 outdata)
187
188 (cond
189 ((eq method 'gpg)
190 (setq outdata (encrypt-gpg-encode-buffer passphrase cipher)))
191 ((eq method 'encrypt-xor)
192 (setq outdata (encrypt-xor-encode-buffer passphrase cipher))))
193
194 (if outdata
195 (progn
196 (message "%s was encrypted with %s (cipher %s)"
197 file (symbol-name method) cipher)
198 (delete-region (point-min) (point-max))
199 (goto-char (point-min))
200 (insert outdata)
201 ;; do not confirm overwrites
202 (write-file file nil))
203 ;; the decryption failed, alas
204 (password-cache-remove password-key)
205 (gnus-error 5 "%s was NOT encrypted with %s (cipher %s)"
206 file (symbol-name method) cipher)))
207 (gnus-error 1 "%s has no associated encryption model! See encrypt-file-alist." file)))
208
209(defun encrypt-xor-encode-buffer (passphrase cipher)
210 (encrypt-xor-process-buffer passphrase cipher t))
211
212(defun encrypt-xor-decode-buffer (passphrase cipher)
213 (encrypt-xor-process-buffer passphrase cipher nil))
214
215(defun encrypt-xor-process-buffer (passphrase
216 cipher
217 &optional encode)
218 "Given PASSPHRASE, xor-encode or decode the contents of the current buffer."
219 (let* ((bs (buffer-substring-no-properties (point-min) (point-max)))
220 ;; passphrase-sum is a simple additive checksum of the
221 ;; passphrase and the cipher
222 (passphrase-sum
223 (when (stringp passphrase)
224 (apply '+ (append cipher passphrase nil))))
225 new-list)
226
227 (with-temp-buffer
228 (if encode
229 (progn
230 (dolist (x (append bs nil))
231 (setq new-list (cons (logxor x passphrase-sum) new-list)))
232
233 (dolist (x new-list)
234 (insert (format "%d " x))))
235 (progn
236 (setq new-list (reverse (split-string bs)))
237 (dolist (x new-list)
238 (setq x (string-to-number x))
239 (insert (format "%c" (logxor x passphrase-sum))))))
240 (buffer-substring-no-properties (point-min) (point-max)))))
241
242(defun encrypt-gpg-encode-buffer (passphrase cipher)
243 (encrypt-gpg-process-buffer passphrase cipher t))
244
245(defun encrypt-gpg-decode-buffer (passphrase cipher)
246 (encrypt-gpg-process-buffer passphrase cipher nil))
247
248(defun encrypt-gpg-process-buffer (passphrase
249 cipher
250 &optional encode)
251 "With PASSPHRASE, use GPG to encode or decode the current buffer."
252 (let* ((program encrypt-gpg-path)
253 (input (buffer-substring-no-properties (point-min) (point-max)))
254 (temp-maker (if (fboundp 'make-temp-file)
255 'make-temp-file
256 'make-temp-name))
257 (temp-file (funcall temp-maker encrypt-temp-prefix))
258 (default-enable-multibyte-characters nil)
259 (args `("--cipher-algo" ,cipher
260 "--status-fd" "2"
261 "--logger-fd" "2"
262 "--passphrase-fd" "0"
263 "--no-tty"))
264 exit-status exit-data)
265
266 (when encode
267 (setq args
268 (append args
269 '("--symmetric"
270 "--armor"))))
271
272 (if program
273 (with-temp-buffer
274 (when passphrase
275 (insert passphrase "\n"))
276 (insert input)
277 (setq exit-status
278 (apply #'call-process-region (point-min) (point-max) program
279 t `(t ,temp-file) nil args))
280 (if (equal exit-status 0)
281 (setq exit-data
282 (buffer-substring-no-properties (point-min) (point-max)))
283 (with-temp-buffer
284 (when (file-exists-p temp-file)
285 (insert-file-contents temp-file))
286 (gnus-error 5 (format "%s exited abnormally: '%s' [%s]"
287 program exit-status (buffer-string)))))
288 (delete-file temp-file))
289 (gnus-error 5 "GPG is not installed."))
290 exit-data))
291
292(provide 'encrypt)
293;;; encrypt.el ends here
294
295;; arch-tag: d907e4f1-71b5-42b1-a180-fc7b84ff0648