From 427c01c27a20e065ff1e58ab9173103cec377e0c Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Thu, 22 Aug 2019 15:11:01 -0400 Subject: [PATCH] [core] Offline work-around for GnuTLS Emacs bug This assumes that gnutls-cli is available on the system. The work-around won't be applied if this executable is not available. --- core/core-emacs-backports.el | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/core/core-emacs-backports.el b/core/core-emacs-backports.el index 937d9f9a5..06d6bc00f 100644 --- a/core/core-emacs-backports.el +++ b/core/core-emacs-backports.el @@ -15,15 +15,26 @@ (when (and (version< "25" emacs-version) (version< emacs-version "26.3")) - ;; Hack to prevent TLS error with Emacs 26.1 and 26.2 and gnutls 3.6.4 and above - ;; see https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34341 - (ignore-errors - (message "Testing if your Emacs version needs the TLS work-around...") - (message "More info at https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34341") - (with-current-buffer (url-retrieve-synchronously "https://api.github.com/users/syl20bnr/repos") - (when (string-empty-p (buffer-string)) - (message "Your Emacs and GnutTLS versions need the work-around, applying it...") - (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3"))))) + ;; Hack to prevent TLS error with Emacs 26.1 and 26.2 and gnutls 3.6.4 and + ;; above see https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34341 + (message (concat "Testing if your Emacs version %s and GnuTLS version " + "need the TLS work-around...") + emacs-version) + (message "More info at https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34341") + (let ((stime (current-time))) + (with-temp-buffer + (ignore-errors (call-process "gnutls-cli" nil t nil "--version")) + (unless (string-empty-p (buffer-string)) + (goto-char (point-min)) + (let ((gnutls-version-line (thing-at-point 'line t))) + (when (string-match ".*\\([0-9]+\\.[0-9]+\\.[0-9]+\\).*" + gnutls-version-line) + (let ((gnutls-version (match-string 1 gnutls-version-line))) + (unless (version<= gnutls-version "3.6.3") + (message (concat "Your Emacs version %s and GnutTLS version %s " + "need the work-around, applying it...") + emacs-version gnutls-version) + (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3"))))))))) (when (version< emacs-version "26") ;; backport fix for macOS battery status