Support S/MIME decryption.
* mm-decode.el (mm-inline-media-tests):
(mm-inlined-types):
(mm-automatic-display):
(mm-attachment-override-types): Add application/{x-,}pkcs7-mime.
* mm-view.el (mm-pkcs7-signed-magic):
(mm-pkcs7-enveloped-magic): New variables.
(mm-view-pkcs7-get-type): New function; identify PKCS#7 type.
(mm-view-pkcs7): New function; mm viewer for PKCS#7 blobs.
(mm-view-pkcs7-decrypt): New function; mm viewer for encrypted
PKCS#7 blobs.
* smime.el (smime-decrypt-region): Expand keyfile.
+2001-07-29 Simon Josefsson <jas@extundo.com>
+
+ Support S/MIME decryption.
+
+ * mm-decode.el (mm-inline-media-tests):
+ (mm-inlined-types):
+ (mm-automatic-display):
+ (mm-attachment-override-types): Add application/{x-,}pkcs7-mime.
+
+ * mm-view.el (mm-pkcs7-signed-magic):
+ (mm-pkcs7-enveloped-magic): New variables.
+ (mm-view-pkcs7-get-type): New function; identify PKCS#7 type.
+ (mm-view-pkcs7): New function; mm viewer for PKCS#7 blobs.
+ (mm-view-pkcs7-decrypt): New function; mm viewer for encrypted
+ PKCS#7 blobs.
+
+ * smime.el (smime-decrypt-region): Expand keyfile.
+
2001-07-29 Simon Josefsson <jas@extundo.com>
* nntp.el (nntp-open-ssl-stream): Don't mess with internal
("application/pgp-signature" ignore identity)
("application/x-pkcs7-signature" ignore identity)
("application/pkcs7-signature" ignore identity)
+ ("application/x-pkcs7-mime" mm-view-pkcs7 identity)
+ ("application/pkcs7-mime" mm-view-pkcs7 identity)
("multipart/alternative" ignore identity)
("multipart/mixed" ignore identity)
("multipart/related" ignore identity)
'("image/.*" "text/.*" "message/delivery-status" "message/rfc822"
"message/partial" "message/external-body" "application/emacs-lisp"
"application/pgp-signature" "application/x-pkcs7-signature"
- "application/pkcs7-signature")
+ "application/pkcs7-signature" "application/x-pkcs7-mime"
+ "application/pkcs7-mime")
"List of media types that are to be displayed inline.
See also `mm-inline-media-tests', which says how to display a media
type inline."
"text/x-vcard" "image/.*" "message/delivery-status" "multipart/.*"
"message/rfc822" "text/x-patch" "application/pgp-signature"
"application/emacs-lisp" "application/x-pkcs7-signature"
- "application/pkcs7-signature")
+ "application/pkcs7-signature" "application/x-pkcs7-mime"
+ "application/pkcs7-mime")
"A list of MIME types to be displayed automatically."
:type '(repeat string)
:group 'mime-display)
-(defcustom mm-attachment-override-types '("text/x-vcard")
+(defcustom mm-attachment-override-types '("text/x-vcard"
+ "application/pkcs7-mime"
+ "application/x-pkcs7-mime")
"Types to have \"attachment\" ignored if they can be displayed inline."
:type '(repeat string)
:group 'mime-display)
(defun mm-display-elisp-inline (handle)
(mm-display-inline-fontify handle 'emacs-lisp-mode))
+;; id-signedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
+;; us(840) rsadsi(113549) pkcs(1) pkcs7(7) 2 }
+(defvar mm-pkcs7-signed-magic
+ (mm-string-as-unibyte
+ (apply 'concat
+ (mapcar 'char-to-string
+ (list ?\x30 ?\x82 ?\x01 ?\x91 ?\x06 ?\x09 ?\x2a ?\x86 ?\x48
+ ?\x86 ?\xf7 ?\x0d ?\x01 ?\x07 ?\x02)))))
+
+;; id-envelopedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
+;; us(840) rsadsi(113549) pkcs(1) pkcs7(7) 3 }
+(defvar mm-pkcs7-enveloped-magic
+ (mm-string-as-unibyte
+ (apply 'concat
+ (mapcar 'char-to-string
+ (list ?\x30 ?\x82 ?\x01 ?\x91 ?\x06 ?\x09 ?\x2a ?\x86 ?\x48
+ ?\x86 ?\xf7 ?\x0d ?\x01 ?\x07 ?\x03)))))
+
+(defun mm-view-pkcs7-get-type (handle)
+ (with-temp-buffer
+ (mm-insert-part handle)
+ (cond ((looking-at (regexp-quote mm-pkcs7-enveloped-magic))
+ 'enveloped)
+ ((looking-at (regexp-quote mm-pkcs7-signed-magic))
+ 'signed)
+ (t
+ (error "Could not identify PKCS#7 type")))))
+
+(defun mm-view-pkcs7 (handle)
+ (case (mm-view-pkcs7-get-type handle)
+ (enveloped (mm-view-pkcs7-decrypt handle))
+ (otherwise (error "Unknown or unimplemented PKCS#7 type"))))
+
+(defun mm-view-pkcs7-decrypt (handle)
+ (let (res)
+ (with-temp-buffer
+ (insert-buffer (mm-handle-buffer handle))
+ (goto-char (point-min))
+ (insert "MIME-Version: 1.0\n")
+ (mm-insert-headers "application/pkcs7-mime" "base64" "smime.p7m")
+ (smime-decrypt-region
+ (point-min) (point-max)
+ (if (= (length smime-keys) 1)
+ (cadar smime-keys)
+ (smime-get-key-by-email
+ (completing-read "Decrypt this part with which key? "
+ smime-keys nil nil
+ (and (listp (car-safe smime-keys))
+ (caar smime-keys))))))
+ (setq res (buffer-string)))
+ (mm-insert-inline handle res)))
+
(provide 'mm-view)
;;; mm-view.el ends here
(setenv "GNUS_SMIME_PASSPHRASE" passphrase))
(when (apply 'smime-call-openssl-region
b e buffer "smime" "-decrypt"
- "-recip" keyfile
+ "-recip" (expand-file-name keyfile)
(if passphrase
(list "-passin" "env:GNUS_SMIME_PASSPHRASE" )))
(delete-region b e)