Ignore:
Timestamp:
Jan 16, 2012 5:05:47 AM (12 years ago)
Author:
nanang
Message:

Close #1014:

  • Added configurable ciphers setting in SIP TLS transport and pjsua app.
  • Added API pj_ssl_cipher_is_supported().
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/1.x/pjlib/src/pj/ssl_sock_ossl.c

    r3610 r3942  
    4040#define DELAYED_CLOSE_TIMEOUT   200 
    4141 
     42/* Maximum ciphers */ 
     43#define MAX_CIPHERS             100 
     44 
    4245/*  
    4346 * Include OpenSSL headers  
     
    270273 
    271274/* OpenSSL available ciphers */ 
    272 static pj_ssl_cipher openssl_ciphers[100]; 
    273275static unsigned openssl_cipher_num; 
     276static struct openssl_ciphers_t { 
     277    pj_ssl_cipher    id; 
     278    const char      *name; 
     279} openssl_ciphers[MAX_CIPHERS]; 
    274280 
    275281/* OpenSSL application data index */ 
     
    330336            SSL_CIPHER *c; 
    331337            c = sk_SSL_CIPHER_value(sk_cipher,i); 
    332             openssl_ciphers[i] = (pj_ssl_cipher) 
    333                                  (pj_uint32_t)c->id & 0x00FFFFFF; 
    334             //printf("%3u: %08x=%s\n", i+1, c->id, SSL_CIPHER_get_name(c)); 
     338            openssl_ciphers[i].id = (pj_ssl_cipher) 
     339                                    (pj_uint32_t)c->id & 0x00FFFFFF; 
     340            openssl_ciphers[i].name = SSL_CIPHER_get_name(c); 
    335341        } 
    336342 
     
    17061712    } 
    17071713 
    1708     if (openssl_cipher_num == 0) 
     1714    if (openssl_cipher_num == 0) { 
     1715        *cipher_num = 0; 
    17091716        return PJ_ENOTFOUND; 
     1717    } 
    17101718 
    17111719    *cipher_num = PJ_MIN(*cipher_num, openssl_cipher_num); 
    17121720 
    17131721    for (i = 0; i < *cipher_num; ++i) 
    1714         ciphers[i] = openssl_ciphers[i]; 
     1722        ciphers[i] = openssl_ciphers[i].id; 
    17151723 
    17161724    return PJ_SUCCESS; 
     1725} 
     1726 
     1727 
     1728/* Get cipher name string */ 
     1729PJ_DEF(const char*) pj_ssl_cipher_name(pj_ssl_cipher cipher) 
     1730{ 
     1731    unsigned i; 
     1732 
     1733    if (openssl_cipher_num == 0) { 
     1734        init_openssl(); 
     1735        shutdown_openssl(); 
     1736    } 
     1737 
     1738    for (i = 0; i < openssl_cipher_num; ++i) { 
     1739        if (cipher == openssl_ciphers[i].id) 
     1740            return openssl_ciphers[i].name; 
     1741    } 
     1742 
     1743    return NULL; 
     1744} 
     1745 
     1746/* Check if the specified cipher is supported by SSL/TLS backend. */ 
     1747PJ_DEF(pj_bool_t) pj_ssl_cipher_is_supported(pj_ssl_cipher cipher) 
     1748{ 
     1749    unsigned i; 
     1750 
     1751    if (openssl_cipher_num == 0) { 
     1752        init_openssl(); 
     1753        shutdown_openssl(); 
     1754    } 
     1755 
     1756    for (i = 0; i < openssl_cipher_num; ++i) { 
     1757        if (cipher == openssl_ciphers[i].id) 
     1758            return PJ_TRUE; 
     1759    } 
     1760 
     1761    return PJ_FALSE; 
    17171762} 
    17181763 
Note: See TracChangeset for help on using the changeset viewer.