diff options
| author | Glenn Morris | 2007-11-04 01:18:24 +0000 |
|---|---|---|
| committer | Glenn Morris | 2007-11-04 01:18:24 +0000 |
| commit | 7c9008ce0cff13f6ad4aa1d97e68bc88ba70b3a2 (patch) | |
| tree | f54e334230a34a39bc03f90769980ecdfdd1ff02 | |
| parent | 6ec21bf4d9c75a69ff7ec78f217245bf1e48434a (diff) | |
| download | emacs-7c9008ce0cff13f6ad4aa1d97e68bc88ba70b3a2.tar.gz emacs-7c9008ce0cff13f6ad4aa1d97e68bc88ba70b3a2.zip | |
Riccardo Murri <riccardo.murri at gmail.com>
Require rx when compiling.
(tls-end-of-info): New variable.
(open-tls-stream): Keep reading input until `tls-end-of-info' is matched.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/net/tls.el | 68 |
2 files changed, 67 insertions, 8 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7bc4e8b1e8b..6a448ccadfe 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2007-11-04 Riccardo Murri <riccardo.murri@gmail.com> | ||
| 2 | |||
| 3 | * net/tls.el: Require rx when compiling. | ||
| 4 | (tls-end-of-info): New variable. | ||
| 5 | (open-tls-stream): Keep reading input until `tls-end-of-info' is | ||
| 6 | matched. | ||
| 7 | |||
| 1 | 2007-11-03 Ulrich Mueller <ulm@gentoo.org> (tiny change) | 8 | 2007-11-03 Ulrich Mueller <ulm@gentoo.org> (tiny change) |
| 2 | 9 | ||
| 3 | * simple.el (bad-packages-alist): Anchor semantic regexp. | 10 | * simple.el (bad-packages-alist): Anchor semantic regexp. |
diff --git a/lisp/net/tls.el b/lisp/net/tls.el index 2e890a4a476..bdade42073f 100644 --- a/lisp/net/tls.el +++ b/lisp/net/tls.el | |||
| @@ -51,10 +51,45 @@ | |||
| 51 | (autoload 'format-spec "format-spec") | 51 | (autoload 'format-spec "format-spec") |
| 52 | (autoload 'format-spec-make "format-spec")) | 52 | (autoload 'format-spec-make "format-spec")) |
| 53 | 53 | ||
| 54 | (eval-when-compile | ||
| 55 | (require 'rx)) | ||
| 56 | |||
| 54 | (defgroup tls nil | 57 | (defgroup tls nil |
| 55 | "Transport Layer Security (TLS) parameters." | 58 | "Transport Layer Security (TLS) parameters." |
| 56 | :group 'comm) | 59 | :group 'comm) |
| 57 | 60 | ||
| 61 | (defcustom tls-end-of-info | ||
| 62 | (rx | ||
| 63 | (or | ||
| 64 | ;; `openssl s_client` regexp | ||
| 65 | (sequence | ||
| 66 | ;; see ssl/ssl_txt.c lines 219--220 | ||
| 67 | line-start | ||
| 68 | " Verify return code: " | ||
| 69 | (one-or-more not-newline) | ||
| 70 | "\n" | ||
| 71 | ;; according to apps/s_client.c line 1515 this is always the last | ||
| 72 | ;; line that is printed by s_client before the real data | ||
| 73 | "---\n") | ||
| 74 | ;; `gnutls` regexp | ||
| 75 | (sequence | ||
| 76 | ;; see src/cli.c lines 721-- | ||
| 77 | (sequence line-start "- Simple Client Mode:\n") | ||
| 78 | (zero-or-more | ||
| 79 | (or | ||
| 80 | "\n" ; ignore blank lines | ||
| 81 | ;; XXX: we have no way of knowing if the STARTTLS handshake | ||
| 82 | ;; sequence has completed successfully, because `gnutls` will | ||
| 83 | ;; only report failure. | ||
| 84 | (sequence line-start "\*\*\* Starting TLS handshake\n")))))) | ||
| 85 | "Regexp matching end of TLS client informational messages. | ||
| 86 | Client data stream begins after the last character matched by | ||
| 87 | this. The default matches `openssl s_client' (version 0.9.8c) | ||
| 88 | and `gnutls-cli' (version 2.0.1) output." | ||
| 89 | :version "22.2" | ||
| 90 | :type 'regexp | ||
| 91 | :group 'tls) | ||
| 92 | |||
| 58 | (defcustom tls-program '("gnutls-cli -p %p %h" | 93 | (defcustom tls-program '("gnutls-cli -p %p %h" |
| 59 | "gnutls-cli -p %p %h --protocols ssl3" | 94 | "gnutls-cli -p %p %h --protocols ssl3" |
| 60 | "openssl s_client -connect %h:%p -no_ssl2") | 95 | "openssl s_client -connect %h:%p -no_ssl2") |
| @@ -130,7 +165,9 @@ Fourth arg PORT is an integer specifying a port to connect to." | |||
| 130 | process cmd done) | 165 | process cmd done) |
| 131 | (if use-temp-buffer | 166 | (if use-temp-buffer |
| 132 | (setq buffer (generate-new-buffer " TLS"))) | 167 | (setq buffer (generate-new-buffer " TLS"))) |
| 133 | (message "Opening TLS connection to `%s'..." host) | 168 | (save-excursion |
| 169 | (set-buffer buffer) | ||
| 170 | (message "Opening TLS connection to `%s'..." host) | ||
| 134 | (while (and (not done) (setq cmd (pop cmds))) | 171 | (while (and (not done) (setq cmd (pop cmds))) |
| 135 | (message "Opening TLS connection with `%s'..." cmd) | 172 | (message "Opening TLS connection with `%s'..." cmd) |
| 136 | (let ((process-connection-type tls-process-connection-type) | 173 | (let ((process-connection-type tls-process-connection-type) |
| @@ -146,19 +183,34 @@ Fourth arg PORT is an integer specifying a port to connect to." | |||
| 146 | port))))) | 183 | port))))) |
| 147 | (while (and process | 184 | (while (and process |
| 148 | (memq (process-status process) '(open run)) | 185 | (memq (process-status process) '(open run)) |
| 149 | (save-excursion | 186 | (progn |
| 150 | (set-buffer buffer) ;; XXX "blue moon" nntp.el bug | ||
| 151 | (goto-char (point-min)) | 187 | (goto-char (point-min)) |
| 152 | (not (setq done (re-search-forward tls-success nil t))))) | 188 | (not (setq done (re-search-forward tls-success nil t))))) |
| 153 | (unless (accept-process-output process 1) | 189 | (unless (accept-process-output process 1) |
| 154 | (sit-for 1))) | 190 | (sit-for 1))) |
| 155 | (message "Opening TLS connection with `%s'...%s" cmd | 191 | (message "Opening TLS connection with `%s'...%s" cmd |
| 156 | (if done "done" "failed")) | 192 | (if done "done" "failed")) |
| 157 | (if done | 193 | (if (not done) |
| 158 | (setq done process) | 194 | (delete-process process) |
| 159 | (delete-process process)))) | 195 | ;; advance point to after all informational messages that |
| 196 | ;; `openssl s_client' and `gnutls' print | ||
| 197 | (let ((start-of-data nil)) | ||
| 198 | (while | ||
| 199 | (not (setq start-of-data | ||
| 200 | ;; the string matching `tls-end-of-info' | ||
| 201 | ;; might come in separate chunks from | ||
| 202 | ;; `accept-process-output', so start the | ||
| 203 | ;; search where `tls-success' ended | ||
| 204 | (save-excursion | ||
| 205 | (if (re-search-forward tls-end-of-info nil t) | ||
| 206 | (match-end 0))))) | ||
| 207 | (accept-process-output process 1)) | ||
| 208 | (if start-of-data | ||
| 209 | ;; move point to start of client data | ||
| 210 | (goto-char start-of-data))) | ||
| 211 | (setq done process)))) | ||
| 160 | (message "Opening TLS connection to `%s'...%s" | 212 | (message "Opening TLS connection to `%s'...%s" |
| 161 | host (if done "done" "failed")) | 213 | host (if done "done" "failed"))) |
| 162 | (when use-temp-buffer | 214 | (when use-temp-buffer |
| 163 | (if done (set-process-buffer process nil)) | 215 | (if done (set-process-buffer process nil)) |
| 164 | (kill-buffer buffer)) | 216 | (kill-buffer buffer)) |