Skip to content

Commit ef14176

Browse files
committed
SRTP fixes:
* in wolfssl/ssl.h, add missing arg names to wolfSSL_CTX_set_tlsext_use_srtp(), wolfSSL_set_tlsext_use_srtp(), and wolfSSL_export_dtls_srtp_keying_material(); * in wolfcrypt/src/kdf.c, call wc_AesFree if and only if wc_AesInit() succeeded; * in src/ssl.c:DtlsSrtpSelProfiles(), fix bugprone-inc-dec-in-conditions; * in tests/suites.c:execute_test_case(), fix several -Wdeclaration-after-statement and -Wmissing-field-initializers; * in wolfcrypt/test/test.c, fix a shiftTooManyBitsSigned warning in srtpkdf_test(), and fix a typo (kaSz/ksSz).
1 parent 8f2a48c commit ef14176

File tree

5 files changed

+40
-22
lines changed

5 files changed

+40
-22
lines changed

src/ssl.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,15 +2240,19 @@ static int DtlsSrtpSelProfiles(word16* id, const char* profile_str)
22402240
do {
22412241
current = next;
22422242
next = XSTRSTR(current, ":");
2243-
current_length = (!next) ? (word32)XSTRLEN(current)
2244-
: (word32)(next - current);
2243+
if (next) {
2244+
current_length = (word32)(next - current);
2245+
++next; /* ++ needed to skip ':' */
2246+
} else {
2247+
current_length = (word32)XSTRLEN(current);
2248+
}
22452249
if (current_length < length)
22462250
length = current_length;
22472251
profile = DtlsSrtpFindProfile(current, current_length, 0);
22482252
if (profile != NULL) {
22492253
*id |= (1 << profile->id); /* selected bit based on ID */
22502254
}
2251-
} while (next != NULL && next++); /* ++ needed to skip ':' */
2255+
} while (next != NULL);
22522256
return WOLFSSL_SUCCESS;
22532257
}
22542258

