diff --git a/t/.gitignore b/t/.gitignore index ab1a8100a..98710b716 100644 --- a/t/.gitignore +++ b/t/.gitignore @@ -87,3 +87,4 @@ test-amr-decode test-amr-encode bufferpool.c uring.c +aead-decrypt diff --git a/t/Makefile b/t/Makefile index cf15bd22c..39509fd43 100644 --- a/t/Makefile +++ b/t/Makefile @@ -66,7 +66,7 @@ endif include ../lib/codec-chain.Makefile -SRCS= test-bitstr.c aes-crypt.c aead-aes-crypt.c test-const_str_hash.strhash.c +SRCS= test-bitstr.c aes-crypt.c aead-aes-crypt.c test-const_str_hash.strhash.c aead-decrypt.c LIBSRCS= loglib.c auxlib.c str.c rtplib.c ssllib.c mix_buffer.c bufferpool.c DAEMONSRCS= crypto.c ssrc.c helpers.c rtp.c HASHSRCS= @@ -120,7 +120,7 @@ all-tests: unit-tests endif true # override linking recipe from common.Makefile -unit-tests: $(TESTS) +unit-tests: $(TESTS) aead-decrypt failed="" ; \ for x in $(TESTS); do \ echo `date +"%Y-%m-%d %H:%M:%S"` testing: $$x ; \ @@ -234,6 +234,8 @@ test-dtmf-detect: test-dtmf-detect.o aes-crypt: aes-crypt.o $(COMMONOBJS) crypto.o +aead-decrypt: aead-decrypt.o $(COMMONOBJS) crypto.o rtp.o + aead-aes-crypt: aead-aes-crypt.o $(COMMONOBJS) crypto.o test-stats: test-stats.o $(COMMONOBJS) codeclib.strhash.o resample.o codec.o ssrc.o call.o ice.o helpers.o \ diff --git a/t/aead-decrypt.c b/t/aead-decrypt.c new file mode 100644 index 000000000..363ceb522 --- /dev/null +++ b/t/aead-decrypt.c @@ -0,0 +1,71 @@ +#include + +#include "crypto.h" +#include "rtplib.h" +#include "log.h" +#include "main.h" +#include "ssrc.h" +#include "rtp.h" +#include "../kernel-module/common_stats.h" + + +struct rtpengine_config rtpe_config = { +}; +int get_local_log_level(unsigned int u) { + return -1; +} + +int main(int argc, char **argv) { + if (argc < 5) { + printf("Usage: %s \n", argv[0]); + printf("Example: %s AEAD_AES_256_GCM \\\n", argv[0]); + printf(" F4mVFvZGU/S50OXT17xvKHCC/8CV5vgp8OgmAlFpKcc= \\\n"); + printf(" fNAN6151Wc6DgFEZ gAhqUYthx4ivfuWtbtq...\n"); + return 1; + } + + crypto_init_main(); + + str suite; + suite = STR(argv[1]); + struct crypto_context cc = {0}; + cc.params.crypto_suite = crypto_find_suite(&suite); + assert(cc.params.crypto_suite); + + const char *key64 = argv[2]; + const char *salt64 = argv[3]; + + size_t len; + uint8_t *key = g_base64_decode(key64, &len); + assert(len == cc.params.crypto_suite->master_key_len); + uint8_t *salt = g_base64_decode(salt64, &len); + assert(len == cc.params.crypto_suite->master_salt_len); + + memcpy(cc.params.master_key, key, cc.params.crypto_suite->master_key_len); + memcpy(cc.params.master_salt, salt, cc.params.crypto_suite->master_salt_len); + + const char *pack64 = argv[4]; + uint8_t *pack = g_base64_decode(pack64, &len); + str s = STR_LEN((char *) pack, len); + + unsigned int roc = 0; + + if (argc >= 6) + roc = atoi(argv[5]); + + struct ssrc_stats stats = { + .ext_seq = roc << 16, + }; + + struct ssrc_entry_call se = { + .input_ctx = { + .parent = &se, + .stats = &stats, + }, + }; + + int ret = rtp_savp2avp(&s, &cc, &se.input_ctx); + assert(ret == 0); + printf("idx %d ROC %d\n", se.input_ctx.stats->ext_seq, se.input_ctx.stats->ext_seq >> 16); + return 0; +}