From a9f09f721e062c87849a73f06c72e52a0030d027 Mon Sep 17 00:00:00 2001 From: Jimmy Yuen Ho Wong Date: Tue, 10 Jul 2018 11:18:45 +0100 Subject: [PATCH] Check TLS certs against CRL * lisp/net/gnutls.el (gnutls-boot-parameters): Return `gnutls-crlfiles' in `:crlfiles'. (gnutls-crlfiles): New defcustom. (gnutls--get-files): New defun. (gnutls-trustfiles, gnutls-crlfiles): Delegate to `gnutls--get-files' to return a list of filenames, accepts glob pattern. --- lisp/net/gnutls.el | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lisp/net/gnutls.el b/lisp/net/gnutls.el index 315932b7e69..8af34c2a99e 100644 --- a/lisp/net/gnutls.el +++ b/lisp/net/gnutls.el @@ -110,6 +110,7 @@ Security'." "/etc/ssl/cert.pem" ; macOS ) "List of CA bundle location filenames or a function returning said list. +If a file path contains glob wildcards, they will be expanded. The files may be in PEM or DER format, as per the GnuTLS documentation. The files may not exist, in which case they will be ignored." :group 'gnutls @@ -138,6 +139,19 @@ node `(emacs) Network Security'." (integer :tag "Number of bits" 512)) :group 'gnutls) +(defcustom gnutls-crlfiles + '( + "/etc/grid-security/certificates/*.crl.pem" + ) + "List of CRL file paths or a function returning said list. +If a file path contains glob wildcards, they will be expanded. +The files may be in PEM or DER format, as per the GnuTLS documentation. +The files may not exist, in which case they will be ignored." + :group 'gnutls + :type '(choice (function :tag "Function to produce list of CRL filenames") + (repeat (file :tag "CRL filename"))) + :version "27.1") + (defun open-gnutls-stream (name buffer host service &optional nowait) "Open a SSL/TLS connection for a service to a host. Returns a subprocess-object to represent the connection. @@ -284,6 +298,7 @@ here's a recent version of the list. It must be omitted, a number, or nil; if omitted or nil it defaults to GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT." (let* ((trustfiles (or trustfiles (gnutls-trustfiles))) + (crlfiles (or crlfiles (gnutls-crlfiles))) (maybe-dumbfw (if (memq 'ClientHello\ Padding (gnutls-available-p)) ":%DUMBFW" "")) @@ -325,13 +340,18 @@ defaults to GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT." :verify-error ,verify-error :callbacks nil))) +(defun gnutls--get-files (files) + (cl-loop for f in files + if f do (setq f (if (functionp f) (funcall f) f)) + append (cl-delete-if-not #'file-exists-p (file-expand-wildcards f t)))) + (defun gnutls-trustfiles () "Return a list of usable trustfiles." - (delq nil - (mapcar (lambda (f) (and f (file-exists-p f) f)) - (if (functionp gnutls-trustfiles) - (funcall gnutls-trustfiles) - gnutls-trustfiles)))) + (gnutls--get-files gnutls-trustfiles)) + +(defun gnutls-crlfiles () + "Return a list of usable CRL files." + (gnutls--get-files gnutls-crlfiles)) (declare-function gnutls-error-string "gnutls.c" (error)) -- 2.39.5