get_cipher fixes

This commit is contained in:
toddouska
2014-08-15 10:56:38 -07:00
parent aaf4e74453
commit 87564bdffe
4 changed files with 39 additions and 33 deletions

View File

@ -153,14 +153,6 @@
typedef byte word24[3]; 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);
const char* GetCipherName(int);
/* Define or comment out the cipher suites you'd like to be compiled in /* 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 make sure to use at least one BUILD_SSL_xxx or BUILD_TLS_xxx is defined
@ -2220,6 +2212,12 @@ CYASSL_LOCAL void FreeX509(CYASSL_X509*);
CYASSL_LOCAL int CopyDecodedToX509(CYASSL_X509*, DecodedCert*); CYASSL_LOCAL int CopyDecodedToX509(CYASSL_X509*, DecodedCert*);
#endif #endif
/* used by ssl.c and cyassl_int.c */
CYASSL_LOCAL void c32to24(word32 in, word24 out);
CYASSL_LOCAL const char* const* GetCipherNames(void);
CYASSL_LOCAL int GetCipherNamesSize(void);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View File

@ -8290,17 +8290,15 @@ const char* const* GetCipherNames(void)
{ {
return cipher_names; return cipher_names;
} }
/* returns the cipher at the specified index of cipher_names */
const char* GetCipherName(int index)
{
return cipher_names[index];
}
/* returns the size of the cipher_names array */ /* returns the size of the cipher_names array */
int GetCipherNamesSize(void) int GetCipherNamesSize(void)
{ {
return sizeof(cipher_names) / sizeof(char*); return (int)(sizeof(cipher_names) / sizeof(char*));
} }
/* return true if set, else false */ /* return true if set, else false */
/* only supports full name from cipher_name[] delimited by : */ /* only supports full name from cipher_name[] delimited by : */
int SetCipherList(Suites* s, const char* list) int SetCipherList(Suites* s, const char* list)

View File

@ -224,31 +224,32 @@ int CyaSSL_set_fd(CYASSL* ssl, int fd)
CYASSL_LEAVE("SSL_set_fd", SSL_SUCCESS); CYASSL_LEAVE("SSL_set_fd", SSL_SUCCESS);
return SSL_SUCCESS; return SSL_SUCCESS;
} }
int CyaSSL_get_ciphers(char* buf, int len) int CyaSSL_get_ciphers(char* buf, int len)
{ {
const char* const* ciphers = GetCipherNames(); const char* const* ciphers = GetCipherNames();
int totalInc = 0; int totalInc = 0;
int step = 0; int step = 0;
char delim = ':'; char delim = ':';
char* tmp = buf; int size = GetCipherNamesSize();
int size = GetCipherNamesSize(); int i;
int i;
/* Loop the array, add each member to the if (buf == NULL || len <= 0)
buffer delimitted by a : return BAD_FUNC_ARG;
*/
for (i = 0; i < size; i++) /* Add each member to the buffer delimitted by a : */
{ for (i = 0; i < size; i++) {
step = strlen(ciphers[i]) + strlen(&delim)-2; step = (int)(XSTRLEN(ciphers[i]) + 1); /* delimiter */
totalInc += step; totalInc += step;
/* Check to make sure buf is large enough and will not overflow */ /* Check to make sure buf is large enough and will not overflow */
if(totalInc <= len) { if (totalInc < len) {
memcpy(tmp, ciphers[i], strlen(ciphers[i])); XSTRNCPY(buf, ciphers[i], XSTRLEN(ciphers[i]));
tmp += strlen(ciphers[i]); buf += XSTRLEN(ciphers[i]);
if(i < size - 1) {
memcpy(tmp, &delim, strlen(&delim)-2); if (i < size - 1)
tmp += strlen(&delim)-2; *buf++ = delim;
}
} }
else else
return BUFFER_E; return BUFFER_E;
@ -256,6 +257,7 @@ int CyaSSL_get_ciphers(char* buf, int len)
return SSL_SUCCESS; return SSL_SUCCESS;
} }
int CyaSSL_get_fd(const CYASSL* ssl) int CyaSSL_get_fd(const CYASSL* ssl)
{ {
CYASSL_ENTER("SSL_get_fd"); CYASSL_ENTER("SSL_get_fd");

View File

@ -161,6 +161,14 @@ int testsuite_test(int argc, char** argv)
if (server_args.return_code != 0) return server_args.return_code; if (server_args.return_code != 0) return server_args.return_code;
} }
/* show ciphers */
{
char ciphers[1024];
XMEMSET(ciphers, 0, sizeof(ciphers));
CyaSSL_get_ciphers(ciphers, sizeof(ciphers)-1);
printf("ciphers = %s\n", ciphers);
}
/* validate output equals input */ /* validate output equals input */
{ {
byte input[SHA256_DIGEST_SIZE]; byte input[SHA256_DIGEST_SIZE];