diff --git a/cyassl/internal.h b/cyassl/internal.h index ccd7c8138..0bd444b84 100644 --- a/cyassl/internal.h +++ b/cyassl/internal.h @@ -156,6 +156,10 @@ typedef byte word24[3]; /* used by ssl.c and cyassl_int.c */ void c32to24(word32 in, word24 out); +/* used by ssl.c */ +const char* const* GetCipherNames(void); +int GetCipherNamesSize(void); + /* Define or comment out the cipher suites you'd like to be compiled in make sure to use at least one BUILD_SSL_xxx or BUILD_TLS_xxx is defined @@ -802,7 +806,6 @@ enum Misc { COPY = 1 /* should we copy static buffer for write */ }; - #ifdef SESSION_INDEX /* Shift values for making a session index */ #define SESSIDX_ROW_SHIFT 4 diff --git a/cyassl/ssl.h b/cyassl/ssl.h index 7109b0726..c69794518 100644 --- a/cyassl/ssl.h +++ b/cyassl/ssl.h @@ -233,6 +233,7 @@ CYASSL_API int CyaSSL_PemCertToDer(const char*, unsigned char*, int); CYASSL_API CYASSL_CTX* CyaSSL_CTX_new(CYASSL_METHOD*); CYASSL_API CYASSL* CyaSSL_new(CYASSL_CTX*); CYASSL_API int CyaSSL_set_fd (CYASSL*, int); +CYASSL_API int CyaSSL_get_ciphers(char*, int); CYASSL_API int CyaSSL_get_fd(const CYASSL*); CYASSL_API void CyaSSL_set_using_nonblock(CYASSL*, int); CYASSL_API int CyaSSL_get_using_nonblock(CYASSL*); diff --git a/src/internal.c b/src/internal.c index eb7baccb5..fc50b9c6e 100644 --- a/src/internal.c +++ b/src/internal.c @@ -7482,7 +7482,8 @@ void SetErrorString(int error, char* str) } -/* be sure to add to cipher_name_idx too !!!! */ +/* be sure to add to cipher_names in + internal.h and cipher_name_idx too !!!! */ static const char* const cipher_names[] = { #ifdef BUILD_SSL_RSA_WITH_RC4_128_SHA @@ -7868,7 +7869,6 @@ static const char* const cipher_names[] = }; - /* cipher suite number that matches above name table */ static int cipher_name_idx[] = { @@ -8255,6 +8255,17 @@ static int cipher_name_idx[] = }; +/* returns the cipher_names array */ +const char* const* GetCipherNames(void) +{ + return cipher_names; +} +/* returns the size of the cipher_names array */ +int GetCipherNamesSize(void) +{ + return sizeof(cipher_names) / sizeof(char*); +} + /* return true if set, else false */ /* only supports full name from cipher_name[] delimited by : */ int SetCipherList(Suites* s, const char* list) diff --git a/src/ssl.c b/src/ssl.c index 1b99e98fd..5bcca0d4e 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -29,7 +29,6 @@ #include #endif - #include #include #include @@ -225,7 +224,37 @@ int CyaSSL_set_fd(CYASSL* ssl, int fd) CYASSL_LEAVE("SSL_set_fd", SSL_SUCCESS); return SSL_SUCCESS; } +int CyaSSL_get_ciphers(char* buf, int len) +{ + const char* const* ciphers = GetCipherNames(); + int totalInc = 0; + int step = 0; + char delim = ':'; + char* tmp = buf; + int size = GetCipherNamesSize(); + int i; + /* Loop the array, add each member to the + buffer delimitted by a : + */ + for (i = 0; i < size; i++) + { + step = strlen(ciphers[i]) + strlen(&delim)-2; + totalInc += step; + /* Check to make sure buf is large enough and will not overflow */ + if(totalInc <= len) { + memcpy(tmp, ciphers[i], strlen(ciphers[i])); + tmp += strlen(ciphers[i]); + if(i < size - 1) { + memcpy(tmp, &delim, strlen(&delim)-2); + tmp += strlen(&delim)-2; + } + } + else + return BUFFER_E; + } + return SSL_SUCCESS; +} int CyaSSL_get_fd(const CYASSL* ssl) {