diff options
| author | Lars Ingebrigtsen | 2019-08-23 04:07:10 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-08-23 04:07:10 +0200 |
| commit | 29d485fb768fbe375d60fd80cb2dbdbd90f3becc (patch) | |
| tree | a5adba77bcaec27891858f08a977e4c2c88d184f | |
| parent | bc1cf28da5532c6052eade7b5d19bb59e7e1f7bf (diff) | |
| download | emacs-29d485fb768fbe375d60fd80cb2dbdbd90f3becc.tar.gz emacs-29d485fb768fbe375d60fd80cb2dbdbd90f3becc.zip | |
Tweak the warning display to be less like a TLS decoding page
* lisp/net/nsm.el (nsm-parse-subject, nsm-certificate-part):
Restore functions for parsing subjects.
(nsm-format-certificate): Use them to display more user-friendly
data. Also change the display to have fewer lines again so that
the data of interest isn't pushed off the screen.
| -rw-r--r-- | lisp/net/nsm.el | 73 |
1 files changed, 56 insertions, 17 deletions
diff --git a/lisp/net/nsm.el b/lisp/net/nsm.el index b0eff811617..c170ec9e4e8 100644 --- a/lisp/net/nsm.el +++ b/lisp/net/nsm.el | |||
| @@ -28,6 +28,7 @@ | |||
| 28 | (require 'rmc) ; read-multiple-choice | 28 | (require 'rmc) ; read-multiple-choice |
| 29 | (require 'subr-x) | 29 | (require 'subr-x) |
| 30 | (require 'seq) | 30 | (require 'seq) |
| 31 | (require 'map) | ||
| 31 | 32 | ||
| 32 | (defvar nsm-permanent-host-settings nil) | 33 | (defvar nsm-permanent-host-settings nil) |
| 33 | (defvar nsm-temporary-host-settings nil) | 34 | (defvar nsm-temporary-host-settings nil) |
| @@ -293,7 +294,7 @@ See also: `nsm-tls-checks' and `nsm-noninteractive'" | |||
| 293 | 'conditions | 294 | 'conditions |
| 294 | problems | 295 | problems |
| 295 | (format-message | 296 | (format-message |
| 296 | "The TLS connection to %s:%s is insecure for the following reason%s:\n\n%s" | 297 | "The TLS connection to %s:%s is insecure\nfor the following reason%s:\n\n%s" |
| 297 | host port | 298 | host port |
| 298 | (if (> (length problems) 1) | 299 | (if (> (length problems) 1) |
| 299 | "s" "") | 300 | "s" "") |
| @@ -835,10 +836,12 @@ protocol." | |||
| 835 | (?n "next" "Next certificate") | 836 | (?n "next" "Next certificate") |
| 836 | (?p "previous" "Previous certificate") | 837 | (?p "previous" "Previous certificate") |
| 837 | (?q "quit" "Quit details view"))) | 838 | (?q "quit" "Quit details view"))) |
| 838 | (answer (read-multiple-choice "Continue connecting?" accept-choices)) | 839 | (answer (read-multiple-choice "Continue connecting?" |
| 840 | accept-choices)) | ||
| 839 | (show-details (char-equal (car answer) ?d)) | 841 | (show-details (char-equal (car answer) ?d)) |
| 840 | (pems (cl-loop for cert in certs | 842 | (pems (cl-loop for cert in certs |
| 841 | collect (gnutls-format-certificate (plist-get cert :pem)))) | 843 | collect (gnutls-format-certificate |
| 844 | (plist-get cert :pem)))) | ||
| 842 | (cert-index 0)) | 845 | (cert-index 0)) |
| 843 | (while show-details | 846 | (while show-details |
| 844 | (unless (get-buffer-window cert-buffer) | 847 | (unless (get-buffer-window cert-buffer) |
| @@ -999,13 +1002,27 @@ protocol." | |||
| 999 | (insert | 1002 | (insert |
| 1000 | (propertize "Certificate information" 'face 'underline) "\n" | 1003 | (propertize "Certificate information" 'face 'underline) "\n" |
| 1001 | " Issued by:" | 1004 | " Issued by:" |
| 1002 | (plist-get cert :issuer) "\n" | 1005 | (nsm-certificate-part (plist-get cert :issuer) "CN" t) "\n" |
| 1003 | " Issued to:" | 1006 | " Issued to:" |
| 1004 | (plist-get cert :subject) "\n") | 1007 | (or (nsm-certificate-part (plist-get cert :subject) "O") |
| 1008 | (nsm-certificate-part (plist-get cert :subject) "OU" t)) | ||
| 1009 | "\n" | ||
| 1010 | " Hostname:" | ||
| 1011 | (nsm-certificate-part (plist-get cert :subject) "CN" t) "\n") | ||
| 1005 | (when (and (plist-get cert :public-key-algorithm) | 1012 | (when (and (plist-get cert :public-key-algorithm) |
| 1006 | (plist-get cert :signature-algorithm)) | 1013 | (plist-get cert :signature-algorithm)) |
| 1007 | (insert " Public key:" (plist-get cert :public-key-algorithm) "\n") | 1014 | (insert |
| 1008 | (insert " Signature:" (plist-get cert :signature-algorithm) "\n")) | 1015 | " Public key:" (plist-get cert :public-key-algorithm) |
| 1016 | ", signature: " (plist-get cert :signature-algorithm) "\n")) | ||
| 1017 | (when (and (plist-get status :key-exchange) | ||
| 1018 | (plist-get status :cipher) | ||
| 1019 | (plist-get status :mac) | ||
| 1020 | (plist-get status :protocol)) | ||
| 1021 | (insert | ||
| 1022 | " Session:" (plist-get status :protocol) | ||
| 1023 | ", key: " (plist-get status :key-exchange) | ||
| 1024 | ", cipher: " (plist-get status :cipher) | ||
| 1025 | ", mac: " (plist-get status :mac) "\n")) | ||
| 1009 | (when (plist-get cert :certificate-security-level) | 1026 | (when (plist-get cert :certificate-security-level) |
| 1010 | (insert | 1027 | (insert |
| 1011 | " Security level:" | 1028 | " Security level:" |
| @@ -1015,16 +1032,7 @@ protocol." | |||
| 1015 | (insert | 1032 | (insert |
| 1016 | " Valid:From " (plist-get cert :valid-from) | 1033 | " Valid:From " (plist-get cert :valid-from) |
| 1017 | " to " (plist-get cert :valid-to) "\n") | 1034 | " to " (plist-get cert :valid-to) "\n") |
| 1018 | ;; Handshake parameters | 1035 | (insert "\n") |
| 1019 | (insert (propertize "Session information" 'face 'underline) "\n") | ||
| 1020 | (insert " Version:" (plist-get status :protocol) "\n") | ||
| 1021 | (insert " Safe renegotiation:" (if (plist-get status :safe-renegotiation) "Yes" "No") "\n") | ||
| 1022 | (insert " Compression:" (plist-get status :compression) "\n") | ||
| 1023 | (insert " Encrypt-then-MAC:" (if (plist-get status :encrypt-then-mac) "Yes" "No") "\n") | ||
| 1024 | (insert " Cipher suite:" (nsm-cipher-suite status) "\n") | ||
| 1025 | (if (string-match "^\\bDHE\\b" (plist-get status :key-exchange)) | ||
| 1026 | (insert " DH prime bits:" (format "%d" (plist-get status :diffie-hellman-prime-bits)) "\n") | ||
| 1027 | (insert "\n")) | ||
| 1028 | (goto-char (point-min)) | 1036 | (goto-char (point-min)) |
| 1029 | (while (re-search-forward "^[^:]+:" nil t) | 1037 | (while (re-search-forward "^[^:]+:" nil t) |
| 1030 | (insert (make-string (- 22 (current-column)) ? ))) | 1038 | (insert (make-string (- 22 (current-column)) ? ))) |
| @@ -1043,6 +1051,37 @@ protocol." | |||
| 1043 | (plist-get status :cipher) | 1051 | (plist-get status :cipher) |
| 1044 | (plist-get status :mac))) | 1052 | (plist-get status :mac))) |
| 1045 | 1053 | ||
| 1054 | (defun nsm-certificate-part (string part &optional full) | ||
| 1055 | (let ((part (cadr (assoc part (nsm-parse-subject string))))) | ||
| 1056 | (cond | ||
| 1057 | (part part) | ||
| 1058 | (full string) | ||
| 1059 | (t nil)))) | ||
| 1060 | |||
| 1061 | (defun nsm-parse-subject (string) | ||
| 1062 | (with-temp-buffer | ||
| 1063 | (insert string) | ||
| 1064 | (goto-char (point-min)) | ||
| 1065 | (let ((start (point)) | ||
| 1066 | (result nil)) | ||
| 1067 | (while (not (eobp)) | ||
| 1068 | (push (replace-regexp-in-string | ||
| 1069 | "[\\]\\(.\\)" "\\1" | ||
| 1070 | (buffer-substring start | ||
| 1071 | (if (re-search-forward "[^\\]," nil 'move) | ||
| 1072 | (1- (point)) | ||
| 1073 | (point)))) | ||
| 1074 | result) | ||
| 1075 | (setq start (point))) | ||
| 1076 | (mapcar | ||
| 1077 | (lambda (elem) | ||
| 1078 | (let ((pos (cl-position ?= elem))) | ||
| 1079 | (if pos | ||
| 1080 | (list (substring elem 0 pos) | ||
| 1081 | (substring elem (1+ pos))) | ||
| 1082 | elem))) | ||
| 1083 | (nreverse result))))) | ||
| 1084 | |||
| 1046 | (define-obsolete-function-alias 'nsm--encryption #'nsm-cipher-suite "27.1") | 1085 | (define-obsolete-function-alias 'nsm--encryption #'nsm-cipher-suite "27.1") |
| 1047 | 1086 | ||
| 1048 | (provide 'nsm) | 1087 | (provide 'nsm) |