tls: do not leak RSA key
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 25 Nov 2018 15:17:26 +0000 (16:17 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 25 Nov 2018 15:17:26 +0000 (16:17 +0100)
function                                             old     new   delta
tls_handshake                                       1957    2059    +102

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
networking/tls.c
networking/tls_rsa.h

index 9b4298de7a5e6d761c0dbf4104eb3073106445ab..9833a0adbee8152423526f1c722b7d1698ffbcd1 100644 (file)
@@ -2168,6 +2168,7 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
        /* application data can be sent/received */
 
        /* free handshake data */
+       psRsaKey_clear(&tls->hsd->server_rsa_pub_key);
 //     if (PARANOIA)
 //             memset(tls->hsd, 0, tls->hsd->hsd_size);
        free(tls->hsd);
index f42923ff5b9120c645469f7a853e878c1debcf71..82bea2a6745a7aa093b81800e86f6540d67c6978 100644 (file)
@@ -13,6 +13,18 @@ typedef struct {
 //bbox psPool_t *pool;
 } psRsaKey_t;
 
+static ALWAYS_INLINE void psRsaKey_clear(psRsaKey_t *key)
+{
+       pstm_clear(&key->N);
+       pstm_clear(&key->e);
+       pstm_clear(&key->d);
+       pstm_clear(&key->p);
+       pstm_clear(&key->q);
+       pstm_clear(&key->dP);
+       pstm_clear(&key->dQ);
+       pstm_clear(&key->qP);
+}
+
 #define psRsaEncryptPub(pool, key, in, inlen, out, outlen, data) \
         psRsaEncryptPub(      key, in, inlen, out, outlen)
 int32 psRsaEncryptPub(psPool_t *pool, psRsaKey_t *key,