From 574671c8bdc1cb5a56b0c4ffe0f35be9fa0161f7 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Thu, 29 Dec 2022 06:43:19 -0800 Subject: [PATCH 1/4] Fix default-port regression in erc-select-read-args * lisp/erc/erc.el (erc--warn-unencrypted): New function, likely temporary, to warn new users connecting interactively to the default server, "irc.libara.chat", via the default non-TLS port, 6667. (erc-select-read-args): Remove stray code from incomplete feature introduced by bug#56514. Ensure connecting always works with default port, which is non-TLS. Respect `erc-prompt-for-password' when user pastes URL containing password component into "server" prompt. Maybe add `erc--warn-unencrypted' as one-off hook for impending connection. * test/lisp/erc/erc-tests.el (erc-select-read-args): Always expect password prompt and sometimes a non-TLS port when `erc' called interactively. (Bug#60428.) --- lisp/erc/erc.el | 38 +++++++++++++++++++++++++++++--------- test/lisp/erc/erc-tests.el | 6 +++--- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index fe1201dd3a8..6315d5aa482 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -2161,6 +2161,23 @@ erc--ensure-url (setq input (concat "irc://" input))) input) +;; A temporary means of addressing the problem of ERC's namesake entry +;; point defaulting to a non-TLS connection with its default server +;; (bug#60428). +(defun erc--warn-unencrypted () + ;; Remove unconditionally to avoid wrong context due to races from + ;; simultaneous dialing or aborting (e.g., via `keybaord-quit'). + (remove-hook 'erc--server-post-connect-hook #'erc--warn-unencrypted) + (when (and (process-contact erc-server-process :nowait) + (equal erc-session-server erc-default-server) + (eql erc-session-port erc-default-port)) + ;; FIXME use the autoloaded `info' instead of `Info-goto-node' in + ;; `erc-button-alist'. + (require 'info nil t) + (erc-display-error-notice + nil (concat "This connection is unencrypted. Please use `erc-tls'" + " from now on. See Info:\"(erc) connecting\" for more.")))) + ;;;###autoload (defun erc-select-read-args () "Prompt the user for values of nick, server, port, and password." @@ -2171,10 +2188,7 @@ erc-select-read-args ;; For legacy reasons, also accept a URL without a scheme. (url (url-generic-parse-url (erc--ensure-url input))) (server (url-host url)) - (sp (and (or (string-suffix-p "s" (url-type url)) - (and (equal server erc-default-server) - (not (string-prefix-p "irc://" input)))) - 'ircs-u)) + (sp (and (string-suffix-p "s" (url-type url)) erc-default-port-tls)) (port (or (url-portspec url) (erc-compute-port (let ((d (erc-compute-port sp))) ; may be a string @@ -2187,13 +2201,19 @@ erc-select-read-args (let ((d (erc-compute-nick))) (read-string (format "Nickname (default is %S): " d) nil 'erc-nick-history-list d)))) - (passwd (or (url-password url) - (if erc-prompt-for-password - (read-passwd "Server password (optional): ") - (with-suppressed-warnings ((obsolete erc-password)) - erc-password))))) + (passwd (let* ((p (with-suppressed-warnings ((obsolete erc-password)) + (or (url-password url) erc-password))) + (m (if p + (format "Server password (default is %S): " p) + "Server password (optional): "))) + (if erc-prompt-for-password (read-passwd m nil p) p)))) (when (and passwd (string= "" passwd)) (setq passwd nil)) + (when (and (equal server erc-default-server) + (eql port erc-default-port) + (not (eql port erc-default-port-tls)) ; not `erc-tls' + (not (string-prefix-p "irc://" input))) ; not yanked URL + (add-hook 'erc--server-post-connect-hook #'erc--warn-unencrypted)) (list :server server :port port :nick nick :password passwd))) ;;;###autoload diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 6807b24bfc6..85506c3d27e 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -1001,11 +1001,11 @@ erc--server-connect-dumb-ipv6-regexp (ert-deftest erc-select-read-args () - (ert-info ("Defaults to TLS") + (ert-info ("Does not default to TLS") (should (equal (ert-simulate-keys "\r\r\r\r" (erc-select-read-args)) (list :server "irc.libera.chat" - :port 6697 + :port 6667 :nick (user-login-name) :password nil)))) @@ -1036,7 +1036,7 @@ erc-select-read-args :password nil)))) (ert-info ("Address includes nick and password") - (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r" + (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r" (erc-select-read-args)) (list :server "localhost" :port 6667 -- 2.38.1