Ignore:
Timestamp:
May 15, 2019 2:43:01 AM (5 years ago)
Author:
nanang
Message:

Close #2179: Wipe out memory used for storing SSL keys before released.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/ssl_sock_imp_common.c

    r5980 r5990  
    597597} 
    598598 
     599 
     600static void wipe_buf(pj_str_t *buf) 
     601{ 
     602    volatile char *p = buf->ptr; 
     603    pj_ssize_t len = buf->slen; 
     604    while (len--) *p++ = 0; 
     605    buf->slen = 0; 
     606} 
     607 
     608static void wipe_cert_buffer(pj_ssl_cert_t *cert) 
     609{ 
     610    wipe_buf(&cert->CA_file); 
     611    wipe_buf(&cert->CA_path); 
     612    wipe_buf(&cert->cert_file); 
     613    wipe_buf(&cert->privkey_file); 
     614    wipe_buf(&cert->privkey_pass); 
     615    wipe_buf(&cert->CA_buf); 
     616    wipe_buf(&cert->cert_buf); 
     617    wipe_buf(&cert->privkey_buf); 
     618} 
     619 
    599620static void ssl_on_destroy(void *arg) 
    600621{ 
     
    614635    } 
    615636 
    616     pj_pool_safe_release(&ssock->pool); 
     637    /* Wipe out cert & key buffer, note that they may not be allocated 
     638     * using SSL socket memory pool. 
     639     */ 
     640    if (ssock->cert) { 
     641        wipe_cert_buffer(ssock->cert); 
     642    } 
     643 
     644    /* Secure release pool, i.e: all memory blocks will be zeroed first */ 
     645    pj_pool_secure_release(&ssock->pool); 
    617646} 
    618647 
Note: See TracChangeset for help on using the changeset viewer.