Mercurial > hg > xemacs-beta
comparison src/tls.c @ 5891:a0e751d6c3ad
Import the #'clear-string API from GNU, use it in tls.c
src/ChangeLog addition:
2015-04-18 Aidan Kehoe <kehoea@parhasard.net>
* sequence.c (Fclear_string): New, API from GNU. Zero a string's
contents, making sure the text is not kept around even when the
string's data is reallocated because of a changed character
length.
* sequence.c (syms_of_sequence): Make it available to Lisp.
* lisp.h: Make it available to C code.
* tls.c (nss_pk11_password): Use it.
* tls.c (gnutls_pk11_password): Use it.
* tls.c (openssl_password): Use it.
tests/ChangeLog addition:
2015-04-18 Aidan Kehoe <kehoea@parhasard.net>
* automated/lisp-tests.el:
Test #'clear-string, just added. Unfortunately there's no way to
be certain from Lisp that the old password data has been erased
after realloc; it may be worth adding a test to tests.c, but
*we'll be reading memory we shouldn't be*, so that gives me pause.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sat, 18 Apr 2015 23:00:14 +0100 |
parents | a85efdabe237 |
children |
comparison
equal
deleted
inserted
replaced
5888:a85efdabe237 | 5891:a0e751d6c3ad |
---|---|
300 | 300 |
301 /* Function that gathers passwords for PKCS #11 tokens. */ | 301 /* Function that gathers passwords for PKCS #11 tokens. */ |
302 static char * | 302 static char * |
303 nss_pk11_password (PK11SlotInfo *slot, PRBool retry, void * UNUSED (arg)) | 303 nss_pk11_password (PK11SlotInfo *slot, PRBool retry, void * UNUSED (arg)) |
304 { | 304 { |
305 Lisp_Object lsp_password, args[2]; | 305 Lisp_Object lsp_password; |
306 Extbyte *c_password, *nss_password; | 306 Extbyte *c_password, *nss_password; |
307 const Extbyte *token_name; | 307 const Extbyte *token_name; |
308 | 308 |
309 if (retry) | 309 if (retry) |
310 return NULL; | 310 return NULL; |
317 build_extstring (token_name, Qnative))); | 317 build_extstring (token_name, Qnative))); |
318 c_password = LISP_STRING_TO_EXTERNAL (lsp_password, Qnative); | 318 c_password = LISP_STRING_TO_EXTERNAL (lsp_password, Qnative); |
319 nss_password = PL_strdup (c_password); | 319 nss_password = PL_strdup (c_password); |
320 | 320 |
321 /* Wipe out the password on the stack and in the Lisp string */ | 321 /* Wipe out the password on the stack and in the Lisp string */ |
322 args[0] = lsp_password; | 322 Fclear_string (lsp_password); |
323 args[1] = make_char ('*'); | |
324 Ffill (2, args); | |
325 memset (c_password, '*', strlen (c_password)); | 323 memset (c_password, '*', strlen (c_password)); |
324 | |
326 return nss_password; | 325 return nss_password; |
327 } | 326 } |
328 | 327 |
329 void | 328 void |
330 init_tls (void) | 329 init_tls (void) |
727 len = pin_max; | 726 len = pin_max; |
728 memcpy (pin, c_password, len); | 727 memcpy (pin, c_password, len); |
729 pin[len] = '\0'; | 728 pin[len] = '\0'; |
730 | 729 |
731 /* Wipe out the password on the stack and in the Lisp string */ | 730 /* Wipe out the password on the stack and in the Lisp string */ |
732 args[0] = lsp_password; | 731 Fclear_string (lsp_password); |
733 args[1] = make_char ('*'); | |
734 Ffill (2, args); | |
735 memset (c_password, '*', strlen (c_password)); | 732 memset (c_password, '*', strlen (c_password)); |
733 | |
736 return GNUTLS_E_SUCCESS; | 734 return GNUTLS_E_SUCCESS; |
737 } | 735 } |
738 | 736 |
739 static void xfree_for_gnutls (void *ptr) | 737 static void xfree_for_gnutls (void *ptr) |
740 { | 738 { |
1073 /* Function that gathers passwords for PKCS #11 tokens. */ | 1071 /* Function that gathers passwords for PKCS #11 tokens. */ |
1074 static int | 1072 static int |
1075 openssl_password (char *buf, int size, int UNUSED (rwflag), | 1073 openssl_password (char *buf, int size, int UNUSED (rwflag), |
1076 void *UNUSED (userdata)) | 1074 void *UNUSED (userdata)) |
1077 { | 1075 { |
1078 Lisp_Object lsp_password, args[2]; | 1076 Lisp_Object lsp_password; |
1079 Extbyte *c_password; | 1077 Extbyte *c_password; |
1080 | 1078 |
1081 lsp_password = | 1079 lsp_password = |
1082 call1 (Qread_passwd, concat2 (prompt, build_ascstring ("PEM: "))); | 1080 call1 (Qread_passwd, concat2 (prompt, build_ascstring ("PEM: "))); |
1083 c_password = LISP_STRING_TO_EXTERNAL (lsp_password, Qnative); | 1081 c_password = LISP_STRING_TO_EXTERNAL (lsp_password, Qnative); |
1084 strncpy (buf, c_password, size); | 1082 strncpy (buf, c_password, size); |
1085 | 1083 |
1086 /* Wipe out the password on the stack and in the Lisp string */ | 1084 /* Wipe out the password on the stack and in the Lisp string */ |
1087 args[0] = lsp_password; | 1085 Fclear_string (lsp_password); |
1088 args[1] = make_char ('*'); | |
1089 Ffill (2, args); | |
1090 memset (c_password, '*', strlen (c_password)); | 1086 memset (c_password, '*', strlen (c_password)); |
1087 | |
1091 return (int) strlen (buf); | 1088 return (int) strlen (buf); |
1092 } | 1089 } |
1093 | 1090 |
1094 void | 1091 void |
1095 init_tls (void) | 1092 init_tls (void) |