Refactor of the cipher suite names to use single array, which contains internal name, IANA name and cipher suite bytes.

This commit is contained in:
David Garske
2018-05-16 12:22:17 -07:00
parent 8ff328cb39
commit 8163225180
5 changed files with 271 additions and 1152 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -644,13 +644,13 @@ int wolfSSL_set_write_fd(WOLFSSL* ssl, int fd)
*/
char* wolfSSL_get_cipher_list(int priority)
{
const char* const* ciphers = GetCipherNames();
const CipherSuiteInfo* ciphers = GetCipherNames();
if (priority >= GetCipherNamesSize() || priority < 0) {
return 0;
}
return (char*)ciphers[priority];
return (char*)ciphers[priority].name;
}
@@ -683,7 +683,7 @@ char* wolfSSL_get_cipher_list_ex(WOLFSSL* ssl, int priority)
int wolfSSL_get_ciphers(char* buf, int len)
{
const char* const* ciphers = GetCipherNames();
const CipherSuiteInfo* ciphers = GetCipherNames();
int totalInc = 0;
int step = 0;
char delim = ':';
@@ -695,13 +695,13 @@ int wolfSSL_get_ciphers(char* buf, int len)
/* Add each member to the buffer delimited by a : */
for (i = 0; i < size; i++) {
step = (int)(XSTRLEN(ciphers[i]) + 1); /* delimiter */
step = (int)(XSTRLEN(ciphers[i].name) + 1); /* delimiter */
totalInc += step;
/* Check to make sure buf is large enough and will not overflow */
if (totalInc < len) {
size_t cipherLen = XSTRLEN(ciphers[i]);
XSTRNCPY(buf, ciphers[i], cipherLen);
size_t cipherLen = XSTRLEN(ciphers[i].name);
XSTRNCPY(buf, ciphers[i].name, cipherLen);
buf += cipherLen;
if (i < size - 1)
@@ -722,8 +722,7 @@ const char* wolfSSL_get_shared_ciphers(WOLFSSL* ssl, char* buf, int len)
if (ssl == NULL)
return NULL;
cipher = wolfSSL_get_cipher_name_from_suite(ssl->options.cipherSuite,
ssl->options.cipherSuite0);
cipher = wolfSSL_get_cipher_name_iana(ssl);
len = min(len, (int)(XSTRLEN(cipher) + 1));
XMEMCPY(buf, cipher, len);
return buf;
@@ -15291,8 +15290,7 @@ const char* wolfSSL_CIPHER_get_name(const WOLFSSL_CIPHER* cipher)
return NULL;
}
return wolfSSL_get_cipher_name_from_suite(cipher->ssl->options.cipherSuite,
cipher->ssl->options.cipherSuite0);
return wolfSSL_get_cipher_name_iana(cipher->ssl);
}
const char* wolfSSL_SESSION_CIPHER_get_name(WOLFSSL_SESSION* session)
@@ -15302,8 +15300,7 @@ const char* wolfSSL_SESSION_CIPHER_get_name(WOLFSSL_SESSION* session)
}
#ifdef SESSION_CERTS
return wolfSSL_get_cipher_name_from_suite(session->cipherSuite,
session->cipherSuite0);
return GetCipherNameIana(session->cipherSuite0, session->cipherSuite);
#else
return NULL;
#endif
@@ -15322,6 +15319,13 @@ const char* wolfSSL_get_cipher_name(WOLFSSL* ssl)
return wolfSSL_get_cipher_name_internal(ssl);
}
const char* wolfSSL_get_cipher_name_from_suite(const byte cipherSuite0,
const byte cipherSuite)
{
return GetCipherNameInternal(cipherSuite0, cipherSuite);
}
#ifdef HAVE_ECC
/* Return the name of the curve used for key exchange as a printable string.
*

View File

@@ -1311,12 +1311,15 @@ static void test_client_nofail(void* args, void *cb)
WOLFSSL_METHOD* method = 0;
WOLFSSL_CTX* ctx = 0;
WOLFSSL* ssl = 0;
WOLFSSL_CIPHER* cipher;
char msg[64] = "hello wolfssl!";
char reply[1024];
int input;
int msgSz = (int)XSTRLEN(msg);
int ret, err = 0;
int cipherSuite;
const char* cipherName1, *cipherName2;
#ifdef WOLFSSL_TIRTOS
fdOpenSession(Task_self());
@@ -1398,6 +1401,19 @@ static void test_client_nofail(void* args, void *cb)
goto done2;
}
/* test the various get cipher methods */
cipherSuite = wolfSSL_get_current_cipher_suite(ssl);
cipherName1 = wolfSSL_get_cipher_name(ssl);
cipherName2 = wolfSSL_get_cipher_name_from_suite(
(cipherSuite >> 8), cipherSuite & 0xFF);
AssertStrEQ(cipherName1, cipherName2);
cipher = wolfSSL_get_current_cipher(ssl);
cipherName1 = wolfSSL_CIPHER_get_name(cipher);
cipherName2 = wolfSSL_get_cipher(ssl);
AssertStrEQ(cipherName1, cipherName2);
if(cb != NULL)((cbType)cb)(ctx, ssl);
if (wolfSSL_write(ssl, msg, msgSz) != msgSz)

