[Mew-dist 16230] Re: S/MIME patch

Ryutaroh Matsumoto ryutaroh at example.com
2001年 2月 7日 (水) 21:26:53 JST


まつもとです。

From: Kazu Yamamoto (山本和彦) <kazu at example.com>
Subject: [Mew-dist 16211] Re: S/MIME patch
> やるなら、やはり 1.95 をベースにされた方がいいです。

やりました。説明などは前と同じなので[Mew-dist 16207]を御覧ください。た
だ、mew-smime-sign-letterという関数の名前をmew-smime-sign-messageに変
えています。1.95b102ベースです。

> XEmacs 21.1 への乗り換えは簡単です。ただ、文字コードに関する環境の設定
> 方法が、Emacs 20.7 のようになっていることに注意しましょう。つまり、
> .emacs に以下のコードを入れる必要があります。
> 
> (set-language-environment "Japanese")

このアドバイスありがとうございます。助かりました。(Emacs 20.7にしたん
ですが日本語の設定がよくわからなかった)

--
松本  隆太郎
-------------- next part --------------
diff -aruN mew-1.95b102/mew-const.el mew-1.95b102-smime0/mew-const.el
--- mew-1.95b102/mew-const.el	Tue Feb  6 17:56:42 2001
+++ mew-1.95b102-smime0/mew-const.el	Wed Feb  7 20:36:01 2001
@@ -92,6 +92,7 @@
 (defconst mew-ct-pgs "application/pgp-signature") ;; due to the RFC 1847 bug
 (defconst mew-ct-pge "application/pgp-encrypted") ;; due to the RFC 1847 bug
 (defconst mew-ct-apk "Application/Pgp-Keys")
+(defconst mew-ct-sms "application/x-pkcs7-signature")
 
 (defconst mew-us-ascii "us-ascii")
 (defconst mew-cs-unknown 'unknown)
diff -aruN mew-1.95b102/mew-decode.el mew-1.95b102-smime0/mew-decode.el
--- mew-1.95b102/mew-decode.el	Tue Dec 26 14:17:00 2000
+++ mew-1.95b102-smime0/mew-decode.el	Wed Feb  7 20:30:07 2001
@@ -29,7 +29,8 @@
   '(("application/pgp-encrypted" mew-pgp-decrypt mew-pgp-ver mew-prog-pgp)))
 
 (defvar mew-decode-multipart-signed-switch
-  '(("application/pgp-signature" mew-pgp-verify mew-pgp-ver mew-prog-pgp)))
+  '(("application/pgp-signature" mew-pgp-verify mew-pgp-ver mew-prog-pgp)
+    ("application/x-pkcs7-signature" mew-smime-verify mew-smime-ver mew-prog-smime)))
 
 ;;
 
diff -aruN mew-1.95b102/mew-encode.el mew-1.95b102-smime0/mew-encode.el
--- mew-1.95b102/mew-encode.el	Fri Jan 19 01:40:46 2001
+++ mew-1.95b102-smime0/mew-encode.el	Wed Feb  7 20:32:38 2001
@@ -27,7 +27,8 @@
   '(("application/pgp-encrypted" mew-pgp-encrypt)))
 
 (defvar mew-encode-multipart-signed-switch
-  '(("application/pgp-signature" mew-pgp-sign)))
+  '(("application/pgp-signature" mew-pgp-sign)
+    ("application/x-pkcs7-signature" mew-smime-sign)))
 
 ;;
 
@@ -760,7 +761,7 @@
   (let* ((boundary (mew-security-multipart-boundary depth))
 	 (switch mew-encode-multipart-signed-switch) ;; save length
 	 (func (mew-encode-get-security-func proto switch))
-	 file1 file2 micalg cte2 fmc errmsg)
+	 file1 file2 micalg cte2 fmc errmsg ct2 cd2)
     (setq file1 (mew-save-transfer-form (point-min) (point-max) 'retain))
     ;; The narrowed region still the ORIGINAL part (i.e. line breaks are LF)
     ;; Call the protocol function
@@ -773,6 +774,7 @@
 		mew-ct-mls mew-temp-dir))))
     (setq file2 (nth 0 fmc) cte2 (nth 1 fmc) micalg (nth 2 fmc))
     (setq errmsg (nth 3 fmc))
