aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2017-07-16 16:22:33 -0700
committerPaul Eggert2017-07-16 16:29:12 -0700
commit59f6972134f312863dc761bf66a954a8036d0d86 (patch)
treecd479a7fe59b72985f98e57c4b4d861c01cf5bc8 /src
parent252444aaa3a7cb9fc70289a5a3920f8a9d848109 (diff)
downloademacs-59f6972134f312863dc761bf66a954a8036d0d86.tar.gz
emacs-59f6972134f312863dc761bf66a954a8036d0d86.zip
Use explicit_bzero to clear GnuTLS keys
* admin/merge-gnulib (GNULIB_MODULES): Add explicit_bzero. * lib/explicit_bzero.c, m4/explicit_bzero.m4: New files. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate. * src/gnutls.c (clear_storage): New function. (gnutls_symmetric_aead): Use it instead of memset.
Diffstat (limited to 'src')
-rw-r--r--src/gnutls.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/gnutls.c b/src/gnutls.c
index e6f01a9cfe1..7d19f90fbb8 100644
--- a/src/gnutls.c
+++ b/src/gnutls.c
@@ -1883,6 +1883,22 @@ The alist key is the cipher name. */)
1883 return ciphers; 1883 return ciphers;
1884} 1884}
1885 1885
1886/* Zero out STORAGE (even if it will become inaccessible. It has
1887 STORAGE_LENGTH bytes. The goal is to improve security a bit, in
1888 case an Emacs module or some buggy part of Emacs attempts to
1889 inspect STORAGE later to retrieve a secret.
1890
1891 Calls to this function document when storage containing a secret is
1892 known to go out of scope. This function is not guaranteed to erase
1893 the secret, as copies of STORAGE may well be accessible elsewhere
1894 on the machine. */
1895
1896static void
1897clear_storage (void *storage, ptrdiff_t storage_length)
1898{
1899 explicit_bzero (storage, storage_length);
1900}
1901
1886static Lisp_Object 1902static Lisp_Object
1887gnutls_symmetric_aead (bool encrypting, gnutls_cipher_algorithm_t gca, 1903gnutls_symmetric_aead (bool encrypting, gnutls_cipher_algorithm_t gca,
1888 Lisp_Object cipher, 1904 Lisp_Object cipher,
@@ -1949,7 +1965,7 @@ gnutls_symmetric_aead (bool encrypting, gnutls_cipher_algorithm_t gca,
1949 1965
1950 if (ret < GNUTLS_E_SUCCESS) 1966 if (ret < GNUTLS_E_SUCCESS)
1951 { 1967 {
1952 memset (storage, 0, storage_length); 1968 clear_storage (storage, storage_length);
1953 SAFE_FREE (); 1969 SAFE_FREE ();
1954 gnutls_aead_cipher_deinit (acipher); 1970 gnutls_aead_cipher_deinit (acipher);
1955 if (encrypting) 1971 if (encrypting)
@@ -1963,7 +1979,7 @@ gnutls_symmetric_aead (bool encrypting, gnutls_cipher_algorithm_t gca,
1963 gnutls_aead_cipher_deinit (acipher); 1979 gnutls_aead_cipher_deinit (acipher);
1964 1980
1965 Lisp_Object output = make_unibyte_string (storage, storage_length); 1981 Lisp_Object output = make_unibyte_string (storage, storage_length);
1966 memset (storage, 0, storage_length); 1982 clear_storage (storage, storage_length);
1967 SAFE_FREE (); 1983 SAFE_FREE ();
1968 return list2 (output, actual_iv); 1984 return list2 (output, actual_iv);
1969#else 1985#else