Changeset 6004 for pjproject/trunk/pjlib/src/pj/ssl_sock_imp_common.c
- Timestamp:
- May 24, 2019 3:32:17 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/ssl_sock_imp_common.c
r5990 r6004 31 31 # define PJ_SSL_SOCK_DELAYED_CLOSE_TIMEOUT 500 32 32 #endif 33 34 enum { MAX_BIND_RETRY = 100 }; 33 35 34 36 #ifdef SSL_SOCK_IMP_USE_CIRC_BUF … … 597 599 } 598 600 599 600 static 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 608 static 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 620 601 static void ssl_on_destroy(void *arg) 621 602 { … … 633 614 ssock->circ_buf_output_mutex = NULL; 634 615 ssock->write_mutex = NULL; 635 }636 637 /* Wipe out cert & key buffer, note that they may not be allocated638 * using SSL socket memory pool.639 */640 if (ssock->cert) {641 wipe_cert_buffer(ssock->cert);642 616 } 643 617 … … 1363 1337 1364 1338 ssl_reset_sock_state(ssock); 1339 1340 /* Wipe out cert & key buffer. */ 1341 if (ssock->cert) { 1342 pj_ssl_cert_wipe_keys(ssock->cert); 1343 ssock->cert = NULL; 1344 } 1345 1365 1346 if (ssock->param.grp_lock) { 1366 1347 pj_grp_lock_dec_ref(ssock->param.grp_lock); … … 1883 1864 * Starts asynchronous socket connect() operation. 1884 1865 */ 1885 PJ_DEF(pj_status_t) pj_ssl_sock_start_connect( pj_ssl_sock_t *ssock, 1886 pj_pool_t *pool, 1887 const pj_sockaddr_t *localaddr, 1888 const pj_sockaddr_t *remaddr, 1889 int addr_len) 1866 PJ_DEF(pj_status_t) pj_ssl_sock_start_connect(pj_ssl_sock_t *ssock, 1867 pj_pool_t *pool, 1868 const pj_sockaddr_t *localaddr, 1869 const pj_sockaddr_t *remaddr, 1870 int addr_len) 1871 { 1872 pj_ssl_start_connect_param param; 1873 param.pool = pool; 1874 param.localaddr = localaddr; 1875 param.local_port_range = 0; 1876 param.remaddr = remaddr; 1877 param.addr_len = addr_len; 1878 1879 return pj_ssl_sock_start_connect2(ssock, ¶m); 1880 } 1881 1882 PJ_DEF(pj_status_t) pj_ssl_sock_start_connect2( 1883 pj_ssl_sock_t *ssock, 1884 pj_ssl_start_connect_param *connect_param) 1890 1885 { 1891 1886 pj_activesock_cb asock_cb; 1892 1887 pj_activesock_cfg asock_cfg; 1893 1888 pj_status_t status; 1889 1890 pj_pool_t *pool = connect_param->pool; 1891 const pj_sockaddr_t *localaddr = connect_param->localaddr; 1892 pj_uint16_t port_range = connect_param->local_port_range; 1893 const pj_sockaddr_t *remaddr = connect_param->remaddr; 1894 int addr_len = connect_param->addr_len; 1894 1895 1895 1896 PJ_ASSERT_RETURN(ssock && pool && localaddr && remaddr && addr_len, … … 1919 1920 1920 1921 /* Bind socket */ 1921 status = pj_sock_bind(ssock->sock, localaddr, addr_len); 1922 if (port_range) { 1923 pj_uint16_t max_bind_retry = MAX_BIND_RETRY; 1924 if (port_range && port_range < max_bind_retry) 1925 { 1926 max_bind_retry = port_range; 1927 } 1928 status = pj_sock_bind_random(ssock->sock, localaddr, port_range, 1929 max_bind_retry); 1930 } else { 1931 status = pj_sock_bind(ssock->sock, localaddr, addr_len); 1932 } 1933 1922 1934 if (status != PJ_SUCCESS) 1923 1935 goto on_error; … … 2013 2025 } 2014 2026 2027 static void wipe_buf(pj_str_t *buf) 2028 { 2029 volatile char *p = buf->ptr; 2030 pj_ssize_t len = buf->slen; 2031 while (len--) *p++ = 0; 2032 buf->slen = 0; 2033 } 2034 2035 PJ_DEF(void) pj_ssl_cert_wipe_keys(pj_ssl_cert_t *cert) 2036 { 2037 if (cert) { 2038 wipe_buf(&cert->CA_file); 2039 wipe_buf(&cert->CA_path); 2040 wipe_buf(&cert->cert_file); 2041 wipe_buf(&cert->privkey_file); 2042 wipe_buf(&cert->privkey_pass); 2043 wipe_buf(&cert->CA_buf); 2044 wipe_buf(&cert->cert_buf); 2045 wipe_buf(&cert->privkey_buf); 2046 } 2047 } 2048 2015 2049 /* Load credentials from files. */ 2016 2050 PJ_DEF(pj_status_t) pj_ssl_cert_load_from_files (pj_pool_t *pool,
Note: See TracChangeset
for help on using the changeset viewer.