+    (setq ct2 (nth 4 fmc) cd2 (nth 5 fmc))
     (if errmsg
 	(progn
 	  (if (file-exists-p file1) (delete-file file1))
@@ -792,7 +794,8 @@
       ;; After the sigend part
       (insert (format "\n--%s\n" boundary))
       (mew-encode-singlepart 
-       (mew-encode-syntax-single file2 (list proto) cte2))
+       (mew-encode-syntax-single file2 (if ct2 ct2 (list protocol))
+        cte2 cd2))
       (insert (format "\n--%s--\n" boundary))
       ;; Throw away the garbage 
       (if (file-exists-p file1) (delete-file file1))
diff -aruN mew-1.95b102/mew-smime.el mew-1.95b102-smime0/mew-smime.el
--- mew-1.95b102/mew-smime.el	Thu Jan  1 09:00:00 1970
+++ mew-1.95b102-smime0/mew-smime.el	Wed Feb  7 21:19:56 2001
@@ -0,0 +1,91 @@
+; This file is based on mew-pgp.el in Mew 1.94.2, whose copyright also 
+; applies to this file. This file is originally written by Ryutaroh
+; Matsumoto <ryutaroh at example.com>, February 7, 2000.
+
+(provide 'mew-smime)
+
+; configuration variables
+(defvar mew-smime-digital-id "/home/lemon/ryutaroh/id.pem"
+"*Filename containing your digital ID in the PEM format.")
+(defvar mew-smime-CA-file "/home/lemon/ryutaroh/CA2.pem"
+"*Filename containing certificates of the trusted CAs, such as VeriSign.")
+
+
+; internal variables
+(defvar mew-smime-running nil)
+(defvar mew-smime-prompt-enter-pass   "Enter S/MIME pass phrase: ")
+(defvar mew-smime-prompt-reenter-pass "Re-enter S/MIME pass phrase: ")
+(defconst mew-smime-msg-enter-pass "Enter PEM pass phrase:")
+(defvar mew-smime-string nil)
+
+; The following variables are used only in the variable
+; mew-decode-multipart-signed-switch in mew-decode.el.
+(defvar mew-smime-ver 0)
+(defvar mew-prog-smime "openssl")
+
+
+(defun mew-smime-passphrase (&optional again)
+  (let ((prompt (if again
+		    mew-smime-prompt-reenter-pass
+		  mew-smime-prompt-enter-pass)))
+      (mew-input-passwd prompt "S/MIME")))
+
+
+(defun mew-smime-process-filter1 (process string)
+  ;; sign or decrypt, not verify
+  (setq mew-smime-string (concat mew-smime-string string))
+  (cond
+   ;; pass phrase for sign or decrypt
+   ((string-match mew-smime-msg-enter-pass string)
+    (process-send-string process (format "%s\n" (mew-smime-passphrase)))
+    (set-process-filter process nil))))
+
+
+(defun mew-smime-process-sentinel (process event)
+(setq mew-smime-running nil))
+
+(defun mew-smime-sign (file1)
+  (message "S/MIME signing ... ")
+  (setq mew-smime-running 'signing)
+  (let ((process-connection-type mew-connection-type2)
+	file2 process)
+    (setq file2 (mew-make-temp-name))
+    ;; not perfectly unique but OK
+    (setq process
+	  (mew-start-process-lang
+	   "S/MIME sign"
+	   nil
+	   "openssl"
+	   "smime" "-sign" "-in" file1 "-out" file2 "-outform" "DER" "-signer" mew-smime-digital-id))
+    (mew-set-process-cs process mew-cs-autoconv mew-cs-dummy)
+    (set-process-filter process 'mew-smime-process-filter1)
+    (set-process-sentinel process 'mew-smime-process-sentinel)
+    ;; Wait for the termination of OpenSSL.
+    ;; Emacs doesn't provide synchronize mechanism with
+    ;; an asynchronous process. So, take this way. 
+    (while mew-smime-running
+	(if mew-xemacs-p
+	    (accept-process-output)
+	  (sit-for 1)
+	  ;; accept-process-output or sleep-for is not enough
+	  (discard-input)))
+    (message "S/MIME signing ... done")
+    (list file2 mew-b64 "sha1" nil
+     (list "application/x-pkcs7-signature" (list "name" "smime.p7s"))
+     (list "attachment" (list "filename" "smime.p7s"))))) ;; return
+
+
+
+(defun mew-smime-sign-message ()
+  "Sign the entire draft with S/MIME. Input your passphrase."
+  (interactive)
+  (mew-draft-make-message 'smime-signature))
+
+
+(defun mew-smime-verify (file1 file2)
+  (message "PGP verifying ... ")
+  (if (= 0 (mew-call-process-lang "openssl" nil nil nil
+    "smime" "-verify" "-inform" "DER" "-in" file2 "-content" file1
+    "-CAfile" mew-smime-CA-file))
+  "S/MIME signature verification succeeded"
+  "S/MIME signature verification failed"))
diff -aruN mew-1.95b102/mew-vars2.el mew-1.95b102-smime0/mew-vars2.el
--- mew-1.95b102/mew-vars2.el	Mon Feb  5 14:50:03 2001
+++ mew-1.95b102-smime0/mew-vars2.el	Wed Feb  7 20:42:29 2001
@@ -389,7 +389,8 @@
 ;;;
 
 (defcustom mew-privacy-database
-  `((pgp-signature  ((,mew-ct-mls ,mew-ct-pgs)) "PS")
+  `((smime-signature ((,mew-ct-mls ,mew-ct-sms)) "SS")
+    (pgp-signature  ((,mew-ct-mls ,mew-ct-pgs)) "PS")
     (pgp-encryption ((,mew-ct-mle ,mew-ct-pge)) "PE")
     (pgp-signature-encryption
      ((,mew-ct-mls ,mew-ct-pgs) (,mew-ct-mle ,mew-ct-pge)) "PSPE")
diff -aruN mew-1.95b102/mew.el mew-1.95b102-smime0/mew.el
--- mew-1.95b102/mew.el	Tue Feb  6 18:04:50 2001
+++ mew-1.95b102-smime0/mew.el	Wed Feb  7 20:39:28 2001
@@ -785,6 +785,7 @@
 (require 'mew-mark)
 (require 'mew-header)
 (require 'mew-pgp)
+(require 'mew-smime)
 (require 'mew-bq)
 (require 'mew-syntax)
 (require 'mew-scan)
-------------- next part --------------
テキスト形式以外の添付ファイルを保管しました...
ファイル名: 無し
型:         application/x-pkcs7-signature
サイズ:     1800 バイト
説明:       attachment; filename="smime.p7s"
URL:        <http://www.mew.org/pipermail/mew-dist/attachments/20010207/09a48719/attachment.bin>


Mew-dist メーリングリストの案内