From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?=C5=81ukasz?= Stelmach Newsgroups: gmane.emacs.bugs Subject: bug#64043: [PATCH] Export SHA-256 digest of a public key Date: Tue, 13 Jun 2023 13:26:39 +0200 Organization: Samsung R&D Institute Poland Message-ID: <20230613112639.2550160-1-stlman@poczta.fm> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10559"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?UTF-8?Q?=C5=81ukasz?= Stelmach To: 64043@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jun 13 13:41:24 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1q92Op-0002W6-Jq for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 13 Jun 2023 13:41:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q92Jg-0003py-Hv; Tue, 13 Jun 2023 07:36:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q92Je-0003oc-P1 for bug-gnu-emacs@gnu.org; Tue, 13 Jun 2023 07:36:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q92Je-000184-GA for bug-gnu-emacs@gnu.org; Tue, 13 Jun 2023 07:36:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q92Jd-0001vL-P0 for bug-gnu-emacs@gnu.org; Tue, 13 Jun 2023 07:36:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?=C5=81ukasz?= Stelmach Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 13 Jun 2023 11:36:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 64043 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16866561077304 (code B ref -1); Tue, 13 Jun 2023 11:36:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 13 Jun 2023 11:35:07 +0000 Original-Received: from localhost ([127.0.0.1]:41486 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q92Ik-0001ti-RM for submit@debbugs.gnu.org; Tue, 13 Jun 2023 07:35:07 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:36160) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q92Ii-0001tY-9X for submit@debbugs.gnu.org; Tue, 13 Jun 2023 07:35:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q92Ii-0002uq-3a for bug-gnu-emacs@gnu.org; Tue, 13 Jun 2023 07:35:04 -0400 Original-Received: from smtpo71.interia.pl ([217.74.67.71]) by eggs.gnu.org with esmtps (TLS1.2:RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q92If-0000o3-Dg for bug-gnu-emacs@gnu.org; Tue, 13 Jun 2023 07:35:03 -0400 Original-Received: from localhost (unknown [213.134.173.245]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by www.poczta.fm (INTERIA.PL) with ESMTPSA; Tue, 13 Jun 2023 13:27:10 +0200 (CEST) X-Mailer: git-send-email 2.30.2 X-IPL-Priority-Group: 0-0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interia.pl; s=biztos; t=1686655631; bh=pONKQ2NIuuqtoJrX4CTmM6Fz+eVcmSucagjwHH5gHh8=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=F0zX5eNeUox6y/aQyfHEwCtjANzvL2GI7fEsG+bPw1pjzuyEo+AZCm2lAvq1syMX0 /YujQ7OL1Ci9MLoEDehf++pio1rh8rc4/s6Xd7BGsti5pvHSTxFOZGAE4s4nFQShDa p4+uzOitYqZOcI1YdJf0NGcYKcRS7nWeANEotxA0= Received-SPF: pass client-ip=217.74.67.71; envelope-from=stlman@poczta.fm; helo=smtpo71.interia.pl X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:263312 Archived-At: * lisp/net/nsm.el (nsm-format-certificate): Show public key digest (SHA-256 if available). Displaying the digest enables users to verify the certificate with other tools like gnutls-cli(1) which present much more detailed information. * src/gnutls (emacs_gnutls_certificate_details): Export SHA-256 public key digest if supported by GnuTLS. --- lisp/net/nsm.el | 8 ++++++-- src/gnutls.c | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lisp/net/nsm.el b/lisp/net/nsm.el index dc04bf50c24..7cbeb48f5be 100644 --- a/lisp/net/nsm.el +++ b/lisp/net/nsm.el @@ -1030,10 +1030,14 @@ nsm-format-certificate " Hostname:" (nsm-certificate-part (plist-get cert :subject) "CN" t) "\n") (when (and (plist-get cert :public-key-algorithm) - (plist-get cert :signature-algorithm)) + (plist-get cert :signature-algorithm) + (or (plist-get cert :public-key-id-sha256) + (plist-get cert :public-key-id))) (insert " Public key:" (plist-get cert :public-key-algorithm) - ", signature: " (plist-get cert :signature-algorithm) "\n")) + ", signature: " (plist-get cert :signature-algorithm) "\n" + " Public key ID:" (or (plist-get cert :public-key-id-sha256) + (plist-get cert :public-key-id)) "\n")) (when (and (plist-get status :key-exchange) (plist-get status :cipher) (plist-get status :mac) diff --git a/src/gnutls.c b/src/gnutls.c index 8f0e2d01703..e3f1093d977 100644 --- a/src/gnutls.c +++ b/src/gnutls.c @@ -51,6 +51,10 @@ # define HAVE_GNUTLS_ETM_STATUS # endif +# if GNUTLS_VERSION_NUMBER >= 0x030401 +# define HAVE_GNUTLS_KEYID_USE_SHA256 +# endif + # if GNUTLS_VERSION_NUMBER < 0x030600 # define HAVE_GNUTLS_COMPRESSION_GET # endif @@ -1278,6 +1282,23 @@ emacs_gnutls_certificate_details (gnutls_x509_crt_t cert) xfree (buf); } +#ifdef HAVE_GNUTLS_KEYID_USE_SHA256 + /* Public key ID, SHA-256 version. */ + buf_size = 0; + err = gnutls_x509_crt_get_key_id (cert, GNUTLS_KEYID_USE_SHA256, NULL, &buf_size); + check_memory_full (err); + if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) + { + void *buf = xmalloc (buf_size); + err = gnutls_x509_crt_get_key_id (cert, GNUTLS_KEYID_USE_SHA256, buf, &buf_size); + check_memory_full (err); + if (err >= GNUTLS_E_SUCCESS) + res = nconc2 (res, list2 (intern (":public-key-id-sha256"), + gnutls_hex_string (buf, buf_size, "sha256:"))); + xfree (buf); + } +#endif + /* Certificate fingerprint. */ buf_size = 0; err = gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1, -- 2.30.2