View File

@@ -1014,6 +1014,7 @@ enum {
enum Misc {
CIPHER_BYTE = 0x00, /* Default ciphers */
ECC_BYTE = 0xC0, /* ECC first cipher suite byte */
QSH_BYTE = 0xD0, /* Quantum-safe Handshake cipher suite */
CHACHA_BYTE = 0xCC, /* ChaCha first cipher suite */
@@ -3964,12 +3965,19 @@ WOLFSSL_LOCAL word32 LowResTimer(void);
WOLFSSL_LOCAL int CopyDecodedToX509(WOLFSSL_X509*, DecodedCert*);
#endif
WOLFSSL_LOCAL const char* const* GetCipherNames(void);
typedef struct CipherSuiteInfo {
const char* name;
const char* name_iana;
byte cipherSuite0;
byte cipherSuite;
} CipherSuiteInfo;
WOLFSSL_LOCAL const CipherSuiteInfo* GetCipherNames(void);
WOLFSSL_LOCAL int GetCipherNamesSize(void);
WOLFSSL_LOCAL const char* GetCipherNameInternal(const char* cipherName, int cipherSuite);
WOLFSSL_LOCAL const char* GetCipherNameInternal(const byte cipherSuite0, const byte cipherSuite);
WOLFSSL_LOCAL const char* GetCipherNameIana(const byte cipherSuite0, const byte cipherSuite);
WOLFSSL_LOCAL const char* wolfSSL_get_cipher_name_internal(WOLFSSL* ssl);
WOLFSSL_LOCAL const char* wolfSSL_get_cipher_name_from_suite(
const unsigned char cipherSuite, const unsigned char cipherSuite0);
WOLFSSL_LOCAL const char* wolfSSL_get_cipher_name_iana(WOLFSSL* ssl);
enum encrypt_side {
ENCRYPT_SIDE_ONLY = 1,

View File

@@ -536,6 +536,8 @@ WOLFSSL_API char* wolfSSL_get_cipher_list(int priority);
WOLFSSL_API char* wolfSSL_get_cipher_list_ex(WOLFSSL* ssl, int priority);
WOLFSSL_API int wolfSSL_get_ciphers(char*, int);
WOLFSSL_API const char* wolfSSL_get_cipher_name(WOLFSSL* ssl);
WOLFSSL_API const char* wolfSSL_get_cipher_name_from_suite(const unsigned char,
const unsigned char);
WOLFSSL_API const char* wolfSSL_get_shared_ciphers(WOLFSSL* ssl, char* buf,
int len);
WOLFSSL_API const char* wolfSSL_get_curve_name(WOLFSSL* ssl);