2001-08-19 Simon Josefsson <jas@extundo.com>
[gnus] / lisp / smime.el
index f7442de..eecfffb 100644 (file)
@@ -89,6 +89,8 @@
 ;; environment variables to pass the password to OpenSSL, which is
 ;; slightly insecure. Hence a new todo: use a better -passin method.
 ;;
+;; Cache password for e.g. 1h
+;;
 ;; Suggestions and comments are appreciated, mail me at simon@josefsson.org.
 
 ;; <rant>
@@ -185,15 +187,17 @@ If nil, use system defaults."
                 string)
   :group 'smime)
 
-(defcustom smime-extra-arguments nil
-  "*List of additional arguments passed to OpenSSL.
-For instance, if you don't have a /dev/random you might be forced
-to set this to e.g. `(\"-rand\" \"/etc/entropy\")'."
-  :type '(repeat string)
-  :group 'smime)
-
 (defvar smime-details-buffer "*OpenSSL output*")
 
+(eval-and-compile
+  (defalias 'smime-make-temp-file
+    (if (fboundp 'make-temp-file)
+       'make-temp-file
+      (lambda (prefix &optional dir-flag) ;; Simple implementation
+       (expand-file-name
+        (make-temp-name prefix)
+        temporary-file-directory)))))
+
 ;; Password dialog function
 
 (defun smime-ask-passphrase ()
@@ -208,8 +212,7 @@ to set this to e.g. `(\"-rand\" \"/etc/entropy\")'."
 ;; OpenSSL wrappers.
 
 (defun smime-call-openssl-region (b e buf &rest args)
-  (case (apply 'call-process-region b e smime-openssl-program nil
-              buf nil (append smime-extra-arguments args))
+  (case (apply 'call-process-region b e smime-openssl-program nil buf nil args)
     (0 t)
     (1 (message "OpenSSL: An error occurred parsing the command options.") nil)
     (2 (message "OpenSSL: One of the input files could not be read.") nil)
@@ -230,11 +233,12 @@ If signing fails, the buffer is not modified.  Region is assumed to
 have proper MIME tags.  KEYFILES is expected to contain a PEM encoded
 private key and certificate as its car, and a list of additional certificates
 to include in its caar."
+  (smime-new-details-buffer)
   (let ((keyfile (car keyfiles))
        (certfiles (and (cdr keyfiles) (cadr keyfiles)))
        (buffer (generate-new-buffer (generate-new-buffer-name " *smime*")))
        (passphrase (smime-ask-passphrase))
-       (tmpfile (make-temp-file "smime")))
+       (tmpfile (smime-make-temp-file "smime")))
     (if passphrase
        (setenv "GNUS_SMIME_PASSPHRASE" passphrase))
     (prog1
@@ -252,10 +256,11 @@ to include in its caar."
                  (delete-file tmpfile)))
          (delete-region b e)
          (insert-buffer-substring buffer)
+         (goto-char b)
          (when (looking-at "^MIME-Version: 1.0$")
            (delete-region (point) (progn (forward-line 1) (point))))
          t)
-      (with-current-buffer (get-buffer-create smime-details-buffer)
+      (with-current-buffer smime-details-buffer
        (goto-char (point-max))
        (insert-buffer-substring buffer))
       (kill-buffer buffer))))
@@ -265,8 +270,9 @@ to include in its caar."
 If encryption fails, the buffer is not modified.  Region is assumed to
 have proper MIME tags.  CERTFILES is a list of filenames, each file
 is expected to contain of a PEM encoded certificate."
+  (smime-new-details-buffer)
   (let ((buffer (generate-new-buffer (generate-new-buffer-name " *smime*")))
-       (tmpfile (make-temp-file "smime")))
+       (tmpfile (smime-make-temp-file "smime")))
     (prog1
        (when (prog1
                  (apply 'smime-call-openssl-region b e (list buffer tmpfile)
@@ -277,10 +283,11 @@ is expected to contain of a PEM encoded certificate."
                  (delete-file tmpfile)))
          (delete-region b e)
          (insert-buffer-substring buffer)
+         (goto-char b)
          (when (looking-at "^MIME-Version: 1.0$")
            (delete-region (point) (progn (forward-line 1) (point))))
          t)
-      (with-current-buffer (get-buffer-create smime-details-buffer)
+      (with-current-buffer smime-details-buffer
        (goto-char (point-max))
        (insert-buffer-substring buffer))
       (kill-buffer buffer))))
@@ -356,7 +363,7 @@ in the buffer specified by `smime-details-buffer'."
   (smime-new-details-buffer)
   (let ((buffer (generate-new-buffer (generate-new-buffer-name " *smime*")))
        CAs (passphrase (smime-ask-passphrase))
-       (tmpfile (make-temp-file "smime")))
+       (tmpfile (smime-make-temp-file "smime")))
     (if passphrase
        (setenv "GNUS_SMIME_PASSPHRASE" passphrase))
     (if (prog1
@@ -463,10 +470,11 @@ A string or a list of strings is returned."
            (caddr curkey)
          (smime-get-certfiles keyfile otherkeys)))))
 
-(defalias 'smime-point-at-eol
-  (if (fboundp 'point-at-eol)
-      'point-at-eol
-    'line-end-position))
+(eval-and-compile
+  (defalias 'smime-point-at-eol
+    (if (fboundp 'point-at-eol)
+       'point-at-eol
+      'line-end-position)))
 
 (defun smime-buffer-as-string-region (b e)
   "Return each line in region between B and E as a list of strings."