annotate lisp/pgg-gpg.el @ 69820:a26627fd2df2

Update copyright, change version.
author J.D. Smith <jdsmith@as.arizona.edu>
date Thu, 06 Apr 2006 18:42:40 +0000
parents f5b96aac4371
children a80d40a59be6
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,
68651
3bd95f4f2941 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 66520
diff changeset
4 ;; 2005, 2006 Free Software Foundation, Inc.
66383
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>
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
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
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
31 (require 'cl) ; for gpg macros
66383
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
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
57 (defun pgg-gpg-process-region (start end passphrase program args)
69689
d9ccf8ac6466 2006-03-27 Daiki Ueno <ueno@unixuser.org>
Simon Josefsson <jas@extundo.com>
parents: 69646
diff changeset
58 (let* ((output-file-name (pgg-make-temp-file "pgg-output"))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
59 (args
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
60 `("--status-fd" "2"
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
61 ,@(if passphrase '("--passphrase-fd" "0"))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
62 "--yes" ; overwrite
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
63 "--output" ,output-file-name
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
64 ,@pgg-gpg-extra-args ,@args))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
65 (output-buffer pgg-output-buffer)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
66 (errors-buffer pgg-errors-buffer)
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
67 (orig-mode (default-file-modes))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
68 (process-connection-type nil)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
69 exit-status)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
70 (with-current-buffer (get-buffer-create errors-buffer)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
71 (buffer-disable-undo)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
72 (erase-buffer))
66383
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)
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
76 (let ((coding-system-for-write 'binary)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
77 (input (buffer-substring-no-properties start end))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
78 (default-enable-multibyte-characters nil))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
79 (with-temp-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
80 (when passphrase
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
81 (insert passphrase "\n"))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
82 (insert input)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
83 (setq exit-status
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
84 (apply #'call-process-region (point-min) (point-max) program
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
85 nil errors-buffer nil args))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
86 (with-current-buffer (get-buffer-create output-buffer)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
87 (buffer-disable-undo)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
88 (erase-buffer)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
89 (if (file-exists-p output-file-name)
69791
4192bb0fddd0 2006-04-04 Daiki Ueno <ueno@unixuser.org>
Simon Josefsson <jas@extundo.com>
parents: 69775
diff changeset
90 (let ((coding-system-for-read (if pgg-text-mode
4192bb0fddd0 2006-04-04 Daiki Ueno <ueno@unixuser.org>
Simon Josefsson <jas@extundo.com>
parents: 69775
diff changeset
91 'raw-text
4192bb0fddd0 2006-04-04 Daiki Ueno <ueno@unixuser.org>
Simon Josefsson <jas@extundo.com>
parents: 69775
diff changeset
92 'binary)))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
93 (insert-file-contents output-file-name)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
94 (set-buffer errors-buffer)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
95 (if (not (equal exit-status 0))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
96 (insert (format "\n%s exited abnormally: '%s'\n"
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
97 program exit-status)))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
98 (if (file-exists-p output-file-name)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
99 (delete-file output-file-name))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
100 (set-default-file-modes orig-mode))))
69689
d9ccf8ac6466 2006-03-27 Daiki Ueno <ueno@unixuser.org>
Simon Josefsson <jas@extundo.com>
parents: 69646
diff changeset
101
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
102 (defun pgg-gpg-possibly-cache-passphrase (passphrase &optional key notruncate)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
103 (if (and pgg-cache-passphrase
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
104 (progn
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
105 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
106 (re-search-forward "^\\[GNUPG:] \\(GOOD_PASSPHRASE\\>\\)\\|\\(SIG_CREATED\\)" nil t)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
107 (pgg-add-passphrase-to-cache
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
108 (or key
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
109 (progn
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
110 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
111 (if (re-search-forward
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
112 "^\\[GNUPG:] NEED_PASSPHRASE\\(_PIN\\)? \\w+ ?\\w*" nil t)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
113 (substring (match-string 0) -8))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
114 passphrase
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
115 notruncate)))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
116
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
117 (defvar pgg-gpg-all-secret-keys 'unknown)
69689
d9ccf8ac6466 2006-03-27 Daiki Ueno <ueno@unixuser.org>
Simon Josefsson <jas@extundo.com>
parents: 69646
diff changeset
118
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
119 (defun pgg-gpg-lookup-all-secret-keys ()
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
120 "Return all secret keys present in secret key ring."
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
121 (when (eq pgg-gpg-all-secret-keys 'unknown)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
122 (setq pgg-gpg-all-secret-keys '())
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
123 (let ((args (list "--with-colons" "--no-greeting" "--batch"
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
124 "--list-secret-keys")))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
125 (with-temp-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
126 (apply #'call-process pgg-gpg-program nil t nil args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
127 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
128 (while (re-search-forward
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
129 "^\\(sec\\|pub\\):[^:]*:[^:]*:[^:]*:\\([^:]*\\)" nil t)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
130 (push (substring (match-string 2) 8)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
131 pgg-gpg-all-secret-keys)))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
132 pgg-gpg-all-secret-keys)
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
133
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
134 (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
135 "Search keys associated with STRING."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
136 (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
137 (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
138 string)))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
139 (with-temp-buffer
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
140 (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
141 (goto-char (point-min))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
142 (if (re-search-forward "^\\(sec\\|pub\\):[^:]*:[^:]*:[^:]*:\\([^:]*\\)"
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
143 nil t)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
144 (substring (match-string 2) 8)))))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
145
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
146 (defun pgg-gpg-lookup-key-owner (string &optional all)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
147 "Search keys associated with STRING and return owner of identified key.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
148
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
149 The value may be just the bare key id, or it may be a combination of the
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
150 user name associated with the key and the key id, with the key id enclosed
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
151 in \"<...>\" angle brackets.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
152
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
153 Optional ALL non-nil means search all keys, including secret keys."
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
154 (let ((args (list "--with-colons" "--no-greeting" "--batch"
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
155 (if all "--list-secret-keys" "--list-keys")
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
156 string))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
157 (key-regexp (concat "^\\(sec\\|pub\\)"
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
158 ":[^:]*:[^:]*:[^:]*:\\([^:]*\\):[^:]*"
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
159 ":[^:]*:[^:]*:[^:]*:\\([^:]*\\):")))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
160 (with-temp-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
161 (apply #'call-process pgg-gpg-program nil t nil args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
162 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
163 (if (re-search-forward key-regexp
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
164 nil t)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
165 (match-string 3)))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
166
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
167 (defun pgg-gpg-key-id-from-key-owner (key-owner)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
168 (cond ((not key-owner) nil)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
169 ;; Extract bare key id from outermost paired angle brackets, if any:
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
170 ((string-match "[^<]*<\\(.+\\)>[^>]*" key-owner)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
171 (substring key-owner (match-beginning 1)(match-end 1)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
172 (key-owner)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
173
66520
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
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
177 If optional argument SIGN is non-nil, do a combined sign and encrypt.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
178
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
179 If optional PASSPHRASE is not specified, it will be obtained from the
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
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))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
182 (passphrase (or passphrase
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
183 (when sign
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
184 (pgg-read-passphrase
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
185 (format "GnuPG passphrase for %s: "
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
186 pgg-gpg-user-id)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
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
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
190 (list "--batch" "--armor" "--always-trust" "--encrypt")
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
191 (if pgg-text-mode (list "--textmode"))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
192 (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
193 (if recipients
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
194 (apply #'nconc
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
195 (mapcar (lambda (rcpt)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
196 (list pgg-gpg-recipient-argument rcpt))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
197 (append recipients
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
198 (if pgg-encrypt-for-me
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
199 (list pgg-gpg-user-id)))))))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
200 (pgg-gpg-process-region start end passphrase pgg-gpg-program args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
201 (when sign
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
202 (with-current-buffer pgg-errors-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
203 ;; Possibly cache passphrase under, e.g. "jas", for future sign.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
204 (pgg-gpg-possibly-cache-passphrase passphrase pgg-gpg-user-id)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
205 ;; Possibly cache passphrase under, e.g. B565716F, for future decrypt.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
206 (pgg-gpg-possibly-cache-passphrase passphrase)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
207 (pgg-process-when-success)))
66383
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)
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
210 "Encrypt the current region between START and END with symmetric cipher.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
211
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
212 If optional PASSPHRASE is not specified, it will be obtained from the
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
213 passphrase cache or user."
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
214 (let* ((passphrase (or passphrase
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
215 (pgg-read-passphrase
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
216 "GnuPG passphrase for symmetric encryption: ")))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
217 (args
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
218 (append (list "--batch" "--armor" "--symmetric" )
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
219 (if pgg-text-mode (list "--textmode")))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
220 (pgg-gpg-process-region start end passphrase pgg-gpg-program args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
221 (pgg-process-when-success)))
66520
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)
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
224 "Decrypt the current region between START and END.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
225
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
226 If optional PASSPHRASE is not specified, it will be obtained from the
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
227 passphrase cache or user."
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
228 (let* ((current-buffer (current-buffer))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
229 (message-keys (with-temp-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
230 (insert-buffer-substring current-buffer)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
231 (pgg-decode-armor-region (point-min) (point-max))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
232 (secret-keys (pgg-gpg-lookup-all-secret-keys))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
233 ;; XXX the user is stuck if they need to use the passphrase for
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
234 ;; any but the first secret key for which the message is
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
235 ;; encrypted. ideally, we would incrementally give them a
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
236 ;; chance with subsequent keys each time they fail with one.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
237 (key (pgg-gpg-select-matching-key message-keys secret-keys))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
238 (key-owner (and key (pgg-gpg-lookup-key-owner key t)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
239 (key-id (pgg-gpg-key-id-from-key-owner key-owner))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
240 (pgg-gpg-user-id (or key-id key
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
241 pgg-gpg-user-id pgg-default-user-id))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
242 (passphrase (or passphrase
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
243 (pgg-read-passphrase
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
244 (format (if (pgg-gpg-symmetric-key-p message-keys)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
245 "Passphrase for symmetric decryption: "
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
246 "GnuPG passphrase for %s: ")
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
247 (or key-owner "??"))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
248 pgg-gpg-user-id)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
249 (args '("--batch" "--decrypt")))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
250 (pgg-gpg-process-region start end passphrase pgg-gpg-program args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
251 (with-current-buffer pgg-errors-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
252 (pgg-gpg-possibly-cache-passphrase passphrase pgg-gpg-user-id)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
253 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
254 (re-search-forward "^\\[GNUPG:] DECRYPTION_OKAY\\>" nil t))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
255
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
256 ;;;###autoload
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
257 (defun pgg-gpg-symmetric-key-p (message-keys)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
258 "True if decoded armor MESSAGE-KEYS has symmetric encryption indicator."
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
259 (let (result)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
260 (dolist (key message-keys result)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
261 (when (and (eq (car key) 3)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
262 (member '(symmetric-key-algorithm) key))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
263 (setq result key)))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
264
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
265 (defun pgg-gpg-select-matching-key (message-keys secret-keys)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
266 "Choose a key from MESSAGE-KEYS that matches one of the keys in SECRET-KEYS."
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
267 (loop for message-key in message-keys
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
268 for message-key-id = (and (equal (car message-key) 1)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
269 (cdr (assq 'key-identifier
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
270 (cdr message-key))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
271 for key = (and message-key-id (pgg-lookup-key message-key-id 'encrypt))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
272 when (and key (member key secret-keys)) return key))
66383
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))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
277 (passphrase (or passphrase
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
278 (pgg-read-passphrase
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
279 (format "GnuPG passphrase for %s: " pgg-gpg-user-id)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
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
68762
970bf6e6463b Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents: 68651
diff changeset
282 (append (list (if cleartext "--clearsign" "--detach-sign")
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
283 "--armor" "--batch" "--verbose"
68762
970bf6e6463b Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents: 68651
diff changeset
284 "--local-user" pgg-gpg-user-id)
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
285 (if pgg-text-mode (list "--textmode"))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
286 (inhibit-read-only t)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
287 buffer-read-only)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
288 (pgg-gpg-process-region start end passphrase pgg-gpg-program args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
289 (with-current-buffer pgg-errors-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
290 ;; Possibly cache passphrase under, e.g. "jas", for future sign.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
291 (pgg-gpg-possibly-cache-passphrase passphrase pgg-gpg-user-id)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
292 ;; Possibly cache passphrase under, e.g. B565716F, for future decrypt.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
293 (pgg-gpg-possibly-cache-passphrase passphrase))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
294 (pgg-process-when-success)))
66383
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."
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
298 (let ((args '("--batch" "--verify")))
66383
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))))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
301 (setq args (append args '("-")))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
302 (pgg-gpg-process-region start end nil pgg-gpg-program args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
303 (with-current-buffer pgg-errors-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
304 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
305 (while (re-search-forward "^gpg: \\(.*\\)\n" nil t)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
306 (with-current-buffer pgg-output-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
307 (insert-buffer-substring pgg-errors-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
308 (match-beginning 1) (match-end 0)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
309 (delete-region (match-beginning 0) (match-end 0)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
310 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
311 (re-search-forward "^\\[GNUPG:] GOODSIG\\>" nil t))))
66383
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))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
316 (args (list "--batch" "--export" "--armor"
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
317 pgg-gpg-user-id)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
318 (pgg-gpg-process-region (point)(point) nil pgg-gpg-program args)
66383
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."
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
323 (let ((args '("--import" "--batch" "-")) status)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
324 (pgg-gpg-process-region start end nil pgg-gpg-program args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
325 (set-buffer pgg-errors-buffer)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
326 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
327 (when (re-search-forward "^\\[GNUPG:] IMPORT_RES\\>" nil t)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
328 (setq status (buffer-substring (match-end 0)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
329 (progn (end-of-line)(point)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
330 status (vconcat (mapcar #'string-to-number (split-string status))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
331 (erase-buffer)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
332 (insert (format "Imported %d key(s).
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
333 \tArmor contains %d key(s) [%d bad, %d old].\n"
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
334 (+ (aref status 2)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
335 (aref status 10))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
336 (aref status 0)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
337 (aref status 1)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
338 (+ (aref status 4)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
339 (aref status 11)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
340 (if (zerop (aref status 9))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
341 ""
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
342 "\tSecret keys are imported.\n")))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
343 (append-to-buffer pgg-output-buffer (point-min)(point-max))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
344 (pgg-process-when-success)))
69631
77a585c555e6 2006-03-22 Simon Josefsson <jas@extundo.com>
Simon Josefsson <jas@extundo.com>
parents: 69627
diff changeset
345
66383
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