Skip to content

Commit 1288d71

Browse files
committed
Address code review
1 parent afd0e5a commit 1288d71

3 files changed

Lines changed: 45 additions & 18 deletions

File tree

src/internal.c

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26198,8 +26198,8 @@ ciphersuites introduced through the "bulk" ciphersuites.
2619826198

2619926199
@return true on success, else false.
2620026200
*/
26201-
int SetCipherList(const WOLFSSL_CTX* ctx, const WOLFSSL* ssl, Suites* suites,
26202-
const char* list)
26201+
static int ParseCipherList(Suites* suites,
26202+
const char* list, ProtocolVersion version, int privateKeySz, byte side)
2620326203
{
2620426204
int ret = 0;
2620526205
int idx = 0;
@@ -26217,21 +26217,11 @@ int SetCipherList(const WOLFSSL_CTX* ctx, const WOLFSSL* ssl, Suites* suites,
2621726217
const int suiteSz = GetCipherNamesSize();
2621826218
const char* next = list;
2621926219

26220-
ProtocolVersion version;
26221-
int privateKeySz = 0;
26222-
byte side;
26223-
26224-
if (suites == NULL || list == NULL || (ctx == NULL && ssl == NULL)) {
26220+
if (suites == NULL || list == NULL) {
2622526221
WOLFSSL_MSG("SetCipherList parameter error");
2622626222
return 0;
2622726223
}
2622826224

26229-
version = ctx != NULL ? ctx->method->version : ssl->version;
26230-
#ifndef NO_CERTS
26231-
privateKeySz = (int)(ctx != NULL ? ctx->privateKeySz : ssl->buffers.keySz);
26232-
#endif
26233-
side = (byte)(ctx != NULL ? ctx->method->side : ssl->options.side);
26234-
2623526225
if (next[0] == 0 || XSTRCMP(next, "ALL") == 0 ||
2623626226
XSTRCMP(next, "DEFAULT") == 0 || XSTRCMP(next, "HIGH") == 0) {
2623726227
/* Add all ciphersuites except anonymous and null ciphers. Prefer RSA */
@@ -26640,6 +26630,41 @@ int SetCipherList(const WOLFSSL_CTX* ctx, const WOLFSSL* ssl, Suites* suites,
2664026630
return ret;
2664126631
}
2664226632

26633+
int SetCipherList_ex(const WOLFSSL_CTX* ctx, const WOLFSSL* ssl,
26634+
Suites* suites, const char* list)
26635+
{
26636+
ProtocolVersion version;
26637+
int privateKeySz = 0;
26638+
byte side;
26639+
26640+
if (ctx != NULL) {
26641+
version = ctx->method->version;
26642+
#ifndef NO_CERTS
26643+
privateKeySz = ctx->privateKeySz;
26644+
#endif
26645+
side = ctx->method->side;
26646+
}
26647+
else if (ssl != NULL) {
26648+
version = ssl->version;
26649+
#ifndef NO_CERTS
26650+
privateKeySz = ssl->buffers.keySz;
26651+
#endif
26652+
side = (byte)ssl->options.side;
26653+
}
26654+
else {
26655+
WOLFSSL_MSG("SetCipherList_ex parameter error");
26656+
return 0;
26657+
}
26658+
26659+
return ParseCipherList(suites, list, version, privateKeySz, side);
26660+
}
26661+
26662+
int SetCipherList(const WOLFSSL_CTX* ctx, Suites* suites,
26663+
const char* list)
26664+
{
26665+
return SetCipherList_ex(ctx, NULL, suites, list);
26666+
}
26667+
2664326668
#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)
2664426669
int SetCipherListFromBytes(WOLFSSL_CTX* ctx, Suites* suites, const byte* list,
2664526670
const int listSz)

src/ssl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11864,7 +11864,7 @@ static int wolfSSL_parse_cipher_list(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
1186411864
/* list has mixed(pre-TLSv13 and TLSv13) suites
1186511865
* update cipher suites the same as before
1186611866
*/
11867-
return (SetCipherList(ctx, ssl, suites, list)) ? WOLFSSL_SUCCESS :
11867+
return (SetCipherList_ex(ctx, ssl, suites, list)) ? WOLFSSL_SUCCESS :
1186811868
WOLFSSL_FAILURE;
1186911869
}
1187011870
else if (listattribute == 1) {
@@ -11905,7 +11905,7 @@ static int wolfSSL_parse_cipher_list(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
1190511905
XMEMCPY(suitesCpy, suites->suites, suites->suiteSz);
1190611906
suitesCpySz = suites->suiteSz;
1190711907

11908-
ret = SetCipherList(ctx, ssl, suites, list);
11908+
ret = SetCipherList_ex(ctx, ssl, suites, list);
1190911909
if (ret != 1) {
1191011910
#ifdef WOLFSSL_SMALL_STACK
1191111911
XFREE(suitesCpy, NULL, DYNAMIC_TYPE_TMP_BUFFER);
@@ -11971,7 +11971,7 @@ int wolfSSL_CTX_set_cipher_list(WOLFSSL_CTX* ctx, const char* list)
1197111971
#ifdef OPENSSL_EXTRA
1197211972
return wolfSSL_parse_cipher_list(ctx, NULL, ctx->suites, list);
1197311973
#else
11974-
return (SetCipherList(ctx, NULL, ctx->suites, list)) ?
11974+
return (SetCipherList(ctx, ctx->suites, list)) ?
1197511975
WOLFSSL_SUCCESS : WOLFSSL_FAILURE;
1197611976
#endif
1197711977
}
@@ -12007,7 +12007,7 @@ int wolfSSL_set_cipher_list(WOLFSSL* ssl, const char* list)
1200712007
#ifdef OPENSSL_EXTRA
1200812008
return wolfSSL_parse_cipher_list(NULL, ssl, ssl->suites, list);
1200912009
#else
12010-
return (SetCipherList(NULL, ssl, ssl->suites, list)) ?
12010+
return (SetCipherList_ex(NULL, ssl, ssl->suites, list)) ?
1201112011
WOLFSSL_SUCCESS :
1201212012
WOLFSSL_FAILURE;
1201312013
#endif

wolfssl/internal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2377,8 +2377,10 @@ typedef struct TLSX TLSX;
23772377
WOLFSSL_LOCAL int MatchSuite_ex(const WOLFSSL* ssl, Suites* peerSuites,
23782378
CipherSuite* cs, TLSX* extensions);
23792379
WOLFSSL_LOCAL int MatchSuite(WOLFSSL* ssl, Suites* peerSuites);
2380-
WOLFSSL_LOCAL int SetCipherList(const WOLFSSL_CTX* ctx, const WOLFSSL* ssl,
2380+
WOLFSSL_LOCAL int SetCipherList_ex(const WOLFSSL_CTX* ctx, const WOLFSSL* ssl,
23812381
Suites* suites, const char* list);
2382+
WOLFSSL_LOCAL int SetCipherList(const WOLFSSL_CTX* ctx, Suites* suites,
2383+
const char* list);
23822384
WOLFSSL_LOCAL int SetCipherListFromBytes(WOLFSSL_CTX* ctx, Suites* suites,
23832385
const byte* list, const int listSz);
23842386
WOLFSSL_LOCAL int SetSuitesHashSigAlgo(Suites* suites, const char* list);

0 commit comments

Comments
 (0)