annotate lisp/pgg-gpg.el @ 67080:d2a044f068e4

*** empty log message ***
author Lars Hansen <larsh@soem.dk>
date Tue, 22 Nov 2005 19:25:50 +0000
parents 67afcf271a8f
children 3bd95f4f2941
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1 ;;; pgg-gpg.el --- GnuPG support for PGG.
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
4 ;; 2005 Free Software Foundation, Inc.
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
5
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
6 ;; Author: Daiki Ueno <ueno@unixuser.org>
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
7 ;; Symmetric encryption added by: Sascha Wilde <wilde@sha-bang.de>
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
8 ;; Created: 1999/10/28
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
9 ;; Keywords: PGP, OpenPGP, GnuPG
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
10
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
12
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
16 ;; any later version.
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
17
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
22
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
26 ;; Boston, MA 02110-1301, USA.
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
27
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
28 ;;; Code:
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
29
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
30 (eval-when-compile
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
31 (require 'cl) ; for gpg macros
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
32 (require 'pgg))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
33
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
34 (defgroup pgg-gpg ()
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
35 "GnuPG interface."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
36 :group 'pgg)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
37
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
38 (defcustom pgg-gpg-program "gpg"
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
39 "The GnuPG executable."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
40 :group 'pgg-gpg
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
41 :type 'string)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
42
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
43 (defcustom pgg-gpg-extra-args nil
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
44 "Extra arguments for every GnuPG invocation."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
45 :group 'pgg-gpg
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
46 :type '(repeat (string :tag "Argument")))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
47
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
48 (defcustom pgg-gpg-recipient-argument "--recipient"
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
49 "GnuPG option to specify recipient."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
50 :group 'pgg-gpg
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
51 :type '(choice (const :tag "New `--recipient' option" "--recipient")
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
52 (const :tag "Old `--remote-user' option" "--remote-user")))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
53
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
54 (defvar pgg-gpg-user-id nil
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
55 "GnuPG ID of your default identity.")
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
56
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
57 (defun pgg-gpg-process-region (start end passphrase program args)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
58 (let* ((output-file-name (pgg-make-temp-file "pgg-output"))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
59 (args
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
60 `("--status-fd" "2"
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
61 ,@(if passphrase '("--passphrase-fd" "0"))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
62 "--yes" ; overwrite
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
63 "--output" ,output-file-name
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
64 ,@pgg-gpg-extra-args ,@args))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
65 (output-buffer pgg-output-buffer)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
66 (errors-buffer pgg-errors-buffer)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
67 (orig-mode (default-file-modes))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
68 (process-connection-type nil)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
69 exit-status)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
70 (with-current-buffer (get-buffer-create errors-buffer)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
71 (buffer-disable-undo)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
72 (erase-buffer))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
73 (unwind-protect
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
74 (progn
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
75 (set-default-file-modes 448)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
76 (let ((coding-system-for-write 'binary)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
77 (input (buffer-substring-no-properties start end))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
78 (default-enable-multibyte-characters nil))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
79 (with-temp-buffer
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
80 (when passphrase
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
81 (insert passphrase "\n"))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
82 (insert input)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
83 (setq exit-status
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
84 (apply #'call-process-region (point-min) (point-max) program
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
85 nil errors-buffer nil args))))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
86 (with-current-buffer (get-buffer-create output-buffer)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
87 (buffer-disable-undo)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
88 (erase-buffer)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
89 (if (file-exists-p output-file-name)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
90 (let ((coding-system-for-read 'raw-text-dos))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
91 (insert-file-contents output-file-name)))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
92 (set-buffer errors-buffer)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
93 (if (not (equal exit-status 0))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
94 (insert (format "\n%s exited abnormally: '%s'\n"
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
95 program exit-status)))))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
96 (if (file-exists-p output-file-name)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
97 (delete-file output-file-name))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
98 (set-default-file-modes orig-mode))))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
99
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
100 (defun pgg-gpg-possibly-cache-passphrase (passphrase &optional key notruncate)
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
101 (if (and pgg-cache-passphrase
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
102 (progn
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
103 (goto-char (point-min))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
104 (re-search-forward "^\\[GNUPG:] \\(GOOD_PASSPHRASE\\>\\)\\|\\(SIG_CREATED\\)" nil t)))
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
105 (pgg-add-passphrase-to-cache
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
106 (or key
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
107 (progn
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
108 (goto-char (point-min))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
109 (if (re-search-forward
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
110 "^\\[GNUPG:] NEED_PASSPHRASE\\(_PIN\\)? \\w+ ?\\w*" nil t)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
111 (substring (match-string 0) -8))))
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
112 passphrase
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
113 notruncate)))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
114
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
115 (defvar pgg-gpg-all-secret-keys 'unknown)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
116
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
117 (defun pgg-gpg-lookup-all-secret-keys ()
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
118 "Return all secret keys present in secret key ring."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
119 (when (eq pgg-gpg-all-secret-keys 'unknown)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
120 (setq pgg-gpg-all-secret-keys '())
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
121 (let ((args (list "--with-colons" "--no-greeting" "--batch"
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
122 "--list-secret-keys")))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
123 (with-temp-buffer
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
124 (apply #'call-process pgg-gpg-program nil t nil args)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
125 (goto-char (point-min))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
126 (while (re-search-forward
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
127 "^\\(sec\\|pub\\):[^:]*:[^:]*:[^:]*:\\([^:]*\\)" nil t)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
128 (push (substring (match-string 2) 8)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
129 pgg-gpg-all-secret-keys)))))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
130 pgg-gpg-all-secret-keys)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
131
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
132 (defun pgg-gpg-lookup-key (string &optional type)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
133 "Search keys associated with STRING."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
134 (let ((args (list "--with-colons" "--no-greeting" "--batch"
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
135 (if type "--list-secret-keys" "--list-keys")
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
136 string)))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
137 (with-temp-buffer
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
138 (apply #'call-process pgg-gpg-program nil t nil args)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
139 (goto-char (point-min))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
140 (if (re-search-forward "^\\(sec\\|pub\\):[^:]*:[^:]*:[^:]*:\\([^:]*\\)"
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
141 nil t)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
142 (substring (match-string 2) 8)))))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
143
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
144 (defun pgg-gpg-lookup-key-owner (string &optional all)
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
145 "Search keys associated with STRING and return owner of identified key.
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
146
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
147 The value may be just the bare key id, or it may be a combination of the
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
148 user name associated with the key and the key id, with the key id enclosed
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
149 in \"<...>\" angle brackets.
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
150
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
151 Optional ALL non-nil means search all keys, including secret keys."
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
152 (let ((args (list "--with-colons" "--no-greeting" "--batch"
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
153 (if all "--list-secret-keys" "--list-keys")
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
154 string))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
155 (key-regexp (concat "^\\(sec\\|pub\\)"
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
156 ":[^:]*:[^:]*:[^:]*:\\([^:]*\\):[^:]*"
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
157 ":[^:]*:[^:]*:[^:]*:\\([^:]*\\):"))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
158 )
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
159 (with-temp-buffer
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
160 (apply #'call-process pgg-gpg-program nil t nil args)
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
161 (goto-char (point-min))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
162 (if (re-search-forward key-regexp
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
163 nil t)
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
164 (match-string 3)))))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
165
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
166 (defun pgg-gpg-key-id-from-key-owner (key-owner)
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
167 (cond ((not key-owner) nil)
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
168 ;; Extract bare key id from outermost paired angle brackets, if any:
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
169 ((string-match "[^<]*<\\(.+\\)>[^>]*" key-owner)
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
170 (substring key-owner (match-beginning 1)(match-end 1)))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
171 (key-owner))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
172 )
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
173
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
174 (defun pgg-gpg-encrypt-region (start end recipients &optional sign passphrase)
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
175 "Encrypt the current region between START and END.
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
176
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
177 If optional argument SIGN is non-nil, do a combined sign and encrypt.
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
178
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
179 If optional PASSPHRASE is not specified, it will be obtained from the
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
180 passphrase cache or user."
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
181 (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
182 (passphrase (or passphrase
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
183 (when sign
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
184 (pgg-read-passphrase
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
185 (format "GnuPG passphrase for %s: "
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
186 pgg-gpg-user-id)
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
187 pgg-gpg-user-id))))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
188 (args
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
189 (append
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
190 (list "--batch" "--textmode" "--armor" "--always-trust" "--encrypt")
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
191 (if sign (list "--sign" "--local-user" pgg-gpg-user-id))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
192 (if recipients
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
193 (apply #'nconc
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
194 (mapcar (lambda (rcpt)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
195 (list pgg-gpg-recipient-argument rcpt))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
196 (append recipients
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
197 (if pgg-encrypt-for-me
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
198 (list pgg-gpg-user-id)))))))))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
199 (pgg-as-lbt start end 'CRLF
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
200 (pgg-gpg-process-region start end passphrase pgg-gpg-program args))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
201 (when sign
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
202 (with-current-buffer pgg-errors-buffer
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
203 ;; Possibly cache passphrase under, e.g. "jas", for future sign.
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
204 (pgg-gpg-possibly-cache-passphrase passphrase pgg-gpg-user-id)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
205 ;; Possibly cache passphrase under, e.g. B565716F, for future decrypt.
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
206 (pgg-gpg-possibly-cache-passphrase passphrase)))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
207 (pgg-process-when-success)))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
208
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
209 (defun pgg-gpg-encrypt-symmetric-region (start end &optional passphrase)
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
210 "Encrypt the current region between START and END with symmetric cipher.
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
211
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
212 If optional PASSPHRASE is not specified, it will be obtained from the
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
213 passphrase cache or user."
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
214 (let* ((passphrase (or passphrase
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
215 (pgg-read-passphrase
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
216 "GnuPG passphrase for symmetric encryption: ")))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
217 (args
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
218 (append (list "--batch" "--textmode" "--armor" "--symmetric" ))))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
219 (pgg-as-lbt start end 'CRLF
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
220 (pgg-gpg-process-region start end passphrase pgg-gpg-program args))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
221 (pgg-process-when-success)))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
222
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
223 (defun pgg-gpg-decrypt-region (start end &optional passphrase)
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
224 "Decrypt the current region between START and END.
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
225
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
226 If optional PASSPHRASE is not specified, it will be obtained from the
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
227 passphrase cache or user."
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
228 (let* ((current-buffer (current-buffer))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
229 (message-keys (with-temp-buffer
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
230 (insert-buffer-substring current-buffer)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
231 (pgg-decode-armor-region (point-min) (point-max))))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
232 (secret-keys (pgg-gpg-lookup-all-secret-keys))
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
233 ;; XXX the user is stuck if they need to use the passphrase for
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
234 ;; any but the first secret key for which the message is
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
235 ;; encrypted. ideally, we would incrementally give them a
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
236 ;; chance with subsequent keys each time they fail with one.
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
237 (key (pgg-gpg-select-matching-key message-keys secret-keys))
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
238 (key-owner (and key (pgg-gpg-lookup-key-owner key t)))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
239 (key-id (pgg-gpg-key-id-from-key-owner key-owner))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
240 (pgg-gpg-user-id (or key-id key
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
241 pgg-gpg-user-id pgg-default-user-id))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
242 (passphrase (or passphrase
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
243 (pgg-read-passphrase
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
244 (format (if (pgg-gpg-symmetric-key-p message-keys)
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
245 "Passphrase for symmetric decryption: "
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
246 "GnuPG passphrase for %s: ")
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
247 (or key-owner "??"))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
248 pgg-gpg-user-id)))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
249 (args '("--batch" "--decrypt")))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
250 (pgg-gpg-process-region start end passphrase pgg-gpg-program args)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
251 (with-current-buffer pgg-errors-buffer
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
252 (pgg-gpg-possibly-cache-passphrase passphrase pgg-gpg-user-id)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
253 (goto-char (point-min))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
254 (re-search-forward "^\\[GNUPG:] DECRYPTION_OKAY\\>" nil t))))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
255
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
256 ;;;###autoload
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
257 (defun pgg-gpg-symmetric-key-p (message-keys)
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
258 "True if decoded armor MESSAGE-KEYS has symmetric encryption indicator."
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
259 (let (result)
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
260 (dolist (key message-keys result)
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
261 (when (and (eq (car key) 3)
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
262 (member '(symmetric-key-algorithm) key))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
263 (setq result key)))))
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
264
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
265 (defun pgg-gpg-select-matching-key (message-keys secret-keys)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
266 "Choose a key from MESSAGE-KEYS that matches one of the keys in SECRET-KEYS."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
267 (loop for message-key in message-keys
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
268 for message-key-id = (and (equal (car message-key) 1)
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
269 (cdr (assq 'key-identifier
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
270 (cdr message-key))))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
271 for key = (and message-key-id (pgg-lookup-key message-key-id 'encrypt))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
272 when (and key (member key secret-keys)) return key))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
273
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
274 (defun pgg-gpg-sign-region (start end &optional cleartext passphrase)
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
275 "Make detached signature from text between START and END."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
276 (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
277 (passphrase (or passphrase
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
278 (pgg-read-passphrase
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
279 (format "GnuPG passphrase for %s: " pgg-gpg-user-id)
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
280 pgg-gpg-user-id)))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
281 (args
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
282 (list (if cleartext "--clearsign" "--detach-sign")
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
283 "--armor" "--batch" "--verbose"
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
284 "--local-user" pgg-gpg-user-id))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
285 (inhibit-read-only t)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
286 buffer-read-only)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
287 (pgg-as-lbt start end 'CRLF
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
288 (pgg-gpg-process-region start end passphrase pgg-gpg-program args))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
289 (with-current-buffer pgg-errors-buffer
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
290 ;; Possibly cache passphrase under, e.g. "jas", for future sign.
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
291 (pgg-gpg-possibly-cache-passphrase passphrase pgg-gpg-user-id)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
292 ;; Possibly cache passphrase under, e.g. B565716F, for future decrypt.
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
293 (pgg-gpg-possibly-cache-passphrase passphrase))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
294 (pgg-process-when-success)))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
295
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
296 (defun pgg-gpg-verify-region (start end &optional signature)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
297 "Verify region between START and END as the detached signature SIGNATURE."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
298 (let ((args '("--batch" "--verify")))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
299 (when (stringp signature)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
300 (setq args (append args (list signature))))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
301 (setq args (append args '("-")))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
302 (pgg-gpg-process-region start end nil pgg-gpg-program args)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
303 (with-current-buffer pgg-errors-buffer
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
304 (goto-char (point-min))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
305 (while (re-search-forward "^gpg: \\(.*\\)\n" nil t)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
306 (with-current-buffer pgg-output-buffer
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
307 (insert-buffer-substring pgg-errors-buffer
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
308 (match-beginning 1) (match-end 0)))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
309 (delete-region (match-beginning 0) (match-end 0)))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
310 (goto-char (point-min))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
311 (re-search-forward "^\\[GNUPG:] GOODSIG\\>" nil t))))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
312
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
313 (defun pgg-gpg-insert-key ()
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
314 "Insert public key at point."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
315 (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
316 (args (list "--batch" "--export" "--armor"
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
317 pgg-gpg-user-id)))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
318 (pgg-gpg-process-region (point)(point) nil pgg-gpg-program args)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
319 (insert-buffer-substring pgg-output-buffer)))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
320
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
321 (defun pgg-gpg-snarf-keys-region (start end)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
322 "Add all public keys in region between START and END to the keyring."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
323 (let ((args '("--import" "--batch" "-")) status)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
324 (pgg-gpg-process-region start end nil pgg-gpg-program args)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
325 (set-buffer pgg-errors-buffer)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
326 (goto-char (point-min))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
327 (when (re-search-forward "^\\[GNUPG:] IMPORT_RES\\>" nil t)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
328 (setq status (buffer-substring (match-end 0)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
329 (progn (end-of-line)(point)))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
330 status (vconcat (mapcar #'string-to-number (split-string status))))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
331 (erase-buffer)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
332 (insert (format "Imported %d key(s).
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
333 \tArmor contains %d key(s) [%d bad, %d old].\n"
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
334 (+ (aref status 2)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
335 (aref status 10))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
336 (aref status 0)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
337 (aref status 1)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
338 (+ (aref status 4)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
339 (aref status 11)))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
340 (if (zerop (aref status 9))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
341 ""
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
342 "\tSecret keys are imported.\n")))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
343 (append-to-buffer pgg-output-buffer (point-min)(point-max))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
344 (pgg-process-when-success)))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
345
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
346 (provide 'pgg-gpg)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
347
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
348 ;;; arch-tag: 2aa5d5d8-93a0-4865-9312-33e29830e000
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
349 ;;; pgg-gpg.el ends here