From 3866e1c3e2173b477cfaceb1f13f8a9458dcfaa3 Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Thu, 7 May 2015 04:48:19 +0000 Subject: Close #1849: Enabled multiple TLS certificate chains (RSA+ECC+DSA) for server socket. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5087 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pj/ssl_sock_ossl.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'pjlib/src/pj') diff --git a/pjlib/src/pj/ssl_sock_ossl.c b/pjlib/src/pj/ssl_sock_ossl.c index e2726f66..bffb5f1e 100644 --- a/pjlib/src/pj/ssl_sock_ossl.c +++ b/pjlib/src/pj/ssl_sock_ossl.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -671,6 +672,49 @@ static pj_status_t create_ssl(pj_ssl_sock_t *ssock) } if (ssock->is_server) { + char *p = NULL; + + /* If certificate file name contains "_rsa.", let's check if there are + * ecc and dsa certificates too. + */ + if (cert && cert->cert_file.slen) { + const pj_str_t RSA = {"_rsa.", 5}; + p = pj_strstr(&cert->cert_file, &RSA); + if (p) p++; /* Skip underscore */ + } + if (p) { + /* Certificate type string length must be exactly 3 */ + enum { CERT_TYPE_LEN = 3 }; + const char* cert_types[] = { "ecc", "dsa" }; + char *cf = cert->cert_file.ptr; + int i; + + /* Check and load ECC & DSA certificates & private keys */ + for (i = 0; i < PJ_ARRAY_SIZE(cert_types); ++i) { + int err; + + pj_memcpy(p, cert_types[i], CERT_TYPE_LEN); + if (!pj_file_exists(cf)) + continue; + + err = SSL_CTX_use_certificate_chain_file(ctx, cf); + if (err == 1) + err = SSL_CTX_use_PrivateKey_file(ctx, cf, + SSL_FILETYPE_PEM); + if (err == 1) { + PJ_LOG(4,(ssock->pool->obj_name, + "Additional certificate '%s' loaded.", cf)); + } else { + pj_perror(1, ssock->pool->obj_name, GET_SSL_STATUS(ssock), + "Error loading certificate file '%s'", cf); + ERR_clear_error(); + } + } + + /* Put back original name */ + pj_memcpy(p, "rsa", CERT_TYPE_LEN); + } + #ifndef SSL_CTRL_SET_ECDH_AUTO #define SSL_CTRL_SET_ECDH_AUTO 94 #endif -- cgit v1.2.3