Skip to content

Commit e11faaa

Browse files
committed
Convert algorithm to upper case for comparison.
1 parent a7f1b1e commit e11faaa

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

modules/dtls_gw/rtpp_dtls_conn.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,18 +286,18 @@ rtpp_dtls_conn_setmode(struct rtpp_dtls_conn *self,
286286
pvt->state);
287287
goto failed;
288288
}
289-
if (rdfsp->algorithm->len != FP_DIGEST_ALG_LEN ||
290-
memcmp(rdfsp->algorithm->s, FP_DIGEST_ALG, FP_DIGEST_ALG_LEN) != 0) {
289+
if (rdfsp->algorithm.len != FP_DIGEST_ALG_LEN ||
290+
memcmp(rdfsp->algorithm.s, FP_DIGEST_ALG, FP_DIGEST_ALG_LEN) != 0) {
291291
RTPP_LOG(RTPP_MOD_SELF.log, RTPP_LOG_ERR, "unsupported fingerprint "
292-
"algorithm: \"%.*s\"", FMTSTR(rdfsp->algorithm));
292+
"algorithm: \"%.*s\"", FMTSTR(&rdfsp->algorithm));
293293
goto failed;
294294
}
295295
if (rdfsp->fingerprint->len != FP_FINGERPRINT_STR_LEN) {
296296
RTPP_LOG(RTPP_MOD_SELF.log, RTPP_LOG_ERR, "invalid fingerprint "
297297
"length: \"%lu\"", rdfsp->fingerprint->len);
298298
goto failed;
299299
}
300-
sprintf(pvt->fingerprint, "%.*s %.*s", FMTSTR(rdfsp->algorithm),
300+
sprintf(pvt->fingerprint, "%.*s %.*s", FMTSTR(&rdfsp->algorithm),
301301
FMTSTR(rdfsp->fingerprint));
302302
if (rdfsp->ssrc != NULL) {
303303
uint32_t ssrc = strtoul(rdfsp->ssrc->s, &ep, 10);

modules/dtls_gw/rtpp_dtls_conn.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ enum rtpp_dtls_mode {
4040

4141
struct rdc_peer_spec {
4242
enum rtpp_dtls_mode peer_mode;
43-
const rtpp_str_t *algorithm;
43+
rtpp_str_const_t algorithm;
4444
const rtpp_str_t *fingerprint;
4545
const rtpp_str_t *ssrc;
46+
char alg_buf[FP_DIGEST_ALG_LEN];
4647
};
4748

4849
DEFINE_METHOD(rtpp_dtls_conn, rtpp_dtls_conn_dtls_recv, void,

modules/dtls_gw/rtpp_dtls_gw.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#include "advanced/pproc_manager.h"
7676

7777
#include "rtpp_dtls.h"
78+
#include "rtpp_dtls_util.h"
7879
#include "rtpp_dtls_conn.h"
7980

8081
struct rtpp_module_priv {
@@ -331,7 +332,15 @@ rtpp_dtls_gw_handle_command(struct rtpp_module_priv *pvt,
331332
switch (rdg_cmd) {
332333
case RDG_CMD_A:
333334
case RDG_CMD_P:
334-
rdfs.algorithm = &argv[1];
335+
rtpp_str_dup2(&argv[1], &rdfs.algorithm);
336+
if (rdfs.algorithm.len > sizeof(rdfs.alg_buf))
337+
goto invalalg;
338+
for (int i = 0; i < rdfs.algorithm.len; i++) {
339+
rdfs.alg_buf[i] = rdfs.algorithm.s[i];
340+
if (rdfs.alg_buf[i] >= 'a')
341+
rdfs.alg_buf[i] -= ('a' - 'A');
342+
}
343+
rdfs.algorithm.s = rdfs.alg_buf;
335344
rdfs.fingerprint = &argv[2];
336345
rdfs.ssrc = (argc == 4) ? &argv[3] : NULL;
337346
rdfsp = &rdfs;
@@ -436,6 +445,10 @@ rtpp_dtls_gw_handle_command(struct rtpp_module_priv *pvt,
436445
RTPP_OBJ_DECREF(rtps_c);
437446
return (0);
438447

448+
invalalg:
449+
RTPP_LOG(RTPP_MOD_SELF.log, RTPP_LOG_ERR, "invalid algorithm: \"%s\"",
450+
argv[1].s);
451+
return (-1);
439452
invalmode:
440453
RTPP_LOG(RTPP_MOD_SELF.log, RTPP_LOG_ERR, "invalid mode: \"%s\"",
441454
argv[0].s);

modules/dtls_gw/rtpp_dtls_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@
3232
FP_FINGERPRINT_STR_LEN)
3333
#define FP_DIGEST_STRBUF_LEN (FP_DIGEST_STR_LEN + 1)
3434

35+
typedef struct x509_st X509;
36+
3537
int rtpp_dtls_fp_gen(const X509 *, char *, int);

0 commit comments

Comments
 (0)