aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2017-08-03 17:57:24 -0700
committerPaul Eggert2017-08-03 18:36:15 -0700
commite8ca0c5e16a6887691ee3db739abfdba25e0d578 (patch)
treecee63ad775d7996718a745a46e646d591a02eaa1 /src
parentddc1ff58dec92a782b233d97a254fc41c1c887eb (diff)
downloademacs-e8ca0c5e16a6887691ee3db739abfdba25e0d578.tar.gz
emacs-e8ca0c5e16a6887691ee3db739abfdba25e0d578.zip
Fix version numbers for some GnuTLS features
Problem reported by Glenn Morris (Bug#27708#58). * src/gnutls.c (HAVE_GNUTLS_X509_SYSTEM_TRUST): New macro. Use it instead of low-level version number checks. (HAVE_GNUTLS_AEAD): Move here from gnutls.h, and rename from HAVE_GNUTLS3_AEAD. All uses changed. Indent preprocessor lines. * src/gnutls.h (HAVE_GNUTLS3_CIPHER, HAVE_GNUTLS3_DIGEST) (HAVE_GNUTLS3_HMAC): Remove, since these were available before GnuTLS 3.0.0 and the code checks them only if HAVE_GNUTLS3 is defined. Remove all uses; this simplifies the code a bit.
Diffstat (limited to 'src')
-rw-r--r--src/gnutls.c370
-rw-r--r--src/gnutls.h16
2 files changed, 171 insertions, 215 deletions
diff --git a/src/gnutls.c b/src/gnutls.c
index 59694074e16..188f995979e 100644
--- a/src/gnutls.c
+++ b/src/gnutls.c
@@ -26,22 +26,36 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26#include "coding.h" 26#include "coding.h"
27#include "buffer.h" 27#include "buffer.h"
28 28
29#ifdef HAVE_GNUTLS 29#if 0x030014 <= GNUTLS_VERSION_NUMBER
30# define HAVE_GNUTLS_X509_SYSTEM_TRUST
31#endif
30 32
31#ifdef WINDOWSNT 33/* Although AEAD support started in GnuTLS 3.4.0 and works in 3.5.14,
32#include <windows.h> 34 it was broken through at least GnuTLS 3.4.10; see:
33#include "w32.h" 35 https://lists.gnu.org/archive/html/emacs-devel/2017-07/msg00992.html
36 The relevant fix seems to have been made in GnuTLS 3.5.1; see:
37 https://gitlab.com/gnutls/gnutls/commit/568935848dd6b82b9315d8b6c529d00e2605e03d
38 So, require 3.5.1. */
39#if 0x030501 <= GNUTLS_VERSION_NUMBER
40# define HAVE_GNUTLS_AEAD
34#endif 41#endif
35 42
43#ifdef HAVE_GNUTLS
44
45# ifdef WINDOWSNT
46# include <windows.h>
47# include "w32.h"
48# endif
49
36static bool emacs_gnutls_handle_error (gnutls_session_t, int); 50static bool emacs_gnutls_handle_error (gnutls_session_t, int);
37 51
38static bool gnutls_global_initialized; 52static bool gnutls_global_initialized;
39 53
40static void gnutls_log_function (int, const char *); 54static void gnutls_log_function (int, const char *);
41static void gnutls_log_function2 (int, const char *, const char *); 55static void gnutls_log_function2 (int, const char *, const char *);
42#ifdef HAVE_GNUTLS3 56# ifdef HAVE_GNUTLS3
43static void gnutls_audit_log_function (gnutls_session_t, const char *); 57static void gnutls_audit_log_function (gnutls_session_t, const char *);
44#endif 58# endif
45 59
46enum extra_peer_verification 60enum extra_peer_verification
47{ 61{
@@ -49,7 +63,7 @@ enum extra_peer_verification
49}; 63};
50 64
51 65
52#ifdef WINDOWSNT 66# ifdef WINDOWSNT
53 67
54DEF_DLL_FN (gnutls_alert_description_t, gnutls_alert_get, 68DEF_DLL_FN (gnutls_alert_description_t, gnutls_alert_get,
55 (gnutls_session_t)); 69 (gnutls_session_t));
@@ -74,12 +88,10 @@ DEF_DLL_FN (int, gnutls_certificate_set_x509_crl_file,
74DEF_DLL_FN (int, gnutls_certificate_set_x509_key_file, 88DEF_DLL_FN (int, gnutls_certificate_set_x509_key_file,
75 (gnutls_certificate_credentials_t, const char *, const char *, 89 (gnutls_certificate_credentials_t, const char *, const char *,
76 gnutls_x509_crt_fmt_t)); 90 gnutls_x509_crt_fmt_t));
77# if ((GNUTLS_VERSION_MAJOR \ 91# ifdef HAVE_GNUTLS_X509_SYSTEM_TRUST
78 + (GNUTLS_VERSION_MINOR > 0 || GNUTLS_VERSION_PATCH >= 20)) \
79 > 3)
80DEF_DLL_FN (int, gnutls_certificate_set_x509_system_trust, 92DEF_DLL_FN (int, gnutls_certificate_set_x509_system_trust,
81 (gnutls_certificate_credentials_t)); 93 (gnutls_certificate_credentials_t));
82# endif 94# endif
83DEF_DLL_FN (int, gnutls_certificate_set_x509_trust_file, 95DEF_DLL_FN (int, gnutls_certificate_set_x509_trust_file,
84 (gnutls_certificate_credentials_t, const char *, 96 (gnutls_certificate_credentials_t, const char *,
85 gnutls_x509_crt_fmt_t)); 97 gnutls_x509_crt_fmt_t));
@@ -96,9 +108,9 @@ DEF_DLL_FN (int, gnutls_dh_get_prime_bits, (gnutls_session_t));
96DEF_DLL_FN (int, gnutls_error_is_fatal, (int)); 108DEF_DLL_FN (int, gnutls_error_is_fatal, (int));
97DEF_DLL_FN (int, gnutls_global_init, (void)); 109DEF_DLL_FN (int, gnutls_global_init, (void));
98DEF_DLL_FN (void, gnutls_global_set_log_function, (gnutls_log_func)); 110DEF_DLL_FN (void, gnutls_global_set_log_function, (gnutls_log_func));
99# ifdef HAVE_GNUTLS3 111# ifdef HAVE_GNUTLS3
100DEF_DLL_FN (void, gnutls_global_set_audit_log_function, (gnutls_audit_log_func)); 112DEF_DLL_FN (void, gnutls_global_set_audit_log_function, (gnutls_audit_log_func));
101# endif 113# endif
102DEF_DLL_FN (void, gnutls_global_set_log_level, (int)); 114DEF_DLL_FN (void, gnutls_global_set_log_level, (int));
103DEF_DLL_FN (int, gnutls_handshake, (gnutls_session_t)); 115DEF_DLL_FN (int, gnutls_handshake, (gnutls_session_t));
104DEF_DLL_FN (int, gnutls_init, (gnutls_session_t *, unsigned int)); 116DEF_DLL_FN (int, gnutls_init, (gnutls_session_t *, unsigned int));
@@ -172,14 +184,13 @@ DEF_DLL_FN (const char *, gnutls_cipher_get_name,
172DEF_DLL_FN (gnutls_mac_algorithm_t, gnutls_mac_get, (gnutls_session_t)); 184DEF_DLL_FN (gnutls_mac_algorithm_t, gnutls_mac_get, (gnutls_session_t));
173DEF_DLL_FN (const char *, gnutls_mac_get_name, (gnutls_mac_algorithm_t)); 185DEF_DLL_FN (const char *, gnutls_mac_get_name, (gnutls_mac_algorithm_t));
174 186
175# ifdef HAVE_GNUTLS3 187# ifdef HAVE_GNUTLS3
176DEF_DLL_FN (int, gnutls_rnd, (gnutls_rnd_level_t, void *, size_t)); 188DEF_DLL_FN (int, gnutls_rnd, (gnutls_rnd_level_t, void *, size_t));
177DEF_DLL_FN (const gnutls_mac_algorithm_t *, gnutls_mac_list, (void)); 189DEF_DLL_FN (const gnutls_mac_algorithm_t *, gnutls_mac_list, (void));
178DEF_DLL_FN (size_t, gnutls_mac_get_nonce_size, (gnutls_mac_algorithm_t)); 190DEF_DLL_FN (size_t, gnutls_mac_get_nonce_size, (gnutls_mac_algorithm_t));
179DEF_DLL_FN (size_t, gnutls_mac_get_key_size, (gnutls_mac_algorithm_t)); 191DEF_DLL_FN (size_t, gnutls_mac_get_key_size, (gnutls_mac_algorithm_t));
180DEF_DLL_FN (const gnutls_digest_algorithm_t *, gnutls_digest_list, (void)); 192DEF_DLL_FN (const gnutls_digest_algorithm_t *, gnutls_digest_list, (void));
181DEF_DLL_FN (const char *, gnutls_digest_get_name, (gnutls_digest_algorithm_t)); 193DEF_DLL_FN (const char *, gnutls_digest_get_name, (gnutls_digest_algorithm_t));
182# ifdef HAVE_GNUTLS3_CIPHER
183DEF_DLL_FN (gnutls_cipher_algorithm_t *, gnutls_cipher_list, (void)); 194DEF_DLL_FN (gnutls_cipher_algorithm_t *, gnutls_cipher_list, (void));
184DEF_DLL_FN (int, gnutls_cipher_get_iv_size, (gnutls_cipher_algorithm_t)); 195DEF_DLL_FN (int, gnutls_cipher_get_iv_size, (gnutls_cipher_algorithm_t));
185DEF_DLL_FN (size_t, gnutls_cipher_get_key_size, (gnutls_cipher_algorithm_t)); 196DEF_DLL_FN (size_t, gnutls_cipher_get_key_size, (gnutls_cipher_algorithm_t));
@@ -194,7 +205,7 @@ DEF_DLL_FN (int, gnutls_cipher_encrypt2,
194DEF_DLL_FN (void, gnutls_cipher_deinit, (gnutls_cipher_hd_t)); 205DEF_DLL_FN (void, gnutls_cipher_deinit, (gnutls_cipher_hd_t));
195DEF_DLL_FN (int, gnutls_cipher_decrypt2, 206DEF_DLL_FN (int, gnutls_cipher_decrypt2,
196 (gnutls_cipher_hd_t, const void *, size_t, void *, size_t)); 207 (gnutls_cipher_hd_t, const void *, size_t, void *, size_t));
197# ifdef HAVE_GNUTLS3_AEAD 208# ifdef HAVE_GNUTLS_AEAD
198DEF_DLL_FN (int, gnutls_aead_cipher_init, 209DEF_DLL_FN (int, gnutls_aead_cipher_init,
199 (gnutls_aead_cipher_hd_t *, gnutls_cipher_algorithm_t, 210 (gnutls_aead_cipher_hd_t *, gnutls_cipher_algorithm_t,
200 const gnutls_datum_t *)); 211 const gnutls_datum_t *));
@@ -205,25 +216,20 @@ DEF_DLL_FN (int, gnutls_aead_cipher_encrypt,
205DEF_DLL_FN (int, gnutls_aead_cipher_decrypt, 216DEF_DLL_FN (int, gnutls_aead_cipher_decrypt,
206 (gnutls_aead_cipher_hd_t, const void *, size_t, const void *, 217 (gnutls_aead_cipher_hd_t, const void *, size_t, const void *,
207 size_t, size_t, const void *, size_t, void *, size_t *)); 218 size_t, size_t, const void *, size_t, void *, size_t *));
208# endif /* HAVE_GNUTLS3_AEAD */ 219# endif
209# ifdef HAVE_GNUTLS3_HMAC
210DEF_DLL_FN (int, gnutls_hmac_init, 220DEF_DLL_FN (int, gnutls_hmac_init,
211 (gnutls_hmac_hd_t *, gnutls_mac_algorithm_t, const void *, size_t)); 221 (gnutls_hmac_hd_t *, gnutls_mac_algorithm_t, const void *, size_t));
212DEF_DLL_FN (int, gnutls_hmac_get_len, (gnutls_mac_algorithm_t)); 222DEF_DLL_FN (int, gnutls_hmac_get_len, (gnutls_mac_algorithm_t));
213DEF_DLL_FN (int, gnutls_hmac, (gnutls_hmac_hd_t, const void *, size_t)); 223DEF_DLL_FN (int, gnutls_hmac, (gnutls_hmac_hd_t, const void *, size_t));
214DEF_DLL_FN (void, gnutls_hmac_deinit, (gnutls_hmac_hd_t, void *)); 224DEF_DLL_FN (void, gnutls_hmac_deinit, (gnutls_hmac_hd_t, void *));
215DEF_DLL_FN (void, gnutls_hmac_output, (gnutls_hmac_hd_t, void *)); 225DEF_DLL_FN (void, gnutls_hmac_output, (gnutls_hmac_hd_t, void *));
216# endif /* HAVE_GNUTLS3_HMAC */
217# endif /* HAVE_GNUTLS3_CIPHER */
218# ifdef HAVE_GNUTLS3_DIGEST
219 DEF_DLL_FN (int, gnutls_hash_init, 226 DEF_DLL_FN (int, gnutls_hash_init,
220 (gnutls_hash_hd_t *, gnutls_digest_algorithm_t)); 227 (gnutls_hash_hd_t *, gnutls_digest_algorithm_t));
221DEF_DLL_FN (int, gnutls_hash_get_len, (gnutls_digest_algorithm_t)); 228DEF_DLL_FN (int, gnutls_hash_get_len, (gnutls_digest_algorithm_t));
222DEF_DLL_FN (int, gnutls_hash, (gnutls_hash_hd_t, const void *, size_t)); 229DEF_DLL_FN (int, gnutls_hash, (gnutls_hash_hd_t, const void *, size_t));
223DEF_DLL_FN (void, gnutls_hash_deinit, (gnutls_hash_hd_t, void *)); 230DEF_DLL_FN (void, gnutls_hash_deinit, (gnutls_hash_hd_t, void *));
224DEF_DLL_FN (void, gnutls_hash_output, (gnutls_hash_hd_t, void *)); 231DEF_DLL_FN (void, gnutls_hash_output, (gnutls_hash_hd_t, void *));
225# endif /* HAVE_GNUTLS3_DIGEST */ 232# endif /* HAVE_GNUTLS3 */
226# endif /* HAVE_GNUTLS3 */
227 233
228 234
229static bool 235static bool
@@ -249,11 +255,9 @@ init_gnutls_functions (void)
249 LOAD_DLL_FN (library, gnutls_certificate_set_verify_flags); 255 LOAD_DLL_FN (library, gnutls_certificate_set_verify_flags);
250 LOAD_DLL_FN (library, gnutls_certificate_set_x509_crl_file); 256 LOAD_DLL_FN (library, gnutls_certificate_set_x509_crl_file);
251 LOAD_DLL_FN (library, gnutls_certificate_set_x509_key_file); 257 LOAD_DLL_FN (library, gnutls_certificate_set_x509_key_file);
252# if ((GNUTLS_VERSION_MAJOR \ 258# ifdef HAVE_GNUTLS_X509_SYSTEM_TRUST
253 + (GNUTLS_VERSION_MINOR > 0 || GNUTLS_VERSION_PATCH >= 20)) \
254 > 3)
255 LOAD_DLL_FN (library, gnutls_certificate_set_x509_system_trust); 259 LOAD_DLL_FN (library, gnutls_certificate_set_x509_system_trust);
256# endif 260# endif
257 LOAD_DLL_FN (library, gnutls_certificate_set_x509_trust_file); 261 LOAD_DLL_FN (library, gnutls_certificate_set_x509_trust_file);
258 LOAD_DLL_FN (library, gnutls_certificate_type_get); 262 LOAD_DLL_FN (library, gnutls_certificate_type_get);
259 LOAD_DLL_FN (library, gnutls_certificate_verify_peers2); 263 LOAD_DLL_FN (library, gnutls_certificate_verify_peers2);
@@ -264,9 +268,9 @@ init_gnutls_functions (void)
264 LOAD_DLL_FN (library, gnutls_error_is_fatal); 268 LOAD_DLL_FN (library, gnutls_error_is_fatal);
265 LOAD_DLL_FN (library, gnutls_global_init); 269 LOAD_DLL_FN (library, gnutls_global_init);
266 LOAD_DLL_FN (library, gnutls_global_set_log_function); 270 LOAD_DLL_FN (library, gnutls_global_set_log_function);
267# ifdef HAVE_GNUTLS3 271# ifdef HAVE_GNUTLS3
268 LOAD_DLL_FN (library, gnutls_global_set_audit_log_function); 272 LOAD_DLL_FN (library, gnutls_global_set_audit_log_function);
269# endif 273# endif
270 LOAD_DLL_FN (library, gnutls_global_set_log_level); 274 LOAD_DLL_FN (library, gnutls_global_set_log_level);
271 LOAD_DLL_FN (library, gnutls_handshake); 275 LOAD_DLL_FN (library, gnutls_handshake);
272 LOAD_DLL_FN (library, gnutls_init); 276 LOAD_DLL_FN (library, gnutls_init);
@@ -309,14 +313,13 @@ init_gnutls_functions (void)
309 LOAD_DLL_FN (library, gnutls_cipher_get_name); 313 LOAD_DLL_FN (library, gnutls_cipher_get_name);
310 LOAD_DLL_FN (library, gnutls_mac_get); 314 LOAD_DLL_FN (library, gnutls_mac_get);
311 LOAD_DLL_FN (library, gnutls_mac_get_name); 315 LOAD_DLL_FN (library, gnutls_mac_get_name);
312# ifdef HAVE_GNUTLS3 316# ifdef HAVE_GNUTLS3
313 LOAD_DLL_FN (library, gnutls_rnd); 317 LOAD_DLL_FN (library, gnutls_rnd);
314 LOAD_DLL_FN (library, gnutls_mac_list); 318 LOAD_DLL_FN (library, gnutls_mac_list);
315 LOAD_DLL_FN (library, gnutls_mac_get_nonce_size); 319 LOAD_DLL_FN (library, gnutls_mac_get_nonce_size);
316 LOAD_DLL_FN (library, gnutls_mac_get_key_size); 320 LOAD_DLL_FN (library, gnutls_mac_get_key_size);
317 LOAD_DLL_FN (library, gnutls_digest_list); 321 LOAD_DLL_FN (library, gnutls_digest_list);
318 LOAD_DLL_FN (library, gnutls_digest_get_name); 322 LOAD_DLL_FN (library, gnutls_digest_get_name);
319# ifdef HAVE_GNUTLS3_CIPHER
320 LOAD_DLL_FN (library, gnutls_cipher_list); 323 LOAD_DLL_FN (library, gnutls_cipher_list);
321 LOAD_DLL_FN (library, gnutls_cipher_get_iv_size); 324 LOAD_DLL_FN (library, gnutls_cipher_get_iv_size);
322 LOAD_DLL_FN (library, gnutls_cipher_get_key_size); 325 LOAD_DLL_FN (library, gnutls_cipher_get_key_size);
@@ -327,28 +330,23 @@ init_gnutls_functions (void)
327 LOAD_DLL_FN (library, gnutls_cipher_encrypt2); 330 LOAD_DLL_FN (library, gnutls_cipher_encrypt2);
328 LOAD_DLL_FN (library, gnutls_cipher_deinit); 331 LOAD_DLL_FN (library, gnutls_cipher_deinit);
329 LOAD_DLL_FN (library, gnutls_cipher_decrypt2); 332 LOAD_DLL_FN (library, gnutls_cipher_decrypt2);
330# ifdef HAVE_GNUTLS3_AEAD 333# ifdef HAVE_GNUTLS_AEAD
331 LOAD_DLL_FN (library, gnutls_aead_cipher_init); 334 LOAD_DLL_FN (library, gnutls_aead_cipher_init);
332 LOAD_DLL_FN (library, gnutls_aead_cipher_deinit); 335 LOAD_DLL_FN (library, gnutls_aead_cipher_deinit);
333 LOAD_DLL_FN (library, gnutls_aead_cipher_encrypt); 336 LOAD_DLL_FN (library, gnutls_aead_cipher_encrypt);
334 LOAD_DLL_FN (library, gnutls_aead_cipher_decrypt); 337 LOAD_DLL_FN (library, gnutls_aead_cipher_decrypt);
335# endif 338# endif
336# ifdef HAVE_GNUTLS3_HMAC
337 LOAD_DLL_FN (library, gnutls_hmac_init); 339 LOAD_DLL_FN (library, gnutls_hmac_init);
338 LOAD_DLL_FN (library, gnutls_hmac_get_len); 340 LOAD_DLL_FN (library, gnutls_hmac_get_len);
339 LOAD_DLL_FN (library, gnutls_hmac); 341 LOAD_DLL_FN (library, gnutls_hmac);
340 LOAD_DLL_FN (library, gnutls_hmac_deinit); 342 LOAD_DLL_FN (library, gnutls_hmac_deinit);
341 LOAD_DLL_FN (library, gnutls_hmac_output); 343 LOAD_DLL_FN (library, gnutls_hmac_output);
342# endif /* HAVE_GNUTLS3_HMAC */
343# endif /* HAVE_GNUTLS3_CIPHER */
344# ifdef HAVE_GNUTLS3_DIGEST
345 LOAD_DLL_FN (library, gnutls_hash_init); 344 LOAD_DLL_FN (library, gnutls_hash_init);
346 LOAD_DLL_FN (library, gnutls_hash_get_len); 345 LOAD_DLL_FN (library, gnutls_hash_get_len);
347 LOAD_DLL_FN (library, gnutls_hash); 346 LOAD_DLL_FN (library, gnutls_hash);
348 LOAD_DLL_FN (library, gnutls_hash_deinit); 347 LOAD_DLL_FN (library, gnutls_hash_deinit);
349 LOAD_DLL_FN (library, gnutls_hash_output); 348 LOAD_DLL_FN (library, gnutls_hash_output);
350# endif 349# endif /* HAVE_GNUTLS3 */
351# endif /* HAVE_GNUTLS3 */
352 350
353 max_log_level = global_gnutls_log_level; 351 max_log_level = global_gnutls_log_level;
354 352
@@ -361,111 +359,105 @@ init_gnutls_functions (void)
361 return 1; 359 return 1;
362} 360}
363 361
364# define gnutls_alert_get fn_gnutls_alert_get 362# define gnutls_alert_get fn_gnutls_alert_get
365# define gnutls_alert_get_name fn_gnutls_alert_get_name 363# define gnutls_alert_get_name fn_gnutls_alert_get_name
366# define gnutls_anon_allocate_client_credentials fn_gnutls_anon_allocate_client_credentials 364# define gnutls_anon_allocate_client_credentials fn_gnutls_anon_allocate_client_credentials
367# define gnutls_anon_free_client_credentials fn_gnutls_anon_free_client_credentials 365# define gnutls_anon_free_client_credentials fn_gnutls_anon_free_client_credentials
368# define gnutls_bye fn_gnutls_bye 366# define gnutls_bye fn_gnutls_bye
369# define gnutls_certificate_allocate_credentials fn_gnutls_certificate_allocate_credentials 367# define gnutls_certificate_allocate_credentials fn_gnutls_certificate_allocate_credentials
370# define gnutls_certificate_free_credentials fn_gnutls_certificate_free_credentials 368# define gnutls_certificate_free_credentials fn_gnutls_certificate_free_credentials
371# define gnutls_certificate_get_peers fn_gnutls_certificate_get_peers 369# define gnutls_certificate_get_peers fn_gnutls_certificate_get_peers
372# define gnutls_certificate_set_verify_flags fn_gnutls_certificate_set_verify_flags 370# define gnutls_certificate_set_verify_flags fn_gnutls_certificate_set_verify_flags
373# define gnutls_certificate_set_x509_crl_file fn_gnutls_certificate_set_x509_crl_file 371# define gnutls_certificate_set_x509_crl_file fn_gnutls_certificate_set_x509_crl_file
374# define gnutls_certificate_set_x509_key_file fn_gnutls_certificate_set_x509_key_file 372# define gnutls_certificate_set_x509_key_file fn_gnutls_certificate_set_x509_key_file
375# define gnutls_certificate_set_x509_system_trust fn_gnutls_certificate_set_x509_system_trust 373# define gnutls_certificate_set_x509_system_trust fn_gnutls_certificate_set_x509_system_trust
376# define gnutls_certificate_set_x509_trust_file fn_gnutls_certificate_set_x509_trust_file 374# define gnutls_certificate_set_x509_trust_file fn_gnutls_certificate_set_x509_trust_file
377# define gnutls_certificate_type_get fn_gnutls_certificate_type_get 375# define gnutls_certificate_type_get fn_gnutls_certificate_type_get
378# define gnutls_certificate_verify_peers2 fn_gnutls_certificate_verify_peers2 376# define gnutls_certificate_verify_peers2 fn_gnutls_certificate_verify_peers2
379# define gnutls_cipher_get fn_gnutls_cipher_get 377# define gnutls_cipher_get fn_gnutls_cipher_get
380# define gnutls_cipher_get_name fn_gnutls_cipher_get_name 378# define gnutls_cipher_get_name fn_gnutls_cipher_get_name
381# define gnutls_credentials_set fn_gnutls_credentials_set 379# define gnutls_credentials_set fn_gnutls_credentials_set
382# define gnutls_deinit fn_gnutls_deinit 380# define gnutls_deinit fn_gnutls_deinit
383# define gnutls_dh_get_prime_bits fn_gnutls_dh_get_prime_bits 381# define gnutls_dh_get_prime_bits fn_gnutls_dh_get_prime_bits
384# define gnutls_dh_set_prime_bits fn_gnutls_dh_set_prime_bits 382# define gnutls_dh_set_prime_bits fn_gnutls_dh_set_prime_bits
385# define gnutls_error_is_fatal fn_gnutls_error_is_fatal 383# define gnutls_error_is_fatal fn_gnutls_error_is_fatal
386# define gnutls_global_init fn_gnutls_global_init 384# define gnutls_global_init fn_gnutls_global_init
387# define gnutls_global_set_audit_log_function fn_gnutls_global_set_audit_log_function 385# define gnutls_global_set_audit_log_function fn_gnutls_global_set_audit_log_function
388# define gnutls_global_set_log_function fn_gnutls_global_set_log_function 386# define gnutls_global_set_log_function fn_gnutls_global_set_log_function
389# define gnutls_global_set_log_level fn_gnutls_global_set_log_level 387# define gnutls_global_set_log_level fn_gnutls_global_set_log_level
390# define gnutls_handshake fn_gnutls_handshake 388# define gnutls_handshake fn_gnutls_handshake
391# define gnutls_init fn_gnutls_init 389# define gnutls_init fn_gnutls_init
392# define gnutls_kx_get fn_gnutls_kx_get 390# define gnutls_kx_get fn_gnutls_kx_get
393# define gnutls_kx_get_name fn_gnutls_kx_get_name 391# define gnutls_kx_get_name fn_gnutls_kx_get_name
394# define gnutls_mac_get fn_gnutls_mac_get 392# define gnutls_mac_get fn_gnutls_mac_get
395# define gnutls_mac_get_name fn_gnutls_mac_get_name 393# define gnutls_mac_get_name fn_gnutls_mac_get_name
396# define gnutls_pk_algorithm_get_name fn_gnutls_pk_algorithm_get_name 394# define gnutls_pk_algorithm_get_name fn_gnutls_pk_algorithm_get_name
397# define gnutls_pk_bits_to_sec_param fn_gnutls_pk_bits_to_sec_param 395# define gnutls_pk_bits_to_sec_param fn_gnutls_pk_bits_to_sec_param
398# define gnutls_priority_set_direct fn_gnutls_priority_set_direct 396# define gnutls_priority_set_direct fn_gnutls_priority_set_direct
399# define gnutls_protocol_get_name fn_gnutls_protocol_get_name 397# define gnutls_protocol_get_name fn_gnutls_protocol_get_name
400# define gnutls_protocol_get_version fn_gnutls_protocol_get_version 398# define gnutls_protocol_get_version fn_gnutls_protocol_get_version
401# define gnutls_record_check_pending fn_gnutls_record_check_pending 399# define gnutls_record_check_pending fn_gnutls_record_check_pending
402# define gnutls_record_recv fn_gnutls_record_recv 400# define gnutls_record_recv fn_gnutls_record_recv
403# define gnutls_record_send fn_gnutls_record_send 401# define gnutls_record_send fn_gnutls_record_send
404# define gnutls_sec_param_get_name fn_gnutls_sec_param_get_name 402# define gnutls_sec_param_get_name fn_gnutls_sec_param_get_name
405# define gnutls_server_name_set fn_gnutls_server_name_set 403# define gnutls_server_name_set fn_gnutls_server_name_set
406# define gnutls_sign_get_name fn_gnutls_sign_get_name 404# define gnutls_sign_get_name fn_gnutls_sign_get_name
407# define gnutls_strerror fn_gnutls_strerror 405# define gnutls_strerror fn_gnutls_strerror
408# define gnutls_transport_set_errno fn_gnutls_transport_set_errno 406# define gnutls_transport_set_errno fn_gnutls_transport_set_errno
409# define gnutls_transport_set_ptr2 fn_gnutls_transport_set_ptr2 407# define gnutls_transport_set_ptr2 fn_gnutls_transport_set_ptr2
410# define gnutls_transport_set_pull_function fn_gnutls_transport_set_pull_function 408# define gnutls_transport_set_pull_function fn_gnutls_transport_set_pull_function
411# define gnutls_transport_set_push_function fn_gnutls_transport_set_push_function 409# define gnutls_transport_set_push_function fn_gnutls_transport_set_push_function
412# define gnutls_x509_crt_check_hostname fn_gnutls_x509_crt_check_hostname 410# define gnutls_x509_crt_check_hostname fn_gnutls_x509_crt_check_hostname
413# define gnutls_x509_crt_check_issuer fn_gnutls_x509_crt_check_issuer 411# define gnutls_x509_crt_check_issuer fn_gnutls_x509_crt_check_issuer
414# define gnutls_x509_crt_deinit fn_gnutls_x509_crt_deinit 412# define gnutls_x509_crt_deinit fn_gnutls_x509_crt_deinit
415# define gnutls_x509_crt_get_activation_time fn_gnutls_x509_crt_get_activation_time 413# define gnutls_x509_crt_get_activation_time fn_gnutls_x509_crt_get_activation_time
416# define gnutls_x509_crt_get_dn fn_gnutls_x509_crt_get_dn 414# define gnutls_x509_crt_get_dn fn_gnutls_x509_crt_get_dn
417# define gnutls_x509_crt_get_expiration_time fn_gnutls_x509_crt_get_expiration_time 415# define gnutls_x509_crt_get_expiration_time fn_gnutls_x509_crt_get_expiration_time
418# define gnutls_x509_crt_get_fingerprint fn_gnutls_x509_crt_get_fingerprint 416# define gnutls_x509_crt_get_fingerprint fn_gnutls_x509_crt_get_fingerprint
419# define gnutls_x509_crt_get_issuer_dn fn_gnutls_x509_crt_get_issuer_dn 417# define gnutls_x509_crt_get_issuer_dn fn_gnutls_x509_crt_get_issuer_dn
420# define gnutls_x509_crt_get_issuer_unique_id fn_gnutls_x509_crt_get_issuer_unique_id 418# define gnutls_x509_crt_get_issuer_unique_id fn_gnutls_x509_crt_get_issuer_unique_id
421# define gnutls_x509_crt_get_key_id fn_gnutls_x509_crt_get_key_id 419# define gnutls_x509_crt_get_key_id fn_gnutls_x509_crt_get_key_id
422# define gnutls_x509_crt_get_pk_algorithm fn_gnutls_x509_crt_get_pk_algorithm 420# define gnutls_x509_crt_get_pk_algorithm fn_gnutls_x509_crt_get_pk_algorithm
423# define gnutls_x509_crt_get_serial fn_gnutls_x509_crt_get_serial 421# define gnutls_x509_crt_get_serial fn_gnutls_x509_crt_get_serial
424# define gnutls_x509_crt_get_signature_algorithm fn_gnutls_x509_crt_get_signature_algorithm 422# define gnutls_x509_crt_get_signature_algorithm fn_gnutls_x509_crt_get_signature_algorithm
425# define gnutls_x509_crt_get_subject_unique_id fn_gnutls_x509_crt_get_subject_unique_id 423# define gnutls_x509_crt_get_subject_unique_id fn_gnutls_x509_crt_get_subject_unique_id
426# define gnutls_x509_crt_get_version fn_gnutls_x509_crt_get_version 424# define gnutls_x509_crt_get_version fn_gnutls_x509_crt_get_version
427# define gnutls_x509_crt_import fn_gnutls_x509_crt_import 425# define gnutls_x509_crt_import fn_gnutls_x509_crt_import
428# define gnutls_x509_crt_init fn_gnutls_x509_crt_init 426# define gnutls_x509_crt_init fn_gnutls_x509_crt_init
429# ifdef HAVE_GNUTLS3 427# ifdef HAVE_GNUTLS3
430# define gnutls_rnd fn_gnutls_rnd 428# define gnutls_rnd fn_gnutls_rnd
431# define gnutls_mac_list fn_gnutls_mac_list 429# define gnutls_mac_list fn_gnutls_mac_list
432# define gnutls_mac_get_nonce_size fn_gnutls_mac_get_nonce_size 430# define gnutls_mac_get_nonce_size fn_gnutls_mac_get_nonce_size
433# define gnutls_mac_get_key_size fn_gnutls_mac_get_key_size 431# define gnutls_mac_get_key_size fn_gnutls_mac_get_key_size
434# define gnutls_digest_list fn_gnutls_digest_list 432# define gnutls_digest_list fn_gnutls_digest_list
435# define gnutls_digest_get_name fn_gnutls_digest_get_name 433# define gnutls_digest_get_name fn_gnutls_digest_get_name
436# ifdef HAVE_GNUTLS3_CIPHER 434# define gnutls_cipher_list fn_gnutls_cipher_list
437# define gnutls_cipher_list fn_gnutls_cipher_list 435# define gnutls_cipher_get_iv_size fn_gnutls_cipher_get_iv_size
438# define gnutls_cipher_get_iv_size fn_gnutls_cipher_get_iv_size 436# define gnutls_cipher_get_key_size fn_gnutls_cipher_get_key_size
439# define gnutls_cipher_get_key_size fn_gnutls_cipher_get_key_size 437# define gnutls_cipher_get_block_size fn_gnutls_cipher_get_block_size
440# define gnutls_cipher_get_block_size fn_gnutls_cipher_get_block_size 438# define gnutls_cipher_get_tag_size fn_gnutls_cipher_get_tag_size
441# define gnutls_cipher_get_tag_size fn_gnutls_cipher_get_tag_size 439# define gnutls_cipher_init fn_gnutls_cipher_init
442# define gnutls_cipher_init fn_gnutls_cipher_init 440# define gnutls_cipher_set_iv fn_gnutls_cipher_set_iv
443# define gnutls_cipher_set_iv fn_gnutls_cipher_set_iv 441# define gnutls_cipher_encrypt2 fn_gnutls_cipher_encrypt2
444# define gnutls_cipher_encrypt2 fn_gnutls_cipher_encrypt2 442# define gnutls_cipher_decrypt2 fn_gnutls_cipher_decrypt2
445# define gnutls_cipher_decrypt2 fn_gnutls_cipher_decrypt2 443# define gnutls_cipher_deinit fn_gnutls_cipher_deinit
446# define gnutls_cipher_deinit fn_gnutls_cipher_deinit 444# ifdef HAVE_GNUTLS_AEAD
447# ifdef HAVE_GNUTLS3_AEAD 445# define gnutls_aead_cipher_encrypt fn_gnutls_aead_cipher_encrypt
448# define gnutls_aead_cipher_encrypt fn_gnutls_aead_cipher_encrypt 446# define gnutls_aead_cipher_decrypt fn_gnutls_aead_cipher_decrypt
449# define gnutls_aead_cipher_decrypt fn_gnutls_aead_cipher_decrypt 447# define gnutls_aead_cipher_init fn_gnutls_aead_cipher_init
450# define gnutls_aead_cipher_init fn_gnutls_aead_cipher_init 448# define gnutls_aead_cipher_deinit fn_gnutls_aead_cipher_deinit
451# define gnutls_aead_cipher_deinit fn_gnutls_aead_cipher_deinit 449# endif
452# endif /* HAVE_GNUTLS3_AEAD */ 450# define gnutls_hmac_init fn_gnutls_hmac_init
453# ifdef HAVE_GNUTLS3_HMAC 451# define gnutls_hmac_get_len fn_gnutls_hmac_get_len
454# define gnutls_hmac_init fn_gnutls_hmac_init 452# define gnutls_hmac fn_gnutls_hmac
455# define gnutls_hmac_get_len fn_gnutls_hmac_get_len 453# define gnutls_hmac_deinit fn_gnutls_hmac_deinit
456# define gnutls_hmac fn_gnutls_hmac 454# define gnutls_hmac_output fn_gnutls_hmac_output
457# define gnutls_hmac_deinit fn_gnutls_hmac_deinit 455# define gnutls_hash_init fn_gnutls_hash_init
458# define gnutls_hmac_output fn_gnutls_hmac_output 456# define gnutls_hash_get_len fn_gnutls_hash_get_len
459# endif /* HAVE_GNUTLS3_HMAC */ 457# define gnutls_hash fn_gnutls_hash
460# endif /* HAVE_GNUTLS3_CIPHER */ 458# define gnutls_hash_deinit fn_gnutls_hash_deinit
461# ifdef HAVE_GNUTLS3_DIGEST 459# define gnutls_hash_output fn_gnutls_hash_output
462# define gnutls_hash_init fn_gnutls_hash_init 460# endif /* HAVE_GNUTLS3 */
463# define gnutls_hash_get_len fn_gnutls_hash_get_len
464# define gnutls_hash fn_gnutls_hash
465# define gnutls_hash_deinit fn_gnutls_hash_deinit
466# define gnutls_hash_output fn_gnutls_hash_output
467# endif
468# endif /* HAVE_GNUTLS3 */
469 461
470/* This wrapper is called from fns.c, which doesn't know about the 462/* This wrapper is called from fns.c, which doesn't know about the
471 LOAD_DLL_FN stuff above. */ 463 LOAD_DLL_FN stuff above. */
@@ -475,7 +467,7 @@ w32_gnutls_rnd (gnutls_rnd_level_t level, void *data, size_t len)
475 return gnutls_rnd (level, data, len); 467 return gnutls_rnd (level, data, len);
476} 468}
477 469
478#endif /* WINDOWSNT */ 470# endif /* WINDOWSNT */
479 471
480 472
481/* Report memory exhaustion if ERR is an out-of-memory indication. */ 473/* Report memory exhaustion if ERR is an out-of-memory indication. */
@@ -489,7 +481,7 @@ check_memory_full (int err)
489 memory_full (0); 481 memory_full (0);
490} 482}
491 483
492#ifdef HAVE_GNUTLS3 484# ifdef HAVE_GNUTLS3
493/* Log a simple audit message. */ 485/* Log a simple audit message. */
494static void 486static void
495gnutls_audit_log_function (gnutls_session_t session, const char *string) 487gnutls_audit_log_function (gnutls_session_t session, const char *string)
@@ -499,7 +491,7 @@ gnutls_audit_log_function (gnutls_session_t session, const char *string)
499 message ("gnutls.c: [audit] %s", string); 491 message ("gnutls.c: [audit] %s", string);
500 } 492 }
501} 493}
502#endif 494# endif
503 495
504/* Log a simple message. */ 496/* Log a simple message. */
505static void 497static void
@@ -552,7 +544,7 @@ gnutls_try_handshake (struct Lisp_Process *proc)
552 return ret; 544 return ret;
553} 545}
554 546
555#ifndef WINDOWSNT 547# ifndef WINDOWSNT
556static int 548static int
557emacs_gnutls_nonblock_errno (gnutls_transport_ptr_t ptr) 549emacs_gnutls_nonblock_errno (gnutls_transport_ptr_t ptr)
558{ 550{
@@ -560,13 +552,13 @@ emacs_gnutls_nonblock_errno (gnutls_transport_ptr_t ptr)
560 552
561 switch (err) 553 switch (err)
562 { 554 {
563# ifdef _AIX 555# ifdef _AIX
564 /* This is taken from the GnuTLS system_errno function circa 2016; 556 /* This is taken from the GnuTLS system_errno function circa 2016;
565 see <http://savannah.gnu.org/support/?107464>. */ 557 see <http://savannah.gnu.org/support/?107464>. */
566 case 0: 558 case 0:
567 errno = EAGAIN; 559 errno = EAGAIN;
568 /* Fall through. */ 560 /* Fall through. */
569# endif 561# endif
570 case EINPROGRESS: 562 case EINPROGRESS:
571 case ENOTCONN: 563 case ENOTCONN:
572 return EAGAIN; 564 return EAGAIN;
@@ -575,7 +567,7 @@ emacs_gnutls_nonblock_errno (gnutls_transport_ptr_t ptr)
575 return err; 567 return err;
576 } 568 }
577} 569}
578#endif /* !WINDOWSNT */ 570# endif /* !WINDOWSNT */
579 571
580static int 572static int
581emacs_gnutls_handshake (struct Lisp_Process *proc) 573emacs_gnutls_handshake (struct Lisp_Process *proc)
@@ -587,7 +579,7 @@ emacs_gnutls_handshake (struct Lisp_Process *proc)
587 579
588 if (proc->gnutls_initstage < GNUTLS_STAGE_TRANSPORT_POINTERS_SET) 580 if (proc->gnutls_initstage < GNUTLS_STAGE_TRANSPORT_POINTERS_SET)
589 { 581 {
590#ifdef WINDOWSNT 582# ifdef WINDOWSNT
591 /* On W32 we cannot transfer socket handles between different runtime 583 /* On W32 we cannot transfer socket handles between different runtime
592 libraries, so we tell GnuTLS to use our special push/pull 584 libraries, so we tell GnuTLS to use our special push/pull
593 functions. */ 585 functions. */
@@ -596,7 +588,7 @@ emacs_gnutls_handshake (struct Lisp_Process *proc)
596 (gnutls_transport_ptr_t) proc); 588 (gnutls_transport_ptr_t) proc);
597 gnutls_transport_set_push_function (state, &emacs_gnutls_push); 589 gnutls_transport_set_push_function (state, &emacs_gnutls_push);
598 gnutls_transport_set_pull_function (state, &emacs_gnutls_pull); 590 gnutls_transport_set_pull_function (state, &emacs_gnutls_pull);
599#else 591# else
600 /* This is how GnuTLS takes sockets: as file descriptors passed 592 /* This is how GnuTLS takes sockets: as file descriptors passed
601 in. For an Emacs process socket, infd and outfd are the 593 in. For an Emacs process socket, infd and outfd are the
602 same but we use this two-argument version for clarity. */ 594 same but we use this two-argument version for clarity. */
@@ -606,7 +598,7 @@ emacs_gnutls_handshake (struct Lisp_Process *proc)
606 if (proc->is_non_blocking_client) 598 if (proc->is_non_blocking_client)
607 gnutls_transport_set_errno_function (state, 599 gnutls_transport_set_errno_function (state,
608 emacs_gnutls_nonblock_errno); 600 emacs_gnutls_nonblock_errno);
609#endif 601# endif
610 602
611 proc->gnutls_initstage = GNUTLS_STAGE_TRANSPORT_POINTERS_SET; 603 proc->gnutls_initstage = GNUTLS_STAGE_TRANSPORT_POINTERS_SET;
612 } 604 }
@@ -620,13 +612,13 @@ emacs_gnutls_record_check_pending (gnutls_session_t state)
620 return gnutls_record_check_pending (state); 612 return gnutls_record_check_pending (state);
621} 613}
622 614
623#ifdef WINDOWSNT 615# ifdef WINDOWSNT
624void 616void
625emacs_gnutls_transport_set_errno (gnutls_session_t state, int err) 617emacs_gnutls_transport_set_errno (gnutls_session_t state, int err)
626{ 618{
627 gnutls_transport_set_errno (state, err); 619 gnutls_transport_set_errno (state, err);
628} 620}
629#endif 621# endif
630 622
631ptrdiff_t 623ptrdiff_t
632emacs_gnutls_write (struct Lisp_Process *proc, const char *buf, ptrdiff_t nbyte) 624emacs_gnutls_write (struct Lisp_Process *proc, const char *buf, ptrdiff_t nbyte)
@@ -732,10 +724,10 @@ emacs_gnutls_handle_error (gnutls_session_t session, int err)
732 /* Mostly ignore "The TLS connection was non-properly 724 /* Mostly ignore "The TLS connection was non-properly
733 terminated" message which just means that the peer closed the 725 terminated" message which just means that the peer closed the
734 connection. */ 726 connection. */
735#ifdef HAVE_GNUTLS3 727# ifdef HAVE_GNUTLS3
736 if (err == GNUTLS_E_PREMATURE_TERMINATION) 728 if (err == GNUTLS_E_PREMATURE_TERMINATION)
737 level = 3; 729 level = 3;
738#endif 730# endif
739 731
740 GNUTLS_LOG2 (level, max_log_level, "fatal error:", str); 732 GNUTLS_LOG2 (level, max_log_level, "fatal error:", str);
741 ret = false; 733 ret = false;
@@ -1300,7 +1292,7 @@ gnutls_ip_address_p (char *string)
1300 return true; 1292 return true;
1301} 1293}
1302 1294
1303#if 0 1295# if 0
1304/* Deinitialize global GnuTLS state. 1296/* Deinitialize global GnuTLS state.
1305 See also `gnutls-global-init'. */ 1297 See also `gnutls-global-init'. */
1306static Lisp_Object 1298static Lisp_Object
@@ -1313,7 +1305,7 @@ emacs_gnutls_global_deinit (void)
1313 1305
1314 return gnutls_make_error (GNUTLS_E_SUCCESS); 1306 return gnutls_make_error (GNUTLS_E_SUCCESS);
1315} 1307}
1316#endif 1308# endif
1317 1309
1318static void ATTRIBUTE_FORMAT_PRINTF (2, 3) 1310static void ATTRIBUTE_FORMAT_PRINTF (2, 3)
1319boot_error (struct Lisp_Process *p, const char *m, ...) 1311boot_error (struct Lisp_Process *p, const char *m, ...)
@@ -1585,9 +1577,9 @@ one trustfile (usually a CA bundle). */)
1585 if (TYPE_RANGED_INTEGERP (int, loglevel)) 1577 if (TYPE_RANGED_INTEGERP (int, loglevel))
1586 { 1578 {
1587 gnutls_global_set_log_function (gnutls_log_function); 1579 gnutls_global_set_log_function (gnutls_log_function);
1588#ifdef HAVE_GNUTLS3 1580# ifdef HAVE_GNUTLS3
1589 gnutls_global_set_audit_log_function (gnutls_audit_log_function); 1581 gnutls_global_set_audit_log_function (gnutls_audit_log_function);
1590#endif 1582# endif
1591 gnutls_global_set_log_level (XINT (loglevel)); 1583 gnutls_global_set_log_level (XINT (loglevel));
1592 max_log_level = XINT (loglevel); 1584 max_log_level = XINT (loglevel);
1593 XPROCESS (proc)->gnutls_log_level = max_log_level; 1585 XPROCESS (proc)->gnutls_log_level = max_log_level;
@@ -1649,8 +1641,7 @@ one trustfile (usually a CA bundle). */)
1649 int file_format = GNUTLS_X509_FMT_PEM; 1641 int file_format = GNUTLS_X509_FMT_PEM;
1650 Lisp_Object tail; 1642 Lisp_Object tail;
1651 1643
1652#if GNUTLS_VERSION_MAJOR + \ 1644# ifdef HAVE_GNUTLS_X509_SYSTEM_TRUST
1653 (GNUTLS_VERSION_MINOR > 0 || GNUTLS_VERSION_PATCH >= 20) > 3
1654 ret = gnutls_certificate_set_x509_system_trust (x509_cred); 1645 ret = gnutls_certificate_set_x509_system_trust (x509_cred);
1655 if (ret < GNUTLS_E_SUCCESS) 1646 if (ret < GNUTLS_E_SUCCESS)
1656 { 1647 {
@@ -1658,7 +1649,7 @@ one trustfile (usually a CA bundle). */)
1658 GNUTLS_LOG2i (4, max_log_level, 1649 GNUTLS_LOG2i (4, max_log_level,
1659 "setting system trust failed with code ", ret); 1650 "setting system trust failed with code ", ret);
1660 } 1651 }
1661#endif 1652# endif
1662 1653
1663 for (tail = trustfiles; CONSP (tail); tail = XCDR (tail)) 1654 for (tail = trustfiles; CONSP (tail); tail = XCDR (tail))
1664 { 1655 {
@@ -1668,12 +1659,12 @@ one trustfile (usually a CA bundle). */)
1668 GNUTLS_LOG2 (1, max_log_level, "setting the trustfile: ", 1659 GNUTLS_LOG2 (1, max_log_level, "setting the trustfile: ",
1669 SSDATA (trustfile)); 1660 SSDATA (trustfile));
1670 trustfile = ENCODE_FILE (trustfile); 1661 trustfile = ENCODE_FILE (trustfile);
1671#ifdef WINDOWSNT 1662# ifdef WINDOWSNT
1672 /* Since GnuTLS doesn't support UTF-8 or UTF-16 encoded 1663 /* Since GnuTLS doesn't support UTF-8 or UTF-16 encoded
1673 file names on Windows, we need to re-encode the file 1664 file names on Windows, we need to re-encode the file
1674 name using the current ANSI codepage. */ 1665 name using the current ANSI codepage. */
1675 trustfile = ansi_encode_filename (trustfile); 1666 trustfile = ansi_encode_filename (trustfile);
1676#endif 1667# endif
1677 ret = gnutls_certificate_set_x509_trust_file 1668 ret = gnutls_certificate_set_x509_trust_file
1678 (x509_cred, 1669 (x509_cred,
1679 SSDATA (trustfile), 1670 SSDATA (trustfile),
@@ -1698,9 +1689,9 @@ one trustfile (usually a CA bundle). */)
1698 GNUTLS_LOG2 (1, max_log_level, "setting the CRL file: ", 1689 GNUTLS_LOG2 (1, max_log_level, "setting the CRL file: ",
1699 SSDATA (crlfile)); 1690 SSDATA (crlfile));
1700 crlfile = ENCODE_FILE (crlfile); 1691 crlfile = ENCODE_FILE (crlfile);
1701#ifdef WINDOWSNT 1692# ifdef WINDOWSNT
1702 crlfile = ansi_encode_filename (crlfile); 1693 crlfile = ansi_encode_filename (crlfile);
1703#endif 1694# endif
1704 ret = gnutls_certificate_set_x509_crl_file 1695 ret = gnutls_certificate_set_x509_crl_file
1705 (x509_cred, SSDATA (crlfile), file_format); 1696 (x509_cred, SSDATA (crlfile), file_format);
1706 1697
@@ -1727,10 +1718,10 @@ one trustfile (usually a CA bundle). */)
1727 SSDATA (certfile)); 1718 SSDATA (certfile));
1728 keyfile = ENCODE_FILE (keyfile); 1719 keyfile = ENCODE_FILE (keyfile);
1729 certfile = ENCODE_FILE (certfile); 1720 certfile = ENCODE_FILE (certfile);
1730#ifdef WINDOWSNT 1721# ifdef WINDOWSNT
1731 keyfile = ansi_encode_filename (keyfile); 1722 keyfile = ansi_encode_filename (keyfile);
1732 certfile = ansi_encode_filename (certfile); 1723 certfile = ansi_encode_filename (certfile);
1733#endif 1724# endif
1734 ret = gnutls_certificate_set_x509_key_file 1725 ret = gnutls_certificate_set_x509_key_file
1735 (x509_cred, SSDATA (certfile), SSDATA (keyfile), file_format); 1726 (x509_cred, SSDATA (certfile), SSDATA (keyfile), file_format);
1736 1727
@@ -1755,10 +1746,10 @@ one trustfile (usually a CA bundle). */)
1755 1746
1756 GNUTLS_LOG (1, max_log_level, "gnutls_init"); 1747 GNUTLS_LOG (1, max_log_level, "gnutls_init");
1757 int gnutls_flags = GNUTLS_CLIENT; 1748 int gnutls_flags = GNUTLS_CLIENT;
1758#ifdef GNUTLS_NONBLOCK 1749# ifdef GNUTLS_NONBLOCK
1759 if (XPROCESS (proc)->is_non_blocking_client) 1750 if (XPROCESS (proc)->is_non_blocking_client)
1760 gnutls_flags |= GNUTLS_NONBLOCK; 1751 gnutls_flags |= GNUTLS_NONBLOCK;
1761#endif 1752# endif
1762 ret = gnutls_init (&state, gnutls_flags); 1753 ret = gnutls_init (&state, gnutls_flags);
1763 XPROCESS (proc)->gnutls_state = state; 1754 XPROCESS (proc)->gnutls_state = state;
1764 if (ret < GNUTLS_E_SUCCESS) 1755 if (ret < GNUTLS_E_SUCCESS)
@@ -1852,7 +1843,6 @@ The alist key is the cipher name. */)
1852{ 1843{
1853 Lisp_Object ciphers = Qnil; 1844 Lisp_Object ciphers = Qnil;
1854 1845
1855#ifdef HAVE_GNUTLS3_CIPHER
1856 const gnutls_cipher_algorithm_t *gciphers = gnutls_cipher_list (); 1846 const gnutls_cipher_algorithm_t *gciphers = gnutls_cipher_list ();
1857 for (ptrdiff_t pos = 0; gciphers[pos] != 0; pos++) 1847 for (ptrdiff_t pos = 0; gciphers[pos] != 0; pos++)
1858 { 1848 {
@@ -1886,7 +1876,6 @@ The alist key is the cipher name. */)
1886 1876
1887 ciphers = Fcons (cp, ciphers); 1877 ciphers = Fcons (cp, ciphers);
1888 } 1878 }
1889#endif
1890 1879
1891 return ciphers; 1880 return ciphers;
1892} 1881}
@@ -1899,7 +1888,7 @@ gnutls_symmetric_aead (bool encrypting, gnutls_cipher_algorithm_t gca,
1899 const char *idata, ptrdiff_t isize, 1888 const char *idata, ptrdiff_t isize,
1900 Lisp_Object aead_auth) 1889 Lisp_Object aead_auth)
1901{ 1890{
1902#ifdef HAVE_GNUTLS3_AEAD 1891# ifdef HAVE_GNUTLS_AEAD
1903 1892
1904 const char *desc = encrypting ? "encrypt" : "decrypt"; 1893 const char *desc = encrypting ? "encrypt" : "decrypt";
1905 Lisp_Object actual_iv = make_unibyte_string (vdata, vsize); 1894 Lisp_Object actual_iv = make_unibyte_string (vdata, vsize);
@@ -1969,10 +1958,10 @@ gnutls_symmetric_aead (bool encrypting, gnutls_cipher_algorithm_t gca,
1969 1958
1970 SAFE_FREE (); 1959 SAFE_FREE ();
1971 return list2 (output, actual_iv); 1960 return list2 (output, actual_iv);
1972#else 1961# else
1973 printmax_t print_gca = gca; 1962 printmax_t print_gca = gca;
1974 error ("GnuTLS AEAD cipher %"pMd" is invalid or not found", print_gca); 1963 error ("GnuTLS AEAD cipher %"pMd" is invalid or not found", print_gca);
1975#endif 1964# endif
1976} 1965}
1977 1966
1978static Lisp_Object 1967static Lisp_Object
@@ -2181,7 +2170,6 @@ name. */)
2181 (void) 2170 (void)
2182{ 2171{
2183 Lisp_Object mac_algorithms = Qnil; 2172 Lisp_Object mac_algorithms = Qnil;
2184#ifdef HAVE_GNUTLS3_HMAC
2185 const gnutls_mac_algorithm_t *macs = gnutls_mac_list (); 2173 const gnutls_mac_algorithm_t *macs = gnutls_mac_list ();
2186 for (ptrdiff_t pos = 0; macs[pos] != 0; pos++) 2174 for (ptrdiff_t pos = 0; macs[pos] != 0; pos++)
2187 { 2175 {
@@ -2204,7 +2192,6 @@ name. */)
2204 make_number (gnutls_mac_get_nonce_size (gma))); 2192 make_number (gnutls_mac_get_nonce_size (gma)));
2205 mac_algorithms = Fcons (mp, mac_algorithms); 2193 mac_algorithms = Fcons (mp, mac_algorithms);
2206 } 2194 }
2207#endif
2208 2195
2209 return mac_algorithms; 2196 return mac_algorithms;
2210} 2197}
@@ -2218,7 +2205,6 @@ method name. */)
2218 (void) 2205 (void)
2219{ 2206{
2220 Lisp_Object digest_algorithms = Qnil; 2207 Lisp_Object digest_algorithms = Qnil;
2221#ifdef HAVE_GNUTLS3_DIGEST
2222 const gnutls_digest_algorithm_t *digests = gnutls_digest_list (); 2208 const gnutls_digest_algorithm_t *digests = gnutls_digest_list ();
2223 for (ptrdiff_t pos = 0; digests[pos] != 0; pos++) 2209 for (ptrdiff_t pos = 0; digests[pos] != 0; pos++)
2224 { 2210 {
@@ -2236,7 +2222,6 @@ method name. */)
2236 2222
2237 digest_algorithms = Fcons (mp, digest_algorithms); 2223 digest_algorithms = Fcons (mp, digest_algorithms);
2238 } 2224 }
2239#endif
2240 2225
2241 return digest_algorithms; 2226 return digest_algorithms;
2242} 2227}
@@ -2423,25 +2408,17 @@ GnuTLS AEAD ciphers : the list will contain `AEAD-ciphers'. */)
2423 2408
2424# ifdef HAVE_GNUTLS3 2409# ifdef HAVE_GNUTLS3
2425 capabilities = Fcons (intern("gnutls3"), capabilities); 2410 capabilities = Fcons (intern("gnutls3"), capabilities);
2426
2427# ifdef HAVE_GNUTLS3_DIGEST
2428 capabilities = Fcons (intern("digests"), capabilities); 2411 capabilities = Fcons (intern("digests"), capabilities);
2429# endif
2430
2431# ifdef HAVE_GNUTLS3_CIPHER
2432 capabilities = Fcons (intern("ciphers"), capabilities); 2412 capabilities = Fcons (intern("ciphers"), capabilities);
2433 2413
2434# ifdef HAVE_GNUTLS3_AEAD 2414# ifdef HAVE_GNUTLS_AEAD
2435 capabilities = Fcons (intern("AEAD-ciphers"), capabilities); 2415 capabilities = Fcons (intern("AEAD-ciphers"), capabilities);
2436# endif 2416# endif
2437 2417
2438# ifdef HAVE_GNUTLS3_HMAC
2439 capabilities = Fcons (intern("macs"), capabilities); 2418 capabilities = Fcons (intern("macs"), capabilities);
2440# endif
2441# endif /* HAVE_GNUTLS3_CIPHER */
2442# endif /* HAVE_GNUTLS3 */ 2419# endif /* HAVE_GNUTLS3 */
2443 2420
2444#ifdef WINDOWSNT 2421# ifdef WINDOWSNT
2445 Lisp_Object found = Fassq (Qgnutls, Vlibrary_cache); 2422 Lisp_Object found = Fassq (Qgnutls, Vlibrary_cache);
2446 if (CONSP (found)) 2423 if (CONSP (found))
2447 return XCDR (found); 2424 return XCDR (found);
@@ -2452,15 +2429,10 @@ GnuTLS AEAD ciphers : the list will contain `AEAD-ciphers'. */)
2452 Vlibrary_cache = Fcons (Fcons (Qgnutls, status), Vlibrary_cache); 2429 Vlibrary_cache = Fcons (Fcons (Qgnutls, status), Vlibrary_cache);
2453 return status; 2430 return status;
2454 } 2431 }
2455#else /* !WINDOWSNT */ 2432# endif /* WINDOWSNT */
2433#endif /* HAVE_GNUTLS */
2456 2434
2457 return capabilities; 2435 return capabilities;
2458
2459#endif /* WINDOWSNT */
2460
2461#else /* !HAVE_GNUTLS */
2462 return Qnil;
2463#endif /* HAVE_GNUTLS */
2464} 2436}
2465 2437
2466void 2438void
diff --git a/src/gnutls.h b/src/gnutls.h
index 8fe4ac3e427..9323cd1aeff 100644
--- a/src/gnutls.h
+++ b/src/gnutls.h
@@ -28,22 +28,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
28# include <gnutls/crypto.h> 28# include <gnutls/crypto.h>
29#endif 29#endif
30 30
31#if 0x030400 <= GNUTLS_VERSION_NUMBER
32# define HAVE_GNUTLS3_CIPHER
33# define HAVE_GNUTLS3_DIGEST
34# define HAVE_GNUTLS3_HMAC
35#endif
36
37/* Although AEAD support started in GnuTLS 3.4.0 and works in 3.5.14,
38 it was broken through at least GnuTLS 3.4.10; see:
39 https://lists.gnu.org/archive/html/emacs-devel/2017-07/msg00992.html
40 The relevant fix seems to have been made in GnuTLS 3.5.1; see:
41 https://gitlab.com/gnutls/gnutls/commit/568935848dd6b82b9315d8b6c529d00e2605e03d
42 So use 3.5.1 for now. */
43#if 0x030501 <= GNUTLS_VERSION_NUMBER
44# define HAVE_GNUTLS3_AEAD
45#endif
46
47#include "lisp.h" 31#include "lisp.h"
48 32
49/* This limits the attempts to handshake per process (connection). It 33/* This limits the attempts to handshake per process (connection). It