;;; mml-smime.el --- S/MIME support for MML
-;; Copyright (c) 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
+
+;; Copyright (C) 2000-2011 Free Software Foundation, Inc.
;; Author: Simon Josefsson <simon@josefsson.org>
;; Keywords: Gnus, MIME, S/MIME, MML
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published
-;; by the Free Software Foundation; either version 2, or (at your
-;; option) any later version.
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
-;; GNU Emacs is distributed in the hope that it will be useful, but
-;; WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-;; General Public License for more details.
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
+;; For Emacs <22.2 and XEmacs.
+(eval-and-compile
+ (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
+
(eval-when-compile (require 'cl))
(require 'smime)
(require 'mm-decode)
+(require 'mml-sec)
(autoload 'message-narrow-to-headers "message")
(autoload 'message-fetch-field "message")
+(defcustom mml-smime-use (if (featurep 'epg) 'epg 'openssl)
+ "Whether to use OpenSSL or EPG to decrypt S/MIME messages.
+Defaults to EPG if it's loaded."
+ :group 'mime-security
+ :type '(choice (const :tag "EPG" epg)
+ (const :tag "OpenSSL" openssl)))
+
+(defvar mml-smime-function-alist
+ '((openssl mml-smime-openssl-sign
+ mml-smime-openssl-encrypt
+ mml-smime-openssl-sign-query
+ mml-smime-openssl-encrypt-query
+ mml-smime-openssl-verify
+ mml-smime-openssl-verify-test)
+ (epg mml-smime-epg-sign
+ mml-smime-epg-encrypt
+ nil
+ nil
+ mml-smime-epg-verify
+ mml-smime-epg-verify-test)))
+
+(defcustom mml-smime-cache-passphrase mml-secure-cache-passphrase
+ "If t, cache passphrase."
+ :group 'mime-security
+ :type 'boolean)
+
+(defcustom mml-smime-passphrase-cache-expiry mml-secure-passphrase-cache-expiry
+ "How many seconds the passphrase is cached.
+Whether the passphrase is cached at all is controlled by
+`mml-smime-cache-passphrase'."
+ :group 'mime-security
+ :type 'integer)
+
+(defcustom mml-smime-signers nil
+ "A list of your own key ID which will be used to sign a message."
+ :group 'mime-security
+ :type '(repeat (string :tag "Key ID")))
+
(defun mml-smime-sign (cont)
+ (let ((func (nth 1 (assq mml-smime-use mml-smime-function-alist))))
+ (if func
+ (funcall func cont)
+ (error "Cannot find sign function"))))
+
+(defun mml-smime-encrypt (cont)
+ (let ((func (nth 2 (assq mml-smime-use mml-smime-function-alist))))
+ (if func
+ (funcall func cont)
+ (error "Cannot find encrypt function"))))
+
+(defun mml-smime-sign-query ()
+ (let ((func (nth 3 (assq mml-smime-use mml-smime-function-alist))))
+ (if func
+ (funcall func))))
+
+(defun mml-smime-encrypt-query ()
+ (let ((func (nth 4 (assq mml-smime-use mml-smime-function-alist))))
+ (if func
+ (funcall func))))
+
+(defun mml-smime-verify (handle ctl)
+ (let ((func (nth 5 (assq mml-smime-use mml-smime-function-alist))))
+ (if func
+ (funcall func handle ctl)
+ handle)))
+
+(defun mml-smime-verify-test (handle ctl)
+ (let ((func (nth 6 (assq mml-smime-use mml-smime-function-alist))))
+ (if func
+ (funcall func handle ctl))))
+
+(defun mml-smime-openssl-sign (cont)
(when (null smime-keys)
(customize-variable 'smime-keys)
(error "No S/MIME keys configured, use customize to add your key"))
(replace-match "\n" t t))
(goto-char (point-max)))
-(defun mml-smime-encrypt (cont)
+(defun mml-smime-openssl-encrypt (cont)
(let (certnames certfiles tmp file tmpfiles)
;; xxx tmp files are always an security issue
(while&nb