cipher name string format

This commit is contained in:
Jacob Barthelmeh
2016-04-28 22:45:54 -06:00
parent 6613ebb642
commit bd4e8ac714
5 changed files with 54 additions and 4 deletions

View File

@@ -11121,6 +11121,46 @@ int GetCipherNamesSize(void)
return (int)(sizeof(cipher_names) / sizeof(char*));
}
/* gets cipher name in the format DHE-RSA-... rather then TLS_DHE... */
const char* wolfSSL_get_cipher_name_internal(WOLFSSL* ssl)
{
const char* fullName;
const char* first;
WOLFSSL_CIPHER* cipher;
word32 i;
if (ssl == NULL) {
WOLFSSL_MSG("Bad argument");
return NULL;
}
cipher = wolfSSL_get_current_cipher(ssl);
fullName = wolfSSL_CIPHER_get_name(cipher);
if (fullName) {
first = (XSTRSTR(fullName, "CHACHA")) ? "CHACHA"
: (XSTRSTR(fullName, "EC")) ? "EC"
: (XSTRSTR(fullName, "CCM")) ? "CCM"
: NULL; /* normal */
for (i = 0; i < sizeof(cipher_name_idx); i++) {
if (cipher_name_idx[i] == ssl->options.cipherSuite) {
const char* nameFound = cipher_names[i];
/* if first is null then not any */
if (first == NULL && !XSTRSTR(nameFound, "CHACHA") &&
!XSTRSTR(nameFound, "EC") && !XSTRSTR(nameFound, "CCM")) {
return cipher_names[i];
}
else if (XSTRSTR(nameFound, first)) {
return cipher_names[i];
}
}
}
}
return NULL; /* error or not found */
}
/**
Set the enabled cipher suites.

View File

@@ -11272,6 +11272,12 @@ const char* wolfSSL_get_cipher(WOLFSSL* ssl)
return wolfSSL_CIPHER_get_name(wolfSSL_get_current_cipher(ssl));
}
/* gets cipher name in the format DHE-RSA-... rather then TLS_DHE... */
const char* wolfSSL_get_cipher_name(WOLFSSL* ssl)
{
/* get access to cipher_name_idx in internal.c */
return wolfSSL_get_cipher_name_internal(ssl);
}
#ifdef OPENSSL_EXTRA

View File

@@ -3064,6 +3064,7 @@ WOLFSSL_LOCAL void c32to24(word32 in, word24 out);
WOLFSSL_LOCAL const char* const* GetCipherNames(void);
WOLFSSL_LOCAL int GetCipherNamesSize(void);
WOLFSSL_LOCAL const char* wolfSSL_get_cipher_name_internal(WOLFSSL* ssl);
enum encrypt_side {

View File

@@ -187,7 +187,9 @@ typedef WOLFSSL_X509_STORE_CTX X509_STORE_CTX;
#define SSL_get_version wolfSSL_get_version
#define SSL_get_current_cipher wolfSSL_get_current_cipher
#define SSL_get_cipher wolfSSL_get_cipher
/* use wolfSSL_get_cipher_name for its return format */
#define SSL_get_cipher wolfSSL_get_cipher_name
#define SSL_CIPHER_description wolfSSL_CIPHER_description
#define SSL_CIPHER_get_name wolfSSL_CIPHER_get_name
#define SSL_get1_session wolfSSL_get1_session

View File

@@ -267,6 +267,7 @@ WOLFSSL_API WOLFSSL* wolfSSL_new(WOLFSSL_CTX*);
WOLFSSL_API int wolfSSL_set_fd (WOLFSSL*, int);
WOLFSSL_API char* wolfSSL_get_cipher_list(int priority);
WOLFSSL_API int wolfSSL_get_ciphers(char*, int);
WOLFSSL_API const char* wolfSSL_get_cipher_name(WOLFSSL* ssl);
WOLFSSL_API int wolfSSL_get_fd(const WOLFSSL*);
WOLFSSL_API void wolfSSL_set_using_nonblock(WOLFSSL*, int);
WOLFSSL_API int wolfSSL_get_using_nonblock(WOLFSSL*);