tests/suites.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,8 @@ static int execute_test_case(int svr_argc, char** svr_argv,
304304
int forceCliDefCipherList)
305305
{
306306
#if defined(WOLFSSL_TIRTOS) || defined(WOLFSSL_SRTP)
307-
func_args cliArgs = {0};
308-
func_args svrArgs = {0};
309-
cliArgs.argc = cli_argc;
310-
cliArgs.argv = cli_argv;
311-
svrArgs.argc = svr_argc;
312-
svrArgs.argv = svr_argv;
307+
func_args cliArgs = {0, NULL, 0, NULL, NULL, NULL};
308+
func_args svrArgs = {0, NULL, 0, NULL, NULL, NULL};
313309
#else
314310
func_args cliArgs = {cli_argc, cli_argv, 0, NULL, NULL};
315311
func_args svrArgs = {svr_argc, svr_argv, 0, NULL, NULL};
@@ -333,6 +329,14 @@ static int execute_test_case(int svr_argc, char** svr_argv,
333329
#if defined(WOLFSSL_SRTP) && defined(WOLFSSL_COND)
334330
srtp_test_helper srtp_helper;
335331
#endif
332+
333+
#if defined(WOLFSSL_TIRTOS) || defined(WOLFSSL_SRTP)
334+
cliArgs.argc = cli_argc;
335+
cliArgs.argv = cli_argv;
336+
svrArgs.argc = svr_argc;
337+
svrArgs.argv = svr_argv;
338+
#endif
339+
336340
/* Is Valid Cipher and Version Checks */
337341
/* build command list for the Is checks below */
338342
commandLine[0] = '\0';

wolfcrypt/src/kdf.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,7 @@ int wc_SRTP_KDF(const byte* key, word32 keySz, const byte* salt, word32 saltSz,
10061006
#else
10071007
Aes aes[1];
10081008
#endif
1009+
int aes_inited = 0;
10091010

10101011
/* Validate parameters. */
10111012
if ((key == NULL) || (keySz > AES_256_KEY_SIZE) || (salt == NULL) ||
@@ -1031,6 +1032,7 @@ int wc_SRTP_KDF(const byte* key, word32 keySz, const byte* salt, word32 saltSz,
10311032
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
10321033
}
10331034
if (ret == 0) {
1035+
aes_inited = 1;
10341036
ret = wc_AesSetKey(aes, key, keySz, NULL, AES_ENCRYPTION);
10351037
}
10361038

@@ -1056,8 +1058,8 @@ int wc_SRTP_KDF(const byte* key, word32 keySz, const byte* salt, word32 saltSz,
10561058
WC_SRTP_LABEL_SALT, key3, key3Sz, aes);
10571059
}
10581060

1059-
/* AES object memset so can always free. */
1060-
wc_AesFree(aes);
1061+
if (aes_inited)
1062+
wc_AesFree(aes);
10611063
#ifdef WOLFSSL_SMALL_STACK
10621064
XFREE(aes, NULL, DYNAMIC_TYPE_CIPHER);
10631065
#endif
@@ -1099,6 +1101,7 @@ int wc_SRTCP_KDF(const byte* key, word32 keySz, const byte* salt, word32 saltSz,
10991101
#else
11001102
Aes aes[1];
11011103
#endif
1104+
int aes_inited = 0;
11021105

11031106
/* Validate parameters. */
11041107
if ((key == NULL) || (keySz > AES_256_KEY_SIZE) || (salt == NULL) ||
@@ -1124,6 +1127,7 @@ int wc_SRTCP_KDF(const byte* key, word32 keySz, const byte* salt, word32 saltSz,
11241127
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
11251128
}
11261129
if (ret == 0) {
1130+
aes_inited = 1;
11271131
ret = wc_AesSetKey(aes, key, keySz, NULL, AES_ENCRYPTION);
11281132
}
11291133

@@ -1149,8 +1153,8 @@ int wc_SRTCP_KDF(const byte* key, word32 keySz, const byte* salt, word32 saltSz,
11491153
WC_SRTCP_LABEL_SALT, key3, key3Sz, aes);
11501154
}
11511155

1152-
/* AES object memset so can always free. */
1153-
wc_AesFree(aes);
1156+
if (aes_inited)
1157+
wc_AesFree(aes);
11541158
#ifdef WOLFSSL_SMALL_STACK
11551159
XFREE(aes, NULL, DYNAMIC_TYPE_CIPHER);
11561160
#endif
@@ -1189,6 +1193,7 @@ int wc_SRTP_KDF_label(const byte* key, word32 keySz, const byte* salt,
11891193
#else
11901194
Aes aes[1];
11911195
#endif
1196+
int aes_inited = 0;
11921197

11931198
/* Validate parameters. */
11941199
if ((key == NULL) || (keySz > AES_256_KEY_SIZE) || (salt == NULL) ||
@@ -1215,6 +1220,7 @@ int wc_SRTP_KDF_label(const byte* key, word32 keySz, const byte* salt,
12151220
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
12161221
}
12171222
if (ret == 0) {
1223+
aes_inited = 1;
12181224
ret = wc_AesSetKey(aes, key, keySz, NULL, AES_ENCRYPTION);
12191225
}
12201226

@@ -1229,8 +1235,8 @@ int wc_SRTP_KDF_label(const byte* key, word32 keySz, const byte* salt,
12291235
outKeySz, aes);
12301236
}
12311237

1232-
/* AES object memset so can always free. */
1233-
wc_AesFree(aes);
1238+
if (aes_inited)
1239+
wc_AesFree(aes);
12341240
#ifdef WOLFSSL_SMALL_STACK
12351241
XFREE(aes, NULL, DYNAMIC_TYPE_CIPHER);
12361242
#endif
@@ -1270,6 +1276,7 @@ int wc_SRTCP_KDF_label(const byte* key, word32 keySz, const byte* salt,
12701276
#else
12711277
Aes aes[1];
12721278
#endif
1279+
int aes_inited = 0;
12731280

12741281
/* Validate parameters. */
12751282
if ((key == NULL) || (keySz > AES_256_KEY_SIZE) || (salt == NULL) ||
@@ -1296,6 +1303,7 @@ int wc_SRTCP_KDF_label(const byte* key, word32 keySz, const byte* salt,
12961303
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
12971304
}
12981305
if (ret == 0) {
1306+
aes_inited = 1;
12991307
ret = wc_AesSetKey(aes, key, keySz, NULL, AES_ENCRYPTION);
13001308
}
13011309

@@ -1310,8 +1318,8 @@ int wc_SRTCP_KDF_label(const byte* key, word32 keySz, const byte* salt,
13101318
outKeySz, aes);
13111319
}
13121320

1313-
/* AES object memset so can always free. */
1314-
wc_AesFree(aes);
1321+
if (aes_inited)
1322+
wc_AesFree(aes);
13151323
#ifdef WOLFSSL_SMALL_STACK
13161324
XFREE(aes, NULL, DYNAMIC_TYPE_CIPHER);
13171325
#endif

wolfcrypt/test/test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25678,7 +25678,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void)
2567825678

2567925679
ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
2568025680
tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_SALT,
25681-
keyS, tv[i].kaSz);
25681+
keyS, tv[i].ksSz);
2568225682
if (ret != 0)
2568325683
return WC_TEST_RET_ENC_EC(ret);
2568425684
if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0)
@@ -25806,7 +25806,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void)
2580625806
if (idx != -1)
2580725807
return WC_TEST_RET_ENC_NC;
2580825808
for (i = 0; i < 32; i++) {
25809-
word32 kdr = 1 << i;
25809+
word32 kdr = 1U << i;
2581025810
idx = wc_SRTP_KDF_kdr_to_idx(kdr);
2581125811
if (idx != i)
2581225812
return WC_TEST_RET_ENC_NC;

wolfssl/ssl.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,16 +1478,18 @@ typedef struct WOLFSSL_SRTP_PROTECTION_PROFILE {
14781478
} WOLFSSL_SRTP_PROTECTION_PROFILE;
14791479

14801480
/* Compatibility API's for SRTP */
1481-
WOLFSSL_API int wolfSSL_CTX_set_tlsext_use_srtp(WOLFSSL_CTX* ctx, const char*);
1482-
WOLFSSL_API int wolfSSL_set_tlsext_use_srtp(WOLFSSL* ssl, const char*);
1481+
WOLFSSL_API int wolfSSL_CTX_set_tlsext_use_srtp(WOLFSSL_CTX* ctx,
1482+
const char* profile_str);
1483+
WOLFSSL_API int wolfSSL_set_tlsext_use_srtp(WOLFSSL* ssl,
1484+
const char* wolfSSL_set_tlsext_use_srtp);
14831485
WOLFSSL_API const WOLFSSL_SRTP_PROTECTION_PROFILE*
14841486
wolfSSL_get_selected_srtp_profile(WOLFSSL* ssl);
14851487
WOLFSSL_API WOLF_STACK_OF(WOLFSSL_SRTP_PROTECTION_PROFILE)*
14861488
wolfSSL_get_srtp_profiles(WOLFSSL* ssl);
14871489

14881490
/* Non standard API for getting the SRTP session keys using KDF */
14891491
WOLFSSL_API int wolfSSL_export_dtls_srtp_keying_material(WOLFSSL* ssl,
1490-
unsigned char*, size_t*);
1492+
unsigned char* out, size_t* olen);
14911493
#endif /* WOLFSSL_SRTP */
14921494

14931495
WOLFSSL_API int wolfSSL_dtls_get_drop_stats(WOLFSSL* ssl,

0 commit comments

Comments
 (0)