diff options
author | Amin Bandali <bandali@gnu.org> | 2021-04-22 20:22:38 -0400 |
---|---|---|
committer | Amin Bandali <bandali@gnu.org> | 2021-04-22 20:22:38 -0400 |
commit | 344f769491a84b6d47ee3722054b214167572219 (patch) | |
tree | 245d79c7eb88df07d02be64c02a9d6632c1b9644 /lisp/erc/erc-backend.el | |
parent | 1c3a86e7fc220963a1691462dbfa25b37799e287 (diff) | |
download | emacs-344f769491a84b6d47ee3722054b214167572219.tar.gz emacs-344f769491a84b6d47ee3722054b214167572219.tar.bz2 emacs-344f769491a84b6d47ee3722054b214167572219.zip |
Add support for using a TLS client certificate with 'erc-tls' (bug#47788)
* lisp/erc/erc-backend.el (erc-session-client-certificate): New
buffer-local variable storing the TLS client certificate used for the
current connection.
(erc-open-network-stream): Use open-network-stream instead of
make-network-process, and pass any additional arguments to it.
(erc-server-connect): Add an optional client-certificate argument
that if present is passed with the :client-certificate keyword as part
of the arguments to erc-server-connect-function.
* lisp/erc/erc.el (erc-open): Add new optional client-certificate
argument, set it as erc-session-client-certificate, and pass it along
to erc-server-connect.
(erc): Clarify documentation string with respect to the full-name
argument.
(erc-tls): Add new client-certificate keyword argument and pass it in
the direct call to erc-open (instead of going through erc).
(erc-open-tls-stream): Pass any additional arguments (such as
:client-certificate) to open-network-stream. Also allow overriding
:nowait if desired.
* doc/misc/erc.texi: Add documentation for erc-tls, including the new
:client-certificate argument.
* etc/NEWS: Announce the change.
Diffstat (limited to 'lisp/erc/erc-backend.el')
-rw-r--r-- | lisp/erc/erc-backend.el | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index b1f97aea069..67db572701f 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -138,6 +138,13 @@ Use `erc-current-nick' to access this.") (defvar-local erc-session-port nil "The port used to connect to.") +(defvar-local erc-session-client-certificate nil + "TLS client certificate used when connecting over TLS. +If non-nil, should either be a list where the first element is +the certificate key file name, and the second element is the +certificate file name itself, or t, which means that +`auth-source' will be queried for the key and the certificate.") + (defvar-local erc-server-announced-name nil "The name the server announced to use.") @@ -505,18 +512,23 @@ The current buffer is given by BUFFER." (memq (process-status erc-server-process) '(run open))))) ;;;; Connecting to a server -(defun erc-open-network-stream (name buffer host service) - "As `open-network-stream', but does non-blocking IO" - (make-network-process :name name :buffer buffer - :host host :service service :nowait t)) +(defun erc-open-network-stream (name buffer host service &rest parameters) + "Like `open-network-stream', but does non-blocking IO." + (let ((p (plist-put parameters :nowait t))) + (open-network-stream name buffer host service p))) -(defun erc-server-connect (server port buffer) +(defun erc-server-connect (server port buffer &optional client-certificate) "Perform the connection and login using the specified SERVER and PORT. -We will store server variables in the buffer given by BUFFER." - (let ((msg (erc-format-message 'connect ?S server ?p port)) process) +We will store server variables in the buffer given by BUFFER. +CLIENT-CERTIFICATE may optionally be used to specify a TLS client +certificate to use for authentication when connecting over +TLS (see `erc-session-client-certificate' for more details)." + (let ((msg (erc-format-message 'connect ?S server ?p port)) process + (args `(,(format "erc-%s-%s" server port) nil ,server ,port))) + (when client-certificate + (setq args `(,@args :client-certificate ,client-certificate))) (message "%s" msg) - (setq process (funcall erc-server-connect-function - (format "erc-%s-%s" server port) nil server port)) + (setq process (apply erc-server-connect-function args)) (unless (processp process) (error "Connection attempt failed")) ;; Misc server variables |