From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Omar Polo Newsgroups: gmane.emacs.devel Subject: [RFC] certfp for rcirc Date: Wed, 11 Nov 2021 10:02:27 +0100 Message-ID: <87mtmb2hg4.fsf@omarpolo.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10469"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.6.9; emacs 29.0.50 To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Nov 11 10:05:10 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ml617-0002SV-SJ for ged-emacs-devel@m.gmane-mx.org; Thu, 11 Nov 2021 10:05:10 +0100 Original-Received: from localhost ([::1]:58508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml616-0003Qy-GC for ged-emacs-devel@m.gmane-mx.org; Thu, 11 Nov 2021 04:05:08 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:51604) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml5zL-0001Ym-2N for emacs-devel@gnu.org; Thu, 11 Nov 2021 04:03:20 -0500 Original-Received: from mail.omarpolo.com ([144.91.116.244]:62075) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml5zI-0001QH-Db for emacs-devel@gnu.org; Thu, 11 Nov 2021 04:03:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omarpolo.com; s=20200327; t=1636621363; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=1aB7UtNGSyLvXEv93sQYgpa9aaQ7c6jMOaq728/NCzE=; b=wNerN8yAIk2/vsCEW2GB+RYsWve0inXy9sWbQ2tcqL9k39RbRgqHOEbHW5eJrLyLw4uSrH I/I9akUBayBq9WUhLiA7FQpWIH0Y0zllmFbc2/ydi+6crDbcTGGHip9cdMlWzuPs6RzD73 q4iePpbPLzZq+ElcTgWGtbBtHmshb9c= Original-Received: from localhost (host-213-45-155-59.pool21345.interbusiness.it [213.45.155.59]) by mail.omarpolo.com (OpenSMTPD) with ESMTPSA id 73382829 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 11 Nov 2021 10:02:42 +0100 (CET) Original-Received: from venera (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id 2af00ffd for ; Thu, 11 Nov 2021 10:02:35 +0100 (CET) Received-SPF: pass client-ip=144.91.116.244; envelope-from=op@omarpolo.com; helo=mail.omarpolo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:279234 Archived-At: Hello, I was told earlier today that is actually possible to log in to an irc server using TLS client certificates. I like the idea and I wanted to used it, but unfortunately, rcirc doesn't seem to support them. I briefly tried circe, which has support for certfp, and while it's a great irc client, I still like rcirc more (eheh) so here's a try at adding the certfp login style to rcirc. It's still missing the documentation bits, but as per the subject, I'd like to get a feedback on the diff before proceding with the documentation. Here's some documentation on how to use certfp: https://libera.chat/guides/certfp To use certfp you need to: 1. generate a certificate (e.g. with openssl(1)) 2. the first time: - connect using the certificate - authenticate via the usual /msg nickserv identify ... - associate the certificate with your account /msg NickServ CERT ADD 3. from now on every time you connect with that cert, you're automatically authenticated. No passwords needed. With the following patch I can connect to libera with the following configuration: (setq rcirc-server-alist '(("irc.libera.chat" :channels (...) :port 6697))) (setq rcirc-authinfo '(("libera" certfp "/home/op/.emacs.d/irc/key.pem" "/home/op/.emacs.d/irc/cert.pem"))) Here's an excerpt from the *irc.libera.chat* server in a emacs -Q with the above config and the custom rcirc.el loaded: [...] 23:28 *** erbium.libera.chat 001 Welcome to the Libera.Chat Internet Relay Chat Network op2 ^^^ note how I'm already logged in [...] 23:28 *** op2 MODE +Zi 23:28 -NickServ- This nickname is registered. Please choose a different nickname, or identify via /msg NickServ IDENTIFY op2 23:28 -NickServ- You have 30 seconds to identify to your nickname before it is changed. 23:28 -NickServ- You are now identified for op2. 23:28 -NickServ- Last login from: ~op on Nov 10 22:27:31 2021 +0000. 23:29 /whois op2 [...] 23:29 *** 276 op2 has client certificate fingerprint [...] For some reason I don't know yet, the NickServ still says that I've got 30 seconds to identify myself, but in reality I'm already logged in. I don't know basically anything about how the irc protocol works, so I'm probably missing something incredibly obvious. What do you think? Cheers, Omar Polo diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el index 52d74a3394..070218ef0a 100644 --- a/lisp/net/rcirc.el +++ b/lisp/net/rcirc.el @@ -262,10 +262,12 @@ The ARGUMENTS for each METHOD symbol are: `bitlbee': NICK PASSWORD `quakenet': ACCOUNT PASSWORD `sasl': NICK PASSWORD + `certfp': KEY CERT Examples: ((\"Libera.Chat\" nickserv \"bob\" \"p455w0rd\") (\"Libera.Chat\" chanserv \"bob\" \"#bobland\" \"passwd99\") + (\"Libera.Chat\" certfp \"/path/to/key.pem\" \"/path/to/cert.pem\") (\"bitlbee\" bitlbee \"robert\" \"sekrit\") (\"dal.net\" nickserv \"bob\" \"sekrit\" \"NickServ@services.dal.net\") (\"quakenet.org\" quakenet \"bobby\" \"sekrit\") @@ -291,7 +293,11 @@ Examples: (list :tag "SASL" (const sasl) (string :tag "Nick") - (string :tag "Password"))))) + (string :tag "Password")) + (list :tag "CertFP" + (const certfp) + (string :tag "Key") + (string :tag "Certificate"))))) (defcustom rcirc-auto-authenticate-flag t "Non-nil means automatically send authentication string to server. @@ -547,6 +553,9 @@ If ARG is non-nil, instead prompt for connection parameters." (password (plist-get (cdr c) :password)) (encryption (plist-get (cdr c) :encryption)) (server-alias (plist-get (cdr c) :server-alias)) + (client-cert (when (eq (rcirc-get-server-method (car c)) + 'certfp) + (rcirc-get-server-cert (car c)))) contact) (when-let (((not password)) (auth (auth-source-search :host server @@ -563,7 +572,7 @@ If ARG is non-nil, instead prompt for connection parameters." (condition-case nil (let ((process (rcirc-connect server port nick user-name full-name channels password encryption - server-alias))) + client-cert server-alias))) (when rcirc-display-server-buffer (pop-to-buffer-same-window (process-buffer process)))) (quit (message "Quit connecting to %s" @@ -662,13 +671,22 @@ See `rcirc-connect' for more details on these variables.") (when (string-match server-i server) (throw 'pass (car args))))))) +(defun rcirc-get-server-cert (server) + "Return a list of key and certificate for SERVER." + (catch 'pass + (dolist (i rcirc-authinfo) + (let ((server-i (car i)) + (args (cddr i))) + (when (string-match server-i server) + (throw 'pass args)))))) + ;;;###autoload (defun rcirc-connect (server &optional port nick user-name full-name startup-channels password encryption - server-alias) + certfp server-alias) "Connect to SERVER. The arguments PORT, NICK, USER-NAME, FULL-NAME, PASSWORD, -ENCRYPTION, SERVER-ALIAS are interpreted as in +ENCRYPTION, CERTFP, SERVER-ALIAS are interpreted as in `rcirc-server-alist'. STARTUP-CHANNELS is a list of channels that are joined after authentication." (save-excursion @@ -692,10 +710,16 @@ that are joined after authentication." (delete-process process)) ;; Set up process - (setq process (open-network-stream - (or server-alias server) nil server port-number - :type (or encryption 'plain) - :nowait t)) + (setq process (if certfp + (open-network-stream + (or server-alias server) nil server port-number + :type 'tls + :nowait t + :client-certificate certfp) + (open-network-stream + (or server-alias server) nil server port-number + :type (or encryption 'plain) + :nowait t))) (set-process-coding-system process 'raw-text 'raw-text) (with-current-buffer (get-buffer-create (rcirc-generate-new-buffer-name process nil)) (set-process-buffer process (current-buffer))