Skip to content

Commit

Permalink
Convert algorithm to upper case for comparison.
Browse files Browse the repository at this point in the history
  • Loading branch information
sobomax committed Sep 20, 2023
1 parent a7f1b1e commit e11faaa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
8 changes: 4 additions & 4 deletions modules/dtls_gw/rtpp_dtls_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,18 @@ rtpp_dtls_conn_setmode(struct rtpp_dtls_conn *self,
pvt->state);
goto failed;
}
if (rdfsp->algorithm->len != FP_DIGEST_ALG_LEN ||
memcmp(rdfsp->algorithm->s, FP_DIGEST_ALG, FP_DIGEST_ALG_LEN) != 0) {
if (rdfsp->algorithm.len != FP_DIGEST_ALG_LEN ||
memcmp(rdfsp->algorithm.s, FP_DIGEST_ALG, FP_DIGEST_ALG_LEN) != 0) {
RTPP_LOG(RTPP_MOD_SELF.log, RTPP_LOG_ERR, "unsupported fingerprint "
"algorithm: \"%.*s\"", FMTSTR(rdfsp->algorithm));
"algorithm: \"%.*s\"", FMTSTR(&rdfsp->algorithm));
goto failed;
}
if (rdfsp->fingerprint->len != FP_FINGERPRINT_STR_LEN) {
RTPP_LOG(RTPP_MOD_SELF.log, RTPP_LOG_ERR, "invalid fingerprint "
"length: \"%lu\"", rdfsp->fingerprint->len);
goto failed;
}
sprintf(pvt->fingerprint, "%.*s %.*s", FMTSTR(rdfsp->algorithm),
sprintf(pvt->fingerprint, "%.*s %.*s", FMTSTR(&rdfsp->algorithm),
FMTSTR(rdfsp->fingerprint));
if (rdfsp->ssrc != NULL) {
uint32_t ssrc = strtoul(rdfsp->ssrc->s, &ep, 10);
Expand Down
3 changes: 2 additions & 1 deletion modules/dtls_gw/rtpp_dtls_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ enum rtpp_dtls_mode {

struct rdc_peer_spec {
enum rtpp_dtls_mode peer_mode;
const rtpp_str_t *algorithm;
rtpp_str_const_t algorithm;
const rtpp_str_t *fingerprint;
const rtpp_str_t *ssrc;
char alg_buf[FP_DIGEST_ALG_LEN];
};

DEFINE_METHOD(rtpp_dtls_conn, rtpp_dtls_conn_dtls_recv, void,
Expand Down
15 changes: 14 additions & 1 deletion modules/dtls_gw/rtpp_dtls_gw.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include "advanced/pproc_manager.h"

#include "rtpp_dtls.h"
#include "rtpp_dtls_util.h"
#include "rtpp_dtls_conn.h"

struct rtpp_module_priv {
Expand Down Expand Up @@ -331,7 +332,15 @@ rtpp_dtls_gw_handle_command(struct rtpp_module_priv *pvt,
switch (rdg_cmd) {
case RDG_CMD_A:
case RDG_CMD_P:
rdfs.algorithm = &argv[1];
rtpp_str_dup2(&argv[1], &rdfs.algorithm);
if (rdfs.algorithm.len > sizeof(rdfs.alg_buf))
goto invalalg;
for (int i = 0; i < rdfs.algorithm.len; i++) {
rdfs.alg_buf[i] = rdfs.algorithm.s[i];
if (rdfs.alg_buf[i] >= 'a')
rdfs.alg_buf[i] -= ('a' - 'A');
}
rdfs.algorithm.s = rdfs.alg_buf;
rdfs.fingerprint = &argv[2];
rdfs.ssrc = (argc == 4) ? &argv[3] : NULL;
rdfsp = &rdfs;
Expand Down Expand Up @@ -436,6 +445,10 @@ rtpp_dtls_gw_handle_command(struct rtpp_module_priv *pvt,
RTPP_OBJ_DECREF(rtps_c);
return (0);

invalalg:
RTPP_LOG(RTPP_MOD_SELF.log, RTPP_LOG_ERR, "invalid algorithm: \"%s\"",
argv[1].s);
return (-1);
invalmode:
RTPP_LOG(RTPP_MOD_SELF.log, RTPP_LOG_ERR, "invalid mode: \"%s\"",
argv[0].s);
Expand Down
2 changes: 2 additions & 0 deletions modules/dtls_gw/rtpp_dtls_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@
FP_FINGERPRINT_STR_LEN)
#define FP_DIGEST_STRBUF_LEN (FP_DIGEST_STR_LEN + 1)

typedef struct x509_st X509;

int rtpp_dtls_fp_gen(const X509 *, char *, int);

0 comments on commit e11faaa

Please sign in to comment.