summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiong Sauw Ming <ming@teluu.com>2014-04-30 08:21:28 +0000
committerLiong Sauw Ming <ming@teluu.com>2014-04-30 08:21:28 +0000
commit88ae49c716c90975e9fcb1bfa96716576a5da172 (patch)
tree8cd84ce5b833a3f4b30bb7dccca1860e658a4f60
parent2e343a7b0b115a3ec1b45a36ffad46ac64ea72a9 (diff)
Fixed #1763: Add pj_ssl_cipher_id() API
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4829 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjlib/include/pj/ssl_sock.h7
-rw-r--r--pjlib/src/pj/ssl_sock_ossl.c18
-rw-r--r--pjlib/src/pj/ssl_sock_symbian.cpp21
3 files changed, 45 insertions, 1 deletions
diff --git a/pjlib/include/pj/ssl_sock.h b/pjlib/include/pj/ssl_sock.h
index bfad5af2..0d24a494 100644
--- a/pjlib/include/pj/ssl_sock.h
+++ b/pjlib/include/pj/ssl_sock.h
@@ -243,6 +243,9 @@ PJ_DECL(pj_status_t) pj_ssl_cert_get_verify_status_strings(
*/
typedef enum pj_ssl_cipher {
+ /* Unsupported cipher */
+ PJ_TLS_UNKNOWN_CIPHER = -1,
+
/* NULL */
PJ_TLS_NULL_WITH_NULL_NULL = 0x00000000,
@@ -353,7 +356,9 @@ PJ_DECL(const char*) pj_ssl_cipher_name(pj_ssl_cipher cipher);
/**
- * Get cipher ID from cipher name string.
+ * Get cipher ID from cipher name string. Note that on different backends
+ * (e.g. OpenSSL or Symbian implementation), cipher names may not be
+ * equivalent for the same cipher ID.
*
* @param cipher_name The cipher name string.
*
diff --git a/pjlib/src/pj/ssl_sock_ossl.c b/pjlib/src/pj/ssl_sock_ossl.c
index 7129f21f..b05f2c03 100644
--- a/pjlib/src/pj/ssl_sock_ossl.c
+++ b/pjlib/src/pj/ssl_sock_ossl.c
@@ -1888,6 +1888,24 @@ PJ_DEF(const char*) pj_ssl_cipher_name(pj_ssl_cipher cipher)
return NULL;
}
+/* Get cipher identifier */
+PJ_DEF(pj_ssl_cipher) pj_ssl_cipher_id(const char *cipher_name)
+{
+ unsigned i;
+
+ if (openssl_cipher_num == 0) {
+ init_openssl();
+ shutdown_openssl();
+ }
+
+ for (i = 0; i < openssl_cipher_num; ++i) {
+ if (!pj_ansi_stricmp(openssl_ciphers[i].name, cipher_name))
+ return openssl_ciphers[i].id;
+ }
+
+ return PJ_TLS_UNKNOWN_CIPHER;
+}
+
/* Check if the specified cipher is supported by SSL/TLS backend. */
PJ_DEF(pj_bool_t) pj_ssl_cipher_is_supported(pj_ssl_cipher cipher)
{
diff --git a/pjlib/src/pj/ssl_sock_symbian.cpp b/pjlib/src/pj/ssl_sock_symbian.cpp
index 47288fae..013318b2 100644
--- a/pjlib/src/pj/ssl_sock_symbian.cpp
+++ b/pjlib/src/pj/ssl_sock_symbian.cpp
@@ -42,6 +42,7 @@ typedef struct cipher_name_t {
/* Cipher name constants */
static cipher_name_t cipher_names[] =
{
+ {PJ_TLS_UNKNOWN_CIPHER, "UNKNOWN"},
{PJ_TLS_NULL_WITH_NULL_NULL, "NULL"},
/* TLS/SSLv3 */
@@ -759,6 +760,26 @@ PJ_DEF(const char*) pj_ssl_cipher_name(pj_ssl_cipher cipher)
}
+/* Get cipher identifier */
+PJ_DEF(pj_ssl_cipher) pj_ssl_cipher_id(const char *cipher_name)
+{
+ unsigned i;
+
+ if (ciphers_num_ == 0) {
+ pj_ssl_cipher c[1];
+ i = 0;
+ pj_ssl_cipher_get_availables(c, &i);
+ }
+
+ for (i = 0; i < ciphers_num_; ++i) {
+ if (!pj_ansi_stricmp(ciphers_[i].name, cipher_name))
+ return ciphers_[i].id;
+ }
+
+ return PJ_TLS_UNKNOWN_CIPHER;
+}
+
+
/* Check if the specified cipher is supported by SSL/TLS backend. */
PJ_DEF(pj_bool_t) pj_ssl_cipher_is_supported(pj_ssl_cipher cipher)
{