diff options
| author | Lars Ingebrigtsen | 2019-09-30 08:41:43 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-09-30 08:41:43 +0200 |
| commit | 5d33839c3fc40308cd29dbd0991888ead81fbfa7 (patch) | |
| tree | 47abda629562e94d15820ee3b74a7e3b4bead5c4 | |
| parent | 542b78eddeba3f020349c2d02ba2d21e8613d99d (diff) | |
| download | emacs-5d33839c3fc40308cd29dbd0991888ead81fbfa7.tar.gz emacs-5d33839c3fc40308cd29dbd0991888ead81fbfa7.zip | |
Refactor mm-decode and friends to be explicit about when errors happen
* lisp/gnus/mm-decode.el (mm-sec-status):
(mm-sec-error): New functions to handle decryption problems more
explicitly (bug#18393).
(mm-possibly-verify-or-decrypt): Use the `sec-error' data to
determine whether the operation failed or not.
* lisp/gnus/mml-smime.el: Ditto.
* lisp/gnus/mml2015.el: Used throughout.
| -rw-r--r-- | lisp/gnus/mm-decode.el | 34 | ||||
| -rw-r--r-- | lisp/gnus/mm-uu.el | 4 | ||||
| -rw-r--r-- | lisp/gnus/mml-smime.el | 42 | ||||
| -rw-r--r-- | lisp/gnus/mml2015.el | 215 |
4 files changed, 123 insertions, 172 deletions
diff --git a/lisp/gnus/mm-decode.el b/lisp/gnus/mm-decode.el index 3de7a0464bb..22e7e118e2e 100644 --- a/lisp/gnus/mm-decode.el +++ b/lisp/gnus/mm-decode.el | |||
| @@ -1646,14 +1646,22 @@ If RECURSIVE, search recursively." | |||
| 1646 | (setq result (buffer-string)))))) | 1646 | (setq result (buffer-string)))))) |
| 1647 | result)) | 1647 | result)) |
| 1648 | 1648 | ||
| 1649 | (defvar mm-security-handle nil) | ||
| 1650 | |||
| 1651 | (defsubst mm-set-handle-multipart-parameter (handle parameter value) | 1649 | (defsubst mm-set-handle-multipart-parameter (handle parameter value) |
| 1652 | ;; HANDLE could be a CTL. | 1650 | ;; HANDLE could be a CTL. |
| 1653 | (when handle | 1651 | (when handle |
| 1654 | (put-text-property 0 (length (car handle)) parameter value | 1652 | (put-text-property 0 (length (car handle)) parameter value |
| 1655 | (car handle)))) | 1653 | (car handle)))) |
| 1656 | 1654 | ||
| 1655 | ;; Interface functions and variables for the decryption/verification | ||
| 1656 | ;; functions. | ||
| 1657 | (defvar mm-security-handle nil) | ||
| 1658 | (defun mm-sec-status (&rest keys) | ||
| 1659 | (cl-loop for (key val) on keys by #'cddr | ||
| 1660 | do (mm-set-handle-multipart-parameter mm-security-handle key val))) | ||
| 1661 | |||
| 1662 | (defun mm-sec-error (&rest keys) | ||
| 1663 | (apply #'mm-sec-status (append '(sec-error t) keys))) | ||
| 1664 | |||
| 1657 | (autoload 'mm-view-pkcs7 "mm-view") | 1665 | (autoload 'mm-view-pkcs7 "mm-view") |
| 1658 | 1666 | ||
| 1659 | (defun mm-possibly-verify-or-decrypt (parts ctl &optional from) | 1667 | (defun mm-possibly-verify-or-decrypt (parts ctl &optional from) |
| @@ -1706,9 +1714,8 @@ If RECURSIVE, search recursively." | |||
| 1706 | (save-excursion | 1714 | (save-excursion |
| 1707 | (if func | 1715 | (if func |
| 1708 | (setq parts (funcall func parts ctl)) | 1716 | (setq parts (funcall func parts ctl)) |
| 1709 | (mm-set-handle-multipart-parameter | 1717 | (mm-sec-error 'gnus-details |
| 1710 | mm-security-handle 'gnus-details | 1718 | (format "Unknown sign protocol (%s)" protocol)))))) |
| 1711 | (format "Unknown sign protocol (%s)" protocol)))))) | ||
| 1712 | ((equal subtype "encrypted") | 1719 | ((equal subtype "encrypted") |
| 1713 | (unless (setq protocol | 1720 | (unless (setq protocol |
| 1714 | (mm-handle-multipart-ctl-parameter ctl 'protocol)) | 1721 | (mm-handle-multipart-ctl-parameter ctl 'protocol)) |
| @@ -1738,22 +1745,23 @@ If RECURSIVE, search recursively." | |||
| 1738 | (save-excursion | 1745 | (save-excursion |
| 1739 | (if func | 1746 | (if func |
| 1740 | (setq parts (funcall func parts ctl)) | 1747 | (setq parts (funcall func parts ctl)) |
| 1741 | (mm-set-handle-multipart-parameter | 1748 | (mm-sec-error |
| 1742 | mm-security-handle 'gnus-details | 1749 | 'gnus-details |
| 1743 | (format "Unknown encrypt protocol (%s)" protocol))))))) | 1750 | (format "Unknown encrypt protocol (%s)" protocol))))))) |
| 1744 | ;; Check the results (which are now in `parts'). | 1751 | ;; Check the results (which are now in `parts'). |
| 1745 | (let ((info (get-text-property 0 'gnus-info (car mm-security-handle)))) | 1752 | (let ((err (get-text-property 0 'sec-error (car mm-security-handle)))) |
| 1746 | (if (or (not info) | 1753 | (if (or (not err) |
| 1747 | (equal info "") | 1754 | (not (equal subtype "encrypted"))) |
| 1748 | (not (equal subtype "encrypted")) | ||
| 1749 | (member "OK" (split-string info "\n"))) | ||
| 1750 | parts | 1755 | parts |
| 1751 | ;; We had an error during decryption. Report what it is. | 1756 | ;; We had an error during decryption. Report what it is. |
| 1752 | (list | 1757 | (list |
| 1753 | (mm-make-handle | 1758 | (mm-make-handle |
| 1754 | (with-current-buffer (generate-new-buffer " *mm*") | 1759 | (with-current-buffer (generate-new-buffer " *mm*") |
| 1755 | (insert "Error! Result from decryption:\n\n" | 1760 | (insert "Error! Result from decryption:\n\n" |
| 1756 | info "\n\n" | 1761 | (or (get-text-property 0 'gnus-details |
| 1762 | (car mm-security-handle)) | ||
| 1763 | "") | ||
| 1764 | "\n\n" | ||
| 1757 | (or (get-text-property 0 'gnus-details | 1765 | (or (get-text-property 0 'gnus-details |
| 1758 | (car mm-security-handle)) | 1766 | (car mm-security-handle)) |
| 1759 | "")) | 1767 | "")) |
diff --git a/lisp/gnus/mm-uu.el b/lisp/gnus/mm-uu.el index a00d64015f2..6143b41bbc1 100644 --- a/lisp/gnus/mm-uu.el +++ b/lisp/gnus/mm-uu.el | |||
| @@ -509,8 +509,8 @@ apply the face `mm-uu-extract'." | |||
| 509 | 'iso-8859-1))) | 509 | 'iso-8859-1))) |
| 510 | (funcall (mml2015-clear-verify-function)))) | 510 | (funcall (mml2015-clear-verify-function)))) |
| 511 | (when (and mml2015-use (null (mml2015-clear-verify-function))) | 511 | (when (and mml2015-use (null (mml2015-clear-verify-function))) |
| 512 | (mm-set-handle-multipart-parameter | 512 | (mml2015--status |
| 513 | mm-security-handle 'gnus-details | 513 | 'gnus-details |
| 514 | (format-message | 514 | (format-message |
| 515 | "Clear verification not supported by `%s'.\n" mml2015-use))) | 515 | "Clear verification not supported by `%s'.\n" mml2015-use))) |
| 516 | (mml2015-extract-cleartext-signature)) | 516 | (mml2015-extract-cleartext-signature)) |
diff --git a/lisp/gnus/mml-smime.el b/lisp/gnus/mml-smime.el index b2e9b783522..659f2b95289 100644 --- a/lisp/gnus/mml-smime.el +++ b/lisp/gnus/mml-smime.el | |||
| @@ -274,10 +274,9 @@ Whether the passphrase is cached at all is controlled by | |||
| 274 | (if (not good-signature) | 274 | (if (not good-signature) |
| 275 | (progn | 275 | (progn |
| 276 | ;; we couldn't verify message, fail with openssl output as message | 276 | ;; we couldn't verify message, fail with openssl output as message |
| 277 | (mm-set-handle-multipart-parameter | 277 | (mm-sec-error |
| 278 | mm-security-handle 'gnus-info "Failed") | 278 | 'gnus-info "Failed" |
| 279 | (mm-set-handle-multipart-parameter | 279 | 'gnus-details |
| 280 | mm-security-handle 'gnus-details | ||
| 281 | (concat "OpenSSL failed to verify message integrity:\n" | 280 | (concat "OpenSSL failed to verify message integrity:\n" |
| 282 | "-------------------------------------------\n" | 281 | "-------------------------------------------\n" |
| 283 | openssl-output))) | 282 | openssl-output))) |
| @@ -290,19 +289,18 @@ Whether the passphrase is cached at all is controlled by | |||
| 290 | (while (re-search-forward "-----END CERTIFICATE-----" nil t) | 289 | (while (re-search-forward "-----END CERTIFICATE-----" nil t) |
| 291 | (when (smime-pkcs7-email-region (point-min) (point)) | 290 | (when (smime-pkcs7-email-region (point-min) (point)) |
| 292 | (setq addresses (append (smime-buffer-as-string-region | 291 | (setq addresses (append (smime-buffer-as-string-region |
| 293 | (point-min) (point)) addresses))) | 292 | (point-min) (point)) |
| 293 | addresses))) | ||
| 294 | (delete-region (point-min) (point))) | 294 | (delete-region (point-min) (point))) |
| 295 | (setq addresses (mapcar 'downcase addresses)))) | 295 | (setq addresses (mapcar 'downcase addresses)))) |
| 296 | (if (not (member (downcase (or (mm-handle-multipart-from ctl) "")) addresses)) | 296 | (if (not (member (downcase (or (mm-handle-multipart-from ctl) "")) |
| 297 | (mm-set-handle-multipart-parameter | 297 | addresses)) |
| 298 | mm-security-handle 'gnus-info "Sender address forged") | 298 | (mm-sec-error 'gnus-info "Sender address forged") |
| 299 | (if good-certificate | 299 | (if good-certificate |
| 300 | (mm-set-handle-multipart-parameter | 300 | (mm-sec-status 'gnus-info "Ok (sender authenticated)") |
| 301 | mm-security-handle 'gnus-info "Ok (sender authenticated)") | 301 | (mm-sec-status 'gnus-info "Ok (sender not trusted)"))) |
| 302 | (mm-set-handle-multipart-parameter | 302 | (mm-sec-status |
| 303 | mm-security-handle 'gnus-info "Ok (sender not trusted)"))) | 303 | 'gnus-details |
| 304 | (mm-set-handle-multipart-parameter | ||
| 305 | mm-security-handle 'gnus-details | ||
| 306 | (concat "Sender claimed to be: " (mm-handle-multipart-from ctl) "\n" | 304 | (concat "Sender claimed to be: " (mm-handle-multipart-from ctl) "\n" |
| 307 | (if addresses | 305 | (if addresses |
| 308 | (concat "Addresses in certificate: " | 306 | (concat "Addresses in certificate: " |
| @@ -411,24 +409,20 @@ Content-Disposition: attachment; filename=smime.p7m | |||
| 411 | (cdr handle) | 409 | (cdr handle) |
| 412 | "application/x-pkcs7-signature" | 410 | "application/x-pkcs7-signature" |
| 413 | nil t))))) | 411 | nil t))))) |
| 414 | (mm-set-handle-multipart-parameter | 412 | (mm-sec-error 'gnus-info "Corrupted") |
| 415 | mm-security-handle 'gnus-info "Corrupted") | ||
| 416 | (throw 'error handle)) | 413 | (throw 'error handle)) |
| 417 | (setq part (replace-regexp-in-string "\n" "\r\n" part) | 414 | (setq part (replace-regexp-in-string "\n" "\r\n" part) |
| 418 | context (epg-make-context 'CMS)) | 415 | context (epg-make-context 'CMS)) |
| 419 | (condition-case error | 416 | (condition-case error |
| 420 | (setq plain (epg-verify-string context (mm-get-part signature) part)) | 417 | (setq plain (epg-verify-string context (mm-get-part signature) part)) |
| 421 | (error | 418 | (error |
| 422 | (mm-set-handle-multipart-parameter | 419 | (mm-sec-error 'gnus-info "Failed") |
| 423 | mm-security-handle 'gnus-info "Failed") | ||
| 424 | (if (eq (car error) 'quit) | 420 | (if (eq (car error) 'quit) |
| 425 | (mm-set-handle-multipart-parameter | 421 | (mm-sec-status 'gnus-details "Quit.") |
| 426 | mm-security-handle 'gnus-details "Quit.") | 422 | (mm-sec-status 'gnus-details (format "%S" error))) |
| 427 | (mm-set-handle-multipart-parameter | ||
| 428 | mm-security-handle 'gnus-details (format "%S" error))) | ||
| 429 | (throw 'error handle))) | 423 | (throw 'error handle))) |
| 430 | (mm-set-handle-multipart-parameter | 424 | (mm-sec-status |
| 431 | mm-security-handle 'gnus-info | 425 | 'gnus-info |
| 432 | (epg-verify-result-to-string (epg-context-result-for context 'verify))) | 426 | (epg-verify-result-to-string (epg-context-result-for context 'verify))) |
| 433 | handle))) | 427 | handle))) |
| 434 | 428 | ||
diff --git a/lisp/gnus/mml2015.el b/lisp/gnus/mml2015.el index 45164ee8f65..c3cf31f1a3c 100644 --- a/lisp/gnus/mml2015.el +++ b/lisp/gnus/mml2015.el | |||
| @@ -191,8 +191,7 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 191 | (unless (setq child (mm-find-part-by-type | 191 | (unless (setq child (mm-find-part-by-type |
| 192 | (cdr handle) | 192 | (cdr handle) |
| 193 | "application/octet-stream" nil t)) | 193 | "application/octet-stream" nil t)) |
| 194 | (mm-set-handle-multipart-parameter | 194 | (mm-sec-error 'gnus-info "Corrupted") |
| 195 | mm-security-handle 'gnus-info "Corrupted") | ||
| 196 | (throw 'error handle)) | 195 | (throw 'error handle)) |
| 197 | (with-temp-buffer | 196 | (with-temp-buffer |
| 198 | (mm-insert-part child) | 197 | (mm-insert-part child) |
| @@ -200,21 +199,18 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 200 | (condition-case err | 199 | (condition-case err |
| 201 | (funcall mml2015-decrypt-function) | 200 | (funcall mml2015-decrypt-function) |
| 202 | (error | 201 | (error |
| 203 | (mm-set-handle-multipart-parameter | 202 | (mm-sec-error 'gnus-details (mml2015-format-error err)) |
| 204 | mm-security-handle 'gnus-details (mml2015-format-error err)) | ||
| 205 | nil) | 203 | nil) |
| 206 | (quit | 204 | (quit |
| 207 | (mm-set-handle-multipart-parameter | 205 | (mm-sec-error 'gnus-details "Quit.") |
| 208 | mm-security-handle 'gnus-details "Quit.") | ||
| 209 | nil))) | 206 | nil))) |
| 210 | (unless (car result) | 207 | (unless (car result) |
| 211 | (mm-set-handle-multipart-parameter | 208 | (mm-sec-error 'gnus-info "Failed") |
| 212 | mm-security-handle 'gnus-info "Failed") | ||
| 213 | (throw 'error handle)) | 209 | (throw 'error handle)) |
| 214 | (setq handles (mm-dissect-buffer t))) | 210 | (setq handles (mm-dissect-buffer t))) |
| 215 | (mm-destroy-parts handle) | 211 | (mm-destroy-parts handle) |
| 216 | (mm-set-handle-multipart-parameter | 212 | (mm-sec-status |
| 217 | mm-security-handle 'gnus-info | 213 | 'gnus-info |
| 218 | (concat "OK" | 214 | (concat "OK" |
| 219 | (let ((sig (with-current-buffer mml2015-result-buffer | 215 | (let ((sig (with-current-buffer mml2015-result-buffer |
| 220 | (mml2015-gpg-extract-signature-details)))) | 216 | (mml2015-gpg-extract-signature-details)))) |
| @@ -281,18 +277,14 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 281 | (condition-case err | 277 | (condition-case err |
| 282 | (funcall mml2015-decrypt-function) | 278 | (funcall mml2015-decrypt-function) |
| 283 | (error | 279 | (error |
| 284 | (mm-set-handle-multipart-parameter | 280 | (mm-sec-error 'gnus-details (mml2015-format-error err)) |
| 285 | mm-security-handle 'gnus-details (mml2015-format-error err)) | ||
| 286 | nil) | 281 | nil) |
| 287 | (quit | 282 | (quit |
| 288 | (mm-set-handle-multipart-parameter | 283 | (mm-sec-error 'gnus-details "Quit.") |
| 289 | mm-security-handle 'gnus-details "Quit.") | ||
| 290 | nil))) | 284 | nil))) |
| 291 | (if (car result) | 285 | (if (car result) |
| 292 | (mm-set-handle-multipart-parameter | 286 | (mm-sec-status 'gnus-info "OK") |
| 293 | mm-security-handle 'gnus-info "OK") | 287 | (mm-sec-error 'gnus-info "Failed")))) |
| 294 | (mm-set-handle-multipart-parameter | ||
| 295 | mm-security-handle 'gnus-info "Failed")))) | ||
| 296 | 288 | ||
| 297 | (defun mml2015-fix-micalg (alg) | 289 | (defun mml2015-fix-micalg (alg) |
| 298 | (and alg | 290 | (and alg |
| @@ -309,8 +301,7 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 309 | ctl 'protocol) | 301 | ctl 'protocol) |
| 310 | "application/pgp-signature") | 302 | "application/pgp-signature") |
| 311 | t)) | 303 | t)) |
| 312 | (mm-set-handle-multipart-parameter | 304 | (mm-sec-error 'gnus-info "Corrupted") |
| 313 | mm-security-handle 'gnus-info "Corrupted") | ||
| 314 | (throw 'error handle)) | 305 | (throw 'error handle)) |
| 315 | (with-temp-buffer | 306 | (with-temp-buffer |
| 316 | (insert "-----BEGIN PGP SIGNED MESSAGE-----\n") | 307 | (insert "-----BEGIN PGP SIGNED MESSAGE-----\n") |
| @@ -329,8 +320,7 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 329 | (forward-line))) | 320 | (forward-line))) |
| 330 | (unless (setq part (mm-find-part-by-type | 321 | (unless (setq part (mm-find-part-by-type |
| 331 | (cdr handle) "application/pgp-signature" nil t)) | 322 | (cdr handle) "application/pgp-signature" nil t)) |
| 332 | (mm-set-handle-multipart-parameter | 323 | (mm-sec-error 'gnus-info "Corrupted") |
| 333 | mm-security-handle 'gnus-info "Corrupted") | ||
| 334 | (throw 'error handle)) | 324 | (throw 'error handle)) |
| 335 | (save-restriction | 325 | (save-restriction |
| 336 | (narrow-to-region (point) (point)) | 326 | (narrow-to-region (point) (point)) |
| @@ -345,8 +335,8 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 345 | (prog1 | 335 | (prog1 |
| 346 | (funcall mml2015-verify-function) | 336 | (funcall mml2015-verify-function) |
| 347 | (if (get-buffer " *mailcrypt stderr temp") | 337 | (if (get-buffer " *mailcrypt stderr temp") |
| 348 | (mm-set-handle-multipart-parameter | 338 | (mm-sec-error |
| 349 | mm-security-handle 'gnus-details | 339 | 'gnus-details |
| 350 | (with-current-buffer " *mailcrypt stderr temp" | 340 | (with-current-buffer " *mailcrypt stderr temp" |
| 351 | (buffer-string)))) | 341 | (buffer-string)))) |
| 352 | (if (get-buffer " *mailcrypt stdout temp") | 342 | (if (get-buffer " *mailcrypt stdout temp") |
| @@ -358,18 +348,14 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 358 | (if (get-buffer mc-gpg-debug-buffer) | 348 | (if (get-buffer mc-gpg-debug-buffer) |
| 359 | (kill-buffer mc-gpg-debug-buffer))) | 349 | (kill-buffer mc-gpg-debug-buffer))) |
| 360 | (error | 350 | (error |
| 361 | (mm-set-handle-multipart-parameter | 351 | (mm-sec-error 'gnus-details (mml2015-format-error err)) |
| 362 | mm-security-handle 'gnus-details (mml2015-format-error err)) | ||
| 363 | nil) | 352 | nil) |
| 364 | (quit | 353 | (quit |
| 365 | (mm-set-handle-multipart-parameter | 354 | (mm-sec-error 'gnus-details "Quit.") |
| 366 | mm-security-handle 'gnus-details "Quit.") | ||
| 367 | nil)) | 355 | nil)) |
| 368 | (mm-set-handle-multipart-parameter | 356 | (mm-sec-error 'gnus-info "Failed") |
| 369 | mm-security-handle 'gnus-info "Failed") | ||
| 370 | (throw 'error handle)))) | 357 | (throw 'error handle)))) |
| 371 | (mm-set-handle-multipart-parameter | 358 | (mm-sec-status 'gnus-info "OK") |
| 372 | mm-security-handle 'gnus-info "OK") | ||
| 373 | handle))) | 359 | handle))) |
| 374 | 360 | ||
| 375 | (defun mml2015-mailcrypt-clear-verify () | 361 | (defun mml2015-mailcrypt-clear-verify () |
| @@ -378,8 +364,8 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 378 | (prog1 | 364 | (prog1 |
| 379 | (funcall mml2015-verify-function) | 365 | (funcall mml2015-verify-function) |
| 380 | (if (get-buffer " *mailcrypt stderr temp") | 366 | (if (get-buffer " *mailcrypt stderr temp") |
| 381 | (mm-set-handle-multipart-parameter | 367 | (mm-sec-error |
| 382 | mm-security-handle 'gnus-details | 368 | 'gnus-details |
| 383 | (with-current-buffer " *mailcrypt stderr temp" | 369 | (with-current-buffer " *mailcrypt stderr temp" |
| 384 | (buffer-string)))) | 370 | (buffer-string)))) |
| 385 | (if (get-buffer " *mailcrypt stdout temp") | 371 | (if (get-buffer " *mailcrypt stdout temp") |
| @@ -391,17 +377,13 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 391 | (if (get-buffer mc-gpg-debug-buffer) | 377 | (if (get-buffer mc-gpg-debug-buffer) |
| 392 | (kill-buffer mc-gpg-debug-buffer))) | 378 | (kill-buffer mc-gpg-debug-buffer))) |
| 393 | (error | 379 | (error |
| 394 | (mm-set-handle-multipart-parameter | 380 | (mm-sec-error 'gnus-details (mml2015-format-error err)) |
| 395 | mm-security-handle 'gnus-details (mml2015-format-error err)) | ||
| 396 | nil) | 381 | nil) |
| 397 | (quit | 382 | (quit |
| 398 | (mm-set-handle-multipart-parameter | 383 | (mm-sec-error 'gnus-details "Quit.") |
| 399 | mm-security-handle 'gnus-details "Quit.") | ||
| 400 | nil)) | 384 | nil)) |
| 401 | (mm-set-handle-multipart-parameter | 385 | (mm-sec-status 'gnus-info "OK") |
| 402 | mm-security-handle 'gnus-info "OK") | 386 | (mm-sec-error 'gnus-info "Failed"))) |
| 403 | (mm-set-handle-multipart-parameter | ||
| 404 | mm-security-handle 'gnus-info "Failed"))) | ||
| 405 | (mml2015-extract-cleartext-signature)) | 387 | (mml2015-extract-cleartext-signature)) |
| 406 | 388 | ||
| 407 | (defun mml2015-mailcrypt-sign (cont) | 389 | (defun mml2015-mailcrypt-sign (cont) |
| @@ -509,8 +491,7 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 509 | (unless (setq child (mm-find-part-by-type | 491 | (unless (setq child (mm-find-part-by-type |
| 510 | (cdr handle) | 492 | (cdr handle) |
| 511 | "application/octet-stream" nil t)) | 493 | "application/octet-stream" nil t)) |
| 512 | (mm-set-handle-multipart-parameter | 494 | (mm-sec-error 'gnus-info "Corrupted") |
| 513 | mm-security-handle 'gnus-info "Corrupted") | ||
| 514 | (throw 'error handle)) | 495 | (throw 'error handle)) |
| 515 | (with-temp-buffer | 496 | (with-temp-buffer |
| 516 | (mm-insert-part child) | 497 | (mm-insert-part child) |
| @@ -520,16 +501,12 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 520 | (setq decrypt-status | 501 | (setq decrypt-status |
| 521 | (with-current-buffer mml2015-result-buffer | 502 | (with-current-buffer mml2015-result-buffer |
| 522 | (buffer-string))) | 503 | (buffer-string))) |
| 523 | (mm-set-handle-multipart-parameter | 504 | (mm-sec-status 'gnus-details decrypt-status)) |
| 524 | mm-security-handle 'gnus-details | ||
| 525 | decrypt-status)) | ||
| 526 | (error | 505 | (error |
| 527 | (mm-set-handle-multipart-parameter | 506 | (mm-sec-error 'gnus-details (mml2015-format-error err)) |
| 528 | mm-security-handle 'gnus-details (mml2015-format-error err)) | ||
| 529 | nil) | 507 | nil) |
| 530 | (quit | 508 | (quit |
| 531 | (mm-set-handle-multipart-parameter | 509 | (mm-sec-error 'gnus-details "Quit.") |
| 532 | mm-security-handle 'gnus-details "Quit.") | ||
| 533 | nil)) | 510 | nil)) |
| 534 | (with-current-buffer pgg-output-buffer | 511 | (with-current-buffer pgg-output-buffer |
| 535 | (goto-char (point-min)) | 512 | (goto-char (point-min)) |
| @@ -537,27 +514,24 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 537 | (replace-match "\n" t t)) | 514 | (replace-match "\n" t t)) |
| 538 | (setq handles (mm-dissect-buffer t)) | 515 | (setq handles (mm-dissect-buffer t)) |
| 539 | (mm-destroy-parts handle) | 516 | (mm-destroy-parts handle) |
| 540 | (mm-set-handle-multipart-parameter | 517 | (mm-sec-status 'gnus-info "OK" |
| 541 | mm-security-handle 'gnus-info "OK") | 518 | 'gnus-details |
| 542 | (mm-set-handle-multipart-parameter | 519 | (concat decrypt-status |
| 543 | mm-security-handle 'gnus-details | 520 | (when (stringp (car handles)) |
| 544 | (concat decrypt-status | 521 | "\n" (mm-handle-multipart-ctl-parameter |
| 545 | (when (stringp (car handles)) | 522 | handles 'gnus-details)))) |
| 546 | "\n" (mm-handle-multipart-ctl-parameter | ||
| 547 | handles 'gnus-details)))) | ||
| 548 | (if (listp (car handles)) | 523 | (if (listp (car handles)) |
| 549 | handles | 524 | handles |
| 550 | (list handles))) | 525 | (list handles))) |
| 551 | (mm-set-handle-multipart-parameter | 526 | (mm-sec-error 'gnus-info "Failed") |
| 552 | mm-security-handle 'gnus-info "Failed") | ||
| 553 | (throw 'error handle)))))) | 527 | (throw 'error handle)))))) |
| 554 | 528 | ||
| 555 | (defun mml2015-pgg-clear-decrypt () | 529 | (defun mml2015-pgg-clear-decrypt () |
| 556 | (let ((pgg-errors-buffer mml2015-result-buffer)) | 530 | (let ((pgg-errors-buffer mml2015-result-buffer)) |
| 557 | (if (prog1 | 531 | (if (prog1 |
| 558 | (pgg-decrypt-region (point-min) (point-max)) | 532 | (pgg-decrypt-region (point-min) (point-max)) |
| 559 | (mm-set-handle-multipart-parameter | 533 | (mm-sec-status |
| 560 | mm-security-handle 'gnus-details | 534 | 'gnus-details |
| 561 | (with-current-buffer mml2015-result-buffer | 535 | (with-current-buffer mml2015-result-buffer |
| 562 | (buffer-string)))) | 536 | (buffer-string)))) |
| 563 | (progn | 537 | (progn |
| @@ -568,10 +542,8 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 568 | (goto-char (point-min)) | 542 | (goto-char (point-min)) |
| 569 | (while (search-forward "\r\n" nil t) | 543 | (while (search-forward "\r\n" nil t) |
| 570 | (replace-match "\n" t t)) | 544 | (replace-match "\n" t t)) |
| 571 | (mm-set-handle-multipart-parameter | 545 | (mm-sec-status 'gnus-info "OK")) |
| 572 | mm-security-handle 'gnus-info "OK")) | 546 | (mm-sec-error 'gnus-info "Failed")))) |
| 573 | (mm-set-handle-multipart-parameter | ||
| 574 | mm-security-handle 'gnus-info "Failed")))) | ||
| 575 | 547 | ||
| 576 | (defun mml2015-pgg-verify (handle ctl) | 548 | (defun mml2015-pgg-verify (handle ctl) |
| 577 | (let ((pgg-errors-buffer mml2015-result-buffer) | 549 | (let ((pgg-errors-buffer mml2015-result-buffer) |
| @@ -581,11 +553,11 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 581 | ctl 'protocol) | 553 | ctl 'protocol) |
| 582 | "application/pgp-signature") | 554 | "application/pgp-signature") |
| 583 | t))) | 555 | t))) |
| 584 | (null (setq signature (mm-find-part-by-type | 556 | (null (setq signature |
| 585 | (cdr handle) "application/pgp-signature" nil t)))) | 557 | (mm-find-part-by-type |
| 558 | (cdr handle) "application/pgp-signature" nil t)))) | ||
| 586 | (progn | 559 | (progn |
| 587 | (mm-set-handle-multipart-parameter | 560 | (mm-sec-error 'gnus-info "Corrupted") |
| 588 | mm-security-handle 'gnus-info "Corrupted") | ||
| 589 | handle) | 561 | handle) |
| 590 | (with-temp-buffer | 562 | (with-temp-buffer |
| 591 | (insert part) | 563 | (insert part) |
| @@ -607,29 +579,26 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 607 | (goto-char (point-min)) | 579 | (goto-char (point-min)) |
| 608 | (while (search-forward "\r\n" nil t) | 580 | (while (search-forward "\r\n" nil t) |
| 609 | (replace-match "\n" t t)) | 581 | (replace-match "\n" t t)) |
| 610 | (mm-set-handle-multipart-parameter | 582 | (mm-sec-status |
| 611 | mm-security-handle 'gnus-details | 583 | 'gnus-details |
| 612 | (concat (with-current-buffer pgg-output-buffer | 584 | (concat (with-current-buffer pgg-output-buffer |
| 613 | (buffer-string)) | 585 | (buffer-string)) |
| 614 | (with-current-buffer pgg-errors-buffer | 586 | (with-current-buffer pgg-errors-buffer |
| 615 | (buffer-string))))) | 587 | (buffer-string))))) |
| 616 | (error | 588 | (error |
| 617 | (mm-set-handle-multipart-parameter | 589 | (mm-sec-error 'gnus-details (mml2015-format-error err)) |
| 618 | mm-security-handle 'gnus-details (mml2015-format-error err)) | ||
| 619 | nil) | 590 | nil) |
| 620 | (quit | 591 | (quit |
| 621 | (mm-set-handle-multipart-parameter | 592 | (mm-sec-error 'gnus-details "Quit.") |
| 622 | mm-security-handle 'gnus-details "Quit.") | ||
| 623 | nil)) | 593 | nil)) |
| 624 | (progn | 594 | (progn |
| 625 | (delete-file signature-file) | 595 | (delete-file signature-file) |
| 626 | (mm-set-handle-multipart-parameter | 596 | (mm-sec-error |
| 627 | mm-security-handle 'gnus-info | 597 | 'gnus-info |
| 628 | (with-current-buffer pgg-errors-buffer | 598 | (with-current-buffer pgg-errors-buffer |
| 629 | (mml2015-gpg-extract-signature-details)))) | 599 | (mml2015-gpg-extract-signature-details)))) |
| 630 | (delete-file signature-file) | 600 | (delete-file signature-file) |
| 631 | (mm-set-handle-multipart-parameter | 601 | (mm-sec-error 'gnus-info "Failed"))))) |
| 632 | mm-security-handle 'gnus-info "Failed"))))) | ||
| 633 | handle) | 602 | handle) |
| 634 | 603 | ||
| 635 | (defun mml2015-pgg-clear-verify () | 604 | (defun mml2015-pgg-clear-verify () |
| @@ -644,26 +613,23 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 644 | (goto-char (point-min)) | 613 | (goto-char (point-min)) |
| 645 | (while (search-forward "\r\n" nil t) | 614 | (while (search-forward "\r\n" nil t) |
| 646 | (replace-match "\n" t t)) | 615 | (replace-match "\n" t t)) |
| 647 | (mm-set-handle-multipart-parameter | 616 | (mm-sec-status |
| 648 | mm-security-handle 'gnus-details | 617 | 'gnus-details |
| 649 | (concat (with-current-buffer pgg-output-buffer | 618 | (concat (with-current-buffer pgg-output-buffer |
| 650 | (buffer-string)) | 619 | (buffer-string)) |
| 651 | (with-current-buffer pgg-errors-buffer | 620 | (with-current-buffer pgg-errors-buffer |
| 652 | (buffer-string))))) | 621 | (buffer-string))))) |
| 653 | (error | 622 | (error |
| 654 | (mm-set-handle-multipart-parameter | 623 | (mm-sec-error 'gnus-details (mml2015-format-error err)) |
| 655 | mm-security-handle 'gnus-details (mml2015-format-error err)) | ||
| 656 | nil) | 624 | nil) |
| 657 | (quit | 625 | (quit |
| 658 | (mm-set-handle-multipart-parameter | 626 | (mm-sec-error 'gnus-details "Quit.") |
| 659 | mm-security-handle 'gnus-details "Quit.") | ||
| 660 | nil)) | 627 | nil)) |
| 661 | (mm-set-handle-multipart-parameter | 628 | (mm-sec-status |
| 662 | mm-security-handle 'gnus-info | 629 | 'gnus-info |
| 663 | (with-current-buffer pgg-errors-buffer | 630 | (with-current-buffer pgg-errors-buffer |
| 664 | (mml2015-gpg-extract-signature-details))) | 631 | (mml2015-gpg-extract-signature-details))) |
| 665 | (mm-set-handle-multipart-parameter | 632 | (mm-sec-error 'gnus-info "Failed"))) |
| 666 | mm-security-handle 'gnus-info "Failed"))) | ||
| 667 | (mml2015-extract-cleartext-signature)) | 633 | (mml2015-extract-cleartext-signature)) |
| 668 | 634 | ||
| 669 | (defun mml2015-pgg-sign (cont) | 635 | (defun mml2015-pgg-sign (cont) |
| @@ -807,8 +773,7 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 807 | (unless (setq child (mm-find-part-by-type | 773 | (unless (setq child (mm-find-part-by-type |
| 808 | (cdr handle) | 774 | (cdr handle) |
| 809 | "application/octet-stream" nil t)) | 775 | "application/octet-stream" nil t)) |
| 810 | (mm-set-handle-multipart-parameter | 776 | (mm-sec-error 'gnus-info "Corrupted") |
| 811 | mm-security-handle 'gnus-info "Corrupted") | ||
| 812 | (throw 'error handle)) | 777 | (throw 'error handle)) |
| 813 | (setq context (epg-make-context)) | 778 | (setq context (epg-make-context)) |
| 814 | (if (or mml2015-cache-passphrase mml-secure-cache-passphrase) | 779 | (if (or mml2015-cache-passphrase mml-secure-cache-passphrase) |
| @@ -820,13 +785,10 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 820 | mml-secure-secret-key-id-list nil) | 785 | mml-secure-secret-key-id-list nil) |
| 821 | (error | 786 | (error |
| 822 | (mml-secure-clear-secret-key-id-list) | 787 | (mml-secure-clear-secret-key-id-list) |
| 823 | (mm-set-handle-multipart-parameter | 788 | (mm-sec-error 'gnus-info "Failed") |
| 824 | mm-security-handle 'gnus-info "Failed") | ||
| 825 | (if (eq (car error) 'quit) | 789 | (if (eq (car error) 'quit) |
| 826 | (mm-set-handle-multipart-parameter | 790 | (mm-sec-status 'gnus-details "Quit.") |
| 827 | mm-security-handle 'gnus-details "Quit.") | 791 | (mm-sec-status 'gnus-details (mml2015-format-error error))) |
| 828 | (mm-set-handle-multipart-parameter | ||
| 829 | mm-security-handle 'gnus-details (mml2015-format-error error))) | ||
| 830 | (throw 'error handle))) | 792 | (throw 'error handle))) |
| 831 | (with-temp-buffer | 793 | (with-temp-buffer |
| 832 | (insert plain) | 794 | (insert plain) |
| @@ -836,16 +798,15 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 836 | (setq handles (mm-dissect-buffer t)) | 798 | (setq handles (mm-dissect-buffer t)) |
| 837 | (mm-destroy-parts handle) | 799 | (mm-destroy-parts handle) |
| 838 | (if (epg-context-result-for context 'verify) | 800 | (if (epg-context-result-for context 'verify) |
| 839 | (mm-set-handle-multipart-parameter | 801 | (mm-sec-status |
| 840 | mm-security-handle 'gnus-info | 802 | 'gnus-info |
| 841 | (concat "OK\n" | 803 | (concat "OK\n" |
| 842 | (mml2015-epg-verify-result-to-string | 804 | (mml2015-epg-verify-result-to-string |
| 843 | (epg-context-result-for context 'verify)))) | 805 | (epg-context-result-for context 'verify)))) |
| 844 | (mm-set-handle-multipart-parameter | 806 | (mm-sec-status 'gnus-info "OK")) |
| 845 | mm-security-handle 'gnus-info "OK")) | ||
| 846 | (if (stringp (car handles)) | 807 | (if (stringp (car handles)) |
| 847 | (mm-set-handle-multipart-parameter | 808 | (mm-sec-status |
| 848 | mm-security-handle 'gnus-details | 809 | 'gnus-details |
| 849 | (mm-handle-multipart-ctl-parameter handles 'gnus-details)))) | 810 | (mm-handle-multipart-ctl-parameter handles 'gnus-details)))) |
| 850 | (if (listp (car handles)) | 811 | (if (listp (car handles)) |
| 851 | handles | 812 | handles |
| @@ -864,13 +825,10 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 864 | mml-secure-secret-key-id-list nil) | 825 | mml-secure-secret-key-id-list nil) |
| 865 | (error | 826 | (error |
| 866 | (mml-secure-clear-secret-key-id-list) | 827 | (mml-secure-clear-secret-key-id-list) |
| 867 | (mm-set-handle-multipart-parameter | 828 | (mm-sec-error 'gnus-info "Failed") |
| 868 | mm-security-handle 'gnus-info "Failed") | ||
| 869 | (if (eq (car error) 'quit) | 829 | (if (eq (car error) 'quit) |
| 870 | (mm-set-handle-multipart-parameter | 830 | (mm-sec-status 'gnus-details "Quit.") |
| 871 | mm-security-handle 'gnus-details "Quit.") | 831 | (mm-sec-status 'gnus-details (mml2015-format-error error))))) |
| 872 | (mm-set-handle-multipart-parameter | ||
| 873 | mm-security-handle 'gnus-details (mml2015-format-error error))))) | ||
| 874 | (when plain | 832 | (when plain |
| 875 | (erase-buffer) | 833 | (erase-buffer) |
| 876 | ;; Treat data which epg returns as a unibyte string. | 834 | ;; Treat data which epg returns as a unibyte string. |
| @@ -879,11 +837,10 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 879 | (goto-char (point-min)) | 837 | (goto-char (point-min)) |
| 880 | (while (search-forward "\r\n" nil t) | 838 | (while (search-forward "\r\n" nil t) |
| 881 | (replace-match "\n" t t)) | 839 | (replace-match "\n" t t)) |
| 882 | (mm-set-handle-multipart-parameter | 840 | (mm-sec-status 'gnus-info "OK") |
| 883 | mm-security-handle 'gnus-info "OK") | ||
| 884 | (if (epg-context-result-for context 'verify) | 841 | (if (epg-context-result-for context 'verify) |
| 885 | (mm-set-handle-multipart-parameter | 842 | (mm-sec-status |
| 886 | mm-security-handle 'gnus-details | 843 | 'gnus-details |
| 887 | (mml2015-epg-verify-result-to-string | 844 | (mml2015-epg-verify-result-to-string |
| 888 | (epg-context-result-for context 'verify))))))) | 845 | (epg-context-result-for context 'verify))))))) |
| 889 | 846 | ||
| @@ -899,8 +856,7 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 899 | (null (setq signature (mm-find-part-by-type | 856 | (null (setq signature (mm-find-part-by-type |
| 900 | (cdr handle) "application/pgp-signature" | 857 | (cdr handle) "application/pgp-signature" |
| 901 | nil t)))) | 858 | nil t)))) |
| 902 | (mm-set-handle-multipart-parameter | 859 | (mm-sec-error 'gnus-info "Corrupted") |
| 903 | mm-security-handle 'gnus-info "Corrupted") | ||
| 904 | (throw 'error handle)) | 860 | (throw 'error handle)) |
| 905 | (setq part (replace-regexp-in-string "\n" "\r\n" part) | 861 | (setq part (replace-regexp-in-string "\n" "\r\n" part) |
| 906 | signature (mm-get-part signature) | 862 | signature (mm-get-part signature) |
| @@ -908,16 +864,12 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 908 | (condition-case error | 864 | (condition-case error |
| 909 | (setq plain (epg-verify-string context signature part)) | 865 | (setq plain (epg-verify-string context signature part)) |
| 910 | (error | 866 | (error |
| 911 | (mm-set-handle-multipart-parameter | 867 | (mm-sec-error 'gnus-info "Failed") |
| 912 | mm-security-handle 'gnus-info "Failed") | ||
| 913 | (if (eq (car error) 'quit) | 868 | (if (eq (car error) 'quit) |
| 914 | (mm-set-handle-multipart-parameter | 869 | (mm-sec-status 'gnus-details "Quit.") |
| 915 | mm-security-handle 'gnus-details "Quit.") | 870 | (mm-sec-status 'gnus-details (mml2015-format-error error))) |
| 916 | (mm-set-handle-multipart-parameter | ||
| 917 | mm-security-handle 'gnus-details (mml2015-format-error error))) | ||
| 918 | (throw 'error handle))) | 871 | (throw 'error handle))) |
| 919 | (mm-set-handle-multipart-parameter | 872 | (mm-sec-status 'gnus-info |
| 920 | mm-security-handle 'gnus-info | ||
| 921 | (mml2015-epg-verify-result-to-string | 873 | (mml2015-epg-verify-result-to-string |
| 922 | (epg-context-result-for context 'verify))) | 874 | (epg-context-result-for context 'verify))) |
| 923 | handle))) | 875 | handle))) |
| @@ -931,17 +883,14 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." | |||
| 931 | (condition-case error | 883 | (condition-case error |
| 932 | (setq plain (epg-verify-string context signature)) | 884 | (setq plain (epg-verify-string context signature)) |
| 933 | (error | 885 | (error |
| 934 | (mm-set-handle-multipart-parameter | 886 | (mm-sec-error 'gnus-info "Failed") |
| 935 | mm-security-handle 'gnus-info "Failed") | ||
| 936 | (if (eq (car error) 'quit) | 887 | (if (eq (car error) 'quit) |
| 937 | (mm-set-handle-multipart-parameter | 888 | (mm-sec-status 'gnus-details "Quit.") |
| 938 | mm-security-handle 'gnus-details "Quit.") | 889 | (mm-sec-status 'gnus-details (mml2015-format-error error))))) |
| 939 | (mm-set-handle-multipart-parameter | ||
| 940 | mm-security-handle 'gnus-details (mml2015-format-error error))))) | ||
| 941 | (if plain | 890 | (if plain |
| 942 | (progn | 891 | (progn |
| 943 | (mm-set-handle-multipart-parameter | 892 | (mm-sec-status |
| 944 | mm-security-handle 'gnus-info | 893 | 'gnus-info |
| 945 | (mml2015-epg-verify-result-to-string | 894 | (mml2015-epg-verify-result-to-string |
| 946 | (epg-context-result-for context 'verify))) | 895 | (epg-context-result-for context 'verify))) |
| 947 | (delete-region (point-min) (point-max)) | 896 | (delete-region (point-min) (point-max)) |