1 ;;; mml2015.el --- MIME Security with Pretty Good Privacy (PGP)
2 ;; Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
5 ;; Keywords: PGP MIME MML
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 2, or (at your
12 ;; option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; RFC 2015 is updated by RFC 3156, this file should be compatible
31 (eval-when-compile (require 'cl))
32 (eval-when-compile (require 'gnus-clfns))
36 (defvar mml2015-use (or
40 (and (fboundp 'pgg-sign-region)
45 (and (fboundp 'gpg-sign-detached)
49 (and (fboundp 'mc-encrypt-generic)
50 (fboundp 'mc-sign-generic)
51 (fboundp 'mc-cleanup-recipient-headers)
53 "The package used for PGP/MIME.")
55 ;; Something is not RFC2015.
56 (defvar mml2015-function-alist
57 '((mailcrypt mml2015-mailcrypt-sign
58 mml2015-mailcrypt-encrypt
59 mml2015-mailcrypt-verify
60 mml2015-mailcrypt-decrypt
61 mml2015-mailcrypt-clear-verify
62 mml2015-mailcrypt-clear-decrypt)
67 mml2015-gpg-clear-verify
68 mml2015-gpg-clear-decrypt)
73 mml2015-pgg-clear-verify
74 mml2015-pgg-clear-decrypt))
75 "Alist of PGP/MIME functions.")
77 (defvar mml2015-result-buffer nil)
79 (defvar mml2015-trust-boundaries-alist
80 '((trust-undefined . nil)
85 "Trust boundaries for a signer's GnuPG key.
86 This alist contains pairs of the form (trust-symbol . boolean), with
87 symbols that are contained in `gpg-unabbrev-trust-alist'. The boolean
88 specifies whether the given trust value is good enough to be trusted
94 (autoload 'mailcrypt-decrypt "mailcrypt")
95 (autoload 'mailcrypt-verify "mailcrypt")
96 (autoload 'mc-pgp-always-sign "mailcrypt")
97 (autoload 'mc-encrypt-generic "mc-toplev")
98 (autoload 'mc-cleanup-recipient-headers "mc-toplev")
99 (autoload 'mc-sign-generic "mc-toplev"))
102 (defvar mc-default-scheme)
105 (defvar mml2015-decrypt-function 'mailcrypt-decrypt)
106 (defvar mml2015-verify-function 'mailcrypt-verify)
108 (defun mml2015-format-error (err)
109 (if (stringp (cadr err))
111 (format "%S" (cdr err))))
113 (defun mml2015-mailcrypt-decrypt (handle ctl)
115 (let (child handles result)
116 (unless (setq child (mm-find-part-by-type
118 "application/octet-stream" nil t))
119 (mm-set-handle-multipart-parameter
120 mm-security-handle 'gnus-info "Corrupted")
121 (throw 'error handle))
123 (mm-insert-part child)
126 (funcall mml2015-decrypt-function)
128 (mm-set-handle-multipart-parameter
129 mm-security-handle 'gnus-details (mml2015-format-error err))
132 (mm-set-handle-multipart-parameter
133 mm-security-handle 'gnus-details "Quit.")
136 (mm-set-handle-multipart-parameter
137 mm-security-handle 'gnus-info "Failed")
138 (throw 'error handle))
139 (setq handles (mm-dissect-buffer t)))
140 (mm-destroy-parts handle)
141 (mm-set-handle-multipart-parameter
142 mm-security-handle 'gnus-info
144 (let ((sig (with-current-buffer mml2015-result-buffer
145 (mml2015-gpg-extract-signature-details))))
146 (concat ", Signer: " sig))))
147 (if (listp (car handles))
151 (defun mml2015-mailcrypt-clear-decrypt ()
155 (funcall mml2015-decrypt-function)
157 (mm-set-handle-multipart-parameter
158 mm-security-handle 'gnus-details (mml2015-format-error err))
161 (mm-set-handle-multipart-parameter
162 mm-security-handle 'gnus-details "Quit.")
165 (mm-set-handle-multipart-parameter
166 mm-security-handle 'gnus-info "OK")
167 (mm-set-handle-multipart-parameter
168 mm-security-handle 'gnus-info "Failed"))))
170 (defun mml2015-fix-micalg (alg)
172 ;; Mutt/1.2.5i has seen sending micalg=php-sha1
173 (upcase (if (string-match "^p[gh]p-" alg)
174 (substring alg (match-end 0))
177 (defun mml2015-mailcrypt-verify (handle ctl)
180 (unless (setq part (mm-find-raw-part-by-type
181 ctl (or (mm-handle-multipart-ctl-parameter
183 "application/pgp-signature")
185 (mm-set-handle-multipart-parameter
186 mm-security-handle 'gnus-info "Corrupted")
187 (throw 'error handle))
189 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n")
190 (insert (format "Hash: %s\n\n"
191 (or (mml2015-fix-micalg
192 (mm-handle-multipart-ctl-parameter
196 (narrow-to-region (point) (point))
198 (goto-char (point-min))
200 (if (looking-at "^-")
203 (unless (setq part (mm-find-part-by-type
204 (cdr handle) "application/pgp-signature" nil t))
205 (mm-set-handle-multipart-parameter
206 mm-security-handle 'gnus-info "Corrupted")
207 (throw 'error handle))
209 (narrow-to-region (point) (point))
210 (mm-insert-part part)
211 (goto-char (point-min))
212 (if (re-search-forward "^-----BEGIN PGP [^-]+-----\r?$" nil t)
213 (replace-match "-----BEGIN PGP SIGNATURE-----" t t))
214 (if (re-search-forward "^-----END PGP [^-]+-----\r?$" nil t)
215 (replace-match "-----END PGP SIGNATURE-----" t t)))
216 (let ((mc-gpg-debug-buffer (get-buffer-create " *gnus gpg debug*")))
217 (unless (condition-case err
219 (funcall mml2015-verify-function)
220 (if (get-buffer " *mailcrypt stderr temp")
221 (mm-set-handle-multipart-parameter
222 mm-security-handle 'gnus-details
223 (with-current-buffer " *mailcrypt stderr temp"
225 (if (get-buffer " *mailcrypt stdout temp")
226 (kill-buffer " *mailcrypt stdout temp"))
227 (if (get-buffer " *mailcrypt stderr temp")
228 (kill-buffer " *mailcrypt stderr temp"))
229 (if (get-buffer " *mailcrypt status temp")
230 (kill-buffer " *mailcrypt status temp"))
231 (if (get-buffer mc-gpg-debug-buffer)
232 (kill-buffer mc-gpg-debug-buffer)))
234 (mm-set-handle-multipart-parameter
235 mm-security-handle 'gnus-details (mml2015-format-error err))
238 (mm-set-handle-multipart-parameter
239 mm-security-handle 'gnus-details "Quit.")
241 (mm-set-handle-multipart-parameter
242 mm-security-handle 'gnus-info "Failed")
243 (throw 'error handle))))
244 (mm-set-handle-multipart-parameter
245 mm-security-handle 'gnus-info "OK")
248 (defun mml2015-mailcrypt-clear-verify ()
249 (let ((mc-gpg-debug-buffer (get-buffer-create " *gnus gpg debug*")))
250 (if (condition-case err
252 (funcall mml2015-verify-function)
253 (if (get-buffer " *mailcrypt stderr temp")
254 (mm-set-handle-multipart-parameter
255 mm-security-handle 'gnus-details
256 (with-current-buffer " *mailcrypt stderr temp"
258 (if (get-buffer " *mailcrypt stdout temp")
259 (kill-buffer " *mailcrypt stdout temp"))
260 (if (get-buffer " *mailcrypt stderr temp")
261 (kill-buffer " *mailcrypt stderr temp"))
262 (if (get-buffer " *mailcrypt status temp")
263 (kill-buffer " *mailcrypt status temp"))
264 (if (get-buffer mc-gpg-debug-buffer)
265 (kill-buffer mc-gpg-debug-buffer)))
267 (mm-set-handle-multipart-parameter
268 mm-security-handle 'gnus-details (mml2015-format-error err))
271 (mm-set-handle-multipart-parameter
272 mm-security-handle 'gnus-details "Quit.")
274 (mm-set-handle-multipart-parameter
275 mm-security-handle 'gnus-info "OK")
276 (mm-set-handle-multipart-parameter
277 mm-security-handle 'gnus-info "Failed"))))
279 (defun mml2015-mailcrypt-sign (cont)
280 (mc-sign-generic (message-options-get 'message-sender)
283 (funcall mml-boundary-function (incf mml-multipart-number)))
285 (goto-char (point-min))
286 (unless (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\r?$" nil t)
287 (error "Cannot find signed begin line"))
288 (goto-char (match-beginning 0))
290 (unless (looking-at "Hash:[ \t]*\\([a-zA-Z0-9]+\\)")
291 (error "Cannot not find PGP hash"))
292 (setq hash (match-string 1))
293 (unless (re-search-forward "^$" nil t)
294 (error "Cannot not find PGP message"))
296 (delete-region (point-min) (point))
297 (insert (format "Content-Type: multipart/signed; boundary=\"%s\";\n"
299 (insert (format "\tmicalg=pgp-%s; protocol=\"application/pgp-signature\"\n"
301 (insert (format "\n--%s\n" boundary))
303 (goto-char (point-max))
304 (unless (re-search-backward "^-----END PGP SIGNATURE-----\r?$" nil t)
305 (error "Cannot find signature part"))
306 (replace-match "-----END PGP MESSAGE-----" t t)
307 (goto-char (match-beginning 0))
308 (unless (re-search-backward "^-----BEGIN PGP SIGNATURE-----\r?$"
310 (error "Cannot find signature part"))
311 (replace-match "-----BEGIN PGP MESSAGE-----" t t)
312 (goto-char (match-beginning 0))
314 (narrow-to-region point (point))
316 (while (re-search-forward "^- -" nil t)
317 (replace-match "-" t t))
318 (goto-char (point-max)))
319 (insert (format "--%s\n" boundary))
320 (insert "Content-Type: application/pgp-signature\n\n")
321 (goto-char (point-max))
322 (insert (format "--%s--\n" boundary))
323 (goto-char (point-max))))
325 (defun mml2015-mailcrypt-encrypt (cont &optional sign)
326 (let ((mc-pgp-always-sign
327 (or mc-pgp-always-sign
329 (eq t (or (message-options-get 'message-sign-encrypt)
331 'message-sign-encrypt
332 (or (y-or-n-p "Sign the message? ")
335 (mm-with-unibyte-current-buffer-mule4
337 (or (message-options-get 'message-recipients)
338 (message-options-set 'message-recipients
339 (mc-cleanup-recipient-headers
340 (read-string "Recipients: "))))
342 (message-options-get 'message-sender))))
343 (goto-char (point-min))
344 (unless (looking-at "-----BEGIN PGP MESSAGE-----")
345 (error "Fail to encrypt the message"))
347 (funcall mml-boundary-function (incf mml-multipart-number))))
348 (insert (format "Content-Type: multipart/encrypted; boundary=\"%s\";\n"
350 (insert "\tprotocol=\"application/pgp-encrypted\"\n\n")
351 (insert (format "--%s\n" boundary))
352 (insert "Content-Type: application/pgp-encrypted\n\n")
353 (insert "Version: 1\n\n")
354 (insert (format "--%s\n" boundary))
355 (insert "Content-Type: application/octet-stream\n\n")
356 (goto-char (point-max))
357 (insert (format "--%s--\n" boundary))
358 (goto-char (point-max))))
363 (autoload 'gpg-decrypt "gpg")
364 (autoload 'gpg-verify "gpg")
365 (autoload 'gpg-verify-cleartext "gpg")
366 (autoload 'gpg-sign-detached "gpg")
367 (autoload 'gpg-sign-encrypt "gpg")
368 (autoload 'gpg-encrypt "gpg")
369 (autoload 'gpg-passphrase-read "gpg"))
371 (defun mml2015-gpg-passphrase ()
372 (or (message-options-get 'gpg-passphrase)
373 (message-options-set 'gpg-passphrase (gpg-passphrase-read))))
375 (defun mml2015-gpg-decrypt-1 ()
376 (let ((cipher (current-buffer)) plain result)
377 (if (with-temp-buffer
379 (gpg-decrypt cipher (setq plain (current-buffer))
380 mml2015-result-buffer nil)
381 (mm-set-handle-multipart-parameter
382 mm-security-handle 'gnus-details
383 (with-current-buffer mml2015-result-buffer
387 (insert-buffer plain)
388 (goto-char (point-min))
389 (while (search-forward "\r\n" nil t)
390 (replace-match "\n" t t))))
392 ;; Some wrong with the return value, check plain text buffer.
393 (if (> (point-max) (point-min))
397 (defun mml2015-gpg-decrypt (handle ctl)
398 (let ((mml2015-decrypt-function 'mml2015-gpg-decrypt-1))
399 (mml2015-mailcrypt-decrypt handle ctl)))
401 (defun mml2015-gpg-clear-decrypt ()
403 (setq result (mml2015-gpg-decrypt-1))
405 (mm-set-handle-multipart-parameter
406 mm-security-handle 'gnus-info "OK")
407 (mm-set-handle-multipart-parameter
408 mm-security-handle 'gnus-info "Failed"))))
410 (defun mml2015-gpg-pretty-print-fpr (fingerprint)
412 (fpr-length (string-width fingerprint))
415 (setq fingerprint (string-to-list fingerprint))
417 (setq fpr-length (- fpr-length 4))
418 (setq slice (butlast fingerprint fpr-length))
419 (setq fingerprint (nthcdr 4 fingerprint))
420 (setq n-slice (1+ n-slice))
426 (otherwise (concat " " slice))))))
429 (defun mml2015-gpg-extract-signature-details ()
430 (goto-char (point-min))
431 (if (and (eq mml2015-use 'gpg)
432 (boundp 'gpg-unabbrev-trust-alist))
433 (let* ((expired (re-search-forward
434 "^\\[GNUPG:\\] SIGEXPIRED$"
436 (signer (and (re-search-forward
437 "^\\[GNUPG:\\] GOODSIG \\([0-9A-Za-z]*\\) \\(.*\\)$"
439 (cons (match-string 1) (match-string 2))))
440 (fprint (and (re-search-forward
441 "^\\[GNUPG:\\] VALIDSIG \\([0-9a-zA-Z]*\\) "
444 (trust (and (re-search-forward "^\\[GNUPG:\\] \\(TRUST_.*\\)$" nil t)
447 (cdr (assoc (cdr (assoc trust gpg-unabbrev-trust-alist))
448 mml2015-trust-boundaries-alist))))
449 (cond ((and signer fprint)
451 (unless trust-good-enough-p
452 (concat "\nUntrusted, Fingerprint: "
453 (mml2015-gpg-pretty-print-fpr fprint)))
455 (format "\nWARNING: Signature from expired key (%s)"
458 "From unknown user")))
459 (if (re-search-forward "^\\(gpg: \\)?Good signature from \"\\(.*\\)\"$" nil t)
461 "From unknown user")))
463 (defun mml2015-gpg-verify (handle ctl)
465 (let (part message signature info-is-set-p)
466 (unless (setq part (mm-find-raw-part-by-type
467 ctl (or (mm-handle-multipart-ctl-parameter
469 "application/pgp-signature")
471 (mm-set-handle-multipart-parameter
472 mm-security-handle 'gnus-info "Corrupted")
473 (throw 'error handle))
475 (setq message (current-buffer))
477 ;; Convert <LF> to <CR><LF> in verify mode. Sign and
478 ;; clearsign use --textmode. The conversion is not necessary.
479 ;; In clearverify, the conversion is not necessary either.
480 (goto-char (point-min))
483 (unless (eq (char-before) ?\r)
488 (setq signature (current-buffer))
489 (unless (setq part (mm-find-part-by-type
490 (cdr handle) "application/pgp-signature" nil t))
491 (mm-set-handle-multipart-parameter
492 mm-security-handle 'gnus-info "Corrupted")
493 (throw 'error handle))
494 (mm-insert-part part)
495 (unless (condition-case err
497 (gpg-verify message signature mml2015-result-buffer)
498 (mm-set-handle-multipart-parameter
499 mm-security-handle 'gnus-details
500 (with-current-buffer mml2015-result-buffer
503 (mm-set-handle-multipart-parameter
504 mm-security-handle 'gnus-details (mml2015-format-error err))
505 (mm-set-handle-multipart-parameter
506 mm-security-handle 'gnus-info "Error.")
507 (setq info-is-set-p t)
510 (mm-set-handle-multipart-parameter
511 mm-security-handle 'gnus-details "Quit.")
512 (mm-set-handle-multipart-parameter
513 mm-security-handle 'gnus-info "Quit.")
514 (setq info-is-set-p t)
516 (unless info-is-set-p
517 (mm-set-handle-multipart-parameter
518 mm-security-handle 'gnus-info "Failed"))
519 (throw 'error handle)))
520 (mm-set-handle-multipart-parameter
521 mm-security-handle 'gnus-info
522 (with-current-buffer mml2015-result-buffer
523 (mml2015-gpg-extract-signature-details))))
526 (defun mml2015-gpg-clear-verify ()
527 (if (condition-case err
529 (gpg-verify-cleartext (current-buffer) mml2015-result-buffer)
530 (mm-set-handle-multipart-parameter
531 mm-security-handle 'gnus-details
532 (with-current-buffer mml2015-result-buffer
535 (mm-set-handle-multipart-parameter
536 mm-security-handle 'gnus-details (mml2015-format-error err))
539 (mm-set-handle-multipart-parameter
540 mm-security-handle 'gnus-details "Quit.")
542 (mm-set-handle-multipart-parameter
543 mm-security-handle 'gnus-info
544 (with-current-buffer mml2015-result-buffer
545 (mml2015-gpg-extract-signature-details)))
546 (mm-set-handle-multipart-parameter
547 mm-security-handle 'gnus-info "Failed")))
549 (defun mml2015-gpg-sign (cont)
551 (funcall mml-boundary-function (incf mml-multipart-number)))
552 (text (current-buffer)) signature)
553 (goto-char (point-max))
557 (unless (gpg-sign-detached text (setq signature (current-buffer))
558 mml2015-result-buffer
560 (message-options-get 'message-sender)
561 t t) ; armor & textmode
562 (unless (> (point-max) (point-min))
563 (pop-to-buffer mml2015-result-buffer)
564 (error "Sign error")))
565 (goto-char (point-min))
566 (while (re-search-forward "\r+$" nil t)
567 (replace-match "" t t))
569 (goto-char (point-min))
570 (insert (format "Content-Type: multipart/signed; boundary=\"%s\";\n"
572 ;;; FIXME: what is the micalg?
573 (insert "\tmicalg=pgp-sha1; protocol=\"application/pgp-signature\"\n")
574 (insert (format "\n--%s\n" boundary))
575 (goto-char (point-max))
576 (insert (format "\n--%s\n" boundary))
577 (insert "Content-Type: application/pgp-signature\n\n")
578 (insert-buffer signature)
579 (goto-char (point-max))
580 (insert (format "--%s--\n" boundary))
581 (goto-char (point-max)))))
583 (defun mml2015-gpg-encrypt (cont &optional sign)
585 (funcall mml-boundary-function (incf mml-multipart-number)))
586 (text (current-buffer))
588 (mm-with-unibyte-current-buffer-mule4
590 ;; set up a function to call the correct gpg encrypt routine
591 ;; with the right arguments. (FIXME: this should be done
593 (flet ((gpg-encrypt-func
594 (sign plaintext ciphertext result recipients &optional
595 passphrase sign-with-key armor textmode)
598 plaintext ciphertext result recipients passphrase
599 sign-with-key armor textmode)
601 plaintext ciphertext result recipients passphrase
603 (unless (gpg-encrypt-func
604 sign ; passed in when using signencrypt
605 text (setq cipher (current-buffer))
606 mml2015-result-buffer
609 (message-options-get 'message-recipients)
610 (message-options-set 'message-recipients
611 (read-string "Recipients: ")))
614 (message-options-get 'message-sender)
615 t t) ; armor & textmode
616 (unless (> (point-max) (point-min))
617 (pop-to-buffer mml2015-result-buffer)
618 (error "Encrypt error"))))
619 (goto-char (point-min))
620 (while (re-search-forward "\r+$" nil t)
621 (replace-match "" t t))
623 (delete-region (point-min) (point-max))
624 (insert (format "Content-Type: multipart/encrypted; boundary=\"%s\";\n"
626 (insert "\tprotocol=\"application/pgp-encrypted\"\n\n")
627 (insert (format "--%s\n" boundary))
628 (insert "Content-Type: application/pgp-encrypted\n\n")
629 (insert "Version: 1\n\n")
630 (insert (format "--%s\n" boundary))
631 (insert "Content-Type: application/octet-stream\n\n")
632 (insert-buffer cipher)
633 (goto-char (point-max))
634 (insert (format "--%s--\n" boundary))
635 (goto-char (point-max))))))
640 (defvar pgg-errors-buffer)
641 (defvar pgg-output-buffer))
644 (autoload 'pgg-decrypt-region "pgg")
645 (autoload 'pgg-verify-region "pgg")
646 (autoload 'pgg-sign-region "pgg")
647 (autoload 'pgg-encrypt-region "pgg"))
649 (defun mml2015-pgg-decrypt (handle ctl)
651 (let ((pgg-errors-buffer mml2015-result-buffer)
652 child handles result decrypt-status)
653 (unless (setq child (mm-find-part-by-type
655 "application/octet-stream" nil t))
656 (mm-set-handle-multipart-parameter
657 mm-security-handle 'gnus-info "Corrupted")
658 (throw 'error handle))
660 (mm-insert-part child)
661 (if (condition-case err
663 (pgg-decrypt-region (point-min) (point-max))
665 (with-current-buffer mml2015-result-buffer
668 (mm-set-handle-multipart-parameter
669 mm-security-handle 'gnus-details (mml2015-format-error err))
672 (mm-set-handle-multipart-parameter
673 mm-security-handle 'gnus-details "Quit.")
675 (with-current-buffer pgg-output-buffer
676 (setq handles (mm-dissect-buffer t))
677 (mm-destroy-parts handle)
678 (mm-set-handle-multipart-parameter
679 mm-security-handle 'gnus-info "OK")
680 (mm-set-handle-multipart-parameter
681 mm-security-handle 'gnus-details
682 (concat decrypt-status
683 (when (stringp (car handles))
684 "\n" (mm-handle-multipart-ctl-parameter
685 handles 'gnus-details))))
686 (if (listp (car handles))
689 (mm-set-handle-multipart-parameter
690 mm-security-handle 'gnus-info "Failed")
691 (throw 'error handle))))))
693 (defun mml2015-pgg-clear-decrypt ()
694 (let ((pgg-errors-buffer mml2015-result-buffer))
696 (pgg-decrypt-region (point-min) (point-max))
697 (mm-set-handle-multipart-parameter
698 mm-security-handle 'gnus-details
699 (with-current-buffer mml2015-result-buffer
703 (insert-buffer pgg-output-buffer)
704 (mm-set-handle-multipart-parameter
705 mm-security-handle 'gnus-info "OK"))
706 (mm-set-handle-multipart-parameter
707 mm-security-handle 'gnus-info "Failed"))))
709 (defun mml2015-pgg-verify (handle ctl)
710 (let ((pgg-errors-buffer mml2015-result-buffer)
711 signature-file part signature)
712 (if (or (null (setq part (mm-find-raw-part-by-type
713 ctl (or (mm-handle-multipart-ctl-parameter
715 "application/pgp-signature")
717 (null (setq signature (mm-find-part-by-type
718 (cdr handle) "application/pgp-signature" nil t))))
720 (mm-set-handle-multipart-parameter
721 mm-security-handle 'gnus-info "Corrupted")
725 ;; Convert <LF> to <CR><LF> in verify mode. Sign and
726 ;; clearsign use --textmode. The conversion is not necessary.
727 ;; In clearverify, the conversion is not necessary either.
728 (goto-char (point-min))
731 (unless (eq (char-before) ?\r)
735 (with-temp-file (setq signature-file (mm-make-temp-file "pgg"))
736 (mm-insert-part signature))
737 (if (condition-case err
739 (pgg-verify-region (point-min) (point-max) signature-file t)
740 (mm-set-handle-multipart-parameter
741 mm-security-handle 'gnus-details
742 (with-current-buffer pgg-output-buffer
745 (mm-set-handle-multipart-parameter
746 mm-security-handle 'gnus-details (mml2015-format-error err))
749 (mm-set-handle-multipart-parameter
750 mm-security-handle 'gnus-details "Quit.")
753 (delete-file signature-file)
754 (mm-set-handle-multipart-parameter
755 mm-security-handle 'gnus-info
756 (with-current-buffer pgg-output-buffer
757 (mml2015-gpg-extract-signature-details))))
758 (delete-file signature-file)
759 (mm-set-handle-multipart-parameter
760 mm-security-handle 'gnus-info "Failed")))))
763 (defun mml2015-pgg-clear-verify ()
764 (let ((pgg-errors-buffer mml2015-result-buffer)
765 (text (current-buffer)))
766 (if (condition-case err
768 (mm-with-unibyte-buffer
770 (pgg-verify-region (point-min) (point-max) nil t))
771 (mm-set-handle-multipart-parameter
772 mm-security-handle 'gnus-details
773 (with-current-buffer mml2015-result-buffer
776 (mm-set-handle-multipart-parameter
777 mm-security-handle 'gnus-details (mml2015-format-error err))
780 (mm-set-handle-multipart-parameter
781 mm-security-handle 'gnus-details "Quit.")
783 (mm-set-handle-multipart-parameter
784 mm-security-handle 'gnus-info
785 (with-current-buffer pgg-output-buffer
786 (mml2015-gpg-extract-signature-details)))
787 (mm-set-handle-multipart-parameter
788 mm-security-handle 'gnus-info "Failed"))))
790 (defun mml2015-pgg-sign (cont)
791 (let ((pgg-errors-buffer mml2015-result-buffer)
792 (boundary (funcall mml-boundary-function (incf mml-multipart-number))))
793 (unless (pgg-sign-region (point-min) (point-max))
794 (pop-to-buffer mml2015-result-buffer)
795 (error "Sign error"))
796 (goto-char (point-min))
797 (insert (format "Content-Type: multipart/signed; boundary=\"%s\";\n"
799 ;;; FIXME: what is the micalg?
800 (insert "\tmicalg=pgp-sha1; protocol=\"application/pgp-signature\"\n")
801 (insert (format "\n--%s\n" boundary))
802 (goto-char (point-max))
803 (insert (format "\n--%s\n" boundary))
804 (insert "Content-Type: application/pgp-signature\n\n")
805 (insert-buffer pgg-output-buffer)
806 (goto-char (point-max))
807 (insert (format "--%s--\n" boundary))
808 (goto-char (point-max))))
810 (defun mml2015-pgg-encrypt (cont &optional sign)
811 (let ((pgg-errors-buffer mml2015-result-buffer)
812 (boundary (funcall mml-boundary-function (incf mml-multipart-number))))
813 (unless (pgg-encrypt-region (point-min) (point-max)
816 (message-options-get 'message-recipients)
817 (message-options-set 'message-recipients
818 (read-string "Recipients: ")))
820 (pop-to-buffer mml2015-result-buffer)
821 (error "Encrypt error"))
822 (delete-region (point-min) (point-max))
823 (goto-char (point-min))
824 (insert (format "Content-Type: multipart/encrypted; boundary=\"%s\";\n"
826 (insert "\tprotocol=\"application/pgp-encrypted\"\n\n")
827 (insert (format "--%s\n" boundary))
828 (insert "Content-Type: application/pgp-encrypted\n\n")
829 (insert "Version: 1\n\n")
830 (insert (format "--%s\n" boundary))
831 (insert "Content-Type: application/octet-stream\n\n")
832 (insert-buffer pgg-output-buffer)
833 (goto-char (point-max))
834 (insert (format "--%s--\n" boundary))
835 (goto-char (point-max))))
839 (defun mml2015-clean-buffer ()
840 (if (gnus-buffer-live-p mml2015-result-buffer)
841 (with-current-buffer mml2015-result-buffer
844 (setq mml2015-result-buffer
845 (gnus-get-buffer-create "*MML2015 Result*"))
848 (defsubst mml2015-clear-decrypt-function ()
849 (nth 6 (assq mml2015-use mml2015-function-alist)))
851 (defsubst mml2015-clear-verify-function ()
852 (nth 5 (assq mml2015-use mml2015-function-alist)))
855 (defun mml2015-decrypt (handle ctl)
856 (mml2015-clean-buffer)
857 (let ((func (nth 4 (assq mml2015-use mml2015-function-alist))))
859 (funcall func handle ctl)
863 (defun mml2015-decrypt-test (handle ctl)
867 (defun mml2015-verify (handle ctl)
868 (mml2015-clean-buffer)
869 (let ((func (nth 3 (assq mml2015-use mml2015-function-alist))))
871 (funcall func handle ctl)
875 (defun mml2015-verify-test (handle ctl)
879 (defun mml2015-encrypt (cont &optional sign)
880 (mml2015-clean-buffer)
881 (let ((func (nth 2 (assq mml2015-use mml2015-function-alist))))
883 (funcall func cont sign)
884 (error "Cannot find encrypt function"))))
887 (defun mml2015-sign (cont)
888 (mml2015-clean-buffer)
889 (let ((func (nth 1 (assq mml2015-use mml2015-function-alist))))
892 (error "Cannot find sign function"))))
895 (defun mml2015-self-encrypt ()
896 (mml2015-encrypt nil))
900 ;;; mml2015.el ends here