Skip to content

Commit

Permalink
Merge pull request #730 from pabuhler/rpt_decoder-mki
Browse files Browse the repository at this point in the history
Add support for a single MKI to rtp_decoder tool
  • Loading branch information
pabuhler authored Nov 28, 2024
2 parents f8bf8af + 68a7c6f commit 28d1735
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions test/rtp_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ int main(int argc, char *argv[])
char *input_key = NULL;
int b64_input = 0;
uint8_t key[MAX_KEY_LEN];
size_t mki_size = 0;
uint8_t mki[SRTP_MAX_MKI_LEN];
srtp_master_key_t masterKey;
srtp_master_key_t *masterKeys[1];
struct bpf_program fp;
char filter_exp[MAX_FILTER] = "";
char pcap_file[MAX_FILE] = "-";
Expand Down Expand Up @@ -207,7 +211,7 @@ int main(int argc, char *argv[])

/* check args */
while (1) {
c = getopt_s(argc, argv, "b:k:gt:ae:ld:f:c:m:p:o:s:r:");
c = getopt_s(argc, argv, "b:k:i:gt:ae:ld:f:c:m:p:o:s:r:");
if (c == -1) {
break;
}
Expand All @@ -218,6 +222,10 @@ int main(int argc, char *argv[])
case 'k':
input_key = optarg_s;
break;
case 'i':
mki_size =
hex_string_to_octet_string(mki, optarg_s, strlen(optarg_s)) / 2;
break;
case 'e':
scs.key_size = atoi(optarg_s);
if (scs.key_size != 128 && scs.key_size != 192 &&
Expand Down Expand Up @@ -514,7 +522,18 @@ int main(int argc, char *argv[])
return -1;
}

policy.key = key;
masterKey.key = key;

if (mki_size) {
policy.use_mki = true;
policy.mki_size = mki_size;
masterKey.mki_id = mki;
}

masterKeys[0] = &masterKey;
policy.keys = masterKeys;
policy.num_master_keys = 1;

policy.next = NULL;
policy.window_size = 128;
policy.allow_repeat_tx = false;
Expand Down Expand Up @@ -565,6 +584,11 @@ int main(int argc, char *argv[])
fprintf(stderr, "%s\n",
octet_string_hex_string(key + key_octets, salt_octets));

if (mki_size) {
fprintf(stderr, "set mki to %s\n",
octet_string_hex_string(mki, mki_size));
}

} else {
fprintf(stderr,
"error: neither encryption or authentication were selected\n");
Expand Down Expand Up @@ -642,6 +666,7 @@ void usage(char *string)
" -t <tag size> Tag size to use (in GCM mode use 8 or 16)\n"
" -k <key> sets the srtp master key given in hexadecimal\n"
" -b <key> sets the srtp master key given in base64\n"
" -i <mki> sets master key index in hexadecimal\n"
" -l list debug modules\n"
" -f \"<pcap filter>\" to filter only the desired SRTP packets\n"
" -d <debug> turn on debugging for module <debug>\n"
Expand Down

0 comments on commit 28d1735

Please sign in to comment.