From afcad687b7483c31693d7eb3ba5b0385504919ab Mon Sep 17 00:00:00 2001 From: "Richard L. Barnes" Date: Wed, 11 Aug 2021 08:35:43 -1000 Subject: [PATCH 001/109] Count blocks instead of bytes in AES-ICM limit computation --- crypto/cipher/aes_icm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crypto/cipher/aes_icm.c b/crypto/cipher/aes_icm.c index e05d9e45a..16043be74 100644 --- a/crypto/cipher/aes_icm.c +++ b/crypto/cipher/aes_icm.c @@ -302,7 +302,9 @@ static srtp_err_status_t srtp_aes_icm_encrypt(void *cv, uint32_t *b; /* check that there's enough segment left*/ - if ((bytes_to_encr + htons(c->counter.v16[7])) > 0xffff) { + unsigned int bytes_of_new_keystream = bytes_to_encr - c->bytes_in_buffer; + unsigned int blocks_of_new_keystream = (bytes_of_new_keystream + 15) >> 4; + if ((blocks_of_new_keystream + htons(c->counter.v16[7])) > 0xffff) { return srtp_err_status_terminus; } From 383329c8101d0558744a1d4223fe4206064b362e Mon Sep 17 00:00:00 2001 From: Pascal Buhler Date: Fri, 13 Aug 2021 21:20:31 +0200 Subject: [PATCH 002/109] Update version to 2.5.0-pre --- CMakeLists.txt | 2 +- configure | 18 +++++++++--------- configure.ac | 2 +- meson.build | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f12b9f0ad..729641bb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.12) -project(libsrtp2 VERSION 2.4.0 LANGUAGES C) +project(libsrtp2 VERSION 2.5.0 LANGUAGES C) set(PACKAGE_VERSION ${CMAKE_PROJECT_VERSION}) set(PACKAGE_STRING "${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_VERSION}") diff --git a/configure b/configure index f48346087..13e6e3ba7 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for libsrtp2 2.4.0. +# Generated by GNU Autoconf 2.69 for libsrtp2 2.5.0-pre. # # Report bugs to . # @@ -580,8 +580,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='libsrtp2' PACKAGE_TARNAME='libsrtp2' -PACKAGE_VERSION='2.4.0' -PACKAGE_STRING='libsrtp2 2.4.0' +PACKAGE_VERSION='2.5.0-pre' +PACKAGE_STRING='libsrtp2 2.5.0-pre' PACKAGE_BUGREPORT='https://github.com/cisco/libsrtp/issues' PACKAGE_URL='' @@ -1277,7 +1277,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures libsrtp2 2.4.0 to adapt to many kinds of systems. +\`configure' configures libsrtp2 2.5.0-pre to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1342,7 +1342,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of libsrtp2 2.4.0:";; + short | recursive ) echo "Configuration of libsrtp2 2.5.0-pre:";; esac cat <<\_ACEOF @@ -1455,7 +1455,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -libsrtp2 configure 2.4.0 +libsrtp2 configure 2.5.0-pre generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2008,7 +2008,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by libsrtp2 $as_me 2.4.0, which was +It was created by libsrtp2 $as_me 2.5.0-pre, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -7136,7 +7136,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by libsrtp2 $as_me 2.4.0, which was +This file was extended by libsrtp2 $as_me 2.5.0-pre, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -7198,7 +7198,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -libsrtp2 config.status 2.4.0 +libsrtp2 config.status 2.5.0-pre configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 4331b5d6f..b10fc6473 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -AC_INIT([libsrtp2], [2.4.0], [https://github.com/cisco/libsrtp/issues]) +AC_INIT([libsrtp2], [2.5.0-pre], [https://github.com/cisco/libsrtp/issues]) dnl Must come before AC_PROG_CC EMPTY_CFLAGS="no" diff --git a/meson.build b/meson.build index c70efd7fd..226b05c34 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('libsrtp2', 'c', version: '2.4.0', +project('libsrtp2', 'c', version: '2.5.0', meson_version: '>= 0.52.0', default_options: ['buildtype=debugoptimized']) From 780c8be7a7e6d4297ac9ba35c7ebe45ed813c623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 16 Aug 2021 10:17:08 +0200 Subject: [PATCH 003/109] Create fromat_check.yml --- .github/workflows/fromat_check.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/fromat_check.yml diff --git a/.github/workflows/fromat_check.yml b/.github/workflows/fromat_check.yml new file mode 100644 index 000000000..29f856ec3 --- /dev/null +++ b/.github/workflows/fromat_check.yml @@ -0,0 +1,13 @@ +name: Code Formatting Check + +on: [push, pull_request] + +jobs: + format-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Clang Format + run: sudo apt install clang-format-3.9 + - name: Run clang format + run: CLANG_FORMAT=clang-format-3.9 ./format.sh -d From 1be3073201ed8a76af658e35b50d8783400958a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 16 Aug 2021 10:33:08 +0200 Subject: [PATCH 004/109] try with older ubuntu release --- .github/workflows/fromat_check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fromat_check.yml b/.github/workflows/fromat_check.yml index 29f856ec3..d10a6c17e 100644 --- a/.github/workflows/fromat_check.yml +++ b/.github/workflows/fromat_check.yml @@ -4,7 +4,7 @@ on: [push, pull_request] jobs: format-check: - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - name: Install Clang Format From 1057a19f919b3860fc8a82904cfcb531d2a11522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 16 Aug 2021 11:56:27 +0200 Subject: [PATCH 005/109] ensure the build for fuzzing works --- .github/workflows/fuzzer_build.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/fuzzer_build.yml diff --git a/.github/workflows/fuzzer_build.yml b/.github/workflows/fuzzer_build.yml new file mode 100644 index 000000000..3139cd3b0 --- /dev/null +++ b/.github/workflows/fuzzer_build.yml @@ -0,0 +1,24 @@ +# This will verify that the fuzzer builds but will not run it +name: Fuzzer build check + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + workflow_dispatch: + +jobs: + fuzz: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install clang + run: sudo apt install clang + + - name: Configure with fuzzing + run: CC=clang CXX=clang++ CXXFLAGS="-fsanitize=fuzzer-no-link,address,undefined -g -O3" CFLAGS="-fsanitize=fuzzer-no-link,address,undefined -g -O3" LDFLAGS="-fsanitize=fuzzer-no-link,address,undefined" ./configure + + - name: Build + run: LIBFUZZER="-fsanitize=fuzzer" make srtp-fuzzer From 99f180a25d31f5955c49cb61026707cee0cd6e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 16 Aug 2021 12:24:22 +0200 Subject: [PATCH 006/109] add action for autotools ci --- .github/workflows/autotools.yml | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/autotools.yml diff --git a/.github/workflows/autotools.yml b/.github/workflows/autotools.yml new file mode 100644 index 000000000..bb74dd733 --- /dev/null +++ b/.github/workflows/autotools.yml @@ -0,0 +1,56 @@ +name: AutoTools CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest] + crypto: [internal, openssl, nss] + include: + - crypto: internal + configure-crypto-enable: "" + - crypto: openssl + configure-crypto-enable: "--enable-openssl" + - crypto: nss + configure-crypto-enable: "--enable-nss" + + runs-on: ${{ matrix.os }} + + steps: + - name: Setup Ubuntu + if: matrix.os == 'ubuntu-latest' + run: sudo apt-get install valgrind + + - name: Setup Ubuntu NSS + if: matrix.os == 'ubuntu-latest' && matrix.crypto == 'nss' + run: sudo apt-get install libnss3-dev + + - name: Setup macOS OpenSSL + if: matrix.os == 'macos-latest' && matrix.crypto == 'openssl' + run: echo "configure-env=PKG_CONFIG_PATH=$(brew --prefix openssl@1.1)/lib/pkgconfig" >> $GITHUB_ENV + + - name: Setup macOS NSS + if: matrix.os == 'macos-latest' && matrix.crypto == 'nss' + run: brew install nss + + - uses: actions/checkout@v2 + + - name: Configure + run: ${{env.configure-env}} EXTRA_CFLAGS=-Werror ./configure ${{ matrix.configure-crypto-enable}} + + - name: Build + run: make + + - name: Test + run: make runtest + + - name: Test Valgrind + if: matrix.os == 'ubuntu-latest' + run: make runtest-valgrind From 392e1001d1ec973e9044a6960cb5e0d6ae1e4771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 16 Aug 2021 14:21:42 +0200 Subject: [PATCH 007/109] trigger coverity scan for pushes into master --- .github/workflows/coverity_scan.yml | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/coverity_scan.yml diff --git a/.github/workflows/coverity_scan.yml b/.github/workflows/coverity_scan.yml new file mode 100644 index 000000000..699c7d2a0 --- /dev/null +++ b/.github/workflows/coverity_scan.yml @@ -0,0 +1,41 @@ +name: Start Coverity Scan +on: + push: + branches: [ master ] + workflow_dispatch: + +jobs: + coverity: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Download Coverity Build Tool + run: | + wget -q https://scan.coverity.com/download/cxx/linux64 --post-data "token=$TOKEN&project=cisco-libSRTP" -O cov-analysis-linux64.tar.gz + mkdir cov-analysis-linux64 + tar xzf cov-analysis-linux64.tar.gz --strip 1 -C cov-analysis-linux64 + env: + TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} + + - name: Configure + run: ./configure + + - name: Build with cov-build + run: | + export PATH=`pwd`/cov-analysis-linux64/bin:$PATH + cov-build --dir cov-int make + + - name: Submit the result to Coverity Scan + run: | + tar czvf libsrtp.tgz cov-int + curl \ + --form project=cisco-libSRTP \ + --form token=$TOKEN \ + --form email=pabuhler@cisco.com \ + --form file=@libsrtp.tgz \ + --form version=2 \ + --form description="libSRTP" \ + https://scan.coverity.com/builds?project=cisco-libSRTP + env: + TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} From 82688d4195011fd64f2bb80c6f62e3a2eacb827c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 16 Aug 2021 15:51:15 +0200 Subject: [PATCH 008/109] Update cmake.yml --- .github/workflows/cmake.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 866be7c98..0dd489544 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -1,6 +1,10 @@ -name: CMake +name: CMake CI -on: [push, pull_request] +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] jobs: build: From 08077b70c8ac65d11f9ec9cc77f19c6629a30e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 16 Aug 2021 15:52:56 +0200 Subject: [PATCH 009/109] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b7072414b..d37be093a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ [![CMake Build](https://github.com/cisco/libsrtp/actions/workflows/cmake.yml/badge.svg)](https://github.com/cisco/libsrtp/actions/workflows/cmake.yml) +[![Autotools Build](https://github.com/cisco/libsrtp/actions/workflows/autotools.yml/badge.svg)](https://github.com/cisco/libsrtp/actions/workflows/autotools.yml) [![Build Status](https://travis-ci.org/cisco/libsrtp.svg?branch=master)](https://travis-ci.org/cisco/libsrtp) [![Coverity Scan Build Status](https://scan.coverity.com/projects/14274/badge.svg)](https://scan.coverity.com/projects/cisco-libsrtp) [![OSS-Fuzz Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/systemd.svg)](https://oss-fuzz-build-logs.storage.googleapis.com/index.html#libsrtp) From 20bb61190fa28d4a28382cbbd7b3d2e1658f87ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Thu, 19 Aug 2021 13:59:37 +0200 Subject: [PATCH 010/109] update format check to use clang-format-10 --- .github/workflows/format_check.yml | 17 +++ .github/workflows/fromat_check.yml | 13 --- crypto/cipher/aes.c | 4 +- crypto/cipher/aes_icm.c | 8 +- crypto/replay/rdbx.c | 14 +-- crypto/test/aes_calc.c | 25 +++-- crypto/test/sha1_driver.c | 159 +++++++++++++++++------------ format.sh | 2 +- srtp/srtp.c | 10 +- test/rtp.h | 4 +- test/rtp_decoder.c | 76 +++++++------- test/rtpw.c | 10 +- test/srtp_driver.c | 35 ++++--- 13 files changed, 212 insertions(+), 165 deletions(-) create mode 100644 .github/workflows/format_check.yml delete mode 100644 .github/workflows/fromat_check.yml diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml new file mode 100644 index 000000000..ce88ba265 --- /dev/null +++ b/.github/workflows/format_check.yml @@ -0,0 +1,17 @@ +name: Code Formatting Check + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + format-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Clang Format + run: sudo apt install clang-format-10 + - name: Run clang format + run: ./format.sh -d diff --git a/.github/workflows/fromat_check.yml b/.github/workflows/fromat_check.yml deleted file mode 100644 index d10a6c17e..000000000 --- a/.github/workflows/fromat_check.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Code Formatting Check - -on: [push, pull_request] - -jobs: - format-check: - runs-on: ubuntu-18.04 - steps: - - uses: actions/checkout@v2 - - name: Install Clang Format - run: sudo apt install clang-format-3.9 - - name: Run clang format - run: CLANG_FORMAT=clang-format-3.9 ./format.sh -d diff --git a/crypto/cipher/aes.c b/crypto/cipher/aes.c index a2060c53e..473fdeb0c 100644 --- a/crypto/cipher/aes.c +++ b/crypto/cipher/aes.c @@ -1818,8 +1818,8 @@ static inline void aes_inv_round(v128_t *state, const v128_t *round_key) { uint32_t column0, column1, column2, column3; -/* compute the columns of the output square in terms of the octets - of state, using the tables U0, U1, U2, U3 */ + /* compute the columns of the output square in terms of the octets + of state, using the tables U0, U1, U2, U3 */ #ifdef WORDS_BIGENDIAN column0 = U0[state->v32[0] >> 24] ^ U1[(state->v32[3] >> 16) & 0xff] ^ diff --git a/crypto/cipher/aes_icm.c b/crypto/cipher/aes_icm.c index e05d9e45a..a5f24c657 100644 --- a/crypto/cipher/aes_icm.c +++ b/crypto/cipher/aes_icm.c @@ -335,10 +335,10 @@ static srtp_err_status_t srtp_aes_icm_encrypt(void *cv, /* fill buffer with new keystream */ srtp_aes_icm_advance(c); -/* - * add keystream into the data buffer (this would be a lot faster - * if we could assume 32-bit alignment!) - */ + /* + * add keystream into the data buffer (this would be a lot faster + * if we could assume 32-bit alignment!) + */ #if ALIGN_32 b = (uint32_t *)buf; diff --git a/crypto/replay/rdbx.c b/crypto/replay/rdbx.c index 40cba01a1..97ff719ac 100644 --- a/crypto/replay/rdbx.c +++ b/crypto/replay/rdbx.c @@ -306,13 +306,13 @@ int32_t srtp_rdbx_estimate_index(const srtp_rdbx_t *rdbx, srtp_xtd_seq_num_t *guess, srtp_sequence_number_t s) { -/* - * if the sequence number and rollover counter in the rdbx are - * non-zero, then use the srtp_index_guess(...) function, otherwise, just - * set the rollover counter to zero (since the srtp_index_guess(...) - * function might incorrectly guess that the rollover counter is - * 0xffffffff) - */ + /* + * if the sequence number and rollover counter in the rdbx are + * non-zero, then use the srtp_index_guess(...) function, otherwise, just + * set the rollover counter to zero (since the srtp_index_guess(...) + * function might incorrectly guess that the rollover counter is + * 0xffffffff) + */ #ifdef NO_64BIT_MATH /* seq_num_median = 0x8000 */ diff --git a/crypto/test/aes_calc.c b/crypto/test/aes_calc.c index 3d0d5cf36..ed76aa4c4 100644 --- a/crypto/test/aes_calc.c +++ b/crypto/test/aes_calc.c @@ -106,16 +106,18 @@ int main(int argc, char *argv[]) /* read in key, checking length */ if (strlen(argv[1]) > AES_MAX_KEY_LEN * 2) { - fprintf(stderr, "error: too many digits in key " - "(should be at most %d hexadecimal digits, found %u)\n", + fprintf(stderr, + "error: too many digits in key " + "(should be at most %d hexadecimal digits, found %u)\n", AES_MAX_KEY_LEN * 2, (unsigned)strlen(argv[1])); exit(1); } len = hex_string_to_octet_string((char *)key, argv[1], AES_MAX_KEY_LEN * 2); /* check that hex string is the right length */ if (len != 32 && len != 48 && len != 64) { - fprintf(stderr, "error: bad number of digits in key " - "(should be 32/48/64 hexadecimal digits, found %d)\n", + fprintf(stderr, + "error: bad number of digits in key " + "(should be 32/48/64 hexadecimal digits, found %d)\n", len); exit(1); } @@ -123,16 +125,18 @@ int main(int argc, char *argv[]) /* read in plaintext, checking length */ if (strlen(argv[2]) > 16 * 2) { - fprintf(stderr, "error: too many digits in plaintext " - "(should be %d hexadecimal digits, found %u)\n", + fprintf(stderr, + "error: too many digits in plaintext " + "(should be %d hexadecimal digits, found %u)\n", 16 * 2, (unsigned)strlen(argv[2])); exit(1); } len = hex_string_to_octet_string((char *)(&data), argv[2], 16 * 2); /* check that hex string is the right length */ if (len < 16 * 2) { - fprintf(stderr, "error: too few digits in plaintext " - "(should be %d hexadecimal digits, found %d)\n", + fprintf(stderr, + "error: too few digits in plaintext " + "(should be %d hexadecimal digits, found %d)\n", 16 * 2, len); exit(1); } @@ -162,8 +166,9 @@ int main(int argc, char *argv[]) printf("%s\n", ciphertext); if (expected_ciphertext && strcmp(ciphertext, expected_ciphertext) != 0) { - fprintf(stderr, "error: calculated ciphertext %s does not match " - "expected ciphertext %s\n", + fprintf(stderr, + "error: calculated ciphertext %s does not match " + "expected ciphertext %s\n", ciphertext, expected_ciphertext); exit(1); } diff --git a/crypto/test/sha1_driver.c b/crypto/test/sha1_driver.c index c64b000f8..160a4b9a9 100644 --- a/crypto/test/sha1_driver.c +++ b/crypto/test/sha1_driver.c @@ -218,100 +218,131 @@ srtp_err_status_t sha1_add_test_cases(void) { 264, "17e81f6ae8c2e5579d69dafa6e070e7111461552d314b691e7a3e7a4feb3fae418", "010def22850deb1168d525e8c84c28116cb8a269" }, - { 272, "d15976b23a1d712ad28fad04d805f572026b54dd64961fda94d5355a0cc9862" - "0cf77", + { 272, + "d15976b23a1d712ad28fad04d805f572026b54dd64961fda94d5355a0cc9862" + "0cf77", "aeaa40ba1717ed5439b1e6ea901b294ba500f9ad" }, - { 280, "09fce4d434f6bd32a44e04b848ff50ec9f642a8a85b37a264dc73f130f22838" - "443328f", + { 280, + "09fce4d434f6bd32a44e04b848ff50ec9f642a8a85b37a264dc73f130f22838" + "443328f", "c6433791238795e34f080a5f1f1723f065463ca0" }, - { 288, "f17af27d776ec82a257d8d46d2b46b639462c56984cc1be9c1222eadb8b2659" - "4a25c709d", + { 288, + "f17af27d776ec82a257d8d46d2b46b639462c56984cc1be9c1222eadb8b2659" + "4a25c709d", "e21e22b89c1bb944a32932e6b2a2f20d491982c3" }, - { 296, "b13ce635d6f8758143ffb114f2f601cb20b6276951416a2f94fbf4ad081779d" - "79f4f195b22", + { 296, + "b13ce635d6f8758143ffb114f2f601cb20b6276951416a2f94fbf4ad081779d" + "79f4f195b22", "575323a9661f5d28387964d2ba6ab92c17d05a8a" }, - { 304, "5498793f60916ff1c918dde572cdea76da8629ba4ead6d065de3dfb48de94d2" - "34cc1c5002910", + { 304, + "5498793f60916ff1c918dde572cdea76da8629ba4ead6d065de3dfb48de94d2" + "34cc1c5002910", "feb44494af72f245bfe68e86c4d7986d57c11db7" }, - { 312, "498a1e0b39fa49582ae688cd715c86fbaf8a81b8b11b4d1594c49c902d197c8" - "ba8a621fd6e3be5", + { 312, + "498a1e0b39fa49582ae688cd715c86fbaf8a81b8b11b4d1594c49c902d197c8" + "ba8a621fd6e3be5", "cff2290b3648ba2831b98dde436a72f9ebf51eee" }, - { 320, "3a36ae71521f9af628b3e34dcb0d4513f84c78ee49f10416a98857150b8b15c" - "b5c83afb4b570376e", + { 320, + "3a36ae71521f9af628b3e34dcb0d4513f84c78ee49f10416a98857150b8b15c" + "b5c83afb4b570376e", "9b4efe9d27b965905b0c3dab67b8d7c9ebacd56c" }, - { 328, "dcc76b40ae0ea3ba253e92ac50fcde791662c5b6c948538cffc2d95e9de99ca" - "c34dfca38910db2678f", + { 328, + "dcc76b40ae0ea3ba253e92ac50fcde791662c5b6c948538cffc2d95e9de99ca" + "c34dfca38910db2678f", "afedb0ff156205bcd831cbdbda43db8b0588c113" }, - { 336, "5b5ec6ec4fd3ad9c4906f65c747fd4233c11a1736b6b228b92e90cddabb0c7c" - "2fcf9716d3fad261dff33", + { 336, + "5b5ec6ec4fd3ad9c4906f65c747fd4233c11a1736b6b228b92e90cddabb0c7c" + "2fcf9716d3fad261dff33", "8deb1e858f88293a5e5e4d521a34b2a4efa70fc4" }, - { 344, "df48a37b29b1d6de4e94717d60cdb4293fcf170bba388bddf7a9035a15d433f" - "20fd697c3e4c8b8c5f590ab", + { 344, + "df48a37b29b1d6de4e94717d60cdb4293fcf170bba388bddf7a9035a15d433f" + "20fd697c3e4c8b8c5f590ab", "95cbdac0f74afa69cebd0e5c7defbc6faf0cbeaf" }, - { 352, "1f179b3b82250a65e1b0aee949e218e2f45c7a8dbfd6ba08de05c55acfc226b" - "48c68d7f7057e5675cd96fcfc", + { 352, + "1f179b3b82250a65e1b0aee949e218e2f45c7a8dbfd6ba08de05c55acfc226b" + "48c68d7f7057e5675cd96fcfc", "f0307bcb92842e5ae0cd4f4f14f3df7f877fbef2" }, - { 360, "ee3d72da3a44d971578972a8e6780ce64941267e0f7d0179b214fa97855e179" - "0e888e09fbe3a70412176cb3b54", + { 360, + "ee3d72da3a44d971578972a8e6780ce64941267e0f7d0179b214fa97855e179" + "0e888e09fbe3a70412176cb3b54", "7b13bb0dbf14964bd63b133ac85e22100542ef55" }, - { 368, "d4d4c7843d312b30f610b3682254c8be96d5f6684503f8fbfbcd15774fc1b08" - "4d3741afb8d24aaa8ab9c104f7258", + { 368, + "d4d4c7843d312b30f610b3682254c8be96d5f6684503f8fbfbcd15774fc1b08" + "4d3741afb8d24aaa8ab9c104f7258", "c314d2b6cf439be678d2a74e890d96cfac1c02ed" }, - { 376, "32c094944f5936a190a0877fb9178a7bf60ceae36fd530671c5b38c5dbd5e6a" - "6c0d615c2ac8ad04b213cc589541cf6", + { 376, + "32c094944f5936a190a0877fb9178a7bf60ceae36fd530671c5b38c5dbd5e6a" + "6c0d615c2ac8ad04b213cc589541cf6", "4d0be361e410b47a9d67d8ce0bb6a8e01c53c078" }, - { 384, "e5d3180c14bf27a5409fa12b104a8fd7e9639609bfde6ee82bbf9648be2546d" - "29688a65e2e3f3da47a45ac14343c9c02", + { 384, + "e5d3180c14bf27a5409fa12b104a8fd7e9639609bfde6ee82bbf9648be2546d" + "29688a65e2e3f3da47a45ac14343c9c02", "e5353431ffae097f675cbf498869f6fbb6e1c9f2" }, - { 392, "e7b6e4b69f724327e41e1188a37f4fe38b1dba19cbf5a7311d6e32f1038e97a" - "b506ee05aebebc1eed09fc0e357109818b9", + { 392, + "e7b6e4b69f724327e41e1188a37f4fe38b1dba19cbf5a7311d6e32f1038e97a" + "b506ee05aebebc1eed09fc0e357109818b9", "b8720a7068a085c018ab18961de2765aa6cd9ac4" }, - { 400, "bc880cb83b8ac68ef2fedc2da95e7677ce2aa18b0e2d8b322701f67af7d5e7a" - "0d96e9e33326ccb7747cfff0852b961bfd475", + { 400, + "bc880cb83b8ac68ef2fedc2da95e7677ce2aa18b0e2d8b322701f67af7d5e7a" + "0d96e9e33326ccb7747cfff0852b961bfd475", "b0732181568543ba85f2b6da602b4b065d9931aa" }, - { 408, "235ea9c2ba7af25400f2e98a47a291b0bccdaad63faa2475721fda5510cc7da" - "d814bce8dabb611790a6abe56030b798b75c944", + { 408, + "235ea9c2ba7af25400f2e98a47a291b0bccdaad63faa2475721fda5510cc7da" + "d814bce8dabb611790a6abe56030b798b75c944", "9c22674cf3222c3ba921672694aafee4ce67b96b" }, - { 416, "07e3e29fed63104b8410f323b975fd9fba53f636af8c4e68a53fb202ca35dd9" - "ee07cb169ec5186292e44c27e5696a967f5e67709", + { 416, + "07e3e29fed63104b8410f323b975fd9fba53f636af8c4e68a53fb202ca35dd9" + "ee07cb169ec5186292e44c27e5696a967f5e67709", "d128335f4cecca9066cdae08958ce656ff0b4cfc" }, - { 424, "65d2a1dd60a517eb27bfbf530cf6a5458f9d5f4730058bd9814379547f34241" - "822bf67e6335a6d8b5ed06abf8841884c636a25733f", + { 424, + "65d2a1dd60a517eb27bfbf530cf6a5458f9d5f4730058bd9814379547f34241" + "822bf67e6335a6d8b5ed06abf8841884c636a25733f", "0b67c57ac578de88a2ae055caeaec8bb9b0085a0" }, - { 432, "dcc86b3bd461615bab739d8daafac231c0f462e819ad29f9f14058f3ab5b759" - "41d4241ea2f17ebb8a458831b37a9b16dead4a76a9b0e", + { 432, + "dcc86b3bd461615bab739d8daafac231c0f462e819ad29f9f14058f3ab5b759" + "41d4241ea2f17ebb8a458831b37a9b16dead4a76a9b0e", "c766f912a89d4ccda88e0cce6a713ef5f178b596" }, - { 440, "4627d54f0568dc126b62a8c35fb46a9ac5024400f2995e51635636e1afc4373" - "dbb848eb32df23914230560b82477e9c3572647a7f2bb92", + { 440, + "4627d54f0568dc126b62a8c35fb46a9ac5024400f2995e51635636e1afc4373" + "dbb848eb32df23914230560b82477e9c3572647a7f2bb92", "9aa3925a9dcb177b15ccff9b78e70cf344858779" }, - { 448, "ba531affd4381168ef24d8b275a84d9254c7f5cc55fded53aa8024b2c5c5c8a" - "a7146fe1d1b83d62b70467e9a2e2cb67b3361830adbab28d7", + { 448, + "ba531affd4381168ef24d8b275a84d9254c7f5cc55fded53aa8024b2c5c5c8a" + "a7146fe1d1b83d62b70467e9a2e2cb67b3361830adbab28d7", "4811fa30042fc076acf37c8e2274d025307e5943" }, - { 456, "8764dcbcf89dcf4282eb644e3d568bdccb4b13508bfa7bfe0ffc05efd1390be" - "22109969262992d377691eb4f77f3d59ea8466a74abf57b2ef4", + { 456, + "8764dcbcf89dcf4282eb644e3d568bdccb4b13508bfa7bfe0ffc05efd1390be" + "22109969262992d377691eb4f77f3d59ea8466a74abf57b2ef4", "6743018450c9730761ee2b130df9b91c1e118150" }, - { 464, "497d9df9ddb554f3d17870b1a31986c1be277bc44feff713544217a9f579623" - "d18b5ffae306c25a45521d2759a72c0459b58957255ab592f3be4", + { 464, + "497d9df9ddb554f3d17870b1a31986c1be277bc44feff713544217a9f579623" + "d18b5ffae306c25a45521d2759a72c0459b58957255ab592f3be4", "71ad4a19d37d92a5e6ef3694ddbeb5aa61ada645" }, - { 472, "72c3c2e065aefa8d9f7a65229e818176eef05da83f835107ba90ec2e95472e7" - "3e538f783b416c04654ba8909f26a12db6e5c4e376b7615e4a25819", + { 472, + "72c3c2e065aefa8d9f7a65229e818176eef05da83f835107ba90ec2e95472e7" + "3e538f783b416c04654ba8909f26a12db6e5c4e376b7615e4a25819", "a7d9dc68dacefb7d6116186048cb355cc548e11d" }, - { 480, "7cc9894454d0055ab5069a33984e2f712bef7e3124960d33559f5f3b81906bb" - "66fe64da13c153ca7f5cabc89667314c32c01036d12ecaf5f9a78de98", + { 480, + "7cc9894454d0055ab5069a33984e2f712bef7e3124960d33559f5f3b81906bb" + "66fe64da13c153ca7f5cabc89667314c32c01036d12ecaf5f9a78de98", "142e429f0522ba5abf5131fa81df82d355b96909" }, - { 488, "74e8404d5a453c5f4d306f2cfa338ca65501c840ddab3fb82117933483afd69" - "13c56aaf8a0a0a6b2a342fc3d9dc7599f4a850dfa15d06c61966d74ea59", + { 488, + "74e8404d5a453c5f4d306f2cfa338ca65501c840ddab3fb82117933483afd69" + "13c56aaf8a0a0a6b2a342fc3d9dc7599f4a850dfa15d06c61966d74ea59", "ef72db70dcbcab991e9637976c6faf00d22caae9" }, - { 496, "46fe5ed326c8fe376fcc92dc9e2714e2240d3253b105adfbb256ff7a19bc409" - "75c604ad7c0071c4fd78a7cb64786e1bece548fa4833c04065fe593f6fb10", + { 496, + "46fe5ed326c8fe376fcc92dc9e2714e2240d3253b105adfbb256ff7a19bc409" + "75c604ad7c0071c4fd78a7cb64786e1bece548fa4833c04065fe593f6fb10", "f220a7457f4588d639dc21407c942e9843f8e26b" }, - { 504, "836dfa2524d621cf07c3d2908835de859e549d35030433c796b81272fd8bc03" - "48e8ddbc7705a5ad1fdf2155b6bc48884ac0cd376925f069a37849c089c864" - "5", + { 504, + "836dfa2524d621cf07c3d2908835de859e549d35030433c796b81272fd8bc03" + "48e8ddbc7705a5ad1fdf2155b6bc48884ac0cd376925f069a37849c089c864" + "5", "ddd2117b6e309c233ede85f962a0c2fc215e5c69" }, - { 512, "7e3a4c325cb9c52b88387f93d01ae86d42098f5efa7f9457388b5e74b6d28b2" - "438d42d8b64703324d4aa25ab6aad153ae30cd2b2af4d5e5c00a8a2d0220c61" - "16", + { 512, + "7e3a4c325cb9c52b88387f93d01ae86d42098f5efa7f9457388b5e74b6d28b2" + "438d42d8b64703324d4aa25ab6aad153ae30cd2b2af4d5e5c00a8a2d0220c61" + "16", "a3054427cdb13f164a610b348702724c808a0dcc" } }; diff --git a/format.sh b/format.sh index fdf23ef3c..56b2d0ee0 100755 --- a/format.sh +++ b/format.sh @@ -7,7 +7,7 @@ # assumes git tree is clean when reporting status if [ -z "${CLANG_FORMAT}" ]; then - CLANG_FORMAT=clang-format + CLANG_FORMAT=clang-format-10 fi a=`git ls-files '*.h' '*.c'` diff --git a/srtp/srtp.c b/srtp/srtp.c index 5c7250eb5..ff9ac44f0 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -173,8 +173,8 @@ srtp_err_status_t srtp_stream_dealloc(srtp_stream_ctx_t *stream, } /* - * deallocate cipher, if it is not the same as that in template - */ + * deallocate cipher, if it is not the same as that in template + */ if (template_session_keys && session_keys->rtp_cipher == template_session_keys->rtp_cipher) { /* do nothing */ @@ -879,7 +879,7 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, /* If RTP or RTCP have a key length > AES-128, assume matching kdf. */ /* TODO: kdf algorithm, master key length, and master salt length should * be part of srtp_policy_t. - */ + */ session_keys = &srtp->session_keys[current_mki_index]; /* initialize key limit to maximum value */ @@ -1293,8 +1293,8 @@ srtp_err_status_t srtp_stream_init(srtp_stream_ctx_t *srtp, void srtp_event_reporter(srtp_event_data_t *data) { - srtp_err_report(srtp_err_level_warning, "srtp: in stream 0x%x: ", - data->ssrc); + srtp_err_report(srtp_err_level_warning, + "srtp: in stream 0x%x: ", data->ssrc); switch (data->event) { case event_ssrc_collision: diff --git a/test/rtp.h b/test/rtp.h index 37921a665..50df88bf1 100644 --- a/test/rtp.h +++ b/test/rtp.h @@ -123,14 +123,14 @@ int srtp_sender_init( struct sockaddr_in name, /* socket name */ srtp_sec_serv_t security_services, /* sec. servs. to be used */ unsigned char *input_key /* master key/salt in hex */ - ); +); int srtp_receiver_init( rtp_receiver_t rtp_ctx, /* structure to be init'ed */ struct sockaddr_in name, /* socket name */ srtp_sec_serv_t security_services, /* sec. servs. to be used */ unsigned char *input_key /* master key/salt in hex */ - ); +); int rtp_sender_init_srtp(rtp_sender_t sender, const srtp_policy_t *policy); diff --git a/test/rtp_decoder.c b/test/rtp_decoder.c index 137e7e6b3..d424b4b10 100644 --- a/test/rtp_decoder.c +++ b/test/rtp_decoder.c @@ -96,39 +96,39 @@ static struct srtp_crypto_suite srtp_crypto_suites[] = { #if 0 {.can_name = "F8_128_HMAC_SHA1_32", .gcm_on = 0, .key_size = 128, .tag_size = 4}, #endif - {.can_name = "AES_CM_128_HMAC_SHA1_32", - .gcm_on = 0, - .key_size = 128, - .tag_size = 4 }, - {.can_name = "AES_CM_128_HMAC_SHA1_80", - .gcm_on = 0, - .key_size = 128, - .tag_size = 10 }, - {.can_name = "AES_192_CM_HMAC_SHA1_32", - .gcm_on = 0, - .key_size = 192, - .tag_size = 4 }, - {.can_name = "AES_192_CM_HMAC_SHA1_80", - .gcm_on = 0, - .key_size = 192, - .tag_size = 10 }, - {.can_name = "AES_256_CM_HMAC_SHA1_32", - .gcm_on = 0, - .key_size = 256, - .tag_size = 4 }, - {.can_name = "AES_256_CM_HMAC_SHA1_80", - .gcm_on = 0, - .key_size = 256, - .tag_size = 10 }, - {.can_name = "AEAD_AES_128_GCM", - .gcm_on = 1, - .key_size = 128, - .tag_size = 16 }, - {.can_name = "AEAD_AES_256_GCM", - .gcm_on = 1, - .key_size = 256, - .tag_size = 16 }, - {.can_name = NULL } + { .can_name = "AES_CM_128_HMAC_SHA1_32", + .gcm_on = 0, + .key_size = 128, + .tag_size = 4 }, + { .can_name = "AES_CM_128_HMAC_SHA1_80", + .gcm_on = 0, + .key_size = 128, + .tag_size = 10 }, + { .can_name = "AES_192_CM_HMAC_SHA1_32", + .gcm_on = 0, + .key_size = 192, + .tag_size = 4 }, + { .can_name = "AES_192_CM_HMAC_SHA1_80", + .gcm_on = 0, + .key_size = 192, + .tag_size = 10 }, + { .can_name = "AES_256_CM_HMAC_SHA1_32", + .gcm_on = 0, + .key_size = 256, + .tag_size = 4 }, + { .can_name = "AES_256_CM_HMAC_SHA1_80", + .gcm_on = 0, + .key_size = 256, + .tag_size = 10 }, + { .can_name = "AEAD_AES_128_GCM", + .gcm_on = 1, + .key_size = 128, + .tag_size = 16 }, + { .can_name = "AEAD_AES_256_GCM", + .gcm_on = 1, + .key_size = 256, + .tag_size = 16 }, + { .can_name = NULL } }; void rtp_decoder_srtp_log_handler(srtp_log_level_t level, @@ -540,14 +540,16 @@ int main(int argc, char *argv[]) } /* check that hex string is the right length */ if (len < expected_len) { - fprintf(stderr, "error: too few digits in key/salt " - "(should be %d digits, found %d)\n", + fprintf(stderr, + "error: too few digits in key/salt " + "(should be %d digits, found %d)\n", expected_len, len); exit(1); } if (strlen(input_key) > policy.rtp.cipher_key_len * 2) { - fprintf(stderr, "error: too many digits in key/salt " - "(should be %d hexadecimal digits, found %u)\n", + fprintf(stderr, + "error: too many digits in key/salt " + "(should be %d hexadecimal digits, found %u)\n", policy.rtp.cipher_key_len * 2, (unsigned)strlen(input_key)); exit(1); } diff --git a/test/rtpw.c b/test/rtpw.c index ad8444829..93b43d670 100644 --- a/test/rtpw.c +++ b/test/rtpw.c @@ -473,14 +473,16 @@ int main(int argc, char *argv[]) } /* check that hex string is the right length */ if (len < expected_len) { - fprintf(stderr, "error: too few digits in key/salt " - "(should be %d digits, found %d)\n", + fprintf(stderr, + "error: too few digits in key/salt " + "(should be %d digits, found %d)\n", expected_len, len); exit(1); } if ((int)strlen(input_key) > policy.rtp.cipher_key_len * 2) { - fprintf(stderr, "error: too many digits in key/salt " - "(should be %d hexadecimal digits, found %u)\n", + fprintf(stderr, + "error: too many digits in key/salt " + "(should be %d hexadecimal digits, found %u)\n", policy.rtp.cipher_key_len * 2, (unsigned)strlen(input_key)); exit(1); } diff --git a/test/srtp_driver.c b/test/srtp_driver.c index 4355022b6..87835753a 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -1097,8 +1097,9 @@ srtp_err_status_t srtp_test(const srtp_policy_t *policy, pkt_end = (uint8_t *)hdr + msg_len + tag_length; for (i = 0; i < 4; i++) { if (pkt_end[i] != 0xff) { - fprintf(stdout, "overwrite in srtp_protect() function " - "(expected %x, found %x in trailing octet %d)\n", + fprintf(stdout, + "overwrite in srtp_protect() function " + "(expected %x, found %x in trailing octet %d)\n", 0xff, ((uint8_t *)hdr)[i], i); free(hdr); free(hdr2); @@ -1312,8 +1313,9 @@ srtp_err_status_t srtcp_test(const srtp_policy_t *policy, int mki_index) pkt_end = (uint8_t *)hdr + msg_len + tag_length; for (i = 0; i < 4; i++) { if (pkt_end[i] != 0xff) { - fprintf(stdout, "overwrite in srtp_protect_rtcp() function " - "(expected %x, found %x in trailing octet %d)\n", + fprintf(stdout, + "overwrite in srtp_protect_rtcp() function " + "(expected %x, found %x in trailing octet %d)\n", 0xff, ((uint8_t *)hdr)[i], i); free(hdr); free(hdr2); @@ -1583,18 +1585,19 @@ char *srtp_packet_to_string(srtp_hdr_t *hdr, int pkt_octet_len) } /* write packet into string */ - sprintf(packet_string, "(s)rtp packet: {\n" - " version:\t%d\n" - " p:\t\t%d\n" - " x:\t\t%d\n" - " cc:\t\t%d\n" - " m:\t\t%d\n" - " pt:\t\t%x\n" - " seq:\t\t%x\n" - " ts:\t\t%x\n" - " ssrc:\t%x\n" - " data:\t%s\n" - "} (%d octets in total)\n", + sprintf(packet_string, + "(s)rtp packet: {\n" + " version:\t%d\n" + " p:\t\t%d\n" + " x:\t\t%d\n" + " cc:\t\t%d\n" + " m:\t\t%d\n" + " pt:\t\t%x\n" + " seq:\t\t%x\n" + " ts:\t\t%x\n" + " ssrc:\t%x\n" + " data:\t%s\n" + "} (%d octets in total)\n", hdr->version, hdr->p, hdr->x, hdr->cc, hdr->m, hdr->pt, hdr->seq, hdr->ts, hdr->ssrc, octet_string_hex_string(data, hex_len), pkt_octet_len); From 4bf8c515b5cc40a58108b911c097ee17ff7406f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Tue, 31 Aug 2021 22:25:01 +0200 Subject: [PATCH 011/109] add set ROC then rollover test that fails for gcm only --- test/srtp_driver.c | 201 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 195 insertions(+), 6 deletions(-) diff --git a/test/srtp_driver.c b/test/srtp_driver.c index 87835753a..94f79951f 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -95,6 +95,8 @@ srtp_err_status_t srtp_test_get_roc(void); srtp_err_status_t srtp_test_set_receiver_roc(void); +srtp_err_status_t srtp_test_set_receiver_roc_then_rollover(void); + srtp_err_status_t srtp_test_set_sender_roc(void); double srtp_bits_per_second(int msg_len_octets, const srtp_policy_t *policy); @@ -126,6 +128,7 @@ extern uint8_t test_key[46]; extern uint8_t test_key_2[46]; extern uint8_t test_mki_id[TEST_MKI_ID_SIZE]; extern uint8_t test_mki_id_2[TEST_MKI_ID_SIZE]; +extern uint8_t test_key_gcm[28]; // clang-format off srtp_master_key_t master_key_1 = { @@ -564,6 +567,14 @@ int main(int argc, char *argv[]) exit(1); } + printf("testing srtp_test_set_receiver_roc_then_rollover()..."); + if (srtp_test_set_receiver_roc_then_rollover() == srtp_err_status_ok) { + printf("passed\n"); + } else { + printf("failed\n"); + exit(1); + } + printf("testing srtp_test_set_sender_roc()..."); if (srtp_test_set_sender_roc() == srtp_err_status_ok) { printf("passed\n"); @@ -1803,12 +1814,6 @@ srtp_err_status_t srtp_validate() srtp_err_status_t srtp_validate_gcm() { // clang-format off - unsigned char test_key_gcm[28] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, - 0xa8, 0xa9, 0xaa, 0xab - }; uint8_t rtp_plaintext_ref[28] = { 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad, 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab, @@ -3364,6 +3369,183 @@ srtp_err_status_t srtp_test_set_receiver_roc() return srtp_err_status_ok; } +srtp_err_status_t srtp_test_set_receiver_roc_then_rollover() +{ + srtp_err_status_t status; + + srtp_policy_t sender_policy; + srtp_t sender_session; + + srtp_policy_t receiver_policy; + srtp_t receiver_session; + + srtp_hdr_t *pkt_1; + unsigned char *recv_pkt_1; + + srtp_hdr_t *pkt_2; + unsigned char *recv_pkt_2; + + uint32_t i; + uint32_t ts; + uint16_t seq; + uint32_t sender_roc; + + int msg_len_octets = 32; + int protected_msg_len_octets_1; + int protected_msg_len_octets_2; + + /* Create sender */ + memset(&sender_policy, 0, sizeof(sender_policy)); +#ifdef GCM + srtp_crypto_policy_set_aes_gcm_128_16_auth(&sender_policy.rtp); + srtp_crypto_policy_set_aes_gcm_128_16_auth(&sender_policy.rtcp); + sender_policy.key = test_key_gcm; +#else + srtp_crypto_policy_set_rtp_default(&sender_policy.rtp); + srtp_crypto_policy_set_rtcp_default(&sender_policy.rtcp); + sender_policy.key = test_key; +#endif + sender_policy.ssrc.type = ssrc_specific; + sender_policy.ssrc.value = 0xcafebabe; + sender_policy.window_size = 128; + + status = srtp_create(&sender_session, &sender_policy); + if (status) { + return status; + } + + /* Create and protect packets to get to seq 65536 and roc == 1 */ + seq = 65535; + ts = 0; + for (i = 0; i < 65535; i++) { + srtp_hdr_t *tmp_pkt; + int tmp_len; + + tmp_pkt = srtp_create_test_packet_extended( + msg_len_octets, sender_policy.ssrc.value, seq, ts, &tmp_len); + status = srtp_protect(sender_session, tmp_pkt, &tmp_len); + free(tmp_pkt); + if (status) { + return status; + } + + seq++; + ts++; + } + + status = srtp_get_stream_roc(sender_session, sender_policy.ssrc.value, + &sender_roc); + if (status) { + return status; + } + + if (sender_roc != 1) { + return srtp_err_status_fail; + } + + /* Create the first packet to decrypt and test for ROC change */ + pkt_1 = srtp_create_test_packet_extended(msg_len_octets, + sender_policy.ssrc.value, 65535, + ts, &protected_msg_len_octets_1); + status = srtp_protect(sender_session, pkt_1, &protected_msg_len_octets_1); + if (status) { + return status; + } + + /* Create the second packet to decrypt and test for ROC change */ + ts++; + pkt_2 = srtp_create_test_packet_extended(msg_len_octets, + sender_policy.ssrc.value, 0, ts, + &protected_msg_len_octets_2); + status = srtp_protect(sender_session, pkt_2, &protected_msg_len_octets_2); + if (status) { + return status; + } + + status = srtp_get_stream_roc(sender_session, sender_policy.ssrc.value, + &sender_roc); + if (status) { + return status; + } + + if (sender_roc != 2) { + return srtp_err_status_fail; + } + + /* Create the receiver */ + memset(&receiver_policy, 0, sizeof(receiver_policy)); +#ifdef GCM + srtp_crypto_policy_set_aes_gcm_128_16_auth(&receiver_policy.rtp); + srtp_crypto_policy_set_aes_gcm_128_16_auth(&receiver_policy.rtcp); + receiver_policy.key = test_key_gcm; +#else + srtp_crypto_policy_set_rtp_default(&receiver_policy.rtp); + srtp_crypto_policy_set_rtcp_default(&receiver_policy.rtcp); + receiver_policy.key = test_key; +#endif + receiver_policy.ssrc.type = ssrc_specific; + receiver_policy.ssrc.value = sender_policy.ssrc.value; + receiver_policy.window_size = 128; + + status = srtp_create(&receiver_session, &receiver_policy); + if (status) { + return status; + } + + /* Make a copy of the first sent protected packet */ + recv_pkt_1 = malloc(protected_msg_len_octets_1); + if (recv_pkt_1 == NULL) { + return srtp_err_status_fail; + } + memcpy(recv_pkt_1, pkt_1, protected_msg_len_octets_1); + + /* Make a copy of the second sent protected packet */ + recv_pkt_2 = malloc(protected_msg_len_octets_2); + if (recv_pkt_2 == NULL) { + return srtp_err_status_fail; + } + memcpy(recv_pkt_2, pkt_2, protected_msg_len_octets_2); + + /* Set the ROC to the wanted value */ + status = + srtp_set_stream_roc(receiver_session, receiver_policy.ssrc.value, 1); + if (status) { + return status; + } + + /* Unprotect the first packet */ + status = srtp_unprotect(receiver_session, recv_pkt_1, + &protected_msg_len_octets_1); + if (status) { + return status; + } + + /* Unprotect the second packet */ + status = srtp_unprotect(receiver_session, recv_pkt_2, + &protected_msg_len_octets_2); + if (status) { + return status; + } + + /* Cleanup */ + status = srtp_dealloc(sender_session); + if (status) { + return status; + } + + status = srtp_dealloc(receiver_session); + if (status) { + return status; + } + + free(pkt_1); + free(recv_pkt_1); + free(pkt_2); + free(recv_pkt_2); + + return srtp_err_status_ok; +} + srtp_err_status_t srtp_test_set_sender_roc() { uint32_t roc; @@ -3427,6 +3609,13 @@ unsigned char test_key_2[46] = { 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6 }; +unsigned char test_key_gcm[28] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab +}; + unsigned char test_mki_id[TEST_MKI_ID_SIZE] = { 0xe1, 0xf9, 0x7a, 0x0d }; From 403cbc63aad5f239b546d90efd56fe4d0f98cde5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Tue, 31 Aug 2021 23:34:10 +0200 Subject: [PATCH 012/109] reset pending_roc when advancing packet index when using gcm This code now has the same behavior as none gcm ciphers. --- srtp/srtp.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index ff9ac44f0..3f8716920 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -1845,7 +1845,8 @@ static srtp_err_status_t srtp_unprotect_aead(srtp_ctx_t *ctx, void *srtp_hdr, unsigned int *pkt_octet_len, srtp_session_keys_t *session_keys, - unsigned int mki_size) + unsigned int mki_size, + int advance_packet_index) { srtp_hdr_t *hdr = (srtp_hdr_t *)srtp_hdr; uint32_t *enc_start; /* pointer to start of encrypted portion */ @@ -2016,7 +2017,15 @@ static srtp_err_status_t srtp_unprotect_aead(srtp_ctx_t *ctx, * the message authentication function passed, so add the packet * index into the replay database */ - srtp_rdbx_add_index(&stream->rtp_rdbx, delta); + if (advance_packet_index) { + uint32_t roc_to_set = (uint32_t)(est >> 16); + uint16_t seq_to_set = (uint16_t)(est & 0xFFFF); + srtp_rdbx_set_roc_seq(&stream->rtp_rdbx, roc_to_set, seq_to_set); + stream->pending_roc = 0; + srtp_rdbx_add_index(&stream->rtp_rdbx, 0); + } else { + srtp_rdbx_add_index(&stream->rtp_rdbx, delta); + } /* decrease the packet length by the length of the auth tag */ *pkt_octet_len -= tag_len; @@ -2479,7 +2488,7 @@ srtp_err_status_t srtp_unprotect_mki(srtp_ctx_t *ctx, session_keys->rtp_cipher->algorithm == SRTP_AES_GCM_256) { return srtp_unprotect_aead(ctx, stream, delta, est, srtp_hdr, (unsigned int *)pkt_octet_len, session_keys, - mki_size); + mki_size, advance_packet_index); } /* get tag length from stream */ From c184423b5e32e29dfa301ec7c876023b1ea64a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Tue, 31 Aug 2021 23:40:14 +0200 Subject: [PATCH 013/109] run set roc test with gcm if available This will exercise both gcm and non gcm code paths in ci. --- test/srtp_driver.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/test/srtp_driver.c b/test/srtp_driver.c index 94f79951f..b214d9ac0 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -3091,11 +3091,17 @@ static srtp_err_status_t test_set_receiver_roc(uint32_t packets, /* Create sender */ memset(&sender_policy, 0, sizeof(sender_policy)); +#ifdef GCM + srtp_crypto_policy_set_aes_gcm_128_16_auth(&sender_policy.rtp); + srtp_crypto_policy_set_aes_gcm_128_16_auth(&sender_policy.rtcp); + sender_policy.key = test_key_gcm; +#else srtp_crypto_policy_set_rtp_default(&sender_policy.rtp); srtp_crypto_policy_set_rtcp_default(&sender_policy.rtcp); + sender_policy.key = test_key; +#endif sender_policy.ssrc.type = ssrc_specific; sender_policy.ssrc.value = 0xcafebabe; - sender_policy.key = test_key; sender_policy.window_size = 128; status = srtp_create(&sender_session, &sender_policy); @@ -3144,11 +3150,17 @@ static srtp_err_status_t test_set_receiver_roc(uint32_t packets, /* Create the receiver */ memset(&receiver_policy, 0, sizeof(receiver_policy)); +#ifdef GCM + srtp_crypto_policy_set_aes_gcm_128_16_auth(&receiver_policy.rtp); + srtp_crypto_policy_set_aes_gcm_128_16_auth(&receiver_policy.rtcp); + receiver_policy.key = test_key_gcm; +#else srtp_crypto_policy_set_rtp_default(&receiver_policy.rtp); srtp_crypto_policy_set_rtcp_default(&receiver_policy.rtcp); + receiver_policy.key = test_key; +#endif receiver_policy.ssrc.type = ssrc_specific; receiver_policy.ssrc.value = sender_policy.ssrc.value; - receiver_policy.key = test_key; receiver_policy.window_size = 128; status = srtp_create(&receiver_session, &receiver_policy); @@ -3230,11 +3242,17 @@ static srtp_err_status_t test_set_sender_roc(uint16_t seq, uint32_t roc_to_set) /* Create sender */ memset(&sender_policy, 0, sizeof(sender_policy)); +#ifdef GCM + srtp_crypto_policy_set_aes_gcm_128_16_auth(&sender_policy.rtp); + srtp_crypto_policy_set_aes_gcm_128_16_auth(&sender_policy.rtcp); + sender_policy.key = test_key_gcm; +#else srtp_crypto_policy_set_rtp_default(&sender_policy.rtp); srtp_crypto_policy_set_rtcp_default(&sender_policy.rtcp); + sender_policy.key = test_key; +#endif sender_policy.ssrc.type = ssrc_specific; sender_policy.ssrc.value = 0xcafebabe; - sender_policy.key = test_key; sender_policy.window_size = 128; status = srtp_create(&sender_session, &sender_policy); @@ -3261,11 +3279,17 @@ static srtp_err_status_t test_set_sender_roc(uint16_t seq, uint32_t roc_to_set) /* Create the receiver */ memset(&receiver_policy, 0, sizeof(receiver_policy)); +#ifdef GCM + srtp_crypto_policy_set_aes_gcm_128_16_auth(&receiver_policy.rtp); + srtp_crypto_policy_set_aes_gcm_128_16_auth(&receiver_policy.rtcp); + receiver_policy.key = test_key_gcm; +#else srtp_crypto_policy_set_rtp_default(&receiver_policy.rtp); srtp_crypto_policy_set_rtcp_default(&receiver_policy.rtcp); + receiver_policy.key = test_key; +#endif receiver_policy.ssrc.type = ssrc_specific; receiver_policy.ssrc.value = sender_policy.ssrc.value; - receiver_policy.key = test_key; receiver_policy.window_size = 128; status = srtp_create(&receiver_session, &receiver_policy); From 54d1d7a6daa8fae35460cddf71ef69bed3b21e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Tue, 31 Aug 2021 23:51:16 +0200 Subject: [PATCH 014/109] reset pending_roc when advancing packet index and protecting using gcm This code now has the same behavior as none gcm ciphers. --- srtp/srtp.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index 3f8716920..ff8e6df2a 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -1740,13 +1740,23 @@ static srtp_err_status_t srtp_protect_aead(srtp_ctx_t *ctx, * estimate the packet index using the start of the replay window * and the sequence number from the header */ - delta = srtp_rdbx_estimate_index(&stream->rtp_rdbx, &est, ntohs(hdr->seq)); - status = srtp_rdbx_check(&stream->rtp_rdbx, delta); - if (status) { - if (status != srtp_err_status_replay_fail || !stream->allow_repeat_tx) { - return status; /* we've been asked to reuse an index */ - } + status = srtp_get_est_pkt_index(hdr, stream, &est, &delta); + + if (status && (status != srtp_err_status_pkt_idx_adv)) + return status; + + if (status == srtp_err_status_pkt_idx_adv) { + srtp_rdbx_set_roc_seq(&stream->rtp_rdbx, (uint32_t)(est >> 16), + (uint16_t)(est & 0xFFFF)); + stream->pending_roc = 0; + srtp_rdbx_add_index(&stream->rtp_rdbx, 0); } else { + status = srtp_rdbx_check(&stream->rtp_rdbx, delta); + if (status) { + if (status != srtp_err_status_replay_fail || + !stream->allow_repeat_tx) + return status; /* we've been asked to reuse an index */ + } srtp_rdbx_add_index(&stream->rtp_rdbx, delta); } @@ -2064,7 +2074,6 @@ srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx, unsigned int mki_size = 0; srtp_session_keys_t *session_keys = NULL; uint8_t *mki_location = NULL; - int advance_packet_index = 0; debug_print0(mod_srtp, "function srtp_protect"); @@ -2215,10 +2224,7 @@ srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx, if (status && (status != srtp_err_status_pkt_idx_adv)) return status; - if (status == srtp_err_status_pkt_idx_adv) - advance_packet_index = 1; - - if (advance_packet_index) { + if (status == srtp_err_status_pkt_idx_adv) { srtp_rdbx_set_roc_seq(&stream->rtp_rdbx, (uint32_t)(est >> 16), (uint16_t)(est & 0xFFFF)); stream->pending_roc = 0; From 89a5f706305649aac2942f602e9e45ea9bca5da0 Mon Sep 17 00:00:00 2001 From: "Richard L. Barnes" Date: Wed, 8 Sep 2021 11:36:03 -0400 Subject: [PATCH 015/109] Use a full-length key even with null ciphers --- srtp/srtp.c | 2 +- test/srtp_driver.c | 171 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 1 deletion(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index ff8e6df2a..8cbe4f73d 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -932,7 +932,7 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, * the legacy CTR mode KDF, which uses a 112 bit master SALT. */ memset(tmp_key, 0x0, MAX_SRTP_KEY_LEN); - memcpy(tmp_key, key, (rtp_base_key_len + rtp_salt_len)); + memcpy(tmp_key, key, kdf_keylen); /* initialize KDF state */ #if defined(OPENSSL) && defined(OPENSSL_KDF) diff --git a/test/srtp_driver.c b/test/srtp_driver.c index b214d9ac0..db6d3f48e 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -61,6 +61,8 @@ srtp_err_status_t srtp_validate(void); +srtp_err_status_t srtp_validate_null(void); + #ifdef GCM srtp_err_status_t srtp_validate_gcm(void); #endif @@ -442,6 +444,15 @@ int main(int argc, char *argv[]) exit(1); } + printf("testing srtp_protect and srtp_unprotect against " + "reference packet using null cipher and HMAC\n"); + if (srtp_validate_null() == srtp_err_status_ok) { + printf("passed\n\n"); + } else { + printf("failed\n"); + exit(1); + } + #ifdef GCM printf("testing srtp_protect and srtp_unprotect against " "reference packet using GCM\n"); @@ -1806,6 +1817,166 @@ srtp_err_status_t srtp_validate() return srtp_err_status_ok; } +/* + * srtp_validate_null() verifies the correctness of libsrtp by comparing + * some computed packets against some pre-computed reference values. + * These packets were made with a policy that applies null encryption + * and HMAC authentication. + */ + +srtp_err_status_t srtp_validate_null() +{ + // clang-format off + uint8_t srtp_plaintext_ref[28] = { + 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad, + 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab, + 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, + 0xab, 0xab, 0xab, 0xab + }; + uint8_t srtp_plaintext[38] = { + 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad, + 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab, + 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, + 0xab, 0xab, 0xab, 0xab, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + uint8_t srtp_ciphertext[38] = { + 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad, + 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab, + 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, + 0xab, 0xab, 0xab, 0xab, 0xab, 0xa1, 0x36, 0x27, + 0x0b, 0x67, 0x91, 0x34, 0xce, 0x9b + }; + uint8_t rtcp_plaintext_ref[24] = { + 0x81, 0xc8, 0x00, 0x0b, 0xca, 0xfe, 0xba, 0xbe, + 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, + 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, + }; + uint8_t rtcp_plaintext[38] = { + 0x81, 0xc8, 0x00, 0x0b, 0xca, 0xfe, 0xba, 0xbe, + 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, + 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + uint8_t srtcp_ciphertext[38] = { + 0x81, 0xc8, 0x00, 0x0b, 0xca, 0xfe, 0xba, 0xbe, + 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, + 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, + 0x00, 0x00, 0x00, 0x01, 0xfe, 0x88, 0xc7, 0xfd, + 0xfd, 0x37, 0xeb, 0xce, 0x61, 0x5d, + }; + // clang-format on + + srtp_t srtp_snd, srtp_recv; + srtp_err_status_t status; + int len; + srtp_policy_t policy; + + /* + * create a session with a single stream using the default srtp + * policy and with the SSRC value 0xcafebabe + */ + memset(&policy, 0, sizeof(policy)); + srtp_crypto_policy_set_null_cipher_hmac_sha1_80(&policy.rtp); + srtp_crypto_policy_set_null_cipher_hmac_sha1_80(&policy.rtcp); + policy.ssrc.type = ssrc_specific; + policy.ssrc.value = 0xcafebabe; + policy.key = test_key; + policy.deprecated_ekt = NULL; + policy.window_size = 128; + policy.allow_repeat_tx = 0; + policy.next = NULL; + + status = srtp_create(&srtp_snd, &policy); + if (status) { + return status; + } + + /* + * protect plaintext, then compare with ciphertext + */ + len = 28; + status = srtp_protect(srtp_snd, srtp_plaintext, &len); + if (status || (len != 38)) { + return srtp_err_status_fail; + } + + debug_print(mod_driver, "ciphertext:\n %s", + octet_string_hex_string(srtp_plaintext, len)); + debug_print(mod_driver, "ciphertext reference:\n %s", + octet_string_hex_string(srtp_ciphertext, len)); + + if (srtp_octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) { + return srtp_err_status_fail; + } + + /* + * protect plaintext rtcp, then compare with srtcp ciphertext + */ + len = 24; + status = srtp_protect_rtcp(srtp_snd, rtcp_plaintext, &len); + if (status || (len != 38)) { + return srtp_err_status_fail; + } + + debug_print(mod_driver, "srtcp ciphertext:\n %s", + octet_string_hex_string(rtcp_plaintext, len)); + debug_print(mod_driver, "srtcp ciphertext reference:\n %s", + octet_string_hex_string(srtcp_ciphertext, len)); + + if (srtp_octet_string_is_eq(rtcp_plaintext, srtcp_ciphertext, len)) { + return srtp_err_status_fail; + } + + /* + * create a receiver session context comparable to the one created + * above - we need to do this so that the replay checking doesn't + * complain + */ + status = srtp_create(&srtp_recv, &policy); + if (status) { + return status; + } + + /* + * unprotect ciphertext, then compare with plaintext + */ + status = srtp_unprotect(srtp_recv, srtp_ciphertext, &len); + if (status || (len != 28)) { + return status; + } + + if (srtp_octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len)) { + return srtp_err_status_fail; + } + + /* + * unprotect srtcp ciphertext, then compare with rtcp plaintext + */ + len = 38; + status = srtp_unprotect_rtcp(srtp_recv, srtcp_ciphertext, &len); + if (status || (len != 24)) { + return status; + } + + if (srtp_octet_string_is_eq(srtcp_ciphertext, rtcp_plaintext_ref, len)) { + return srtp_err_status_fail; + } + + status = srtp_dealloc(srtp_snd); + if (status) { + return status; + } + + status = srtp_dealloc(srtp_recv); + if (status) { + return status; + } + + return srtp_err_status_ok; +} + #ifdef GCM /* * srtp_validate_gcm() verifies the correctness of libsrtp by comparing From 15e64b9c935f2d5ea94e758527b509a9727ea8ae Mon Sep 17 00:00:00 2001 From: "Richard L. Barnes" Date: Wed, 8 Sep 2021 17:46:51 -0400 Subject: [PATCH 016/109] Accommodate shorter GCM keys --- srtp/srtp.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index 8cbe4f73d..9a7e8caa3 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -776,6 +776,25 @@ static inline int base_key_length(const srtp_cipher_type_t *cipher, } } +/* Get the key length that the application should supply for the given cipher */ +static inline int full_key_length(const srtp_cipher_type_t *cipher) { + switch (cipher->id) { + case SRTP_NULL_CIPHER: + case SRTP_AES_ICM_128: + return SRTP_AES_ICM_128_KEY_LEN_WSALT; + case SRTP_AES_ICM_192: + return SRTP_AES_ICM_192_KEY_LEN_WSALT; + case SRTP_AES_ICM_256: + return SRTP_AES_ICM_256_KEY_LEN_WSALT; + case SRTP_AES_GCM_128: + return SRTP_AES_GCM_128_KEY_LEN_WSALT; + case SRTP_AES_GCM_256: + return SRTP_AES_ICM_256_KEY_LEN_WSALT; + default: + return 0; + } +} + unsigned int srtp_validate_policy_master_keys(const srtp_policy_t *policy) { unsigned long i = 0; @@ -870,6 +889,7 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, srtp_err_status_t stat; srtp_kdf_t kdf; uint8_t tmp_key[MAX_SRTP_KEY_LEN]; + int input_keylen, input_keylen_rtcp; int kdf_keylen = 30, rtp_keylen, rtcp_keylen; int rtp_base_key_len, rtp_salt_len; int rtcp_base_key_len, rtcp_salt_len; @@ -906,6 +926,12 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, session_keys->mki_size = master_key->mki_size; + input_keylen = full_key_length(session_keys->rtp_cipher->type); + input_keylen_rtcp = full_key_length(session_keys->rtcp_cipher->type); + if (input_keylen_rtcp > input_keylen) { + input_keylen = input_keylen_rtcp; + } + rtp_keylen = srtp_cipher_get_key_length(session_keys->rtp_cipher); rtcp_keylen = srtp_cipher_get_key_length(session_keys->rtcp_cipher); rtp_base_key_len = @@ -920,6 +946,11 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, kdf_keylen = 46; /* AES-CTR mode is always used for KDF */ } + if (input_keylen > kdf_keylen) { + kdf_keylen = 46; /* AES-CTR mode is always used for KDF */ + } + + debug_print(mod_srtp, "input key len;: %d", input_keylen); debug_print(mod_srtp, "srtp key len: %d", rtp_keylen); debug_print(mod_srtp, "srtcp key len: %d", rtcp_keylen); debug_print(mod_srtp, "base key len: %d", rtp_base_key_len); @@ -932,7 +963,7 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, * the legacy CTR mode KDF, which uses a 112 bit master SALT. */ memset(tmp_key, 0x0, MAX_SRTP_KEY_LEN); - memcpy(tmp_key, key, kdf_keylen); + memcpy(tmp_key, key, input_keylen); /* initialize KDF state */ #if defined(OPENSSL) && defined(OPENSSL_KDF) From f3830315d6770ef51223d3483d859193c31ca220 Mon Sep 17 00:00:00 2001 From: "Richard L. Barnes" Date: Wed, 8 Sep 2021 17:51:11 -0400 Subject: [PATCH 017/109] Formatting --- srtp/srtp.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index 9a7e8caa3..7d10eee3a 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -777,8 +777,9 @@ static inline int base_key_length(const srtp_cipher_type_t *cipher, } /* Get the key length that the application should supply for the given cipher */ -static inline int full_key_length(const srtp_cipher_type_t *cipher) { - switch (cipher->id) { +static inline int full_key_length(const srtp_cipher_type_t *cipher) +{ + switch (cipher->id) { case SRTP_NULL_CIPHER: case SRTP_AES_ICM_128: return SRTP_AES_ICM_128_KEY_LEN_WSALT; @@ -792,7 +793,7 @@ static inline int full_key_length(const srtp_cipher_type_t *cipher) { return SRTP_AES_ICM_256_KEY_LEN_WSALT; default: return 0; - } + } } unsigned int srtp_validate_policy_master_keys(const srtp_policy_t *policy) @@ -929,7 +930,7 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, input_keylen = full_key_length(session_keys->rtp_cipher->type); input_keylen_rtcp = full_key_length(session_keys->rtcp_cipher->type); if (input_keylen_rtcp > input_keylen) { - input_keylen = input_keylen_rtcp; + input_keylen = input_keylen_rtcp; } rtp_keylen = srtp_cipher_get_key_length(session_keys->rtp_cipher); From c4a54553babd170d2e00c06d81017c76da4a7bad Mon Sep 17 00:00:00 2001 From: "Richard L. Barnes" Date: Thu, 9 Sep 2021 08:38:48 -0400 Subject: [PATCH 018/109] Set full-size key length in crypto policies --- srtp/srtp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index 7d10eee3a..d0517aaa8 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -951,7 +951,7 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, kdf_keylen = 46; /* AES-CTR mode is always used for KDF */ } - debug_print(mod_srtp, "input key len;: %d", input_keylen); + debug_print(mod_srtp, "input key len: %d", input_keylen); debug_print(mod_srtp, "srtp key len: %d", rtp_keylen); debug_print(mod_srtp, "srtcp key len: %d", rtcp_keylen); debug_print(mod_srtp, "base key len: %d", rtp_base_key_len); From 812a683c8554f53b80f64b94966c790c59b7de32 Mon Sep 17 00:00:00 2001 From: "Richard L. Barnes" Date: Thu, 9 Sep 2021 08:46:15 -0400 Subject: [PATCH 019/109] Set full-size key length in crypto policies --- srtp/srtp.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index d0517aaa8..c7f6bb9f4 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -757,22 +757,20 @@ static inline int base_key_length(const srtp_cipher_type_t *cipher, int key_length) { switch (cipher->id) { + case SRTP_NULL_CIPHER: + return 0; case SRTP_AES_ICM_128: case SRTP_AES_ICM_192: case SRTP_AES_ICM_256: /* The legacy modes are derived from * the configured key length on the policy */ return key_length - SRTP_SALT_LEN; - break; case SRTP_AES_GCM_128: return key_length - SRTP_AEAD_SALT_LEN; - break; case SRTP_AES_GCM_256: return key_length - SRTP_AEAD_SALT_LEN; - break; default: return key_length; - break; } } @@ -3279,7 +3277,7 @@ void srtp_crypto_policy_set_null_cipher_hmac_sha1_80(srtp_crypto_policy_t *p) */ p->cipher_type = SRTP_NULL_CIPHER; - p->cipher_key_len = 0; + p->cipher_key_len = 16; p->auth_type = SRTP_HMAC_SHA1; p->auth_key_len = 20; p->auth_tag_len = 10; @@ -3293,7 +3291,7 @@ void srtp_crypto_policy_set_null_cipher_hmac_null(srtp_crypto_policy_t *p) */ p->cipher_type = SRTP_NULL_CIPHER; - p->cipher_key_len = 0; + p->cipher_key_len = 16; p->auth_type = SRTP_NULL_AUTH; p->auth_key_len = 0; p->auth_tag_len = 0; From 096166c0fb1f444a852cf75cfbfd4636a9d43ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Wed, 18 Aug 2021 21:49:02 +0200 Subject: [PATCH 020/109] add rtp_decoder to cmake build This will build as part of test apps. A very simple find PCAP package is supported. This should be sufficient as it is a seldom used test tool. It can be expanded as needed. --- CMakeLists.txt | 6 ++++++ cmake/FindPCAP.cmake | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 cmake/FindPCAP.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 729641bb3..e15e851c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -265,6 +265,12 @@ install(FILES include/srtp.h crypto/include/auth.h if(TEST_APPS) enable_testing() + find_package(PCAP) + if (PCAP_FOUND) + add_executable(rtp_decoder test/rtp_decoder.c test/getopt_s.c test/util.c) + target_link_libraries(rtp_decoder srtp2 ${PCAP_LIBRARY}) + endif() + if(NOT (BUILD_SHARED_LIBS AND WIN32)) if(NOT USE_EXTERNAL_CRYPTO) add_executable(aes_calc crypto/test/aes_calc.c test/getopt_s.c test/util.c) diff --git a/cmake/FindPCAP.cmake b/cmake/FindPCAP.cmake new file mode 100644 index 000000000..fae210291 --- /dev/null +++ b/cmake/FindPCAP.cmake @@ -0,0 +1,12 @@ +find_path(PCAP_INCLUDE_DIR_TEMP pcap.h) +find_library(PCAP_LIBRARY_TEMP pcap) + +if (PCAP_INCLUDE_DIR_TEMP AND PCAP_LIBRARY_TEMP) + set(PCAP_LIBRARY pcap) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PCAP DEFAULT_MSG + PCAP_LIBRARY) + +mark_as_advanced(PCAP_LIBRARY) From 3fba14d14f09f152dbd797eefa3f99d2048f3e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Thu, 19 Aug 2021 09:25:50 +0200 Subject: [PATCH 021/109] change argument for setting crypto suite to -c This will break existing usage of the tool but the breakage will not be silent, it will produce an error. The impact of this change should be small as it is assumed that there are not many users of this tool. --- test/rtp_decoder.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/rtp_decoder.c b/test/rtp_decoder.c index d424b4b10..50b645aee 100644 --- a/test/rtp_decoder.c +++ b/test/rtp_decoder.c @@ -202,7 +202,7 @@ int main(int argc, char *argv[]) /* check args */ while (1) { - c = getopt_s(argc, argv, "b:k:gt:ae:ld:f:s:m:p:o:"); + c = getopt_s(argc, argv, "b:k:gt:ae:ld:f:c:m:p:o:"); if (c == -1) { break; } @@ -256,7 +256,7 @@ int main(int argc, char *argv[]) case 'l': do_list_mods = 1; break; - case 's': + case 'c': for (i_scsp = &srtp_crypto_suites[0]; i_scsp->can_name != NULL; i_scsp++) { if (strcasecmp(i_scsp->can_name, optarg_s) == 0) { @@ -622,7 +622,7 @@ void usage(char *string) { fprintf( stderr, - "usage: %s [-d ]* [[-k][-b] ] [-a][-t][-e] [-s " + "usage: %s [-d ]* [[-k][-b] ] [-a][-t][-e] [-c " "] [-m ]\n" "or %s -l\n" "where -a use message authentication\n" @@ -634,7 +634,7 @@ void usage(char *string) " -l list debug modules\n" " -f \"\" to filter only the desired SRTP packets\n" " -d turn on debugging for module \n" - " -s \"\" to set both key and tag size based\n" + " -c \"\" to set both key and tag size based\n" " on RFC4568-style crypto suite specification\n" " -m set the mode to be one of [rtp]|rtcp|rtcp-mux\n" " -p path to pcap file (defaults to stdin)\n" From 6213c42753f8101dae34688551557d6c172930e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Thu, 19 Aug 2021 11:55:28 +0200 Subject: [PATCH 022/109] rtp_decoder: support setting SSRC and initial ROC This allows decryption of pcap's that do not contain the beginning of the RTP stream, where the sequence number may have already wrapped. In order to set a initial ROC then the SSRC is also required. --- test/rtp_decoder.c | 38 ++++++++++++++++++++++++++++++++------ test/rtp_decoder.h | 3 ++- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/test/rtp_decoder.c b/test/rtp_decoder.c index 50b645aee..6d88e4340 100644 --- a/test/rtp_decoder.c +++ b/test/rtp_decoder.c @@ -177,6 +177,8 @@ int main(int argc, char *argv[]) rtp_decoder_t dec; srtp_policy_t policy = { { 0 } }; rtp_decoder_mode_t mode = mode_rtp; + srtp_ssrc_t ssrc = { ssrc_any_inbound, 0 }; + uint32_t roc = 0; srtp_err_status_t status; int len; int expected_len; @@ -202,7 +204,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:"); + c = getopt_s(argc, argv, "b:k:gt:ae:ld:f:c:m:p:o:s:r:"); if (c == -1) { break; } @@ -297,6 +299,13 @@ int main(int argc, char *argv[]) case 'o': rtp_packet_offset = atoi(optarg_s); break; + case 's': + ssrc.type = ssrc_specific; + ssrc.value = strtol(optarg_s, NULL, 0); + break; + case 'r': + roc = atoi(optarg_s); + break; default: usage(argv[0]); } @@ -567,6 +576,13 @@ int main(int argc, char *argv[]) exit(1); } + policy.ssrc = ssrc; + + if (roc != 0 && policy.ssrc.type != ssrc_specific) { + fprintf(stderr, "error: setting ROC (-r) requires -s \n"); + exit(1); + } + pcap_handle = pcap_open_offline(pcap_file, errbuf); if (!pcap_handle) { @@ -590,7 +606,7 @@ int main(int argc, char *argv[]) exit(1); } fprintf(stderr, "Starting decoder\n"); - if (rtp_decoder_init(dec, policy, mode, rtp_packet_offset)) { + if (rtp_decoder_init(dec, policy, mode, rtp_packet_offset, roc)) { fprintf(stderr, "error: init failed\n"); exit(1); } @@ -623,7 +639,7 @@ void usage(char *string) fprintf( stderr, "usage: %s [-d ]* [[-k][-b] ] [-a][-t][-e] [-c " - "] [-m ]\n" + "] [-m ] [-s [-r ]]\n" "or %s -l\n" "where -a use message authentication\n" " -e use encryption (use 128 or 256 for key size)\n" @@ -638,7 +654,11 @@ void usage(char *string) " on RFC4568-style crypto suite specification\n" " -m set the mode to be one of [rtp]|rtcp|rtcp-mux\n" " -p path to pcap file (defaults to stdin)\n" - " -o byte offset of RTP packet in capture (defaults to 42)\n", + " -o byte offset of RTP packet in capture (defaults to 42)\n" + " -s restrict decrypting to the given SSRC (in host byte " + "order)\n" + " -r initial rollover counter, requires -s " + "(defaults to 0)\n", string, string); exit(1); } @@ -664,7 +684,8 @@ int rtp_decoder_deinit(rtp_decoder_t decoder) int rtp_decoder_init(rtp_decoder_t dcdr, srtp_policy_t policy, rtp_decoder_mode_t mode, - int rtp_packet_offset) + int rtp_packet_offset, + uint32_t roc) { dcdr->rtp_offset = rtp_packet_offset; dcdr->srtp_ctx = NULL; @@ -676,11 +697,16 @@ int rtp_decoder_init(rtp_decoder_t dcdr, dcdr->rtcp_cnt = 0; dcdr->mode = mode; dcdr->policy = policy; - dcdr->policy.ssrc.type = ssrc_any_inbound; if (srtp_create(&dcdr->srtp_ctx, &dcdr->policy)) { return 1; } + + if (policy.ssrc.type == ssrc_specific && roc != 0) { + if (srtp_set_stream_roc(dcdr->srtp_ctx, policy.ssrc.value, roc)) { + return 1; + } + } return 0; } diff --git a/test/rtp_decoder.h b/test/rtp_decoder.h index 955caf640..6a9c15134 100644 --- a/test/rtp_decoder.h +++ b/test/rtp_decoder.h @@ -102,7 +102,8 @@ void rtp_decoder_dealloc(rtp_decoder_t rtp_ctx); int rtp_decoder_init(rtp_decoder_t dcdr, srtp_policy_t policy, rtp_decoder_mode_t mode, - int rtp_packet_offset); + int rtp_packet_offset, + uint32_t roc); int rtp_decoder_deinit(rtp_decoder_t decoder); From 3a5d26c45c7a5a60c78d6ee60d409ff464f629fd Mon Sep 17 00:00:00 2001 From: Lorenzo Miniero Date: Mon, 13 Sep 2021 16:13:45 +0200 Subject: [PATCH 023/109] Fix typo introduced by PR 559 --- srtp/srtp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index c7f6bb9f4..dbb099095 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -788,7 +788,7 @@ static inline int full_key_length(const srtp_cipher_type_t *cipher) case SRTP_AES_GCM_128: return SRTP_AES_GCM_128_KEY_LEN_WSALT; case SRTP_AES_GCM_256: - return SRTP_AES_ICM_256_KEY_LEN_WSALT; + return SRTP_AES_GCM_256_KEY_LEN_WSALT; default: return 0; } From 1e7b25f4a957e290d362c3e67afa2c8bac8be82c Mon Sep 17 00:00:00 2001 From: Stepan Saiko Date: Sun, 10 Oct 2021 13:33:52 +0500 Subject: [PATCH 024/109] Include directory should point to 'include' not to 'include/srtp2' --- include/srtp2/meson.build | 1 - meson.build | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/srtp2/meson.build b/include/srtp2/meson.build index 88d068a33..9b8390e0d 100644 --- a/include/srtp2/meson.build +++ b/include/srtp2/meson.build @@ -5,4 +5,3 @@ foreach h : public_headers output: '@BASENAME@.h', copy: true) endforeach -public_incs = include_directories('.') diff --git a/meson.build b/meson.build index 226b05c34..a25197ad4 100644 --- a/meson.build +++ b/meson.build @@ -264,7 +264,8 @@ else libsrtp2 = libsrtp2_static endif -subdir('include/srtp2') # copies public_headers into the builddir and sets public_incs +subdir('include/srtp2') # copies public_headers into the builddir +public_incs = include_directories('include') # sets public_incs libsrtp2_dep = declare_dependency(link_with: libsrtp2, include_directories: public_incs) From 52de41970582ec69f94fa32ec62f84a70dbd6345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 11 Oct 2021 10:40:26 +0200 Subject: [PATCH 025/109] cast time_t values to known types for formatting in fprintf This is a fix suggested in issue #566 to address build issues with debian x32. --- test/rtp_decoder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/rtp_decoder.c b/test/rtp_decoder.c index 6d88e4340..9bbf62ea2 100644 --- a/test/rtp_decoder.c +++ b/test/rtp_decoder.c @@ -792,7 +792,7 @@ void rtp_decoder_handle_pkt(u_char *arg, dcdr->rtcp_cnt++; } timersub(&hdr->ts, &dcdr->start_tv, &delta); - fprintf(stdout, "%02ld:%02ld.%06ld\n", delta.tv_sec / 60, delta.tv_sec % 60, - (long)delta.tv_usec); + fprintf(stdout, "%02ld:%02d.%06ld\n", (long)(delta.tv_sec / 60), + (int)(delta.tv_sec % 60), (long)delta.tv_usec); hexdump(&message, octets_recvd); } From 38f5ccb11453fc2d612b06aa7a506c28d8f8363f Mon Sep 17 00:00:00 2001 From: SE2Dev <5873790+SE2Dev@users.noreply.github.com> Date: Wed, 13 Oct 2021 22:45:11 +0000 Subject: [PATCH 026/109] Export CMake Targets --- CMakeLists.txt | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- Config.cmake.in | 3 +++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index e15e851c1..4e47a2a43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -240,7 +240,11 @@ add_library(srtp2 set_target_properties(srtp2 PROPERTIES VERSION ${CMAKE_PROJECT_VERSION}) -target_include_directories(srtp2 PUBLIC crypto/include include) +target_include_directories(srtp2 PUBLIC + $ + $ + $ +) if(ENABLE_OPENSSL) target_include_directories(srtp2 PRIVATE ${OPENSSL_INCLUDE_DIR}) target_link_libraries(srtp2 OpenSSL::Crypto) @@ -256,7 +260,10 @@ if(WIN32) target_compile_definitions(srtp2 PUBLIC _CRT_SECURE_NO_WARNINGS) endif() -install(TARGETS srtp2 DESTINATION lib) +install(TARGETS srtp2 DESTINATION lib + EXPORT libSRTPTargets +) + install(FILES include/srtp.h crypto/include/auth.h crypto/include/cipher.h crypto/include/crypto_types.h @@ -352,3 +359,40 @@ if(TEST_APPS) endif() endif() endif() + +# Export targets +install( + EXPORT libSRTPTargets + FILE libSRTPTargets.cmake + NAMESPACE libSRTP:: + DESTINATION lib/cmake/libSRTP +) + +#-------------------------------------------------------------------- +# Create generated files +#-------------------------------------------------------------------- +include(CMakePackageConfigHelpers) + +# Generate the config file that is includes the exports +configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/libSRTPConfig.cmake" + INSTALL_DESTINATION "${CONFIG_FILE_DIR}" + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) + +# Generate the version file for the config file +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/libSRTPConfigVersion.cmake" + VERSION "${CMAKE_PROJECT_VERSION}" + COMPATIBILITY AnyNewerVersion +) + +#-------------------------------------------------------------------- +# Install CMake config files +#-------------------------------------------------------------------- +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/libSRTPConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/libSRTPConfigVersion.cmake + DESTINATION lib/cmake/libSRTP +) diff --git a/Config.cmake.in b/Config.cmake.in new file mode 100644 index 000000000..0ad9b1777 --- /dev/null +++ b/Config.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ + +include ( "${CMAKE_CURRENT_LIST_DIR}/libSRTPTargets.cmake" ) From 3291018b0dffee1a07d79b2c3496ec55c28b7734 Mon Sep 17 00:00:00 2001 From: Alexander Traud Date: Thu, 14 Oct 2021 17:02:31 +0200 Subject: [PATCH 027/109] Update README.md to include NSS --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d37be093a..1e42a0bae 100644 --- a/README.md +++ b/README.md @@ -283,11 +283,13 @@ Option | Description -------------------------------|-------------------- \-\-help \-h | Display help \-\-enable-debug-logging | Enable debug logging in all modules -\-\-enable-log-stdout | Enable logging to stdout \-\-enable-openssl | Enable OpenSSL crypto engine +\-\-enable-nss | Enable NSS crypto engine \-\-enable-openssl-kdf | Enable OpenSSL KDF algorithm -\-\-with-log-file | Use file for logging +\-\-enable-log-stdout | Enable logging to stdout \-\-with-openssl-dir | Location of OpenSSL installation +\-\-with-nss-dir | Location of NSS installation +\-\-with-log-file | Use file for logging By default there is no log output, logging can be enabled to be output to stdout or a given file using the configure options. From 921159ed1f35d098bd5e436630550939928a530a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Wed, 27 Oct 2021 20:58:35 +0200 Subject: [PATCH 028/109] add compile time check of format arguments to srtp_err_report() --- crypto/include/err.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crypto/include/err.h b/crypto/include/err.h index 326f5e96b..6624d018f 100644 --- a/crypto/include/err.h +++ b/crypto/include/err.h @@ -49,6 +49,17 @@ #include #include "srtp.h" +#if defined(__clang__) || (defined(__GNUC__) && defined(__has_attribute)) +#if __has_attribute(format) +#define LIBSRTP_FORMAT_PRINTF(fmt, args) \ + __attribute__((format(__printf__, fmt, args))) +#else +#define LIBSRTP_FORMAT_PRINTF(fmt, args) +#endif +#else +#define LIBSRTP_FORMAT_PRINTF(fmt, args) +#endif + #ifdef __cplusplus extern "C" { #endif @@ -96,7 +107,8 @@ srtp_err_status_t srtp_install_err_report_handler( * */ -void srtp_err_report(srtp_err_reporting_level_t level, const char *format, ...); +void srtp_err_report(srtp_err_reporting_level_t level, const char *format, ...) + LIBSRTP_FORMAT_PRINTF(2, 3); /* * debug_module_t defines a debug module From 9345ca5c1080bb14f5b17aa035d0b0728d9f4883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Thu, 28 Oct 2021 20:40:04 +0200 Subject: [PATCH 029/109] test for out of order after rollover This is a test case to check if issue #567 is reproducible. --- test/srtp_driver.c | 228 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 228 insertions(+) diff --git a/test/srtp_driver.c b/test/srtp_driver.c index db6d3f48e..12da98feb 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -93,6 +93,8 @@ srtp_err_status_t srtp_test_protect_trailer_length(void); srtp_err_status_t srtp_test_protect_rtcp_trailer_length(void); +srtp_err_status_t srtp_test_out_of_order_after_rollover(void); + srtp_err_status_t srtp_test_get_roc(void); srtp_err_status_t srtp_test_set_receiver_roc(void); @@ -562,6 +564,14 @@ int main(int argc, char *argv[]) exit(1); } + printf("testing srtp_test_out_of_order_after_rollover()..."); + if (srtp_test_out_of_order_after_rollover() == srtp_err_status_ok) { + printf("passed\n"); + } else { + printf("failed\n"); + exit(1); + } + printf("testing srtp_test_get_roc()..."); if (srtp_test_get_roc() == srtp_err_status_ok) { printf("passed\n"); @@ -3171,6 +3181,224 @@ srtp_err_status_t srtp_test_protect_rtcp_trailer_length() return srtp_err_status_ok; } +srtp_err_status_t srtp_test_out_of_order_after_rollover() +{ + srtp_err_status_t status; + + srtp_policy_t sender_policy; + srtp_t sender_session; + + srtp_policy_t receiver_policy; + srtp_t receiver_session; + + const int num_pkts = 5; + srtp_hdr_t *pkts[5]; + int pkt_len_octets[5]; + + uint32_t i; + uint32_t stream_roc; + + /* Create sender */ + memset(&sender_policy, 0, sizeof(sender_policy)); +#ifdef GCM + srtp_crypto_policy_set_aes_gcm_128_16_auth(&sender_policy.rtp); + srtp_crypto_policy_set_aes_gcm_128_16_auth(&sender_policy.rtcp); + sender_policy.key = test_key_gcm; +#else + srtp_crypto_policy_set_rtp_default(&sender_policy.rtp); + srtp_crypto_policy_set_rtcp_default(&sender_policy.rtcp); + sender_policy.key = test_key; +#endif + sender_policy.ssrc.type = ssrc_specific; + sender_policy.ssrc.value = 0xcafebabe; + sender_policy.window_size = 128; + + status = srtp_create(&sender_session, &sender_policy); + if (status) { + return status; + } + + /* Create the receiver */ + memset(&receiver_policy, 0, sizeof(receiver_policy)); +#ifdef GCM + srtp_crypto_policy_set_aes_gcm_128_16_auth(&receiver_policy.rtp); + srtp_crypto_policy_set_aes_gcm_128_16_auth(&receiver_policy.rtcp); + receiver_policy.key = test_key_gcm; +#else + srtp_crypto_policy_set_rtp_default(&receiver_policy.rtp); + srtp_crypto_policy_set_rtcp_default(&receiver_policy.rtcp); + receiver_policy.key = test_key; +#endif + receiver_policy.ssrc.type = ssrc_specific; + receiver_policy.ssrc.value = sender_policy.ssrc.value; + receiver_policy.window_size = 128; + + status = srtp_create(&receiver_session, &receiver_policy); + if (status) { + return status; + } + + /* Create and protect packets to get to get roc == 1 */ + pkts[0] = srtp_create_test_packet_extended(64, sender_policy.ssrc.value, + 65534, 0, &pkt_len_octets[0]); + status = srtp_protect(sender_session, pkts[0], &pkt_len_octets[0]); + if (status) { + return status; + } + status = srtp_get_stream_roc(sender_session, sender_policy.ssrc.value, + &stream_roc); + if (status) { + return status; + } + if (stream_roc != 0) { + return srtp_err_status_fail; + } + + pkts[1] = srtp_create_test_packet_extended(64, sender_policy.ssrc.value, + 65535, 1, &pkt_len_octets[1]); + status = srtp_protect(sender_session, pkts[1], &pkt_len_octets[1]); + if (status) { + return status; + } + status = srtp_get_stream_roc(sender_session, sender_policy.ssrc.value, + &stream_roc); + if (status) { + return status; + } + if (stream_roc != 0) { + return srtp_err_status_fail; + } + + pkts[2] = srtp_create_test_packet_extended(64, sender_policy.ssrc.value, 0, + 2, &pkt_len_octets[2]); + status = srtp_protect(sender_session, pkts[2], &pkt_len_octets[2]); + if (status) { + return status; + } + status = srtp_get_stream_roc(sender_session, sender_policy.ssrc.value, + &stream_roc); + if (status) { + return status; + } + if (stream_roc != 1) { + return srtp_err_status_fail; + } + + pkts[3] = srtp_create_test_packet_extended(64, sender_policy.ssrc.value, 1, + 3, &pkt_len_octets[3]); + status = srtp_protect(sender_session, pkts[3], &pkt_len_octets[3]); + if (status) { + return status; + } + status = srtp_get_stream_roc(sender_session, sender_policy.ssrc.value, + &stream_roc); + if (status) { + return status; + } + if (stream_roc != 1) { + return srtp_err_status_fail; + } + + pkts[4] = srtp_create_test_packet_extended(64, sender_policy.ssrc.value, 2, + 4, &pkt_len_octets[4]); + status = srtp_protect(sender_session, pkts[4], &pkt_len_octets[4]); + if (status) { + return status; + } + status = srtp_get_stream_roc(sender_session, sender_policy.ssrc.value, + &stream_roc); + if (status) { + return status; + } + if (stream_roc != 1) { + return srtp_err_status_fail; + } + + /* Unprotect packets in this seq order 65534, 0, 2, 1, 65535 which is + * equivalent to index 0, 2, 4, 3, 1*/ + status = srtp_unprotect(receiver_session, pkts[0], &pkt_len_octets[0]); + if (status) { + return status; + } + status = srtp_get_stream_roc(receiver_session, receiver_policy.ssrc.value, + &stream_roc); + if (status) { + return status; + } + if (stream_roc != 0) { + return srtp_err_status_fail; + } + + status = srtp_unprotect(receiver_session, pkts[2], &pkt_len_octets[2]); + if (status) { + return status; + } + status = srtp_get_stream_roc(receiver_session, receiver_policy.ssrc.value, + &stream_roc); + if (status) { + return status; + } + if (stream_roc != 1) { + return srtp_err_status_fail; + } + + status = srtp_unprotect(receiver_session, pkts[4], &pkt_len_octets[4]); + if (status) { + return status; + } + status = srtp_get_stream_roc(receiver_session, receiver_policy.ssrc.value, + &stream_roc); + if (status) { + return status; + } + if (stream_roc != 1) { + return srtp_err_status_fail; + } + + status = srtp_unprotect(receiver_session, pkts[3], &pkt_len_octets[3]); + if (status) { + return status; + } + status = srtp_get_stream_roc(receiver_session, receiver_policy.ssrc.value, + &stream_roc); + if (status) { + return status; + } + if (stream_roc != 1) { + return srtp_err_status_fail; + } + + status = srtp_unprotect(receiver_session, pkts[1], &pkt_len_octets[1]); + if (status) { + return status; + } + status = srtp_get_stream_roc(receiver_session, receiver_policy.ssrc.value, + &stream_roc); + if (status) { + return status; + } + if (stream_roc != 1) { + return srtp_err_status_fail; + } + + /* Cleanup */ + status = srtp_dealloc(sender_session); + if (status) { + return status; + } + + status = srtp_dealloc(receiver_session); + if (status) { + return status; + } + + for (i = 0; i < num_pkts; i++) { + free(pkts[i]); + } + + return srtp_err_status_ok; +} + srtp_err_status_t srtp_test_get_roc() { srtp_err_status_t status; From db4dc8973394b5b370f549512d578e720b8870b9 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Wed, 17 Nov 2021 16:16:38 +0300 Subject: [PATCH 030/109] Avoid initializing local char table when converting nibble to hex. --- crypto/math/datatypes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto/math/datatypes.c b/crypto/math/datatypes.c index 0eb9d919b..88957b2cc 100644 --- a/crypto/math/datatypes.c +++ b/crypto/math/datatypes.c @@ -64,8 +64,8 @@ static char bit_string[MAX_PRINT_STRING_LEN + 1]; uint8_t srtp_nibble_to_hex_char(uint8_t nibble) { - char buf[16] = { '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; + static const char buf[16] = { '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; return buf[nibble & 0xF]; } From f1d1e57a49dca345e086e01b5fccc44e723221e0 Mon Sep 17 00:00:00 2001 From: "Richard L. Barnes" Date: Thu, 9 Dec 2021 15:40:18 -0500 Subject: [PATCH 031/109] Correctly set null cipher key sizes --- srtp/srtp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index dbb099095..7ce2b5395 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -3277,7 +3277,8 @@ void srtp_crypto_policy_set_null_cipher_hmac_sha1_80(srtp_crypto_policy_t *p) */ p->cipher_type = SRTP_NULL_CIPHER; - p->cipher_key_len = 16; + p->cipher_key_len = + SRTP_AES_ICM_128_KEY_LEN_WSALT; /* 128 bit key, 112 bit salt */; p->auth_type = SRTP_HMAC_SHA1; p->auth_key_len = 20; p->auth_tag_len = 10; @@ -3291,7 +3292,8 @@ void srtp_crypto_policy_set_null_cipher_hmac_null(srtp_crypto_policy_t *p) */ p->cipher_type = SRTP_NULL_CIPHER; - p->cipher_key_len = 16; + p->cipher_key_len = + SRTP_AES_ICM_128_KEY_LEN_WSALT; /* 128 bit key, 112 bit salt */; p->auth_type = SRTP_NULL_AUTH; p->auth_key_len = 0; p->auth_tag_len = 0; From 2542d684ce351f1acb27309aaeb5c615c63d1469 Mon Sep 17 00:00:00 2001 From: "Richard L. Barnes" Date: Thu, 9 Dec 2021 16:19:43 -0500 Subject: [PATCH 032/109] Fix key sizes in null cipher test policies --- srtp/srtp.c | 10 ++++++++++ test/srtp_driver.c | 48 +++++++++++++++++++++++----------------------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index 7ce2b5395..e8f377398 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -937,6 +937,16 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, base_key_length(session_keys->rtp_cipher->type, rtp_keylen); rtp_salt_len = rtp_keylen - rtp_base_key_len; + /* + * We assume that the `key` buffer provided by the caller has a length + * equal to the greater of `rtp_keylen` and `rtcp_keylen`. Since we are + * about to read `input_keylen` bytes from it, we need to check that we will + * not overrun. + */ + if ((rtp_keylen < input_keylen) && (rtcp_keylen < input_keylen)) { + return srtp_err_status_bad_param; + } + if (rtp_keylen > kdf_keylen) { kdf_keylen = 46; /* AES-CTR mode is always used for KDF */ } diff --git a/test/srtp_driver.c b/test/srtp_driver.c index db6d3f48e..ed55b218b 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -3883,20 +3883,20 @@ const srtp_policy_t aes_only_policy = { const srtp_policy_t hmac_only_policy = { { ssrc_any_outbound, 0 }, /* SSRC */ { - SRTP_NULL_CIPHER, /* cipher type */ - 0, /* cipher key length in octets */ - SRTP_HMAC_SHA1, /* authentication func type */ - 20, /* auth key length in octets */ - 4, /* auth tag length in octets */ - sec_serv_auth /* security services flag */ + SRTP_NULL_CIPHER, /* cipher type */ + SRTP_AES_ICM_128_KEY_LEN_WSALT, /* cipher key length in octets */ + SRTP_HMAC_SHA1, /* authentication func type */ + 20, /* auth key length in octets */ + 4, /* auth tag length in octets */ + sec_serv_auth /* security services flag */ }, { - SRTP_NULL_CIPHER, /* cipher type */ - 0, /* cipher key length in octets */ - SRTP_HMAC_SHA1, /* authentication func type */ - 20, /* auth key length in octets */ - 4, /* auth tag length in octets */ - sec_serv_auth /* security services flag */ + SRTP_NULL_CIPHER, /* cipher type */ + SRTP_AES_ICM_128_KEY_LEN_WSALT, /* cipher key length in octets */ + SRTP_HMAC_SHA1, /* authentication func type */ + 20, /* auth key length in octets */ + 4, /* auth tag length in octets */ + sec_serv_auth /* security services flag */ }, NULL, (srtp_master_key_t **)test_keys, @@ -4038,20 +4038,20 @@ const srtp_policy_t aes256_gcm_8_cauth_policy = { const srtp_policy_t null_policy = { { ssrc_any_outbound, 0 }, /* SSRC */ { - SRTP_NULL_CIPHER, /* cipher type */ - 0, /* cipher key length in octets */ - SRTP_NULL_AUTH, /* authentication func type */ - 0, /* auth key length in octets */ - 0, /* auth tag length in octets */ - sec_serv_none /* security services flag */ + SRTP_NULL_CIPHER, /* cipher type */ + SRTP_AES_GCM_256_KEY_LEN_WSALT, /* cipher key length in octets */ + SRTP_NULL_AUTH, /* authentication func type */ + 0, /* auth key length in octets */ + 0, /* auth tag length in octets */ + sec_serv_none /* security services flag */ }, { - SRTP_NULL_CIPHER, /* cipher type */ - 0, /* cipher key length in octets */ - SRTP_NULL_AUTH, /* authentication func type */ - 0, /* auth key length in octets */ - 0, /* auth tag length in octets */ - sec_serv_none /* security services flag */ + SRTP_NULL_CIPHER, /* cipher type */ + SRTP_AES_GCM_256_KEY_LEN_WSALT, /* cipher key length in octets */ + SRTP_NULL_AUTH, /* authentication func type */ + 0, /* auth key length in octets */ + 0, /* auth tag length in octets */ + sec_serv_none /* security services flag */ }, NULL, (srtp_master_key_t **)test_keys, From c3db75c3c4317a5a2901c7876a3dcc86a9b534e1 Mon Sep 17 00:00:00 2001 From: "Richard L. Barnes" Date: Thu, 9 Dec 2021 16:29:57 -0500 Subject: [PATCH 033/109] clang-format --- srtp/srtp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index e8f377398..c47830b2a 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -944,7 +944,7 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, * not overrun. */ if ((rtp_keylen < input_keylen) && (rtcp_keylen < input_keylen)) { - return srtp_err_status_bad_param; + return srtp_err_status_bad_param; } if (rtp_keylen > kdf_keylen) { @@ -3288,7 +3288,7 @@ void srtp_crypto_policy_set_null_cipher_hmac_sha1_80(srtp_crypto_policy_t *p) p->cipher_type = SRTP_NULL_CIPHER; p->cipher_key_len = - SRTP_AES_ICM_128_KEY_LEN_WSALT; /* 128 bit key, 112 bit salt */; + SRTP_AES_ICM_128_KEY_LEN_WSALT; /* 128 bit key, 112 bit salt */ p->auth_type = SRTP_HMAC_SHA1; p->auth_key_len = 20; p->auth_tag_len = 10; @@ -3303,7 +3303,7 @@ void srtp_crypto_policy_set_null_cipher_hmac_null(srtp_crypto_policy_t *p) p->cipher_type = SRTP_NULL_CIPHER; p->cipher_key_len = - SRTP_AES_ICM_128_KEY_LEN_WSALT; /* 128 bit key, 112 bit salt */; + SRTP_AES_ICM_128_KEY_LEN_WSALT; /* 128 bit key, 112 bit salt */ p->auth_type = SRTP_NULL_AUTH; p->auth_key_len = 0; p->auth_tag_len = 0; From d11035441aca0096105a643851b686af0f2877f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Fri, 10 Dec 2021 08:34:53 +0100 Subject: [PATCH 034/109] Update cmake.yml Seems and update is now needed before installing nss on Ubuntu --- .github/workflows/cmake.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 0dd489544..109e5f22a 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -38,7 +38,9 @@ jobs: steps: - name: Setup Ubuntu NSS if: matrix.os == 'ubuntu-latest' && matrix.crypto == 'nss' - run: sudo apt-get install libnss3-dev + run: | + sudo apt-get update + sudo apt-get install libnss3-dev - name: Setup Ubuntu MbedTLS if: matrix.os == 'ubuntu-latest' && matrix.crypto == 'mbedtls' From b156e95032dcf118cf98830b6bd514270c355d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Fri, 10 Dec 2021 08:42:27 +0100 Subject: [PATCH 035/109] Update autotools.yml Same update for autotools yml --- .github/workflows/autotools.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/autotools.yml b/.github/workflows/autotools.yml index bb74dd733..fd98794bb 100644 --- a/.github/workflows/autotools.yml +++ b/.github/workflows/autotools.yml @@ -30,7 +30,9 @@ jobs: - name: Setup Ubuntu NSS if: matrix.os == 'ubuntu-latest' && matrix.crypto == 'nss' - run: sudo apt-get install libnss3-dev + run: | + sudo apt-get update + sudo apt-get install libnss3-dev - name: Setup macOS OpenSSL if: matrix.os == 'macos-latest' && matrix.crypto == 'openssl' From 0d1ec9971cbaebdf9864c1c1a48e3e135e5fb708 Mon Sep 17 00:00:00 2001 From: Yann Droneaud Date: Fri, 10 Dec 2021 10:50:13 +0100 Subject: [PATCH 036/109] EVP_CIPHER_CTX_cleanup() is deprecated in OpenSSL 1.1.0 Starting from OpenSSL 1.1.0, EVP_CIPHER_CTX_cleanup() and EVP_CIPHER_CTX_init() are deprecated, and not available when OpenSSL is built with "no-deprecated" option (aka. OPENSSL_NO_DEPRECATED). Use EVP_CIPHER_CTX_reset() instead: "EVP_CIPHER_CTX was made opaque in OpenSSL 1.1.0. As a result, EVP_CIPHER_CTX_reset() appeared and EVP_CIPHER_CTX_cleanup() disappeared." https://www.openssl.org/docs/man1.1.1/man3/EVP_CIPHER_CTX_reset.html --- crypto/cipher/aes_gcm_ossl.c | 5 +++++ crypto/cipher/aes_icm_ossl.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/crypto/cipher/aes_gcm_ossl.c b/crypto/cipher/aes_gcm_ossl.c index 3e2d6bb11..2b87561bb 100644 --- a/crypto/cipher/aes_gcm_ossl.c +++ b/crypto/cipher/aes_gcm_ossl.c @@ -193,7 +193,12 @@ static srtp_err_status_t srtp_aes_gcm_openssl_context_init(void *cv, break; } +#if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_CIPHER_CTX_cleanup(c->ctx); +#else + EVP_CIPHER_CTX_reset(c->ctx); +#endif + if (!EVP_CipherInit_ex(c->ctx, evp, NULL, key, NULL, 0)) { return (srtp_err_status_init_fail); } diff --git a/crypto/cipher/aes_icm_ossl.c b/crypto/cipher/aes_icm_ossl.c index f960a33ec..e0aea4fae 100644 --- a/crypto/cipher/aes_icm_ossl.c +++ b/crypto/cipher/aes_icm_ossl.c @@ -249,7 +249,12 @@ static srtp_err_status_t srtp_aes_icm_openssl_context_init(void *cv, break; } +#if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_CIPHER_CTX_cleanup(c->ctx); +#else + EVP_CIPHER_CTX_reset(c->ctx); +#endif + if (!EVP_EncryptInit_ex(c->ctx, evp, NULL, key, NULL)) { return srtp_err_status_fail; } else { From 03e0b72a56d060990e7db656a8eb92550a5eed30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Fri, 10 Dec 2021 18:25:07 +0100 Subject: [PATCH 037/109] set include path to be relative not absolute and remove some whitespace --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e47a2a43..75a3af40f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -243,7 +243,7 @@ set_target_properties(srtp2 PROPERTIES VERSION ${CMAKE_PROJECT_VERSION}) target_include_directories(srtp2 PUBLIC $ $ - $ + $ ) if(ENABLE_OPENSSL) target_include_directories(srtp2 PRIVATE ${OPENSSL_INCLUDE_DIR}) @@ -261,7 +261,7 @@ if(WIN32) endif() install(TARGETS srtp2 DESTINATION lib - EXPORT libSRTPTargets + EXPORT libSRTPTargets ) install(FILES include/srtp.h crypto/include/auth.h From 16483b18a9980575bee23898b2dbfbe2a4675d84 Mon Sep 17 00:00:00 2001 From: Klemens Nanni Date: Sat, 15 Jan 2022 23:19:35 +0300 Subject: [PATCH 038/109] Remove compatibility code for legacy OpenSSL to fix LibreSSL build In current LibreSSL, `HMAC_CTX` aka. `struct hmac_ctx_st` is an opaque structure as of LibreSSL hmac.h revision 1.15 (14.01.2022) [0], thus `sizeof(HMAC_CTX)` fails to compile. The non-legacy code path should compile with LibreSSL versions as old as 2.7.0 (21.03.2018). Found while building https://github.com/desktop-app/tg_owt which bundles libsrtp 2.2.0 [1] on OpenBSD 7.0 -CURRENT/with latest LibreSSL. Suggestion to remove the legacy code from Theo Buehler, thanks. 0: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libcrypto/hmac/hmac.h?rev=1.15&content-type=text/x-cvsweb-markup 1: https://github.com/desktop-app/tg_owt/blob/6708e0d31a73e64fe12f54829bf4060c41b2658e/src/third_party/libsrtp/crypto/hash/hmac_ossl.c#L85 --- crypto/hash/hmac_ossl.c | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/crypto/hash/hmac_ossl.c b/crypto/hash/hmac_ossl.c index ee6b0b585..c23c7f216 100644 --- a/crypto/hash/hmac_ossl.c +++ b/crypto/hash/hmac_ossl.c @@ -78,26 +78,6 @@ static srtp_err_status_t srtp_hmac_alloc(srtp_auth_t **a, return srtp_err_status_bad_param; } -/* OpenSSL 1.1.0 made HMAC_CTX an opaque structure, which must be allocated - using HMAC_CTX_new. But this function doesn't exist in OpenSSL 1.0.x. */ -#if OPENSSL_VERSION_NUMBER < 0x10100000L || LIBRESSL_VERSION_NUMBER - { - /* allocate memory for auth and HMAC_CTX structures */ - uint8_t *pointer; - HMAC_CTX *new_hmac_ctx; - pointer = (uint8_t *)srtp_crypto_alloc(sizeof(HMAC_CTX) + - sizeof(srtp_auth_t)); - if (pointer == NULL) { - return srtp_err_status_alloc_fail; - } - *a = (srtp_auth_t *)pointer; - (*a)->state = pointer + sizeof(srtp_auth_t); - new_hmac_ctx = (HMAC_CTX *)((*a)->state); - - HMAC_CTX_init(new_hmac_ctx); - } - -#else *a = (srtp_auth_t *)srtp_crypto_alloc(sizeof(srtp_auth_t)); if (*a == NULL) { return srtp_err_status_alloc_fail; @@ -109,7 +89,6 @@ static srtp_err_status_t srtp_hmac_alloc(srtp_auth_t **a, *a = NULL; return srtp_err_status_alloc_fail; } -#endif /* set pointers */ (*a)->type = &srtp_hmac; @@ -126,18 +105,10 @@ static srtp_err_status_t srtp_hmac_dealloc(srtp_auth_t *a) hmac_ctx = (HMAC_CTX *)a->state; -#if OPENSSL_VERSION_NUMBER < 0x10100000L || LIBRESSL_VERSION_NUMBER - HMAC_CTX_cleanup(hmac_ctx); - - /* zeroize entire state*/ - octet_string_set_to_zero(a, sizeof(HMAC_CTX) + sizeof(srtp_auth_t)); - -#else HMAC_CTX_free(hmac_ctx); /* zeroize entire state*/ octet_string_set_to_zero(a, sizeof(srtp_auth_t)); -#endif /* free memory */ srtp_crypto_free(a); From 15e87094e4f5622cccc307cee9eafad36ff74c13 Mon Sep 17 00:00:00 2001 From: Niels De Graef Date: Mon, 24 Jan 2022 14:58:50 +0100 Subject: [PATCH 039/109] Use inet_pton() when available `inet_aton()` and `inet_ntoa()` are considered deprecated, and can even show up under certain scanners. Use the replacement `inet_pton()` instead. --- CMakeLists.txt | 1 + config_in.h | 3 +++ config_in_cmake.h | 3 +++ configure | 2 +- configure.ac | 2 +- meson.build | 1 + test/rtpw.c | 12 +++++++++++- 7 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e15e851c1..2fa09174f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ check_include_file(winsock2.h HAVE_WINSOCK2_H) check_function_exists(sigaction HAVE_SIGACTION) check_function_exists(inet_aton HAVE_INET_ATON) +check_function_exists(inet_pton HAVE_INET_PTON) check_function_exists(usleep HAVE_USLEEP) check_type_size(uint8_t UINT8_T) diff --git a/config_in.h b/config_in.h index 31e6ffe38..1a3737c5c 100644 --- a/config_in.h +++ b/config_in.h @@ -30,6 +30,9 @@ /* Define to 1 if you have the `inet_aton' function. */ #undef HAVE_INET_ATON +/* Define to 1 if you have the `inet_pton' function. */ +#undef HAVE_INET_PTON + /* Define to 1 if the system has the type `int16_t'. */ #undef HAVE_INT16_T diff --git a/config_in_cmake.h b/config_in_cmake.h index 73113471a..b884cb377 100644 --- a/config_in_cmake.h +++ b/config_in_cmake.h @@ -82,6 +82,9 @@ /* Define to 1 if you have the `inet_aton' function. */ #cmakedefine HAVE_INET_ATON 1 +/* Define to 1 if you have the `inet_pton' function. */ +#cmakedefine HAVE_INET_PTON 1 + /* Define to 1 if you have the `sigaction' function. */ #cmakedefine HAVE_SIGACTION 1 diff --git a/configure b/configure index 13e6e3ba7..8c735bbb3 100755 --- a/configure +++ b/configure @@ -5195,7 +5195,7 @@ _ACEOF fi -for ac_func in socket inet_aton usleep sigaction +for ac_func in socket inet_aton inet_pton usleep sigaction do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.ac b/configure.ac index b10fc6473..d2f7190ff 100644 --- a/configure.ac +++ b/configure.ac @@ -166,7 +166,7 @@ AC_C_INLINE AC_TYPE_SIZE_T dnl Checks for library functions. -AC_CHECK_FUNCS([socket inet_aton usleep sigaction]) +AC_CHECK_FUNCS([socket inet_aton inet_pton usleep sigaction]) dnl Find socket function if not found yet. if test "x$ac_cv_func_socket" = "xno"; then diff --git a/meson.build b/meson.build index a25197ad4..a9ab7ca7d 100644 --- a/meson.build +++ b/meson.build @@ -46,6 +46,7 @@ endforeach check_functions = [ 'sigaction', 'inet_aton', + 'inet_pton', 'usleep', 'socket', ] diff --git a/test/rtpw.c b/test/rtpw.c index 93b43d670..906f12637 100644 --- a/test/rtpw.c +++ b/test/rtpw.c @@ -285,7 +285,17 @@ int main(int argc, char *argv[]) port = atoi(argv[optind_s++]); /* set address */ -#ifdef HAVE_INET_ATON +#ifdef HAVE_INET_PTON + if (0 == inet_pton(AF_INET, address, &rcvr_addr)) { + fprintf(stderr, "%s: cannot parse IP v4 address %s\n", argv[0], + address); + exit(1); + } + if (rcvr_addr.s_addr == INADDR_NONE) { + fprintf(stderr, "%s: address error", argv[0]); + exit(1); + } +#elif HAVE_INET_ATON if (0 == inet_aton(address, &rcvr_addr)) { fprintf(stderr, "%s: cannot parse IP v4 address %s\n", argv[0], address); From 2203114ae11178e80b537b6ed6d61da685433527 Mon Sep 17 00:00:00 2001 From: "Richard L. Barnes" Date: Mon, 31 Jan 2022 13:53:47 -0500 Subject: [PATCH 040/109] Skip unnecessary prep in receiver ROC tests --- test/srtp_driver.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/srtp_driver.c b/test/srtp_driver.c index 666239c9f..98ce5766b 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -3483,6 +3483,7 @@ static srtp_err_status_t test_set_receiver_roc(uint32_t packets, uint32_t i; uint32_t ts; uint16_t seq; + uint16_t stride; int msg_len_octets = 32; int protected_msg_len_octets_1; @@ -3509,9 +3510,11 @@ static srtp_err_status_t test_set_receiver_roc(uint32_t packets, } /* Create and protect packets */ + i = 0; seq = 0; ts = 0; - for (i = 0; i < packets; i++) { + stride = 0x4000; + while (i < packets) { srtp_hdr_t *tmp_pkt; int tmp_len; @@ -3523,7 +3526,12 @@ static srtp_err_status_t test_set_receiver_roc(uint32_t packets, return status; } - seq++; + while (stride > (packets - i) && stride > 1) { + stride >>= 1; + } + + i += stride; + seq += stride; ts++; } From 1fe2dbd7e16e0a2fc58cb475b58a4060fc952dd8 Mon Sep 17 00:00:00 2001 From: "Richard L. Barnes" Date: Mon, 31 Jan 2022 13:57:54 -0500 Subject: [PATCH 041/109] Move set-and-rollover test in to set-ROC test --- test/srtp_driver.c | 184 +-------------------------------------------- 1 file changed, 1 insertion(+), 183 deletions(-) diff --git a/test/srtp_driver.c b/test/srtp_driver.c index 98ce5766b..d7c6d368b 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -99,8 +99,6 @@ srtp_err_status_t srtp_test_get_roc(void); srtp_err_status_t srtp_test_set_receiver_roc(void); -srtp_err_status_t srtp_test_set_receiver_roc_then_rollover(void); - srtp_err_status_t srtp_test_set_sender_roc(void); double srtp_bits_per_second(int msg_len_octets, const srtp_policy_t *policy); @@ -588,14 +586,6 @@ int main(int argc, char *argv[]) exit(1); } - printf("testing srtp_test_set_receiver_roc_then_rollover()..."); - if (srtp_test_set_receiver_roc_then_rollover() == srtp_err_status_ok) { - printf("passed\n"); - } else { - printf("failed\n"); - exit(1); - } - printf("testing srtp_test_set_sender_roc()..."); if (srtp_test_set_sender_roc() == srtp_err_status_ok) { printf("passed\n"); @@ -3797,183 +3787,11 @@ srtp_err_status_t srtp_test_set_receiver_roc() return status; } - return srtp_err_status_ok; -} - -srtp_err_status_t srtp_test_set_receiver_roc_then_rollover() -{ - srtp_err_status_t status; - - srtp_policy_t sender_policy; - srtp_t sender_session; - - srtp_policy_t receiver_policy; - srtp_t receiver_session; - - srtp_hdr_t *pkt_1; - unsigned char *recv_pkt_1; - - srtp_hdr_t *pkt_2; - unsigned char *recv_pkt_2; - - uint32_t i; - uint32_t ts; - uint16_t seq; - uint32_t sender_roc; - - int msg_len_octets = 32; - int protected_msg_len_octets_1; - int protected_msg_len_octets_2; - - /* Create sender */ - memset(&sender_policy, 0, sizeof(sender_policy)); -#ifdef GCM - srtp_crypto_policy_set_aes_gcm_128_16_auth(&sender_policy.rtp); - srtp_crypto_policy_set_aes_gcm_128_16_auth(&sender_policy.rtcp); - sender_policy.key = test_key_gcm; -#else - srtp_crypto_policy_set_rtp_default(&sender_policy.rtp); - srtp_crypto_policy_set_rtcp_default(&sender_policy.rtcp); - sender_policy.key = test_key; -#endif - sender_policy.ssrc.type = ssrc_specific; - sender_policy.ssrc.value = 0xcafebabe; - sender_policy.window_size = 128; - - status = srtp_create(&sender_session, &sender_policy); - if (status) { - return status; - } - - /* Create and protect packets to get to seq 65536 and roc == 1 */ - seq = 65535; - ts = 0; - for (i = 0; i < 65535; i++) { - srtp_hdr_t *tmp_pkt; - int tmp_len; - - tmp_pkt = srtp_create_test_packet_extended( - msg_len_octets, sender_policy.ssrc.value, seq, ts, &tmp_len); - status = srtp_protect(sender_session, tmp_pkt, &tmp_len); - free(tmp_pkt); - if (status) { - return status; - } - - seq++; - ts++; - } - - status = srtp_get_stream_roc(sender_session, sender_policy.ssrc.value, - &sender_roc); - if (status) { - return status; - } - - if (sender_roc != 1) { - return srtp_err_status_fail; - } - - /* Create the first packet to decrypt and test for ROC change */ - pkt_1 = srtp_create_test_packet_extended(msg_len_octets, - sender_policy.ssrc.value, 65535, - ts, &protected_msg_len_octets_1); - status = srtp_protect(sender_session, pkt_1, &protected_msg_len_octets_1); - if (status) { - return status; - } - - /* Create the second packet to decrypt and test for ROC change */ - ts++; - pkt_2 = srtp_create_test_packet_extended(msg_len_octets, - sender_policy.ssrc.value, 0, ts, - &protected_msg_len_octets_2); - status = srtp_protect(sender_session, pkt_2, &protected_msg_len_octets_2); - if (status) { - return status; - } - - status = srtp_get_stream_roc(sender_session, sender_policy.ssrc.value, - &sender_roc); - if (status) { - return status; - } - - if (sender_roc != 2) { - return srtp_err_status_fail; - } - - /* Create the receiver */ - memset(&receiver_policy, 0, sizeof(receiver_policy)); -#ifdef GCM - srtp_crypto_policy_set_aes_gcm_128_16_auth(&receiver_policy.rtp); - srtp_crypto_policy_set_aes_gcm_128_16_auth(&receiver_policy.rtcp); - receiver_policy.key = test_key_gcm; -#else - srtp_crypto_policy_set_rtp_default(&receiver_policy.rtp); - srtp_crypto_policy_set_rtcp_default(&receiver_policy.rtcp); - receiver_policy.key = test_key; -#endif - receiver_policy.ssrc.type = ssrc_specific; - receiver_policy.ssrc.value = sender_policy.ssrc.value; - receiver_policy.window_size = 128; - - status = srtp_create(&receiver_session, &receiver_policy); - if (status) { - return status; - } - - /* Make a copy of the first sent protected packet */ - recv_pkt_1 = malloc(protected_msg_len_octets_1); - if (recv_pkt_1 == NULL) { - return srtp_err_status_fail; - } - memcpy(recv_pkt_1, pkt_1, protected_msg_len_octets_1); - - /* Make a copy of the second sent protected packet */ - recv_pkt_2 = malloc(protected_msg_len_octets_2); - if (recv_pkt_2 == NULL) { - return srtp_err_status_fail; - } - memcpy(recv_pkt_2, pkt_2, protected_msg_len_octets_2); - - /* Set the ROC to the wanted value */ - status = - srtp_set_stream_roc(receiver_session, receiver_policy.ssrc.value, 1); - if (status) { - return status; - } - - /* Unprotect the first packet */ - status = srtp_unprotect(receiver_session, recv_pkt_1, - &protected_msg_len_octets_1); - if (status) { - return status; - } - - /* Unprotect the second packet */ - status = srtp_unprotect(receiver_session, recv_pkt_2, - &protected_msg_len_octets_2); - if (status) { - return status; - } - - /* Cleanup */ - status = srtp_dealloc(sender_session); + status = test_set_receiver_roc(packets + 65535, roc); if (status) { return status; } - status = srtp_dealloc(receiver_session); - if (status) { - return status; - } - - free(pkt_1); - free(recv_pkt_1); - free(pkt_2); - free(recv_pkt_2); - return srtp_err_status_ok; } From 94e7d4016a356c41bb920465c81dfcb1e378299e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Fri, 4 Feb 2022 09:41:55 +0100 Subject: [PATCH 042/109] Update test/srtp_driver.c format code --- test/srtp_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/srtp_driver.c b/test/srtp_driver.c index d7c6d368b..b8c14c771 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -3517,7 +3517,7 @@ static srtp_err_status_t test_set_receiver_roc(uint32_t packets, } while (stride > (packets - i) && stride > 1) { - stride >>= 1; + stride >>= 1; } i += stride; From d3e154bd8378f2eefabd8ed808bf77e27e762732 Mon Sep 17 00:00:00 2001 From: Klemens Nanni Date: Sun, 16 Jan 2022 00:19:28 +0300 Subject: [PATCH 043/109] test: Use pkill(1) not killall(1) Not all operating systems, e.g. OpenBSD, have killall; pkill(1) however should be available on all OSes shipping killall(1). This makes tests pass on OpenBSD without further changes. --- test/rtpw_test.sh | 4 ++-- test/rtpw_test_gcm.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/rtpw_test.sh b/test/rtpw_test.sh index 8fcb35f36..d6d047449 100755 --- a/test/rtpw_test.sh +++ b/test/rtpw_test.sh @@ -66,13 +66,13 @@ key=Ky7cUDT2GnI0XKWYbXv9AYmqbcLsqzL9mvdN9t/G ARGS="-b $key -a -e 128" -# First, we run "killall" to get rid of all existing rtpw processes. +# First, we run "pkill" to get rid of all existing rtpw processes. # This step also enables this script to clean up after itself; if this # script is interrupted after the rtpw processes are started but before # they are killed, those processes will linger. Re-running the script # will get rid of them. -killall rtpw 2>/dev/null +pkill -x rtpw 2>/dev/null if test -n $MESON_EXE_WRAPPER || test -x $RTPW; then diff --git a/test/rtpw_test_gcm.sh b/test/rtpw_test_gcm.sh index 1722f44ea..e0cf9c103 100755 --- a/test/rtpw_test_gcm.sh +++ b/test/rtpw_test_gcm.sh @@ -62,13 +62,13 @@ RTPW=./rtpw$EXE DEST_PORT=9999 DURATION=3 -# First, we run "killall" to get rid of all existing rtpw processes. +# First, we run "pkill" to get rid of all existing rtpw processes. # This step also enables this script to clean up after itself; if this # script is interrupted after the rtpw processes are started but before # they are killed, those processes will linger. Re-running the script # will get rid of them. -killall rtpw 2>/dev/null +pkill -x rtpw 2>/dev/null if test -n $MESON_EXE_WRAPPER || test -x $RTPW; then From d2fbea82d71f2f79ad05630cd145299acfdcb128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Tue, 22 Feb 2022 17:52:08 +0100 Subject: [PATCH 044/109] Update autotools.yml update to new "main" branch name --- .github/workflows/autotools.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/autotools.yml b/.github/workflows/autotools.yml index fd98794bb..ee94f06ba 100644 --- a/.github/workflows/autotools.yml +++ b/.github/workflows/autotools.yml @@ -2,9 +2,9 @@ name: AutoTools CI on: push: - branches: [ master ] + branches: [ main ] pull_request: - branches: [ master ] + branches: [ main ] jobs: build: From 06707077cdf2ccd3fe3eca6a66c9ff53edce358a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Tue, 22 Feb 2022 17:52:38 +0100 Subject: [PATCH 045/109] Update cmake.yml update to new "main" branch name --- .github/workflows/cmake.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 109e5f22a..f4bd13ba6 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -2,9 +2,9 @@ name: CMake CI on: push: - branches: [ master ] + branches: [ main ] pull_request: - branches: [ master ] + branches: [ main ] jobs: build: From 003202b994f2c54cd8cae94a8a185baf9837d654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Tue, 22 Feb 2022 17:53:11 +0100 Subject: [PATCH 046/109] Update format_check.yml update to new "main" branch name --- .github/workflows/format_check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml index ce88ba265..bc7f632fa 100644 --- a/.github/workflows/format_check.yml +++ b/.github/workflows/format_check.yml @@ -2,9 +2,9 @@ name: Code Formatting Check on: push: - branches: [ master ] + branches: [ main ] pull_request: - branches: [ master ] + branches: [ main ] jobs: format-check: From 53e2b5b22456e340fb009ee3929550d7e72cd412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Tue, 22 Feb 2022 17:53:50 +0100 Subject: [PATCH 047/109] Update fuzzer_build.yml update to new "main" branch name --- .github/workflows/fuzzer_build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/fuzzer_build.yml b/.github/workflows/fuzzer_build.yml index 3139cd3b0..e43e80d05 100644 --- a/.github/workflows/fuzzer_build.yml +++ b/.github/workflows/fuzzer_build.yml @@ -3,9 +3,9 @@ name: Fuzzer build check on: push: - branches: [ master ] + branches: [ main ] pull_request: - branches: [ master ] + branches: [ main ] workflow_dispatch: jobs: From 11366ac018642e06a5c05018937ef34d13b66a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Tue, 22 Feb 2022 17:54:29 +0100 Subject: [PATCH 048/109] Update coverity_scan.yml update to new "main" branch name --- .github/workflows/coverity_scan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverity_scan.yml b/.github/workflows/coverity_scan.yml index 699c7d2a0..f5a25d945 100644 --- a/.github/workflows/coverity_scan.yml +++ b/.github/workflows/coverity_scan.yml @@ -1,7 +1,7 @@ name: Start Coverity Scan on: push: - branches: [ master ] + branches: [ main ] workflow_dispatch: jobs: From c8a9fd19f1136965d50f76d5ef39ef506fed1d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 2 May 2022 09:32:00 +0200 Subject: [PATCH 049/109] Treat warnings as errors when building with cmake This will catch OpenSSL deprecated api warnings. Only enabled for Clang and GNU at this point. --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec76b385d..76b3fb4d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,10 @@ if(BUILD_WITH_SANITIZERS AND NOT WIN32) set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=${SANITIZERS}") endif() +if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU") + add_compile_options(-Werror) +endif() + set(SOURCES_C srtp/srtp.c ) From 2a12d3b5fff4a90170cd8f82484d39a7e5364fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 2 May 2022 10:52:08 +0200 Subject: [PATCH 050/109] Add more wranings flags to cmake CI build Enable warnings as errors on windows. --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 76b3fb4d8..658127c4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,7 +117,9 @@ if(BUILD_WITH_SANITIZERS AND NOT WIN32) endif() if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU") - add_compile_options(-Werror) + add_compile_options(-Wall -pedantic -Wextra -Werror) +elseif(MSVC) + add_compile_options(/W4 /WX) endif() set(SOURCES_C From b19d4e50e46de0f06e0924609e053298e712fa03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 2 May 2022 10:56:05 +0200 Subject: [PATCH 051/109] Fix warnings after enabling in CI --- crypto/cipher/aes_gcm_mbedtls.c | 2 -- crypto/cipher/aes_gcm_ossl.c | 2 +- crypto/cipher/aes_icm.c | 2 ++ crypto/cipher/aes_icm_mbedtls.c | 3 +++ crypto/cipher/aes_icm_nss.c | 2 ++ crypto/cipher/aes_icm_ossl.c | 2 ++ crypto/cipher/null_cipher.c | 10 +++++++++- crypto/hash/hmac_nss.c | 2 +- crypto/hash/hmac_ossl.c | 2 +- crypto/hash/null_auth.c | 13 +++++++++++++ crypto/include/datatypes.h | 5 +++++ crypto/replay/rdbx.c | 2 +- crypto/test/cipher_driver.c | 2 +- crypto/test/datatypes_driver.c | 8 ++++---- crypto/test/sha1_driver.c | 2 +- srtp/srtp.c | 7 +++---- test/rdbx_driver.c | 8 ++++---- test/roc_driver.c | 2 +- test/rtp_decoder.c | 13 +++++++------ test/rtp_decoder.h | 4 ++-- test/srtp_driver.c | 9 +++++++-- test/test_srtp.c | 5 ++--- test/ut_sim.c | 2 ++ test/util.c | 6 ++---- 24 files changed, 76 insertions(+), 39 deletions(-) diff --git a/crypto/cipher/aes_gcm_mbedtls.c b/crypto/cipher/aes_gcm_mbedtls.c index d7d4b61cd..05b83804b 100644 --- a/crypto/cipher/aes_gcm_mbedtls.c +++ b/crypto/cipher/aes_gcm_mbedtls.c @@ -256,7 +256,6 @@ static srtp_err_status_t srtp_aes_gcm_mbedtls_set_aad(void *cv, uint32_t aad_len) { FUNC_ENTRY(); - int errCode = 0; srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv; debug_print(srtp_mod_aes_gcm, "setting AAD: %s", @@ -343,7 +342,6 @@ static srtp_err_status_t srtp_aes_gcm_mbedtls_decrypt(void *cv, FUNC_ENTRY(); srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv; int errCode = 0; - int len = *enc_len; if (c->dir != srtp_direction_encrypt && c->dir != srtp_direction_decrypt) { return (srtp_err_status_bad_param); diff --git a/crypto/cipher/aes_gcm_ossl.c b/crypto/cipher/aes_gcm_ossl.c index 2b87561bb..1c900f207 100644 --- a/crypto/cipher/aes_gcm_ossl.c +++ b/crypto/cipher/aes_gcm_ossl.c @@ -280,7 +280,7 @@ static srtp_err_status_t srtp_aes_gcm_openssl_set_aad(void *cv, } rv = EVP_Cipher(c->ctx, NULL, aad, aad_len); - if (rv != aad_len) { + if (rv < 0 || (uint32_t)rv != aad_len) { return (srtp_err_status_algo_fail); } else { return (srtp_err_status_ok); diff --git a/crypto/cipher/aes_icm.c b/crypto/cipher/aes_icm.c index 561747145..a5426dd22 100644 --- a/crypto/cipher/aes_icm.c +++ b/crypto/cipher/aes_icm.c @@ -98,6 +98,7 @@ static srtp_err_status_t srtp_aes_icm_alloc(srtp_cipher_t **c, int tlen) { srtp_aes_icm_ctx_t *icm; + (void)tlen; debug_print(srtp_mod_aes_icm, "allocating cipher with key length %d", key_len); @@ -238,6 +239,7 @@ static srtp_err_status_t srtp_aes_icm_set_iv(void *cv, { srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv; v128_t nonce; + (void)direction; /* set nonce (for alignment) */ v128_copy_octet_string(&nonce, iv); diff --git a/crypto/cipher/aes_icm_mbedtls.c b/crypto/cipher/aes_icm_mbedtls.c index 9893ded70..bb5c4b79f 100644 --- a/crypto/cipher/aes_icm_mbedtls.c +++ b/crypto/cipher/aes_icm_mbedtls.c @@ -118,6 +118,7 @@ static srtp_err_status_t srtp_aes_icm_mbedtls_alloc(srtp_cipher_t **c, int tlen) { srtp_aes_icm_ctx_t *icm; + (void)tlen; debug_print(srtp_mod_aes_icm, "allocating cipher with key length %d", key_len); @@ -264,6 +265,8 @@ static srtp_err_status_t srtp_aes_icm_mbedtls_set_iv( { srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv; v128_t nonce; + (void)dir; + c->nc_off = 0; /* set nonce (for alignment) */ v128_copy_octet_string(&nonce, iv); diff --git a/crypto/cipher/aes_icm_nss.c b/crypto/cipher/aes_icm_nss.c index 04323b4fe..e08ecff67 100644 --- a/crypto/cipher/aes_icm_nss.c +++ b/crypto/cipher/aes_icm_nss.c @@ -107,6 +107,7 @@ static srtp_err_status_t srtp_aes_icm_nss_alloc(srtp_cipher_t **c, { srtp_aes_icm_ctx_t *icm; NSSInitContext *nss; + (void)tlen; debug_print(srtp_mod_aes_icm, "allocating cipher with key length %d", key_len); @@ -275,6 +276,7 @@ static srtp_err_status_t srtp_aes_icm_nss_set_iv(void *cv, { srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv; v128_t nonce; + (void)dir; /* set nonce (for alignment) */ v128_copy_octet_string(&nonce, iv); diff --git a/crypto/cipher/aes_icm_ossl.c b/crypto/cipher/aes_icm_ossl.c index e0aea4fae..c468d73e5 100644 --- a/crypto/cipher/aes_icm_ossl.c +++ b/crypto/cipher/aes_icm_ossl.c @@ -112,6 +112,7 @@ static srtp_err_status_t srtp_aes_icm_openssl_alloc(srtp_cipher_t **c, int tlen) { srtp_aes_icm_ctx_t *icm; + (void)tlen; debug_print(srtp_mod_aes_icm, "allocating cipher with key length %d", key_len); @@ -275,6 +276,7 @@ static srtp_err_status_t srtp_aes_icm_openssl_set_iv( { srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv; v128_t nonce; + (void)dir; /* set nonce (for alignment) */ v128_copy_octet_string(&nonce, iv); diff --git a/crypto/cipher/null_cipher.c b/crypto/cipher/null_cipher.c index 969724611..a58ba5c91 100644 --- a/crypto/cipher/null_cipher.c +++ b/crypto/cipher/null_cipher.c @@ -59,6 +59,7 @@ static srtp_err_status_t srtp_null_cipher_alloc(srtp_cipher_t **c, int tlen) { extern const srtp_cipher_type_t srtp_null_cipher; + (void)tlen; debug_print(srtp_mod_cipher, "allocating cipher with key length %d", key_len); @@ -96,7 +97,8 @@ static srtp_err_status_t srtp_null_cipher_dealloc(srtp_cipher_t *c) static srtp_err_status_t srtp_null_cipher_init(void *cv, const uint8_t *key) { /* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */ - + (void)cv; + (void)key; debug_print0(srtp_mod_cipher, "initializing null cipher"); return srtp_err_status_ok; @@ -107,6 +109,9 @@ static srtp_err_status_t srtp_null_cipher_set_iv(void *cv, srtp_cipher_direction_t dir) { /* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */ + (void)cv; + (void)iv; + (void)dir; return srtp_err_status_ok; } @@ -115,6 +120,9 @@ static srtp_err_status_t srtp_null_cipher_encrypt(void *cv, unsigned int *bytes_to_encr) { /* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */ + (void)cv; + (void)buf; + (void)bytes_to_encr; return srtp_err_status_ok; } diff --git a/crypto/hash/hmac_nss.c b/crypto/hash/hmac_nss.c index 8d1e42f62..d815b46cf 100644 --- a/crypto/hash/hmac_nss.c +++ b/crypto/hash/hmac_nss.c @@ -256,7 +256,7 @@ static srtp_err_status_t srtp_hmac_compute(void *statev, return srtp_err_status_auth_fail; } - if (len < tag_len) + if (tag_len < 0 || len < (unsigned int)tag_len) return srtp_err_status_auth_fail; /* copy hash_value to *result */ diff --git a/crypto/hash/hmac_ossl.c b/crypto/hash/hmac_ossl.c index c23c7f216..c5b54ac57 100644 --- a/crypto/hash/hmac_ossl.c +++ b/crypto/hash/hmac_ossl.c @@ -179,7 +179,7 @@ static srtp_err_status_t srtp_hmac_compute(void *statev, if (HMAC_Final(state, hash_value, &len) == 0) return srtp_err_status_auth_fail; - if (len < tag_len) + if (tag_len < 0 || len < (unsigned int)tag_len) return srtp_err_status_auth_fail; /* copy hash_value to *result */ diff --git a/crypto/hash/null_auth.c b/crypto/hash/null_auth.c index 5194417ca..ae723c2ca 100644 --- a/crypto/hash/null_auth.c +++ b/crypto/hash/null_auth.c @@ -102,6 +102,10 @@ static srtp_err_status_t srtp_null_auth_init(void *statev, int key_len) { /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ + (void)statev; + (void)key; + (void)key_len; + /* accept any length of key, and do nothing */ return srtp_err_status_ok; @@ -114,6 +118,11 @@ static srtp_err_status_t srtp_null_auth_compute(void *statev, uint8_t *result) { /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ + (void)statev; + (void)message; + (void)msg_octets; + (void)tag_len; + (void)result; return srtp_err_status_ok; } @@ -123,6 +132,9 @@ static srtp_err_status_t srtp_null_auth_update(void *statev, int msg_octets) { /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ + (void)statev; + (void)message; + (void)msg_octets; return srtp_err_status_ok; } @@ -130,6 +142,7 @@ static srtp_err_status_t srtp_null_auth_update(void *statev, static srtp_err_status_t srtp_null_auth_start(void *statev) { /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ + (void)statev; return srtp_err_status_ok; } diff --git a/crypto/include/datatypes.h b/crypto/include/datatypes.h index 5164cf002..98042a379 100644 --- a/crypto/include/datatypes.h +++ b/crypto/include/datatypes.h @@ -166,6 +166,11 @@ void octet_string_set_to_zero(void *s, size_t len); #include #define be32_to_cpu(x) bswap_32((x)) #define be64_to_cpu(x) bswap_64((x)) +#elif defined(__APPLE__) +// Mac OS X / Darwin features +#include +#define be32_to_cpu(x) OSSwapInt32(x) +#define be64_to_cpu(x) OSSwapInt64(x) #else /* WORDS_BIGENDIAN */ #if defined(__GNUC__) && (defined(HAVE_X86) || defined(__x86_64__)) diff --git a/crypto/replay/rdbx.c b/crypto/replay/rdbx.c index 97ff719ac..e12005cd4 100644 --- a/crypto/replay/rdbx.c +++ b/crypto/replay/rdbx.c @@ -279,7 +279,7 @@ srtp_err_status_t srtp_rdbx_add_index(srtp_rdbx_t *rdbx, int delta) { if (delta > 0) { /* shift forward by delta */ - srtp_index_advance(&rdbx->index, delta); + srtp_index_advance(&rdbx->index, (srtp_sequence_number_t)delta); bitvector_left_shift(&rdbx->bitmask, delta); bitvector_set_bit(&rdbx->bitmask, bitvector_get_length(&rdbx->bitmask) - 1); diff --git a/crypto/test/cipher_driver.c b/crypto/test/cipher_driver.c index 4fbcd95e3..33f8e73ec 100644 --- a/crypto/test/cipher_driver.c +++ b/crypto/test/cipher_driver.c @@ -389,7 +389,7 @@ srtp_err_status_t cipher_driver_test_buffering(srtp_cipher_t *c) /* make sure that len doesn't cause us to overreach the buffer */ if (current + len > end) - len = end - current; + len = (unsigned)(end - current); status = srtp_cipher_encrypt(c, current, &len); if (status) diff --git a/crypto/test/datatypes_driver.c b/crypto/test/datatypes_driver.c index db1be7f66..95a14c59f 100644 --- a/crypto/test/datatypes_driver.c +++ b/crypto/test/datatypes_driver.c @@ -139,12 +139,12 @@ int main(void) void byte_order(void) { - int i; + size_t i; v128_t e; printf("byte ordering of crypto/math datatypes:\n"); for (i = 0; i < sizeof(e); i++) - e.v8[i] = i; + e.v8[i] = (uint8_t)i; printf("v128_t: %s\n", v128_hex_string(&e)); } @@ -155,12 +155,12 @@ void test_hex_string_funcs(void) char raw[10]; int len; - len = hex_string_to_octet_string(raw, hex1, strlen(hex1)); + len = hex_string_to_octet_string(raw, hex1, (int)strlen(hex1)); printf("computed length: %d\tstring: %s\n", len, octet_string_hex_string(raw, len / 2)); printf("expected length: %u\tstring: %s\n", (unsigned)strlen(hex1), hex1); - len = hex_string_to_octet_string(raw, hex2, strlen(hex2)); + len = hex_string_to_octet_string(raw, hex2, (int)strlen(hex2)); printf("computed length: %d\tstring: %s\n", len, octet_string_hex_string(raw, len / 2)); printf("expected length: %d\tstring: %s\n", 16, "0123456789abcdef"); diff --git a/crypto/test/sha1_driver.c b/crypto/test/sha1_driver.c index 160a4b9a9..0d7089a5e 100644 --- a/crypto/test/sha1_driver.c +++ b/crypto/test/sha1_driver.c @@ -143,7 +143,7 @@ srtp_err_status_t sha1_test_case_validate(const hash_test_case_t *test_case) struct hex_sha1_test_case_t { unsigned bit_len; char hex_data[MAX_HASH_DATA_LEN * 2]; - char hex_hash[40]; + char hex_hash[40 + 1]; }; srtp_err_status_t sha1_add_test_cases(void) diff --git a/srtp/srtp.c b/srtp/srtp.c index c47830b2a..2d3faaf47 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -1845,7 +1845,7 @@ static srtp_err_status_t srtp_protect_aead(srtp_ctx_t *ctx, /* * Set the AAD over the RTP header */ - aad_len = (uint8_t *)enc_start - (uint8_t *)hdr; + aad_len = (uint32_t)((uint8_t *)enc_start - (uint8_t *)hdr); status = srtp_cipher_set_aad(session_keys->rtp_cipher, (uint8_t *)hdr, aad_len); if (status) { @@ -1991,7 +1991,7 @@ static srtp_err_status_t srtp_unprotect_aead(srtp_ctx_t *ctx, /* * Set the AAD for AES-GCM, which is the RTP header */ - aad_len = (uint8_t *)enc_start - (uint8_t *)hdr; + aad_len = (uint32_t)((uint8_t *)enc_start - (uint8_t *)hdr); status = srtp_cipher_set_aad(session_keys->rtp_cipher, (uint8_t *)hdr, aad_len); if (status) { @@ -3552,7 +3552,6 @@ static srtp_err_status_t srtp_calc_aead_iv_srtcp( * AES-GCM mode with 128 or 256 bit keys. */ static srtp_err_status_t srtp_protect_rtcp_aead( - srtp_t ctx, srtp_stream_ctx_t *stream, void *rtcp_hdr, unsigned int *pkt_octet_len, @@ -4004,7 +4003,7 @@ srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx, */ if (session_keys->rtp_cipher->algorithm == SRTP_AES_GCM_128 || session_keys->rtp_cipher->algorithm == SRTP_AES_GCM_256) { - return srtp_protect_rtcp_aead(ctx, stream, rtcp_hdr, + return srtp_protect_rtcp_aead(stream, rtcp_hdr, (unsigned int *)pkt_octet_len, session_keys, use_mki); } diff --git a/test/rdbx_driver.c b/test/rdbx_driver.c index 430e28389..2cb676f0f 100644 --- a/test/rdbx_driver.c +++ b/test/rdbx_driver.c @@ -143,7 +143,7 @@ srtp_err_status_t rdbx_check_add(srtp_rdbx_t *rdbx, uint32_t idx) int delta; srtp_xtd_seq_num_t est; - delta = srtp_index_guess(&rdbx->index, &est, idx); + delta = srtp_index_guess(&rdbx->index, &est, (srtp_sequence_number_t)idx); if (srtp_rdbx_check(rdbx, delta) != srtp_err_status_ok) { printf("replay_check failed at index %u\n", idx); @@ -176,7 +176,7 @@ srtp_err_status_t rdbx_check_expect_failure(srtp_rdbx_t *rdbx, uint32_t idx) srtp_xtd_seq_num_t est; srtp_err_status_t status; - delta = srtp_index_guess(&rdbx->index, &est, idx); + delta = srtp_index_guess(&rdbx->index, &est, (srtp_sequence_number_t)idx); status = srtp_rdbx_check(rdbx, delta); if (status == srtp_err_status_ok) { @@ -194,7 +194,7 @@ srtp_err_status_t rdbx_check_add_unordered(srtp_rdbx_t *rdbx, uint32_t idx) srtp_xtd_seq_num_t est; srtp_err_status_t rstat; - delta = srtp_index_guess(&rdbx->index, &est, idx); + delta = srtp_index_guess(&rdbx->index, &est, (srtp_sequence_number_t)idx); rstat = srtp_rdbx_check(rdbx, delta); if ((rstat != srtp_err_status_ok) && @@ -333,7 +333,7 @@ double rdbx_check_adds_per_second(int num_trials, unsigned long ws) failures = 0; timer = clock(); for (i = 0; (int)i < num_trials; i++) { - delta = srtp_index_guess(&rdbx.index, &est, i); + delta = srtp_index_guess(&rdbx.index, &est, (srtp_sequence_number_t)i); if (srtp_rdbx_check(&rdbx, delta) != srtp_err_status_ok) ++failures; diff --git a/test/roc_driver.c b/test/roc_driver.c index 439862039..11d1bbb0c 100644 --- a/test/roc_driver.c +++ b/test/roc_driver.c @@ -145,7 +145,7 @@ srtp_err_status_t roc_test(int num_trials) /* now update local srtp_xtd_seq_num_t as necessary */ if (delta > 0) - srtp_index_advance(&local, delta); + srtp_index_advance(&local, (srtp_sequence_number_t)delta); if (ref != est) { #if ROC_VERBOSE diff --git a/test/rtp_decoder.c b/test/rtp_decoder.c index 9bbf62ea2..c5d052b82 100644 --- a/test/rtp_decoder.c +++ b/test/rtp_decoder.c @@ -135,6 +135,7 @@ void rtp_decoder_srtp_log_handler(srtp_log_level_t level, const char *msg, void *data) { + (void)data; char level_char = '?'; switch (level) { case srtp_log_level_error: @@ -173,9 +174,9 @@ int main(int argc, char *argv[]) struct bpf_program fp; char filter_exp[MAX_FILTER] = ""; char pcap_file[MAX_FILE] = "-"; - int rtp_packet_offset = DEFAULT_RTP_OFFSET; + size_t rtp_packet_offset = DEFAULT_RTP_OFFSET; rtp_decoder_t dec; - srtp_policy_t policy = { { 0 } }; + srtp_policy_t policy = { 0 }; rtp_decoder_mode_t mode = mode_rtp; srtp_ssrc_t ssrc = { ssrc_any_inbound, 0 }; uint32_t roc = 0; @@ -555,7 +556,7 @@ int main(int argc, char *argv[]) expected_len, len); exit(1); } - if (strlen(input_key) > policy.rtp.cipher_key_len * 2) { + if (strlen(input_key) > (size_t)policy.rtp.cipher_key_len * 2) { fprintf(stderr, "error: too many digits in key/salt " "(should be %d hexadecimal digits, found %u)\n", @@ -684,7 +685,7 @@ int rtp_decoder_deinit(rtp_decoder_t decoder) int rtp_decoder_init(rtp_decoder_t dcdr, srtp_policy_t policy, rtp_decoder_mode_t mode, - int rtp_packet_offset, + size_t rtp_packet_offset, uint32_t roc) { dcdr->rtp_offset = rtp_packet_offset; @@ -716,11 +717,11 @@ int rtp_decoder_init(rtp_decoder_t dcdr, void hexdump(const void *ptr, size_t size) { - int i, j; + size_t i, j; const unsigned char *cptr = ptr; for (i = 0; i < size; i += 16) { - fprintf(stdout, "%04x ", i); + fprintf(stdout, "%04x ", (unsigned int)i); for (j = 0; j < 16 && i + j < size; j++) { fprintf(stdout, "%02x ", cptr[i + j]); } diff --git a/test/rtp_decoder.h b/test/rtp_decoder.h index 6a9c15134..fd63bac96 100644 --- a/test/rtp_decoder.h +++ b/test/rtp_decoder.h @@ -62,7 +62,7 @@ typedef struct rtp_decoder_ctx_t { srtp_policy_t policy; srtp_ctx_t *srtp_ctx; rtp_decoder_mode_t mode; - int rtp_offset; + size_t rtp_offset; struct timeval start_tv; int frame_nr; int error_cnt; @@ -102,7 +102,7 @@ void rtp_decoder_dealloc(rtp_decoder_t rtp_ctx); int rtp_decoder_init(rtp_decoder_t dcdr, srtp_policy_t policy, rtp_decoder_mode_t mode, - int rtp_packet_offset, + size_t rtp_packet_offset, uint32_t roc); int rtp_decoder_deinit(rtp_decoder_t decoder); diff --git a/test/srtp_driver.c b/test/srtp_driver.c index b8c14c771..07e511383 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -168,6 +168,7 @@ void usage(char *prog_name) void log_handler(srtp_log_level_t level, const char *msg, void *data) { char level_char = '?'; + (void)data; switch (level) { case srtp_log_level_error: level_char = 'e'; @@ -219,12 +220,13 @@ int main(int argc, char *argv[]) unsigned do_list_mods = 0; unsigned do_log_stdout = 0; srtp_err_status_t status; + size_t hdr_size = 12; /* * verify that the compiler has interpreted the header data * structure srtp_hdr_t correctly */ - if (sizeof(srtp_hdr_t) != 12) { + if (sizeof(srtp_hdr_t) != hdr_size) { printf("error: srtp_hdr_t has incorrect size" "(size is %ld bytes, expected 12)\n", (long)sizeof(srtp_hdr_t)); @@ -2986,6 +2988,9 @@ srtp_err_status_t srtp_test_setup_protect_trailer_streams( #ifdef GCM srtp_policy_t policy_aes_gcm; srtp_policy_t policy_aes_gcm_mki; +#else + (void)srtp_send_aes_gcm; + (void)srtp_send_aes_gcm_mki; #endif // GCM memset(&policy, 0, sizeof(policy)); @@ -3181,7 +3186,7 @@ srtp_err_status_t srtp_test_out_of_order_after_rollover() srtp_policy_t receiver_policy; srtp_t receiver_session; - const int num_pkts = 5; + const uint32_t num_pkts = 5; srtp_hdr_t *pkts[5]; int pkt_len_octets[5]; diff --git a/test/test_srtp.c b/test/test_srtp.c index 0cea1f3c3..7d2051b7e 100644 --- a/test/test_srtp.c +++ b/test/test_srtp.c @@ -78,7 +78,7 @@ TEST_LIST = { { "srtp_calc_aead_iv_srtcp_all_zero_input_yield_zero_output()", srtp_calc_aead_iv_srtcp_seq_num_over_0x7FFFFFFF_bad_param }, { "srtp_calc_aead_iv_srtcp_distinct_iv_per_sequence_number()", srtp_calc_aead_iv_srtcp_distinct_iv_per_sequence_number }, - { NULL } /* End of tests */ }; + { 0 } /* End of tests */ }; /* * Implementation. @@ -94,8 +94,7 @@ void srtp_calc_aead_iv_srtcp_all_zero_input_yield_zero_output() // Postconditions srtp_err_status_t status; - const v128_t zero_vector; - memset((v128_t *)&zero_vector, 0, sizeof(v128_t)); + const v128_t zero_vector = { 0 }; // Given memset(&session_keys, 0, sizeof(srtp_session_keys_t)); diff --git a/test/ut_sim.c b/test/ut_sim.c index 2825b68df..98d9ab283 100644 --- a/test/ut_sim.c +++ b/test/ut_sim.c @@ -54,6 +54,8 @@ int ut_compar(const void *a, const void *b) { uint8_t r; + (void)a; + (void)b; srtp_cipher_rand_for_tests(&r, sizeof(r)); return r > (UINT8_MAX / 2) ? -1 : 1; } diff --git a/test/util.c b/test/util.c index c0f761490..ac2d9a2b7 100644 --- a/test/util.c +++ b/test/util.c @@ -101,8 +101,6 @@ static inline int hex_char_to_nibble(uint8_t c) default: return -1; /* this flags an error */ } - /* NOTREACHED */ - return -1; /* this keeps compilers from complaining */ } uint8_t nibble_to_hex_char(uint8_t nibble) @@ -129,7 +127,7 @@ int hex_string_to_octet_string(char *raw, char *hex, int len) if (tmp == -1) { return hex_len; } - x = (tmp << 4); + x = (uint8_t)(tmp << 4); hex_len++; tmp = hex_char_to_nibble(hex[1]); if (tmp == -1) { @@ -176,7 +174,7 @@ static int base64_block_to_octet_triple(char *out, char *in) for (i = 0; i < 4; i++) { char *p = strchr(b64chars, in[i]); if (p != NULL) { - sextets[i] = p - b64chars; + sextets[i] = (unsigned char)(p - b64chars); } else { j++; } From 324b4ff3416c16e2055b99dd4c1bff4cc90526a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 2 May 2022 20:03:08 +0200 Subject: [PATCH 052/109] set hdr_size as const --- test/srtp_driver.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/srtp_driver.c b/test/srtp_driver.c index 07e511383..fd199c5bf 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -220,7 +220,7 @@ int main(int argc, char *argv[]) unsigned do_list_mods = 0; unsigned do_log_stdout = 0; srtp_err_status_t status; - size_t hdr_size = 12; + const size_t hdr_size = 12; /* * verify that the compiler has interpreted the header data @@ -228,8 +228,8 @@ int main(int argc, char *argv[]) */ if (sizeof(srtp_hdr_t) != hdr_size) { printf("error: srtp_hdr_t has incorrect size" - "(size is %ld bytes, expected 12)\n", - (long)sizeof(srtp_hdr_t)); + "(size is %ld bytes, expected %ld)\n", + (long)sizeof(srtp_hdr_t), (long)hdr_size); exit(1); } From fa104f4778addb0c3d6dbe06a066816373751818 Mon Sep 17 00:00:00 2001 From: Rick Porter <99488405+rickwporter@users.noreply.github.com> Date: Wed, 4 May 2022 09:00:42 -0400 Subject: [PATCH 053/109] Fix compile error due to unused variable Without this change, I see the following error: In file included from test/test_srtp.c:54: ./test/cutest.h:262:16: warning: variable 'n' set but not used [-Wunused-but-set-variable] size_t n = 0; ^ --- test/cutest.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/cutest.h b/test/cutest.h index f46626d39..f64667143 100644 --- a/test/cutest.h +++ b/test/cutest.h @@ -259,16 +259,15 @@ int test_check__(int cond, const char *file, int line, const char *fmt, ...) } if (test_verbose_level__ >= verbose_level) { - size_t n = 0; va_list args; printf(" "); if (file != NULL) - n += printf("%s:%d: Check ", file, line); + printf("%s:%d: Check ", file, line); va_start(args, fmt); - n += vprintf(fmt, args); + vprintf(fmt, args); va_end(args); printf("... "); From adc976fe324a71ad1c81ea15f28da866345bae2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Wed, 4 May 2022 20:52:41 +0200 Subject: [PATCH 054/109] cmake warnings as errors configurable Default on. --- CMakeLists.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 658127c4f..8454caa80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,7 @@ set(ENABLE_MBEDTLS OFF CACHE BOOL "Enable MbedTLS crypto engine") set(ENABLE_NSS OFF CACHE BOOL "Enable NSS crypto engine") set(TEST_APPS ON CACHE BOOL "Build test applications") set(BUILD_WITH_SANITIZERS OFF CACHE BOOL "Adds sanitizer flags to compiler") +set(BUILD_WITH_WARNINGS ON CACHE BOOL "Adds warnings and warning as error flags to compiler") option(BUILD_SHARED_LIBS "Build shared library" OFF) if(ENABLE_OPENSSL OR ENABLE_MBEDTLS OR ENABLE_NSS) @@ -116,10 +117,13 @@ if(BUILD_WITH_SANITIZERS AND NOT WIN32) set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=${SANITIZERS}") endif() -if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU") - add_compile_options(-Wall -pedantic -Wextra -Werror) -elseif(MSVC) - add_compile_options(/W4 /WX) + +if(BUILD_WITH_WARNINGS) + if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU") + add_compile_options(-Wall -pedantic -Wextra -Werror) + elseif(MSVC) + add_compile_options(/W4 /WX) + endif() endif() set(SOURCES_C From c93b79f16161a52b1d01bb202e4bdb24691f6dc6 Mon Sep 17 00:00:00 2001 From: "Paul E. Jones" Date: Mon, 30 May 2022 15:07:05 -0400 Subject: [PATCH 055/109] Minor edits: unreached line of code, consistency, spelling --- crypto/cipher/aes_icm_ossl.c | 8 +++----- crypto/hash/hmac_ossl.c | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/crypto/cipher/aes_icm_ossl.c b/crypto/cipher/aes_icm_ossl.c index c468d73e5..b76c4fbc5 100644 --- a/crypto/cipher/aes_icm_ossl.c +++ b/crypto/cipher/aes_icm_ossl.c @@ -169,7 +169,7 @@ static srtp_err_status_t srtp_aes_icm_openssl_alloc(srtp_cipher_t **c, break; } - /* set key size */ + /* set key size */ (*c)->key_len = key_len; return srtp_err_status_ok; @@ -258,8 +258,6 @@ static srtp_err_status_t srtp_aes_icm_openssl_context_init(void *cv, if (!EVP_EncryptInit_ex(c->ctx, evp, NULL, key, NULL)) { return srtp_err_status_fail; - } else { - return srtp_err_status_ok; } return srtp_err_status_ok; @@ -290,9 +288,9 @@ static srtp_err_status_t srtp_aes_icm_openssl_set_iv( if (!EVP_EncryptInit_ex(c->ctx, NULL, NULL, NULL, c->counter.v8)) { return srtp_err_status_fail; - } else { - return srtp_err_status_ok; } + + return srtp_err_status_ok; } /* diff --git a/crypto/hash/hmac_ossl.c b/crypto/hash/hmac_ossl.c index c5b54ac57..d95b66328 100644 --- a/crypto/hash/hmac_ossl.c +++ b/crypto/hash/hmac_ossl.c @@ -55,7 +55,7 @@ #define SHA1_DIGEST_SIZE 20 -/* the debug module for authentiation */ +/* the debug module for authentication */ srtp_debug_module_t srtp_mod_hmac = { 0, /* debugging is off by default */ From 50675e20c5d5645b6a517941cd46e3024b6408f5 Mon Sep 17 00:00:00 2001 From: "Paul E. Jones" Date: Fri, 2 Sep 2022 02:17:42 -0400 Subject: [PATCH 056/109] Create alias for srtp2 as libSRTP::srtp2 --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8454caa80..858917a78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -248,6 +248,7 @@ add_library(srtp2 ${REPLAY_SOURCES_C} ${SOURCES_H} ) +add_library(libSRTP::srtp2 ALIAS srtp2) set_target_properties(srtp2 PROPERTIES VERSION ${CMAKE_PROJECT_VERSION}) From 6a8eea3c94a83673bcbd621d5d928dfb071c1b61 Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Mon, 5 Sep 2022 12:51:17 +0200 Subject: [PATCH 057/109] add stream list interface --- include/srtp_priv.h | 1 + include/stream_list_priv.h | 118 +++++++++++++++++++++++++++++++++++++ srtp/srtp.c | 92 +++++++++++++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 include/stream_list_priv.h diff --git a/include/srtp_priv.h b/include/srtp_priv.h index 48dc65c7d..ade8622e8 100644 --- a/include/srtp_priv.h +++ b/include/srtp_priv.h @@ -66,6 +66,7 @@ extern "C" { typedef struct srtp_stream_ctx_t_ srtp_stream_ctx_t; typedef srtp_stream_ctx_t *srtp_stream_t; +typedef struct srtp_stream_list_ctx_t_ *srtp_stream_list_t; /* * the following declarations are libSRTP internal functions diff --git a/include/stream_list_priv.h b/include/stream_list_priv.h new file mode 100644 index 000000000..815d77dce --- /dev/null +++ b/include/stream_list_priv.h @@ -0,0 +1,118 @@ +/* + * stream_list_priv.h + * + * list of SRTP streams, keyed by SSRC + * + * Alba Mendez + */ +/* + * + * Copyright (c) 2001-2017, Cisco Systems, Inc. + * Copyright (c) 2022, Dolby Laboratories, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of the Cisco Systems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef SRTP_STREAM_LIST_PRIV_H +#define SRTP_STREAM_LIST_PRIV_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * srtp_stream_list_t holds a list of srtp_stream_t, each identified + * by their SSRC. + * + * the API was extracted to allow downstreams to override its + * implementation by defining the `SRTP_NO_STREAM_LIST` preprocessor + * directive, which removes the default implementation of these + * functions. if this is done, the `next` field is free for the + * implementation to use. + * + * this is still an internal interface; there is no stability + * guarantee--downstreams should watch this file for changes in + * signatures or semantics. + */ + +/** + * allocate and initialize a stream list instance + */ +srtp_err_status_t srtp_stream_list_create(srtp_stream_list_t *list); + +/** + * insert a stream into the list + * + * ownership is transferred from caller to the list. + * + * if another stream with the same SSRC already exists in the list, + * behavior is undefined. if the SSRC field is mutated while the + * stream is inserted, further operations have undefined behavior + */ +void srtp_stream_list_insert(srtp_stream_list_t *list, srtp_stream_t stream); + +/* + * look up the stream corresponding to the specified SSRC and return it. + * if no such SSRC is found, NULL is returned. + */ +srtp_stream_t srtp_stream_list_get(srtp_stream_list_t *list, uint32_t ssrc); + +/** + * delete the stream associated to the specified SSRC. + * + * if a stream is found and removed, it's returned and ownership is + * transferred to the caller. if not found, NULL is returned. + */ +srtp_stream_t srtp_stream_list_delete(srtp_stream_list_t *list, uint32_t ssrc); + +/** + * iterate through all stored streams. while iterating, it is allowed to delete + * the current element; any other mutation to the list is undefined behavior. + * returning non-zero from callback aborts the iteration. + */ +void srtp_stream_list_for_each(srtp_stream_list_t *list, + int (*callback)(srtp_stream_t, void *), + void *data); + +/** + * deallocate a stream list instance and all streams inserted in it + */ +srtp_err_status_t srtp_stream_list_dealloc(srtp_stream_list_t *list, + srtp_stream_t template_); + +#ifdef __cplusplus +} +#endif + +#endif /* SRTP_STREAM_LIST_PRIV_H */ diff --git a/srtp/srtp.c b/srtp/srtp.c index 2d3faaf47..af1db9858 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -46,6 +46,7 @@ #include "config.h" #include "srtp_priv.h" +#include "stream_list_priv.h" #include "crypto_types.h" #include "err.h" #include "alloc.h" /* for srtp_crypto_alloc() */ @@ -4747,3 +4748,94 @@ srtp_err_status_t srtp_get_stream_roc(srtp_t session, return srtp_err_status_ok; } + +#ifndef SRTP_NO_STREAM_LIST + +/* in the default implementation, we have an intrusive linked list */ +struct { + srtp_stream_ctx_t dummy; +} srtp_stream_list_ctx_t_; + +srtp_err_status_t srtp_stream_list_create(srtp_stream_list_t *list) +{ + (*list) = NULL; + return srtp_err_status_ok; +} + +void srtp_stream_list_insert(srtp_stream_list_t *list_, srtp_stream_t stream) +{ + srtp_stream_t *list = (srtp_stream_t *)list_; + + /* insert at the head of the list */ + stream->next = (*list); + (*list) = stream; +} + +srtp_stream_t srtp_stream_list_get(srtp_stream_list_t *list_, uint32_t ssrc) +{ + srtp_stream_t *list = (srtp_stream_t *)list_; + + /* walk down list until ssrc is found */ + srtp_stream_t stream = (*list); + while (stream != NULL) { + if (stream->ssrc == ssrc) + return stream; + stream = stream->next; + } + + /* we haven't found our ssrc, so return a null */ + return NULL; +} + +srtp_stream_t srtp_stream_list_delete(srtp_stream_list_t *list_, uint32_t ssrc) +{ + srtp_stream_t *list = (srtp_stream_t *)list_; + + /* walk down list until ssrc is found */ + srtp_stream_t *stream = list; + while ((*stream) != NULL) { + if ((*stream)->ssrc == ssrc) { + srtp_stream_t tmp = (*stream); + (*stream) = tmp->next; + return tmp; + } + stream = &(*stream)->next; + } + + /* we haven't found our ssrc, so return a null */ + return NULL; +} + +void srtp_stream_list_for_each(srtp_stream_list_t *list_, + int (*callback)(srtp_stream_t, void *), + void *data) +{ + srtp_stream_t *list = (srtp_stream_t *)list_; + srtp_stream_t stream = (*list); + while (stream != NULL) { + srtp_stream_t tmp = stream; + stream = stream->next; + if (callback(tmp, data)) + break; + } +} + +srtp_err_status_t srtp_stream_list_dealloc(srtp_stream_list_t *list_, + srtp_stream_t template) +{ + srtp_stream_t *list = (srtp_stream_t *)list_; + srtp_err_status_t status; + + /* walk list of streams, deallocating as we go */ + while ((*list) != NULL) { + srtp_stream_t next = (*list)->next; + status = srtp_stream_dealloc((*list), template); + if (status) + return status; + (*list) = next; + } + + return srtp_err_status_ok; +} + +#endif From b8734bb7443ceb63374b44fd01d78fb92572e69a Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Tue, 6 Sep 2022 02:32:29 +0200 Subject: [PATCH 058/109] 1/2 use it --- srtp/srtp.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index af1db9858..940bc4dd6 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -2056,9 +2056,8 @@ static srtp_err_status_t srtp_unprotect_aead(srtp_ctx_t *ctx, return status; } - /* add new stream to the head of the stream_list */ - new_stream->next = ctx->stream_list; - ctx->stream_list = new_stream; + /* add new stream to the list */ + srtp_stream_list_insert(&ctx->stream_list, new_stream); /* set stream (the pointer used in this function) */ stream = new_stream; @@ -2147,9 +2146,8 @@ srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx, if (status) return status; - /* add new stream to the head of the stream_list */ - new_stream->next = ctx->stream_list; - ctx->stream_list = new_stream; + /* add new stream to the list */ + srtp_stream_list_insert(&ctx->stream_list, new_stream); /* set direction to outbound */ new_stream->direction = dir_srtp_sender; @@ -2746,9 +2744,8 @@ srtp_err_status_t srtp_unprotect_mki(srtp_ctx_t *ctx, if (status) return status; - /* add new stream to the head of the stream_list */ - new_stream->next = ctx->stream_list; - ctx->stream_list = new_stream; + /* add new stream to the list */ + srtp_stream_list_insert(&ctx->stream_list, new_stream); /* set stream (the pointer used in this function) */ stream = new_stream; @@ -3900,9 +3897,8 @@ static srtp_err_status_t srtp_unprotect_rtcp_aead( return status; } - /* add new stream to the head of the stream_list */ - new_stream->next = ctx->stream_list; - ctx->stream_list = new_stream; + /* add new stream to the list */ + srtp_stream_list_insert(&ctx->stream_list, new_stream); /* set stream (the pointer used in this function) */ stream = new_stream; @@ -3966,9 +3962,8 @@ srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx, if (status) return status; - /* add new stream to the head of the stream_list */ - new_stream->next = ctx->stream_list; - ctx->stream_list = new_stream; + /* add new stream to the list */ + srtp_stream_list_insert(&ctx->stream_list, new_stream); /* set stream (the pointer used in this function) */ stream = new_stream; @@ -4413,9 +4408,8 @@ srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx, if (status) return status; - /* add new stream to the head of the stream_list */ - new_stream->next = ctx->stream_list; - ctx->stream_list = new_stream; + /* add new stream to the list */ + srtp_stream_list_insert(&ctx->stream_list, new_stream); /* set stream (the pointer used in this function) */ stream = new_stream; From 8e314717511d9e410e0454139ee8334722a25bc8 Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Mon, 5 Sep 2022 23:33:04 +0200 Subject: [PATCH 059/109] 2/2 use it --- include/srtp_priv.h | 2 +- srtp/srtp.c | 71 +++++++++++++++------------------------------ 2 files changed, 24 insertions(+), 49 deletions(-) diff --git a/include/srtp_priv.h b/include/srtp_priv.h index ade8622e8..f1977e2e9 100644 --- a/include/srtp_priv.h +++ b/include/srtp_priv.h @@ -157,7 +157,7 @@ typedef struct srtp_stream_ctx_t_ { * an srtp_ctx_t holds a stream list and a service description */ typedef struct srtp_ctx_t_ { - struct srtp_stream_ctx_t_ *stream_list; /* linked list of streams */ + srtp_stream_list_t stream_list; /* linked list of streams */ struct srtp_stream_ctx_t_ *stream_template; /* act as template for other */ /* streams */ void *user_data; /* user custom data */ diff --git a/srtp/srtp.c b/srtp/srtp.c index 940bc4dd6..0ffeff8d1 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -2803,32 +2803,13 @@ srtp_err_status_t srtp_shutdown() return srtp_err_status_ok; } -/* - * srtp_get_stream(ssrc) returns a pointer to the stream corresponding - * to ssrc, or NULL if no stream exists for that ssrc - * - * this is an internal function - */ - srtp_stream_ctx_t *srtp_get_stream(srtp_t srtp, uint32_t ssrc) { - srtp_stream_ctx_t *stream; - - /* walk down list until ssrc is found */ - stream = srtp->stream_list; - while (stream != NULL) { - if (stream->ssrc == ssrc) - return stream; - stream = stream->next; - } - - /* we haven't found our ssrc, so return a null */ - return NULL; + return srtp_stream_list_get(&srtp->stream_list, ssrc); } srtp_err_status_t srtp_dealloc(srtp_t session) { - srtp_stream_ctx_t *stream; srtp_err_status_t status; /* @@ -2837,15 +2818,11 @@ srtp_err_status_t srtp_dealloc(srtp_t session) * memory and just return an error */ - /* walk list of streams, deallocating as we go */ - stream = session->stream_list; - while (stream != NULL) { - srtp_stream_t next = stream->next; - status = srtp_stream_dealloc(stream, session->stream_template); - if (status) - return status; - stream = next; - } + /* deallocate streams */ + status = srtp_stream_list_dealloc(&session->stream_list, + session->stream_template); + if (status) + return status; /* deallocate stream template, if there is one */ if (session->stream_template != NULL) { @@ -2914,8 +2891,7 @@ srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy) session->stream_template->direction = dir_srtp_receiver; break; case (ssrc_specific): - tmp->next = session->stream_list; - session->stream_list = tmp; + srtp_stream_list_insert(&session->stream_list, tmp); break; case (ssrc_undefined): default: @@ -2947,13 +2923,23 @@ srtp_err_status_t srtp_create(srtp_t *session, /* handle for session */ return srtp_err_status_alloc_fail; *session = ctx; + ctx->stream_template = NULL; + ctx->stream_list = NULL; + ctx->user_data = NULL; + + /* allocate stream list */ + stat = srtp_stream_list_create(&ctx->stream_list); + if (stat) { + /* clean up everything */ + srtp_dealloc(*session); + *session = NULL; + return stat; + } + /* * loop over elements in the policy list, allocating and * initializing a stream for each element */ - ctx->stream_template = NULL; - ctx->stream_list = NULL; - ctx->user_data = NULL; while (policy != NULL) { stat = srtp_add_stream(ctx, policy); if (stat) { @@ -2972,29 +2958,18 @@ srtp_err_status_t srtp_create(srtp_t *session, /* handle for session */ srtp_err_status_t srtp_remove_stream(srtp_t session, uint32_t ssrc) { - srtp_stream_ctx_t *stream, *last_stream; + srtp_stream_ctx_t *stream; srtp_err_status_t status; /* sanity check arguments */ if (session == NULL) return srtp_err_status_bad_param; - /* find stream in list; complain if not found */ - last_stream = stream = session->stream_list; - while ((stream != NULL) && (ssrc != stream->ssrc)) { - last_stream = stream; - stream = stream->next; - } + /* find and remove stream from the list */ + stream = srtp_stream_list_delete(&session->stream_list, ssrc); if (stream == NULL) return srtp_err_status_no_ctx; - /* remove stream from the list */ - if (last_stream == stream) - /* stream was first in list */ - session->stream_list = stream->next; - else - last_stream->next = stream->next; - /* deallocate the stream */ status = srtp_stream_dealloc(stream, session->stream_template); if (status) From feac4cea58d6d88a49c7a07d7690c69f2562b283 Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Mon, 5 Sep 2022 23:35:49 +0200 Subject: [PATCH 060/109] use in update_template_streams() to make it work with the generalized interface, instead of removing only the matching streams and then merging both lists, we remove & add every stream. the old stream is then deallocated and replaced by the newly produced one --- srtp/srtp.c | 140 +++++++++++++++++++++++++++------------------------- 1 file changed, 72 insertions(+), 68 deletions(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index 0ffeff8d1..16586175d 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -3005,12 +3005,60 @@ srtp_err_status_t srtp_update(srtp_t session, const srtp_policy_t *policy) return srtp_err_status_ok; } +struct update_template_stream_data { + srtp_err_status_t status; + srtp_t session; + srtp_stream_t new_stream_template; + srtp_stream_list_t *new_stream_list; +}; + +static int update_template_stream(srtp_stream_t stream, void *raw_data) +{ + struct update_template_stream_data *data = + (struct update_template_stream_data *)raw_data; + srtp_t session = data->session; + uint32_t ssrc = stream->ssrc; + srtp_xtd_seq_num_t old_index; + srtp_rdb_t old_rtcp_rdb; + + /* old / non-template streams are copied unchanged */ + if (stream->session_keys[0].rtp_auth != + session->stream_template->session_keys[0].rtp_auth) { + srtp_stream_list_delete(&session->stream_list, ssrc); + srtp_stream_list_insert(data->new_stream_list, stream); + return 0; + } + + /* save old extendard seq */ + old_index = stream->rtp_rdbx.index; + old_rtcp_rdb = stream->rtcp_rdb; + + /* remove stream */ + data->status = srtp_remove_stream(session, ssrc); + if (data->status) + return 1; + + /* allocate and initialize a new stream */ + data->status = srtp_stream_clone(data->new_stream_template, ssrc, &stream); + if (data->status) + return 1; + + /* add new stream to the head of the new_stream_list */ + srtp_stream_list_insert(data->new_stream_list, stream); + + /* restore old extended seq */ + stream->rtp_rdbx.index = old_index; + stream->rtcp_rdb = old_rtcp_rdb; + + return 0; +} + static srtp_err_status_t update_template_streams(srtp_t session, const srtp_policy_t *policy) { srtp_err_status_t status; srtp_stream_t new_stream_template; - srtp_stream_t new_stream_list = NULL; + srtp_stream_list_t new_stream_list; status = srtp_valid_policy(policy); if (status != srtp_err_status_ok) { @@ -3034,77 +3082,33 @@ static srtp_err_status_t update_template_streams(srtp_t session, return status; } - /* for all old templated streams */ - for (;;) { - srtp_stream_t stream; - uint32_t ssrc; - srtp_xtd_seq_num_t old_index; - srtp_rdb_t old_rtcp_rdb; - - stream = session->stream_list; - while ((stream != NULL) && - (stream->session_keys[0].rtp_auth != - session->stream_template->session_keys[0].rtp_auth)) { - stream = stream->next; - } - if (stream == NULL) { - /* no more templated streams */ - break; - } - - /* save old extendard seq */ - ssrc = stream->ssrc; - old_index = stream->rtp_rdbx.index; - old_rtcp_rdb = stream->rtcp_rdb; - - /* remove stream */ - status = srtp_remove_stream(session, ssrc); - if (status) { - /* free new allocations */ - while (new_stream_list != NULL) { - srtp_stream_t next = new_stream_list->next; - srtp_stream_dealloc(new_stream_list, new_stream_template); - new_stream_list = next; - } - srtp_stream_dealloc(new_stream_template, NULL); - return status; - } - - /* allocate and initialize a new stream */ - status = srtp_stream_clone(new_stream_template, ssrc, &stream); - if (status) { - /* free new allocations */ - while (new_stream_list != NULL) { - srtp_stream_t next = new_stream_list->next; - srtp_stream_dealloc(new_stream_list, new_stream_template); - new_stream_list = next; - } - srtp_stream_dealloc(new_stream_template, NULL); - return status; - } - - /* add new stream to the head of the new_stream_list */ - stream->next = new_stream_list; - new_stream_list = stream; + /* allocate new stream list */ + status = srtp_stream_list_create(&new_stream_list); + if (status) { + srtp_crypto_free(new_stream_template); + return status; + } - /* restore old extended seq */ - stream->rtp_rdbx.index = old_index; - stream->rtcp_rdb = old_rtcp_rdb; + /* process streams */ + struct update_template_stream_data data = { srtp_err_status_ok, session, + new_stream_template, + &new_stream_list }; + srtp_stream_list_for_each(&session->stream_list, &update_template_stream, + &data); + if (data.status) { + /* free new allocations */ + srtp_stream_list_dealloc(&new_stream_list, new_stream_template); + srtp_stream_dealloc(new_stream_template, NULL); + return data.status; } - /* dealloc old template */ + + /* dealloc old list / template */ + srtp_stream_list_dealloc(&session->stream_list, session->stream_template); srtp_stream_dealloc(session->stream_template, NULL); - /* set new template */ + /* set new list / template */ session->stream_template = new_stream_template; - /* add new list */ - if (new_stream_list) { - srtp_stream_t tail = new_stream_list; - while (tail->next) { - tail = tail->next; - } - tail->next = session->stream_list; - session->stream_list = new_stream_list; - } - return status; + session->stream_list = new_stream_list; + return srtp_err_status_ok; } static srtp_err_status_t update_stream(srtp_t session, From 6653a8667e9065ddbd5f8f914324121aa22a7488 Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Tue, 6 Sep 2022 02:34:07 +0200 Subject: [PATCH 061/109] use in get_protect_trailer_length --- srtp/srtp.c | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index 16586175d..3ba259059 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -4569,6 +4569,32 @@ srtp_err_status_t stream_get_protect_trailer_length(srtp_stream_ctx_t *stream, return srtp_err_status_ok; } +struct get_protect_trailer_length_data { + int valid; + uint32_t length; + uint32_t is_rtp; + uint32_t use_mki; + uint32_t mki_index; +}; + +static int get_protect_trailer_length_cb(srtp_stream_t stream, void *raw_data) +{ + struct get_protect_trailer_length_data *data = + (struct get_protect_trailer_length_data *)raw_data; + uint32_t temp_length; + + data->valid = 1; + if (stream_get_protect_trailer_length(stream, data->is_rtp, data->use_mki, + data->mki_index, + &temp_length) == srtp_err_status_ok) { + if (temp_length > data->length) { + data->length = temp_length; + } + } + + return 0; +} + srtp_err_status_t get_protect_trailer_length(srtp_t session, uint32_t is_rtp, uint32_t use_mki, @@ -4576,38 +4602,29 @@ srtp_err_status_t get_protect_trailer_length(srtp_t session, uint32_t *length) { srtp_stream_ctx_t *stream; + struct get_protect_trailer_length_data data = { 0, 0, is_rtp, use_mki, + mki_index }; if (session == NULL) { return srtp_err_status_bad_param; } - if (session->stream_template == NULL && session->stream_list == NULL) { - return srtp_err_status_bad_param; - } - - *length = 0; - stream = session->stream_template; if (stream != NULL) { + data.valid = 1; stream_get_protect_trailer_length(stream, is_rtp, use_mki, mki_index, - length); + &data.length); } - stream = session->stream_list; + srtp_stream_list_for_each(&session->stream_list, + &get_protect_trailer_length_cb, &data); - while (stream != NULL) { - uint32_t temp_length; - if (stream_get_protect_trailer_length(stream, is_rtp, use_mki, - mki_index, &temp_length) == - srtp_err_status_ok) { - if (temp_length > *length) { - *length = temp_length; - } - } - stream = stream->next; + if (!data.valid) { + return srtp_err_status_bad_param; } + *length = data.length; return srtp_err_status_ok; } From f161ac16c28c9552729cfe3850cd6886b57f96d5 Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Mon, 5 Sep 2022 12:57:10 +0200 Subject: [PATCH 062/109] expose missing internal method custom implementations need to have it available --- include/srtp_priv.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/srtp_priv.h b/include/srtp_priv.h index f1977e2e9..90045942d 100644 --- a/include/srtp_priv.h +++ b/include/srtp_priv.h @@ -103,6 +103,9 @@ srtp_err_status_t srtp_steam_init_all_master_keys( */ srtp_err_status_t srtp_stream_init(srtp_stream_t srtp, const srtp_policy_t *p); +srtp_err_status_t srtp_stream_dealloc(srtp_stream_ctx_t *stream, + const srtp_stream_ctx_t *stream_template); + /* * libsrtp internal datatypes */ From 6b0aa2dadbc41dd1f34e20324b7d86e6aff57faa Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Wed, 7 Sep 2022 02:42:46 +0200 Subject: [PATCH 063/109] update tests removes code duplication as well --- test/srtp_driver.c | 155 ++++++++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 81 deletions(-) diff --git a/test/srtp_driver.c b/test/srtp_driver.c index fd199c5bf..1ddb5cd05 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -49,6 +49,7 @@ #include "getopt_s.h" /* for local getopt() */ #include "srtp_priv.h" +#include "stream_list_priv.h" #include "util.h" #ifdef HAVE_NETINET_IN_H @@ -1467,13 +1468,75 @@ srtp_err_status_t srtcp_test(const srtp_policy_t *policy, int mki_index) return srtp_err_status_ok; } +struct srtp_session_print_stream_data { + // set by callback to indicate failure + srtp_err_status_t status; + // indicates if it is the template stream or a regular stream + int is_template; +}; + +int srtp_session_print_stream(srtp_stream_t stream, void *raw_data) +{ + static const char *serv_descr[4] = { "none", "confidentiality", + "authentication", + "confidentiality and authentication" }; + static const char *direction[3] = { "unknown", "outbound", "inbound" }; + + struct srtp_session_print_stream_data *data = + (struct srtp_session_print_stream_data *)raw_data; + srtp_session_keys_t *session_keys = &stream->session_keys[0]; + char ssrc_text[32]; + + if (!data->is_template && stream->rtp_services > sec_serv_conf_and_auth) { + data->status = srtp_err_status_bad_param; + return 1; + } + + if (data->is_template) { + snprintf(ssrc_text, sizeof(ssrc_text), "any %s", + direction[stream->direction]); + } else { + snprintf(ssrc_text, sizeof(ssrc_text), "0x%08x", stream->ssrc); + } + + printf("# SSRC: %s\r\n" + "# rtp cipher: %s\r\n" + "# rtp auth: %s\r\n" + "# rtp services: %s\r\n" + "# rtcp cipher: %s\r\n" + "# rtcp auth: %s\r\n" + "# rtcp services: %s\r\n" + "# window size: %lu\r\n" + "# tx rtx allowed:%s\r\n", + ssrc_text, session_keys->rtp_cipher->type->description, + session_keys->rtp_auth->type->description, + serv_descr[stream->rtp_services], + session_keys->rtcp_cipher->type->description, + session_keys->rtcp_auth->type->description, + serv_descr[stream->rtcp_services], + srtp_rdbx_get_window_size(&stream->rtp_rdbx), + stream->allow_repeat_tx ? "true" : "false"); + + printf("# Encrypted extension headers: "); + if (stream->enc_xtn_hdr && stream->enc_xtn_hdr_count > 0) { + int *enc_xtn_hdr = stream->enc_xtn_hdr; + int count = stream->enc_xtn_hdr_count; + while (count > 0) { + printf("%d ", *enc_xtn_hdr); + enc_xtn_hdr++; + count--; + } + printf("\n"); + } else { + printf("none\n"); + } + + return 0; +} + srtp_err_status_t srtp_session_print_policy(srtp_t srtp) { - char *serv_descr[4] = { "none", "confidentiality", "authentication", - "confidentiality and authentication" }; - char *direction[3] = { "unknown", "outbound", "inbound" }; - srtp_stream_t stream; - srtp_session_keys_t *session_keys = NULL; + struct srtp_session_print_stream_data data = { srtp_err_status_ok, 0 }; /* sanity checking */ if (srtp == NULL) { @@ -1482,86 +1545,16 @@ srtp_err_status_t srtp_session_print_policy(srtp_t srtp) /* if there's a template stream, print it out */ if (srtp->stream_template != NULL) { - stream = srtp->stream_template; - session_keys = &stream->session_keys[0]; - printf("# SSRC: any %s\r\n" - "# rtp cipher: %s\r\n" - "# rtp auth: %s\r\n" - "# rtp services: %s\r\n" - "# rtcp cipher: %s\r\n" - "# rtcp auth: %s\r\n" - "# rtcp services: %s\r\n" - "# window size: %lu\r\n" - "# tx rtx allowed:%s\r\n", - direction[stream->direction], - session_keys->rtp_cipher->type->description, - session_keys->rtp_auth->type->description, - serv_descr[stream->rtp_services], - session_keys->rtcp_cipher->type->description, - session_keys->rtcp_auth->type->description, - serv_descr[stream->rtcp_services], - srtp_rdbx_get_window_size(&stream->rtp_rdbx), - stream->allow_repeat_tx ? "true" : "false"); - - printf("# Encrypted extension headers: "); - if (stream->enc_xtn_hdr && stream->enc_xtn_hdr_count > 0) { - int *enc_xtn_hdr = stream->enc_xtn_hdr; - int count = stream->enc_xtn_hdr_count; - while (count > 0) { - printf("%d ", *enc_xtn_hdr); - enc_xtn_hdr++; - count--; - } - printf("\n"); - } else { - printf("none\n"); - } + data.is_template = 1; + srtp_session_print_stream(srtp->stream_template, &data); } /* loop over streams in session, printing the policy of each */ - stream = srtp->stream_list; - while (stream != NULL) { - if (stream->rtp_services > sec_serv_conf_and_auth) { - return srtp_err_status_bad_param; - } - session_keys = &stream->session_keys[0]; - - printf("# SSRC: 0x%08x\r\n" - "# rtp cipher: %s\r\n" - "# rtp auth: %s\r\n" - "# rtp services: %s\r\n" - "# rtcp cipher: %s\r\n" - "# rtcp auth: %s\r\n" - "# rtcp services: %s\r\n" - "# window size: %lu\r\n" - "# tx rtx allowed:%s\r\n", - stream->ssrc, session_keys->rtp_cipher->type->description, - session_keys->rtp_auth->type->description, - serv_descr[stream->rtp_services], - session_keys->rtcp_cipher->type->description, - session_keys->rtcp_auth->type->description, - serv_descr[stream->rtcp_services], - srtp_rdbx_get_window_size(&stream->rtp_rdbx), - stream->allow_repeat_tx ? "true" : "false"); - - printf("# Encrypted extension headers: "); - if (stream->enc_xtn_hdr && stream->enc_xtn_hdr_count > 0) { - int *enc_xtn_hdr = stream->enc_xtn_hdr; - int count = stream->enc_xtn_hdr_count; - while (count > 0) { - printf("%d ", *enc_xtn_hdr); - enc_xtn_hdr++; - count--; - } - printf("\n"); - } else { - printf("none\n"); - } + data.is_template = 0; + srtp_stream_list_for_each(&srtp->stream_list, &srtp_session_print_stream, + &data); - /* advance to next stream in the list */ - stream = stream->next; - } - return srtp_err_status_ok; + return data.status; } srtp_err_status_t srtp_print_policy(const srtp_policy_t *policy) From 55f409f6129196e0f22c2b28fabce130712b9b09 Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Mon, 12 Sep 2022 13:31:37 +0200 Subject: [PATCH 064/109] allow insertions to fail --- include/stream_list_priv.h | 7 +++-- srtp/srtp.c | 52 ++++++++++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/include/stream_list_priv.h b/include/stream_list_priv.h index 815d77dce..0245126a4 100644 --- a/include/stream_list_priv.h +++ b/include/stream_list_priv.h @@ -74,13 +74,16 @@ srtp_err_status_t srtp_stream_list_create(srtp_stream_list_t *list); /** * insert a stream into the list * - * ownership is transferred from caller to the list. + * returns srtp_err_status_alloc_fail if insertion failed due to unavailable + * capacity in the list. if operation succeeds, srtp_err_status_ok is returned + * and ownership is transferred from caller into the list * * if another stream with the same SSRC already exists in the list, * behavior is undefined. if the SSRC field is mutated while the * stream is inserted, further operations have undefined behavior */ -void srtp_stream_list_insert(srtp_stream_list_t *list, srtp_stream_t stream); +srtp_err_status_t srtp_stream_list_insert(srtp_stream_list_t *list, + srtp_stream_t stream); /* * look up the stream corresponding to the specified SSRC and return it. diff --git a/srtp/srtp.c b/srtp/srtp.c index 3ba259059..6e65f5348 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -279,6 +279,16 @@ srtp_err_status_t srtp_stream_dealloc(srtp_stream_ctx_t *stream, return srtp_err_status_ok; } +/* try to insert stream in list or deallocate it */ +static srtp_err_status_t srtp_insert_or_dealloc_stream(srtp_stream_list_t *list, srtp_stream_t stream, srtp_stream_t template) +{ + srtp_err_status_t status = srtp_stream_list_insert(list, stream); + /* on failure, ownership wasn't transferred and we need to deallocate */ + if (status) + srtp_stream_dealloc(stream, template); + return status; +} + static srtp_err_status_t srtp_valid_policy(const srtp_policy_t *p) { if (p != NULL && p->deprecated_ekt != NULL) { @@ -2057,7 +2067,9 @@ static srtp_err_status_t srtp_unprotect_aead(srtp_ctx_t *ctx, } /* add new stream to the list */ - srtp_stream_list_insert(&ctx->stream_list, new_stream); + status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, ctx->stream_template); + if (status) + return status; /* set stream (the pointer used in this function) */ stream = new_stream; @@ -2147,7 +2159,9 @@ srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx, return status; /* add new stream to the list */ - srtp_stream_list_insert(&ctx->stream_list, new_stream); + status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, ctx->stream_template); + if (status) + return status; /* set direction to outbound */ new_stream->direction = dir_srtp_sender; @@ -2745,7 +2759,9 @@ srtp_err_status_t srtp_unprotect_mki(srtp_ctx_t *ctx, return status; /* add new stream to the list */ - srtp_stream_list_insert(&ctx->stream_list, new_stream); + status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, ctx->stream_template); + if (status) + return status; /* set stream (the pointer used in this function) */ stream = new_stream; @@ -2891,7 +2907,9 @@ srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy) session->stream_template->direction = dir_srtp_receiver; break; case (ssrc_specific): - srtp_stream_list_insert(&session->stream_list, tmp); + status = srtp_insert_or_dealloc_stream(&session->stream_list, tmp, session->stream_template); + if (status) + return status; break; case (ssrc_undefined): default: @@ -3024,8 +3042,10 @@ static int update_template_stream(srtp_stream_t stream, void *raw_data) /* old / non-template streams are copied unchanged */ if (stream->session_keys[0].rtp_auth != session->stream_template->session_keys[0].rtp_auth) { - srtp_stream_list_delete(&session->stream_list, ssrc); - srtp_stream_list_insert(data->new_stream_list, stream); + stream = srtp_stream_list_delete(&session->stream_list, ssrc); + data->status = srtp_insert_or_dealloc_stream(data->new_stream_list, stream, session->stream_template); + if (data->status) + return 1; return 0; } @@ -3044,7 +3064,9 @@ static int update_template_stream(srtp_stream_t stream, void *raw_data) return 1; /* add new stream to the head of the new_stream_list */ - srtp_stream_list_insert(data->new_stream_list, stream); + data->status = srtp_insert_or_dealloc_stream(data->new_stream_list, stream, data->new_stream_template); + if (data->status) + return 1; /* restore old extended seq */ stream->rtp_rdbx.index = old_index; @@ -3877,7 +3899,9 @@ static srtp_err_status_t srtp_unprotect_rtcp_aead( } /* add new stream to the list */ - srtp_stream_list_insert(&ctx->stream_list, new_stream); + status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, ctx->stream_template); + if (status) + return status; /* set stream (the pointer used in this function) */ stream = new_stream; @@ -3942,7 +3966,9 @@ srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx, return status; /* add new stream to the list */ - srtp_stream_list_insert(&ctx->stream_list, new_stream); + status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, ctx->stream_template); + if (status) + return status; /* set stream (the pointer used in this function) */ stream = new_stream; @@ -4388,7 +4414,9 @@ srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx, return status; /* add new stream to the list */ - srtp_stream_list_insert(&ctx->stream_list, new_stream); + status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, ctx->stream_template); + if (status) + return status; /* set stream (the pointer used in this function) */ stream = new_stream; @@ -4752,13 +4780,15 @@ srtp_err_status_t srtp_stream_list_create(srtp_stream_list_t *list) return srtp_err_status_ok; } -void srtp_stream_list_insert(srtp_stream_list_t *list_, srtp_stream_t stream) +srtp_err_status_t srtp_stream_list_insert(srtp_stream_list_t *list_, srtp_stream_t stream) { srtp_stream_t *list = (srtp_stream_t *)list_; /* insert at the head of the list */ stream->next = (*list); (*list) = stream; + + return srtp_err_status_ok; } srtp_stream_t srtp_stream_list_get(srtp_stream_list_t *list_, uint32_t ssrc) From 0bc8b9bdaf52b92db9d409094c3375ea092a25d5 Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Mon, 12 Sep 2022 20:33:38 +0200 Subject: [PATCH 065/109] (format) --- srtp/srtp.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index 6e65f5348..c96080b6d 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -280,7 +280,9 @@ srtp_err_status_t srtp_stream_dealloc(srtp_stream_ctx_t *stream, } /* try to insert stream in list or deallocate it */ -static srtp_err_status_t srtp_insert_or_dealloc_stream(srtp_stream_list_t *list, srtp_stream_t stream, srtp_stream_t template) +static srtp_err_status_t srtp_insert_or_dealloc_stream(srtp_stream_list_t *list, + srtp_stream_t stream, + srtp_stream_t template) { srtp_err_status_t status = srtp_stream_list_insert(list, stream); /* on failure, ownership wasn't transferred and we need to deallocate */ @@ -2067,7 +2069,8 @@ static srtp_err_status_t srtp_unprotect_aead(srtp_ctx_t *ctx, } /* add new stream to the list */ - status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, ctx->stream_template); + status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, + ctx->stream_template); if (status) return status; @@ -2159,7 +2162,8 @@ srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx, return status; /* add new stream to the list */ - status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, ctx->stream_template); + status = srtp_insert_or_dealloc_stream( + &ctx->stream_list, new_stream, ctx->stream_template); if (status) return status; @@ -2759,7 +2763,8 @@ srtp_err_status_t srtp_unprotect_mki(srtp_ctx_t *ctx, return status; /* add new stream to the list */ - status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, ctx->stream_template); + status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, + ctx->stream_template); if (status) return status; @@ -2907,7 +2912,8 @@ srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy) session->stream_template->direction = dir_srtp_receiver; break; case (ssrc_specific): - status = srtp_insert_or_dealloc_stream(&session->stream_list, tmp, session->stream_template); + status = srtp_insert_or_dealloc_stream(&session->stream_list, tmp, + session->stream_template); if (status) return status; break; @@ -3043,7 +3049,8 @@ static int update_template_stream(srtp_stream_t stream, void *raw_data) if (stream->session_keys[0].rtp_auth != session->stream_template->session_keys[0].rtp_auth) { stream = srtp_stream_list_delete(&session->stream_list, ssrc); - data->status = srtp_insert_or_dealloc_stream(data->new_stream_list, stream, session->stream_template); + data->status = srtp_insert_or_dealloc_stream( + data->new_stream_list, stream, session->stream_template); if (data->status) return 1; return 0; @@ -3064,7 +3071,8 @@ static int update_template_stream(srtp_stream_t stream, void *raw_data) return 1; /* add new stream to the head of the new_stream_list */ - data->status = srtp_insert_or_dealloc_stream(data->new_stream_list, stream, data->new_stream_template); + data->status = srtp_insert_or_dealloc_stream(data->new_stream_list, stream, + data->new_stream_template); if (data->status) return 1; @@ -3899,7 +3907,8 @@ static srtp_err_status_t srtp_unprotect_rtcp_aead( } /* add new stream to the list */ - status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, ctx->stream_template); + status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, + ctx->stream_template); if (status) return status; @@ -3966,7 +3975,8 @@ srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx, return status; /* add new stream to the list */ - status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, ctx->stream_template); + status = srtp_insert_or_dealloc_stream( + &ctx->stream_list, new_stream, ctx->stream_template); if (status) return status; @@ -4414,7 +4424,8 @@ srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx, return status; /* add new stream to the list */ - status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, ctx->stream_template); + status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, + ctx->stream_template); if (status) return status; @@ -4780,7 +4791,8 @@ srtp_err_status_t srtp_stream_list_create(srtp_stream_list_t *list) return srtp_err_status_ok; } -srtp_err_status_t srtp_stream_list_insert(srtp_stream_list_t *list_, srtp_stream_t stream) +srtp_err_status_t srtp_stream_list_insert(srtp_stream_list_t *list_, + srtp_stream_t stream) { srtp_stream_t *list = (srtp_stream_t *)list_; From 4b78d08a3fb710e4437107c6961657afed7bcf9a Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Sun, 6 Nov 2022 21:50:17 -0500 Subject: [PATCH 066/109] Call get_tag in cipher performance test when possible --- crypto/cipher/cipher.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crypto/cipher/cipher.c b/crypto/cipher/cipher.c index de93bc90d..085cb6397 100644 --- a/crypto/cipher/cipher.c +++ b/crypto/cipher/cipher.c @@ -632,8 +632,9 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c, clock_t timer; unsigned char *enc_buf; unsigned int len = octets_in_buffer; + uint32_t tag_len = 32; - enc_buf = (unsigned char *)srtp_crypto_alloc(octets_in_buffer); + enc_buf = (unsigned char *)srtp_crypto_alloc(octets_in_buffer + tag_len); if (enc_buf == NULL) { return 0; /* indicate bad parameters by returning null */ } @@ -650,6 +651,15 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c, srtp_crypto_free(enc_buf); return 0; } + + // Get tag if supported by the cipher + if (c->type->get_tag) { + if (srtp_cipher_get_tag(c, (uint8_t*)(enc_buf + octets_in_buffer), &tag_len) != + srtp_err_status_ok) { + srtp_crypto_free(enc_buf); + return 0; + } + } } timer = clock() - timer; From 1f9cf2c68bc0e94f75a02ebb55ff5cd8d7522476 Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Sun, 6 Nov 2022 21:57:30 -0500 Subject: [PATCH 067/109] Also set AAD --- crypto/cipher/cipher.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crypto/cipher/cipher.c b/crypto/cipher/cipher.c index 085cb6397..c55271bc2 100644 --- a/crypto/cipher/cipher.c +++ b/crypto/cipher/cipher.c @@ -633,6 +633,8 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c, unsigned char *enc_buf; unsigned int len = octets_in_buffer; uint32_t tag_len = 32; + unsigned char aad[4] = {0, 0, 0, 0}; + uint32_t aad_len = 4; enc_buf = (unsigned char *)srtp_crypto_alloc(octets_in_buffer + tag_len); if (enc_buf == NULL) { @@ -642,11 +644,22 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c, v128_set_to_zero(&nonce); timer = clock(); for (i = 0; i < num_trials; i++, nonce.v32[3] = i) { + // Set IV if (srtp_cipher_set_iv(c, (uint8_t *)&nonce, srtp_direction_encrypt) != srtp_err_status_ok) { srtp_crypto_free(enc_buf); return 0; } + + // Set (empty) AAD if supported by the cipher + if (c->type->set_aad) { + if (srtp_cipher_set_aad(c, aad, aad_len) != srtp_err_status_ok) { + srtp_crypto_free(enc_buf); + return 0; + } + } + + // Encrypt the buffer if (srtp_cipher_encrypt(c, enc_buf, &len) != srtp_err_status_ok) { srtp_crypto_free(enc_buf); return 0; From c038fac38e4c19d363b39062579cfd5824ae9f5b Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Mon, 7 Nov 2022 11:45:38 -0500 Subject: [PATCH 068/109] clang-format --- crypto/cipher/cipher.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crypto/cipher/cipher.c b/crypto/cipher/cipher.c index c55271bc2..d4f1adc7f 100644 --- a/crypto/cipher/cipher.c +++ b/crypto/cipher/cipher.c @@ -633,7 +633,7 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c, unsigned char *enc_buf; unsigned int len = octets_in_buffer; uint32_t tag_len = 32; - unsigned char aad[4] = {0, 0, 0, 0}; + unsigned char aad[4] = { 0, 0, 0, 0 }; uint32_t aad_len = 4; enc_buf = (unsigned char *)srtp_crypto_alloc(octets_in_buffer + tag_len); @@ -667,11 +667,11 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c, // Get tag if supported by the cipher if (c->type->get_tag) { - if (srtp_cipher_get_tag(c, (uint8_t*)(enc_buf + octets_in_buffer), &tag_len) != - srtp_err_status_ok) { - srtp_crypto_free(enc_buf); - return 0; - } + if (srtp_cipher_get_tag(c, (uint8_t *)(enc_buf + octets_in_buffer), + &tag_len) != srtp_err_status_ok) { + srtp_crypto_free(enc_buf); + return 0; + } } } timer = clock() - timer; From 9b26f8adf0d1fcf57a9af202a62e4478bddca896 Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Mon, 7 Nov 2022 14:22:54 -0500 Subject: [PATCH 069/109] Use more accurate lengths --- crypto/cipher/cipher.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto/cipher/cipher.c b/crypto/cipher/cipher.c index d4f1adc7f..fc913e8e3 100644 --- a/crypto/cipher/cipher.c +++ b/crypto/cipher/cipher.c @@ -632,7 +632,7 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c, clock_t timer; unsigned char *enc_buf; unsigned int len = octets_in_buffer; - uint32_t tag_len = 32; + uint32_t tag_len = SRTP_MAX_TAG_LEN; unsigned char aad[4] = { 0, 0, 0, 0 }; uint32_t aad_len = 4; @@ -667,7 +667,7 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c, // Get tag if supported by the cipher if (c->type->get_tag) { - if (srtp_cipher_get_tag(c, (uint8_t *)(enc_buf + octets_in_buffer), + if (srtp_cipher_get_tag(c, (uint8_t *)(enc_buf + len), &tag_len) != srtp_err_status_ok) { srtp_crypto_free(enc_buf); return 0; From e1cb78ce03cb55b32ef26d844f94e53ec9f95060 Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Mon, 7 Nov 2022 14:28:46 -0500 Subject: [PATCH 070/109] clang-format --- crypto/cipher/cipher.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto/cipher/cipher.c b/crypto/cipher/cipher.c index fc913e8e3..ddb265e26 100644 --- a/crypto/cipher/cipher.c +++ b/crypto/cipher/cipher.c @@ -667,8 +667,8 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c, // Get tag if supported by the cipher if (c->type->get_tag) { - if (srtp_cipher_get_tag(c, (uint8_t *)(enc_buf + len), - &tag_len) != srtp_err_status_ok) { + if (srtp_cipher_get_tag(c, (uint8_t *)(enc_buf + len), &tag_len) != + srtp_err_status_ok) { srtp_crypto_free(enc_buf); return 0; } From 998491b1893059b331a34626db46c6ed7c672ac0 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Sun, 20 Nov 2022 16:22:15 -0800 Subject: [PATCH 071/109] add CIFuzz Github action to workflows --- .github/workflows/cifuzz.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/cifuzz.yml diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml new file mode 100644 index 000000000..080b233e0 --- /dev/null +++ b/.github/workflows/cifuzz.yml @@ -0,0 +1,26 @@ +name: CIFuzz +on: [pull_request] +jobs: + Fuzzing: + runs-on: ubuntu-latest + steps: + - name: Build Fuzzers + id: build + uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master + with: + oss-fuzz-project-name: 'libsrtp' + dry-run: false + language: c++ + - name: Run Fuzzers + uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master + with: + oss-fuzz-project-name: 'libsrtp' + fuzz-seconds: 300 + dry-run: false + language: c++ + - name: Upload Crash + uses: actions/upload-artifact@v3 + if: failure() && steps.build.outcome == 'success' + with: + name: artifacts + path: ./out/artifacts From e19efdc1683dcf03710eb0fbc640c5a3359b535f Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Mon, 21 Nov 2022 10:53:59 -0500 Subject: [PATCH 072/109] Use current directions in stream update test --- test/srtp_driver.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/srtp_driver.c b/test/srtp_driver.c index b8c14c771..1f4fc5e27 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -2831,16 +2831,16 @@ srtp_err_status_t srtp_test_update() policy.window_size = 128; policy.allow_repeat_tx = 0; policy.next = NULL; - policy.ssrc.type = ssrc_any_outbound; policy.key = test_key; /* create a send and recive ctx with defualt profile and test_key */ - status = srtp_create(&srtp_recv, &policy); + policy.ssrc.type = ssrc_any_outbound; + status = srtp_create(&srtp_snd, &policy); if (status) return status; policy.ssrc.type = ssrc_any_inbound; - status = srtp_create(&srtp_snd, &policy); + status = srtp_create(&srtp_recv, &policy); if (status) return status; From b94649cae911d8cdb8c083187c59246d70eb4b25 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Thu, 24 Nov 2022 15:05:40 -0800 Subject: [PATCH 073/109] run CIFuzz on push too --- .github/workflows/cifuzz.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml index 080b233e0..c07c7fc80 100644 --- a/.github/workflows/cifuzz.yml +++ b/.github/workflows/cifuzz.yml @@ -1,5 +1,5 @@ name: CIFuzz -on: [pull_request] +on: [ push, pull_request ] jobs: Fuzzing: runs-on: ubuntu-latest @@ -9,14 +9,12 @@ jobs: uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master with: oss-fuzz-project-name: 'libsrtp' - dry-run: false language: c++ - name: Run Fuzzers uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master with: oss-fuzz-project-name: 'libsrtp' fuzz-seconds: 300 - dry-run: false language: c++ - name: Upload Crash uses: actions/upload-artifact@v3 From 5e03b6403478b4a8c8430d908ae5d0b88ee04784 Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Fri, 25 Nov 2022 17:23:47 +0100 Subject: [PATCH 074/109] Hide some more symbols --- crypto/kernel/crypto_kernel.c | 2 +- crypto/math/datatypes.c | 2 +- srtp/srtp.c | 21 ++++++++++++--------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/crypto/kernel/crypto_kernel.c b/crypto/kernel/crypto_kernel.c index 764e7ecfa..67a86f0d4 100644 --- a/crypto/kernel/crypto_kernel.c +++ b/crypto/kernel/crypto_kernel.c @@ -60,7 +60,7 @@ srtp_debug_module_t srtp_mod_crypto_kernel = { /* crypto_kernel is a global variable, the only one of its datatype */ -srtp_crypto_kernel_t crypto_kernel = { +static srtp_crypto_kernel_t crypto_kernel = { srtp_crypto_kernel_state_insecure, /* start off in insecure state */ NULL, /* no cipher types yet */ NULL, /* no auth types yet */ diff --git a/crypto/math/datatypes.c b/crypto/math/datatypes.c index 88957b2cc..4b6f6f3f5 100644 --- a/crypto/math/datatypes.c +++ b/crypto/math/datatypes.c @@ -62,7 +62,7 @@ /* include space for null terminator */ static char bit_string[MAX_PRINT_STRING_LEN + 1]; -uint8_t srtp_nibble_to_hex_char(uint8_t nibble) +static uint8_t srtp_nibble_to_hex_char(uint8_t nibble) { static const char buf[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; diff --git a/srtp/srtp.c b/srtp/srtp.c index 2d3faaf47..b80de7966 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -148,8 +148,9 @@ unsigned int srtp_get_version() return rv; } -srtp_err_status_t srtp_stream_dealloc(srtp_stream_ctx_t *stream, - const srtp_stream_ctx_t *stream_template) +static srtp_err_status_t srtp_stream_dealloc( + srtp_stream_ctx_t *stream, + const srtp_stream_ctx_t *stream_template) { srtp_err_status_t status; unsigned int i = 0; @@ -287,8 +288,8 @@ static srtp_err_status_t srtp_valid_policy(const srtp_policy_t *p) return srtp_err_status_ok; } -srtp_err_status_t srtp_stream_alloc(srtp_stream_ctx_t **str_ptr, - const srtp_policy_t *p) +static srtp_err_status_t srtp_stream_alloc(srtp_stream_ctx_t **str_ptr, + const srtp_policy_t *p) { srtp_stream_ctx_t *str; srtp_err_status_t stat; @@ -452,9 +453,10 @@ srtp_err_status_t srtp_stream_alloc(srtp_stream_ctx_t **str_ptr, * the SSRC */ -srtp_err_status_t srtp_stream_clone(const srtp_stream_ctx_t *stream_template, - uint32_t ssrc, - srtp_stream_ctx_t **str_ptr) +static srtp_err_status_t srtp_stream_clone( + const srtp_stream_ctx_t *stream_template, + uint32_t ssrc, + srtp_stream_ctx_t **str_ptr) { srtp_err_status_t status; srtp_stream_ctx_t *str; @@ -794,7 +796,8 @@ static inline int full_key_length(const srtp_cipher_type_t *cipher) } } -unsigned int srtp_validate_policy_master_keys(const srtp_policy_t *policy) +static unsigned int srtp_validate_policy_master_keys( + const srtp_policy_t *policy) { unsigned long i = 0; @@ -4675,7 +4678,7 @@ srtp_err_status_t srtp_list_debug_modules(void) static srtp_log_handler_func_t *srtp_log_handler = NULL; static void *srtp_log_handler_data = NULL; -void srtp_err_handler(srtp_err_reporting_level_t level, const char *msg) +static void srtp_err_handler(srtp_err_reporting_level_t level, const char *msg) { if (srtp_log_handler) { srtp_log_level_t log_level = srtp_log_level_error; From 5c09a690a52c5cf08fa7d5514c9587c2cd7dfdd1 Mon Sep 17 00:00:00 2001 From: Pascal Buhler Date: Wed, 7 Dec 2022 23:32:38 +0100 Subject: [PATCH 075/109] switch to use ubuntu-20.04 in workflows ubuntu-latest in moving to ubuntu-22.04, this wil require updates fro clang format and openssl3, so in the mean time use ubuntu-20.04, #622 --- .github/workflows/autotools.yml | 8 ++++---- .github/workflows/cmake.yml | 6 +++--- .github/workflows/coverity_scan.yml | 2 +- .github/workflows/format_check.yml | 2 +- .github/workflows/fuzzer_build.yml | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/autotools.yml b/.github/workflows/autotools.yml index ee94f06ba..92369c2db 100644 --- a/.github/workflows/autotools.yml +++ b/.github/workflows/autotools.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-20.04, macos-latest] crypto: [internal, openssl, nss] include: - crypto: internal @@ -25,11 +25,11 @@ jobs: steps: - name: Setup Ubuntu - if: matrix.os == 'ubuntu-latest' + if: matrix.os == 'ubuntu-20.04' run: sudo apt-get install valgrind - name: Setup Ubuntu NSS - if: matrix.os == 'ubuntu-latest' && matrix.crypto == 'nss' + if: matrix.os == 'ubuntu-20.04' && matrix.crypto == 'nss' run: | sudo apt-get update sudo apt-get install libnss3-dev @@ -54,5 +54,5 @@ jobs: run: make runtest - name: Test Valgrind - if: matrix.os == 'ubuntu-latest' + if: matrix.os == 'ubuntu-20.04' run: make runtest-valgrind diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index f4bd13ba6..ed914a637 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-20.04, macos-latest, windows-latest] crypto: [internal, openssl, nss, mbedtls] exclude: - os: windows-latest @@ -37,13 +37,13 @@ jobs: steps: - name: Setup Ubuntu NSS - if: matrix.os == 'ubuntu-latest' && matrix.crypto == 'nss' + if: matrix.os == 'ubuntu-20.04' && matrix.crypto == 'nss' run: | sudo apt-get update sudo apt-get install libnss3-dev - name: Setup Ubuntu MbedTLS - if: matrix.os == 'ubuntu-latest' && matrix.crypto == 'mbedtls' + if: matrix.os == 'ubuntu-20.04' && matrix.crypto == 'mbedtls' run: sudo apt-get install libmbedtls-dev - name: Setup macOS OpenSSL diff --git a/.github/workflows/coverity_scan.yml b/.github/workflows/coverity_scan.yml index f5a25d945..26a83bbb5 100644 --- a/.github/workflows/coverity_scan.yml +++ b/.github/workflows/coverity_scan.yml @@ -6,7 +6,7 @@ on: jobs: coverity: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml index bc7f632fa..3110a7dfd 100644 --- a/.github/workflows/format_check.yml +++ b/.github/workflows/format_check.yml @@ -8,7 +8,7 @@ on: jobs: format-check: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Install Clang Format diff --git a/.github/workflows/fuzzer_build.yml b/.github/workflows/fuzzer_build.yml index e43e80d05..610e8fa8f 100644 --- a/.github/workflows/fuzzer_build.yml +++ b/.github/workflows/fuzzer_build.yml @@ -10,7 +10,7 @@ on: jobs: fuzz: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 From cb9677366995ab437663cacc172a5c73c07dc729 Mon Sep 17 00:00:00 2001 From: Pascal Buhler Date: Wed, 7 Dec 2022 23:00:33 +0100 Subject: [PATCH 076/109] Add policy_set_aes_cm_192_xxx symbols to def file This is just for completness, see #615 --- srtp.def | 3 +++ 1 file changed, 3 insertions(+) diff --git a/srtp.def b/srtp.def index d418b1464..c9e95c5b9 100644 --- a/srtp.def +++ b/srtp.def @@ -17,6 +17,9 @@ srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32 srtp_crypto_policy_set_aes_cm_128_null_auth srtp_crypto_policy_set_null_cipher_hmac_sha1_80 srtp_crypto_policy_set_null_cipher_hmac_null +srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80 +srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32 +srtp_crypto_policy_set_aes_cm_192_null_auth srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80 srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32 srtp_crypto_policy_set_aes_cm_256_null_auth From 059bce7b1b9f2fab6311a5bd081bc9d801cd8e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 2 May 2022 09:46:14 +0200 Subject: [PATCH 077/109] Add OpenSSL3 build to cmake CI For now this is only for macos as it is simple to add and covers the usecase required. --- .github/workflows/cmake.yml | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index ed914a637..f15f00899 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -12,26 +12,32 @@ jobs: fail-fast: false matrix: os: [ubuntu-20.04, macos-latest, windows-latest] - crypto: [internal, openssl, nss, mbedtls] + crypto: [internal, openssl, openssl3, nss, mbedtls] exclude: - os: windows-latest crypto: openssl + - os: windows-latest + crypto: openssl3 - os: windows-latest crypto: nss - os: windows-latest crypto: mbedtls + - os: ubuntu-latest + crypto: openssl3 include: - crypto: internal cmake-crypto-enable: "" - crypto: openssl cmake-crypto-enable: "-DENABLE_OPENSSL=ON" + - crypto: openssl3 + cmake-crypto-enable: "-DENABLE_OPENSSL=ON" - crypto: nss cmake-crypto-enable: "-DENABLE_NSS=ON" - crypto: mbedtls cmake-crypto-enable: "-DENABLE_MBEDTLS=ON" runs-on: ${{ matrix.os }} - + env: CTEST_OUTPUT_ON_FAILURE: 1 @@ -41,23 +47,29 @@ jobs: run: | sudo apt-get update sudo apt-get install libnss3-dev - + - name: Setup Ubuntu MbedTLS if: matrix.os == 'ubuntu-20.04' && matrix.crypto == 'mbedtls' run: sudo apt-get install libmbedtls-dev - + - name: Setup macOS OpenSSL if: matrix.os == 'macos-latest' && matrix.crypto == 'openssl' run: echo "cmake-crypto-dir=-DOPENSSL_ROOT_DIR=$(brew --prefix openssl@1.1)" >> $GITHUB_ENV - + + - name: Setup macOS OpenSSL3 + if: matrix.os == 'macos-latest' && matrix.crypto == 'openssl3' + run: | + brew install openssl@3 + echo "cmake-crypto-dir=-DOPENSSL_ROOT_DIR=$(brew --prefix openssl@3)" >> $GITHUB_ENV + - name: Setup macOS NSS if: matrix.os == 'macos-latest' && matrix.crypto == 'nss' run: brew install nss - + - name: Setup macOS MbedTLS if: matrix.os == 'macos-latest' && matrix.crypto == 'mbedtls' run: brew install mbedtls - + - uses: actions/checkout@v2 - name: Create Build Environment From 63b8f4412bb17e3ead6862da755b4d118c252596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 2 May 2022 10:20:19 +0200 Subject: [PATCH 078/109] Use OpenSSl EVP MAC api if it is available With OpenSSL 3 the HAMC CTX api has been deprecated and EVP MAC should be used instead. This change adds a compile time check on OpeenSSL version and will use the new api if the version is greater than or equal to 3 . --- crypto/hash/hmac_ossl.c | 115 +++++++++++++++++++++++++++++++++------- 1 file changed, 97 insertions(+), 18 deletions(-) diff --git a/crypto/hash/hmac_ossl.c b/crypto/hash/hmac_ossl.c index d95b66328..83a666944 100644 --- a/crypto/hash/hmac_ossl.c +++ b/crypto/hash/hmac_ossl.c @@ -51,7 +51,14 @@ #include "err.h" /* for srtp_debug */ #include "auth_test_cases.h" #include + +#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3) +#define SRTP_OSSL_USE_EVP_MAC +#endif + +#ifndef SRTP_OSSL_USE_EVP_MAC #include +#endif #define SHA1_DIGEST_SIZE 20 @@ -62,11 +69,21 @@ srtp_debug_module_t srtp_mod_hmac = { "hmac sha-1 openssl" /* printable name for module */ }; +typedef struct { +#ifdef SRTP_OSSL_USE_EVP_MAC + EVP_MAC *mac; + EVP_MAC_CTX *ctx; +#else + HMAC_CTX *ctx; +#endif +} srtp_hmac_ossl_ctx_t; + static srtp_err_status_t srtp_hmac_alloc(srtp_auth_t **a, int key_len, int out_len) { extern const srtp_auth_type_t srtp_hmac; + srtp_hmac_ossl_ctx_t *hmac; debug_print(srtp_mod_hmac, "allocating auth func with key length %d", key_len); @@ -83,14 +100,39 @@ static srtp_err_status_t srtp_hmac_alloc(srtp_auth_t **a, return srtp_err_status_alloc_fail; } - (*a)->state = HMAC_CTX_new(); - if ((*a)->state == NULL) { + hmac = + (srtp_hmac_ossl_ctx_t *)srtp_crypto_alloc(sizeof(srtp_hmac_ossl_ctx_t)); + if (hmac == NULL) { + srtp_crypto_free(*a); + *a = NULL; + return srtp_err_status_alloc_fail; + } + +#ifdef SRTP_OSSL_USE_EVP_MAC + hmac->mac = EVP_MAC_fetch(NULL, "HMAC", NULL); + if (hmac->mac == NULL) { + srtp_crypto_free(hmac); + srtp_crypto_free(*a); + *a = NULL; + return srtp_err_status_alloc_fail; + } + + hmac->ctx = EVP_MAC_CTX_new(hmac->mac); +#else + hmac->ctx = HMAC_CTX_new(); +#endif + if (hmac->ctx == NULL) { +#ifdef SRTP_OSSL_USE_EVP_MAC + EVP_MAC_free(hmac->mac); +#endif + srtp_crypto_free(hmac); srtp_crypto_free(*a); *a = NULL; return srtp_err_status_alloc_fail; } /* set pointers */ + (*a)->state = hmac; (*a)->type = &srtp_hmac; (*a)->out_len = out_len; (*a)->key_len = key_len; @@ -101,11 +143,20 @@ static srtp_err_status_t srtp_hmac_alloc(srtp_auth_t **a, static srtp_err_status_t srtp_hmac_dealloc(srtp_auth_t *a) { - HMAC_CTX *hmac_ctx; - - hmac_ctx = (HMAC_CTX *)a->state; + srtp_hmac_ossl_ctx_t *hmac = (srtp_hmac_ossl_ctx_t *)a->state; + + if (hmac) { +#ifdef SRTP_OSSL_USE_EVP_MAC + EVP_MAC_CTX_free(hmac->ctx); + EVP_MAC_free(hmac->mac); +#else + HMAC_CTX_free(hmac->ctx); +#endif + /* zeroize entire state*/ + octet_string_set_to_zero(hmac, sizeof(srtp_hmac_ossl_ctx_t)); - HMAC_CTX_free(hmac_ctx); + srtp_crypto_free(hmac); + } /* zeroize entire state*/ octet_string_set_to_zero(a, sizeof(srtp_auth_t)); @@ -118,11 +169,15 @@ static srtp_err_status_t srtp_hmac_dealloc(srtp_auth_t *a) static srtp_err_status_t srtp_hmac_start(void *statev) { - HMAC_CTX *state = (HMAC_CTX *)statev; + srtp_hmac_ossl_ctx_t *hmac = (srtp_hmac_ossl_ctx_t *)statev; - if (HMAC_Init_ex(state, NULL, 0, NULL, NULL) == 0) +#ifdef SRTP_OSSL_USE_EVP_MAC + if (EVP_MAC_init(hmac->ctx, NULL, 0, NULL) == 0) return srtp_err_status_auth_fail; - +#else + if (HMAC_Init_ex(hmac->ctx, NULL, 0, NULL, NULL) == 0) + return srtp_err_status_auth_fail; +#endif return srtp_err_status_ok; } @@ -130,11 +185,20 @@ static srtp_err_status_t srtp_hmac_init(void *statev, const uint8_t *key, int key_len) { - HMAC_CTX *state = (HMAC_CTX *)statev; + srtp_hmac_ossl_ctx_t *hmac = (srtp_hmac_ossl_ctx_t *)statev; - if (HMAC_Init_ex(state, key, key_len, EVP_sha1(), NULL) == 0) - return srtp_err_status_auth_fail; +#ifdef SRTP_OSSL_USE_EVP_MAC + OSSL_PARAM params[2]; + params[0] = OSSL_PARAM_construct_utf8_string("digest", "SHA1", 0); + params[1] = OSSL_PARAM_construct_end(); + + if (EVP_MAC_init(hmac->ctx, key, key_len, params) == 0) + return srtp_err_status_auth_fail; +#else + if (HMAC_Init_ex(hmac->ctx, key, key_len, EVP_sha1(), NULL) == 0) + return srtp_err_status_auth_fail; +#endif return srtp_err_status_ok; } @@ -142,14 +206,18 @@ static srtp_err_status_t srtp_hmac_update(void *statev, const uint8_t *message, int msg_octets) { - HMAC_CTX *state = (HMAC_CTX *)statev; + srtp_hmac_ossl_ctx_t *hmac = (srtp_hmac_ossl_ctx_t *)statev; debug_print(srtp_mod_hmac, "input: %s", srtp_octet_string_hex_string(message, msg_octets)); - if (HMAC_Update(state, message, msg_octets) == 0) +#ifdef SRTP_OSSL_USE_EVP_MAC + if (EVP_MAC_update(hmac->ctx, message, msg_octets) == 0) return srtp_err_status_auth_fail; - +#else + if (HMAC_Update(hmac->ctx, message, msg_octets) == 0) + return srtp_err_status_auth_fail; +#endif return srtp_err_status_ok; } @@ -159,10 +227,14 @@ static srtp_err_status_t srtp_hmac_compute(void *statev, int tag_len, uint8_t *result) { - HMAC_CTX *state = (HMAC_CTX *)statev; + srtp_hmac_ossl_ctx_t *hmac = (srtp_hmac_ossl_ctx_t *)statev; uint8_t hash_value[SHA1_DIGEST_SIZE]; int i; +#ifdef SRTP_OSSL_USE_EVP_MAC + size_t len; +#else unsigned int len; +#endif debug_print(srtp_mod_hmac, "input: %s", srtp_octet_string_hex_string(message, msg_octets)); @@ -173,12 +245,19 @@ static srtp_err_status_t srtp_hmac_compute(void *statev, } /* hash message, copy output into H */ - if (HMAC_Update(state, message, msg_octets) == 0) +#ifdef SRTP_OSSL_USE_EVP_MAC + if (EVP_MAC_update(hmac->ctx, message, msg_octets) == 0) return srtp_err_status_auth_fail; - if (HMAC_Final(state, hash_value, &len) == 0) + if (EVP_MAC_final(hmac->ctx, hash_value, &len, sizeof hash_value) == 0) + return srtp_err_status_auth_fail; +#else + if (HMAC_Update(hmac->ctx, message, msg_octets) == 0) return srtp_err_status_auth_fail; + if (HMAC_Final(hmac->ctx, hash_value, &len) == 0) + return srtp_err_status_auth_fail; +#endif if (tag_len < 0 || len < (unsigned int)tag_len) return srtp_err_status_auth_fail; From d010371dfb201ca6c2ec27c185926df46491d465 Mon Sep 17 00:00:00 2001 From: Pascal Buhler Date: Wed, 4 May 2022 17:29:52 +0200 Subject: [PATCH 079/109] use EVP_MAC_CTX_dup for OpenSSL3 versions less than 3.0.3 The new EVP_MAC_CTX api in OpenSSL3 did not initially support calling EVP_MAC_init to reintialize a CTX like the old HMAC_Init_ex could be used. A work around is to duplicate the CTX but this comes at a perfromance cost. Use runtime version check to use EVP_MAC_CTX_dup if version is less than 3.0.3 otherwise use EVP_MAC_init. --- crypto/hash/hmac_ossl.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/crypto/hash/hmac_ossl.c b/crypto/hash/hmac_ossl.c index 83a666944..299959636 100644 --- a/crypto/hash/hmac_ossl.c +++ b/crypto/hash/hmac_ossl.c @@ -54,6 +54,9 @@ #if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3) #define SRTP_OSSL_USE_EVP_MAC +/* before this version reinit of EVP_MAC_CTX was not supported so need to + * duplicate the CTX each time */ +#define SRTP_OSSL_MIN_REINIT_VERSION 0x30000030L #endif #ifndef SRTP_OSSL_USE_EVP_MAC @@ -73,6 +76,8 @@ typedef struct { #ifdef SRTP_OSSL_USE_EVP_MAC EVP_MAC *mac; EVP_MAC_CTX *ctx; + int use_dup; + EVP_MAC_CTX *ctx_dup; #else HMAC_CTX *ctx; #endif @@ -107,6 +112,7 @@ static srtp_err_status_t srtp_hmac_alloc(srtp_auth_t **a, *a = NULL; return srtp_err_status_alloc_fail; } + memset(hmac, 0, sizeof(srtp_hmac_ossl_ctx_t)); #ifdef SRTP_OSSL_USE_EVP_MAC hmac->mac = EVP_MAC_fetch(NULL, "HMAC", NULL); @@ -118,6 +124,10 @@ static srtp_err_status_t srtp_hmac_alloc(srtp_auth_t **a, } hmac->ctx = EVP_MAC_CTX_new(hmac->mac); + + hmac->use_dup = + OpenSSL_version_num() < SRTP_OSSL_MIN_REINIT_VERSION ? 1 : 0; + #else hmac->ctx = HMAC_CTX_new(); #endif @@ -147,7 +157,12 @@ static srtp_err_status_t srtp_hmac_dealloc(srtp_auth_t *a) if (hmac) { #ifdef SRTP_OSSL_USE_EVP_MAC - EVP_MAC_CTX_free(hmac->ctx); + if (hmac->ctx_dup) { + EVP_MAC_CTX_free(hmac->ctx_dup); + } + if (hmac->ctx) { + EVP_MAC_CTX_free(hmac->ctx); + } EVP_MAC_free(hmac->mac); #else HMAC_CTX_free(hmac->ctx); @@ -172,8 +187,18 @@ static srtp_err_status_t srtp_hmac_start(void *statev) srtp_hmac_ossl_ctx_t *hmac = (srtp_hmac_ossl_ctx_t *)statev; #ifdef SRTP_OSSL_USE_EVP_MAC - if (EVP_MAC_init(hmac->ctx, NULL, 0, NULL) == 0) - return srtp_err_status_auth_fail; + if (hmac->use_dup) { + if (hmac->ctx_dup) { + EVP_MAC_CTX_free(hmac->ctx_dup); + } + hmac->ctx_dup = EVP_MAC_CTX_dup(hmac->ctx); + if (hmac->ctx_dup == NULL) { + return srtp_err_status_alloc_fail; + } + } else { + if (EVP_MAC_init(hmac->ctx, NULL, 0, NULL) == 0) + return srtp_err_status_auth_fail; + } #else if (HMAC_Init_ex(hmac->ctx, NULL, 0, NULL, NULL) == 0) return srtp_err_status_auth_fail; @@ -212,7 +237,8 @@ static srtp_err_status_t srtp_hmac_update(void *statev, srtp_octet_string_hex_string(message, msg_octets)); #ifdef SRTP_OSSL_USE_EVP_MAC - if (EVP_MAC_update(hmac->ctx, message, msg_octets) == 0) + if (EVP_MAC_update(hmac->use_dup ? hmac->ctx_dup : hmac->ctx, message, + msg_octets) == 0) return srtp_err_status_auth_fail; #else if (HMAC_Update(hmac->ctx, message, msg_octets) == 0) @@ -246,10 +272,12 @@ static srtp_err_status_t srtp_hmac_compute(void *statev, /* hash message, copy output into H */ #ifdef SRTP_OSSL_USE_EVP_MAC - if (EVP_MAC_update(hmac->ctx, message, msg_octets) == 0) + if (EVP_MAC_update(hmac->use_dup ? hmac->ctx_dup : hmac->ctx, message, + msg_octets) == 0) return srtp_err_status_auth_fail; - if (EVP_MAC_final(hmac->ctx, hash_value, &len, sizeof hash_value) == 0) + if (EVP_MAC_final(hmac->use_dup ? hmac->ctx_dup : hmac->ctx, hash_value, + &len, sizeof hash_value) == 0) return srtp_err_status_auth_fail; #else if (HMAC_Update(hmac->ctx, message, msg_octets) == 0) From 7a1416d8bb12f15370512835a9949daf9783848e Mon Sep 17 00:00:00 2001 From: Pascal Buhler Date: Mon, 12 Dec 2022 01:09:23 +0100 Subject: [PATCH 080/109] Show configured warning when running cmake --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 858917a78..de0915fc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,10 +120,12 @@ endif() if(BUILD_WITH_WARNINGS) if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU") - add_compile_options(-Wall -pedantic -Wextra -Werror) + set(WARNINGS -Wall -pedantic -Wextra -Werror) elseif(MSVC) - add_compile_options(/W4 /WX) + set(WARNINGS /W4 /WX) endif() + message(STATUS "Using warnings: ${WARNINGS}") + add_compile_options(${WARNINGS}) endif() set(SOURCES_C From 46fb1a2c2dc91e1410d3e9043fd088158bed4c92 Mon Sep 17 00:00:00 2001 From: Pascal Buhler Date: Mon, 12 Dec 2022 01:22:47 +0100 Subject: [PATCH 081/109] Include some information about supported ciphers Provide a little info on the consequence of configuring different crypto backends, as request in #620 . --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 1e42a0bae..22cda488b 100644 --- a/README.md +++ b/README.md @@ -220,11 +220,21 @@ will want to read the Security Considerations section of [RFC 3711](https://tool In addition, it is important that you read and understand the terms outlined in the [License and Disclaimer](#license-and-disclaimer) section. +This library also supports the AES-GCM Authenticated Encryption methods +described in [RFC 7714](https://tools.ietf.org/html/rfc7714) + -------------------------------------------------------------------------------- ## Implementation Notes + * It is possible to configure which 3rd party (ie openssl/nss/etc) crypto backend + libSRTP will be built with. If no 3rd party backend is set then libSRTP provides + an internal implementation of AES and Sha1. The internal implementation only + supports AES-128 & AES-256, so to use AES-192 or the AES-GCM group of ciphers a + 3rd party crypto backend must be configured. For this and performance reasons it + is highly recommended to use a 3rd party crypto backend. + * The `srtp_protect()` function assumes that the buffer holding the rtp packet has enough storage allocated that the authentication tag can be written to the end of that packet. If this assumption From 7041beb12e8a27aa9fa8b8f78684c4dbd416531e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 12 Dec 2022 03:03:54 +0100 Subject: [PATCH 082/109] update to clang-format-12 For CI this will work on both Ubuntu 20.04 & 22.04 . This will allow CI to move to ubuntu-latest, see #622 --- .github/workflows/format_check.yml | 2 +- format.sh | 2 +- test/rtp.c | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml index 3110a7dfd..bbbd0c65d 100644 --- a/.github/workflows/format_check.yml +++ b/.github/workflows/format_check.yml @@ -12,6 +12,6 @@ jobs: steps: - uses: actions/checkout@v2 - name: Install Clang Format - run: sudo apt install clang-format-10 + run: sudo apt install clang-format-12 - name: Run clang format run: ./format.sh -d diff --git a/format.sh b/format.sh index 56b2d0ee0..b67828c93 100755 --- a/format.sh +++ b/format.sh @@ -7,7 +7,7 @@ # assumes git tree is clean when reporting status if [ -z "${CLANG_FORMAT}" ]; then - CLANG_FORMAT=clang-format-10 + CLANG_FORMAT=clang-format-12 fi a=`git ls-files '*.h' '*.c'` diff --git a/test/rtp.c b/test/rtp.c index 70248ee2b..fac031170 100644 --- a/test/rtp.c +++ b/test/rtp.c @@ -131,10 +131,9 @@ int rtp_recvfrom(rtp_receiver_t receiver, void *msg, int *len) if (stat) { fprintf(stderr, "error: srtp unprotection failed with code %d%s\n", stat, - stat == srtp_err_status_replay_fail - ? " (replay check failed)" - : stat == srtp_err_status_auth_fail ? " (auth check failed)" - : ""); + stat == srtp_err_status_replay_fail ? " (replay check failed)" + : stat == srtp_err_status_auth_fail ? " (auth check failed)" + : ""); return -1; } strncpy(msg, receiver->message.body, octets_recvd); From 97d1c2121d1208456b2b10555d7a19361c086fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Mon, 28 Nov 2022 21:52:52 +0100 Subject: [PATCH 083/109] Make definitions prototypes --- crypto/kernel/crypto_kernel.c | 8 ++++---- crypto/kernel/err.c | 2 +- srtp/srtp.c | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crypto/kernel/crypto_kernel.c b/crypto/kernel/crypto_kernel.c index 764e7ecfa..c7b082dd4 100644 --- a/crypto/kernel/crypto_kernel.c +++ b/crypto/kernel/crypto_kernel.c @@ -69,7 +69,7 @@ srtp_crypto_kernel_t crypto_kernel = { #define MAX_RNG_TRIALS 25 -srtp_err_status_t srtp_crypto_kernel_init() +srtp_err_status_t srtp_crypto_kernel_init(void) { srtp_err_status_t status; @@ -168,7 +168,7 @@ srtp_err_status_t srtp_crypto_kernel_init() return srtp_err_status_ok; } -srtp_err_status_t srtp_crypto_kernel_status() +srtp_err_status_t srtp_crypto_kernel_status(void) { srtp_err_status_t status; srtp_kernel_cipher_type_t *ctype = crypto_kernel.cipher_type_list; @@ -209,7 +209,7 @@ srtp_err_status_t srtp_crypto_kernel_status() return srtp_err_status_ok; } -srtp_err_status_t srtp_crypto_kernel_list_debug_modules() +srtp_err_status_t srtp_crypto_kernel_list_debug_modules(void) { srtp_kernel_debug_module_t *dm = crypto_kernel.debug_module_list; @@ -228,7 +228,7 @@ srtp_err_status_t srtp_crypto_kernel_list_debug_modules() return srtp_err_status_ok; } -srtp_err_status_t srtp_crypto_kernel_shutdown() +srtp_err_status_t srtp_crypto_kernel_shutdown(void) { /* * free dynamic memory used in crypto_kernel at present diff --git a/crypto/kernel/err.c b/crypto/kernel/err.c index 9db5bfb43..cfdf9851d 100644 --- a/crypto/kernel/err.c +++ b/crypto/kernel/err.c @@ -54,7 +54,7 @@ static FILE *srtp_err_file = NULL; -srtp_err_status_t srtp_err_reporting_init() +srtp_err_status_t srtp_err_reporting_init(void) { #ifdef ERR_REPORTING_STDOUT srtp_err_file = stdout; diff --git a/srtp/srtp.c b/srtp/srtp.c index 2d3faaf47..9745556a7 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -109,7 +109,7 @@ static srtp_err_status_t srtp_validate_rtp_header(void *rtp_hdr, return srtp_err_status_ok; } -const char *srtp_get_version_string() +const char *srtp_get_version_string(void) { /* * Simply return the autotools generated string @@ -117,7 +117,7 @@ const char *srtp_get_version_string() return SRTP_VER_STRING; } -unsigned int srtp_get_version() +unsigned int srtp_get_version(void) { unsigned int major = 0, minor = 0, micro = 0; unsigned int rv = 0; @@ -2774,7 +2774,7 @@ srtp_err_status_t srtp_unprotect_mki(srtp_ctx_t *ctx, return srtp_err_status_ok; } -srtp_err_status_t srtp_init() +srtp_err_status_t srtp_init(void) { srtp_err_status_t status; @@ -2791,7 +2791,7 @@ srtp_err_status_t srtp_init() return srtp_err_status_ok; } -srtp_err_status_t srtp_shutdown() +srtp_err_status_t srtp_shutdown(void) { srtp_err_status_t status; From e9618775d57dee40fbc89e3ced6769d8a9af16c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 12 Dec 2022 04:48:21 +0100 Subject: [PATCH 084/109] prevent "set but not used warning" Failures where counted but never used, so just remove. --- test/replay_driver.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/test/replay_driver.c b/test/replay_driver.c index 9807e50c1..e5bb29551 100644 --- a/test/replay_driver.c +++ b/test/replay_driver.c @@ -251,7 +251,6 @@ double rdb_check_adds_per_second(void) uint32_t i; srtp_rdb_t rdb; clock_t timer; - int failures = 0; /* count number of failures */ if (srtp_rdb_init(&rdb) != srtp_err_status_ok) { printf("rdb_init failed\n"); @@ -260,18 +259,12 @@ double rdb_check_adds_per_second(void) timer = clock(); for (i = 0; i < REPLAY_NUM_TRIALS; i += 3) { - if (srtp_rdb_check(&rdb, i + 2) != srtp_err_status_ok) - ++failures; - if (srtp_rdb_add_index(&rdb, i + 2) != srtp_err_status_ok) - ++failures; - if (srtp_rdb_check(&rdb, i + 1) != srtp_err_status_ok) - ++failures; - if (srtp_rdb_add_index(&rdb, i + 1) != srtp_err_status_ok) - ++failures; - if (srtp_rdb_check(&rdb, i) != srtp_err_status_ok) - ++failures; - if (srtp_rdb_add_index(&rdb, i) != srtp_err_status_ok) - ++failures; + srtp_rdb_check(&rdb, i + 2); + srtp_rdb_add_index(&rdb, i + 2); + srtp_rdb_check(&rdb, i + 1); + srtp_rdb_add_index(&rdb, i + 1); + srtp_rdb_check(&rdb, i); + srtp_rdb_add_index(&rdb, i); } timer = clock() - timer; From 38ccf12c3472c58ff1363a0b75aeb54242bef1ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 12 Dec 2022 04:52:47 +0100 Subject: [PATCH 085/109] prevent "declaration without a prototype" warnings Full warning: "a function declaration without a prototype is deprecated in all versions of C" --- test/replay_driver.c | 2 +- test/srtp_driver.c | 32 ++++++++++++++++---------------- test/test_srtp.c | 6 +++--- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/test/replay_driver.c b/test/replay_driver.c index e5bb29551..45aec02f2 100644 --- a/test/replay_driver.c +++ b/test/replay_driver.c @@ -132,7 +132,7 @@ srtp_err_status_t rdb_check_add_unordered(srtp_rdb_t *rdb, uint32_t idx) return srtp_err_status_ok; } -srtp_err_status_t test_rdb_db() +srtp_err_status_t test_rdb_db(void) { srtp_rdb_t rdb; uint32_t idx, ircvd; diff --git a/test/srtp_driver.c b/test/srtp_driver.c index 69aef332d..20957a60e 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -1666,7 +1666,7 @@ double mips_estimate(int num_trials, int *ignore) * These packets were made with the default SRTP policy. */ -srtp_err_status_t srtp_validate() +srtp_err_status_t srtp_validate(void) { // clang-format off uint8_t srtp_plaintext_ref[28] = { @@ -1826,7 +1826,7 @@ srtp_err_status_t srtp_validate() * and HMAC authentication. */ -srtp_err_status_t srtp_validate_null() +srtp_err_status_t srtp_validate_null(void) { // clang-format off uint8_t srtp_plaintext_ref[28] = { @@ -1984,7 +1984,7 @@ srtp_err_status_t srtp_validate_null() * srtp_validate_gcm() verifies the correctness of libsrtp by comparing * an computed packet against the known ciphertext for the plaintext. */ -srtp_err_status_t srtp_validate_gcm() +srtp_err_status_t srtp_validate_gcm(void) { // clang-format off uint8_t rtp_plaintext_ref[28] = { @@ -2146,7 +2146,7 @@ srtp_err_status_t srtp_validate_gcm() /* * Test vectors taken from RFC 6904, Appendix A */ -srtp_err_status_t srtp_validate_encrypted_extensions_headers() +srtp_err_status_t srtp_validate_encrypted_extensions_headers(void) { // clang-format off unsigned char test_key_ext_headers[30] = { @@ -2269,7 +2269,7 @@ srtp_err_status_t srtp_validate_encrypted_extensions_headers() /* * Headers of test vectors taken from RFC 6904, Appendix A */ -srtp_err_status_t srtp_validate_encrypted_extensions_headers_gcm() +srtp_err_status_t srtp_validate_encrypted_extensions_headers_gcm(void) { // clang-format off unsigned char test_key_ext_headers[30] = { @@ -2392,7 +2392,7 @@ srtp_err_status_t srtp_validate_encrypted_extensions_headers_gcm() * These packets were made with the AES-CM-256/HMAC-SHA-1-80 policy. */ -srtp_err_status_t srtp_validate_aes_256() +srtp_err_status_t srtp_validate_aes_256(void) { // clang-format off unsigned char aes_256_test_key[46] = { @@ -2551,7 +2551,7 @@ srtp_err_status_t srtp_dealloc_big_policy(srtp_policy_t *list) return srtp_err_status_ok; } -srtp_err_status_t srtp_test_empty_payload() +srtp_err_status_t srtp_test_empty_payload(void) { srtp_t srtp_snd, srtp_recv; srtp_err_status_t status; @@ -2627,7 +2627,7 @@ srtp_err_status_t srtp_test_empty_payload() } #ifdef GCM -srtp_err_status_t srtp_test_empty_payload_gcm() +srtp_err_status_t srtp_test_empty_payload_gcm(void) { srtp_t srtp_snd, srtp_recv; srtp_err_status_t status; @@ -2703,7 +2703,7 @@ srtp_err_status_t srtp_test_empty_payload_gcm() } #endif // GCM -srtp_err_status_t srtp_test_remove_stream() +srtp_err_status_t srtp_test_remove_stream(void) { srtp_err_status_t status; srtp_policy_t *policy_list, policy; @@ -2816,7 +2816,7 @@ unsigned char test_alt_key[46] = { * atempts to prove that srtp_update does not reset the ROC. */ -srtp_err_status_t srtp_test_update() +srtp_err_status_t srtp_test_update(void) { srtp_err_status_t status; uint32_t ssrc = 0x12121212; @@ -3061,7 +3061,7 @@ srtp_err_status_t srtp_test_setup_protect_trailer_streams( return srtp_err_status_ok; } -srtp_err_status_t srtp_test_protect_trailer_length() +srtp_err_status_t srtp_test_protect_trailer_length(void) { srtp_t srtp_send; srtp_t srtp_send_mki; @@ -3118,7 +3118,7 @@ srtp_err_status_t srtp_test_protect_trailer_length() return srtp_err_status_ok; } -srtp_err_status_t srtp_test_protect_rtcp_trailer_length() +srtp_err_status_t srtp_test_protect_rtcp_trailer_length(void) { srtp_t srtp_send; srtp_t srtp_send_mki; @@ -3176,7 +3176,7 @@ srtp_err_status_t srtp_test_protect_rtcp_trailer_length() return srtp_err_status_ok; } -srtp_err_status_t srtp_test_out_of_order_after_rollover() +srtp_err_status_t srtp_test_out_of_order_after_rollover(void) { srtp_err_status_t status; @@ -3394,7 +3394,7 @@ srtp_err_status_t srtp_test_out_of_order_after_rollover() return srtp_err_status_ok; } -srtp_err_status_t srtp_test_get_roc() +srtp_err_status_t srtp_test_get_roc(void) { srtp_err_status_t status; srtp_policy_t policy; @@ -3736,7 +3736,7 @@ static srtp_err_status_t test_set_sender_roc(uint16_t seq, uint32_t roc_to_set) return srtp_err_status_ok; } -srtp_err_status_t srtp_test_set_receiver_roc() +srtp_err_status_t srtp_test_set_receiver_roc(void) { int packets; uint32_t roc; @@ -3800,7 +3800,7 @@ srtp_err_status_t srtp_test_set_receiver_roc() return srtp_err_status_ok; } -srtp_err_status_t srtp_test_set_sender_roc() +srtp_err_status_t srtp_test_set_sender_roc(void) { uint32_t roc; uint16_t seq; diff --git a/test/test_srtp.c b/test/test_srtp.c index 7d2051b7e..e739239b4 100644 --- a/test/test_srtp.c +++ b/test/test_srtp.c @@ -84,7 +84,7 @@ TEST_LIST = { { "srtp_calc_aead_iv_srtcp_all_zero_input_yield_zero_output()", * Implementation. */ -void srtp_calc_aead_iv_srtcp_all_zero_input_yield_zero_output() +void srtp_calc_aead_iv_srtcp_all_zero_input_yield_zero_output(void) { // Preconditions srtp_session_keys_t session_keys; @@ -111,7 +111,7 @@ void srtp_calc_aead_iv_srtcp_all_zero_input_yield_zero_output() TEST_CHECK(memcmp(&zero_vector, &init_vector, sizeof(v128_t)) == 0); } -void srtp_calc_aead_iv_srtcp_seq_num_over_0x7FFFFFFF_bad_param() +void srtp_calc_aead_iv_srtcp_seq_num_over_0x7FFFFFFF_bad_param(void) { // Preconditions srtp_session_keys_t session_keys; @@ -143,7 +143,7 @@ void srtp_calc_aead_iv_srtcp_seq_num_over_0x7FFFFFFF_bad_param() * Ensure that for each valid sequence number where the most significant bit is * high that we get an expected and unique IV. */ -void srtp_calc_aead_iv_srtcp_distinct_iv_per_sequence_number() +void srtp_calc_aead_iv_srtcp_distinct_iv_per_sequence_number(void) { #define SAMPLE_COUNT (3) // Preconditions From d332304b2f9d4fcf41337d06ff63d914ea6935a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Tue, 13 Dec 2022 23:44:02 +0100 Subject: [PATCH 086/109] Apply suggestions from code review Co-authored-by: Richard Barnes --- crypto/hash/hmac_ossl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crypto/hash/hmac_ossl.c b/crypto/hash/hmac_ossl.c index 299959636..b0a8d2bab 100644 --- a/crypto/hash/hmac_ossl.c +++ b/crypto/hash/hmac_ossl.c @@ -131,6 +131,7 @@ static srtp_err_status_t srtp_hmac_alloc(srtp_auth_t **a, #else hmac->ctx = HMAC_CTX_new(); #endif + if (hmac->ctx == NULL) { #ifdef SRTP_OSSL_USE_EVP_MAC EVP_MAC_free(hmac->mac); @@ -196,8 +197,9 @@ static srtp_err_status_t srtp_hmac_start(void *statev) return srtp_err_status_alloc_fail; } } else { - if (EVP_MAC_init(hmac->ctx, NULL, 0, NULL) == 0) + if (EVP_MAC_init(hmac->ctx, NULL, 0, NULL) == 0) { return srtp_err_status_auth_fail; + } } #else if (HMAC_Init_ex(hmac->ctx, NULL, 0, NULL, NULL) == 0) From 1ccdd7612fe11154be14ac08caf04f1412efdb4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Tue, 13 Dec 2022 23:20:27 +0100 Subject: [PATCH 087/109] memset not required when using srtp_crypto_alloc srtp_crypto_alloc uses calloc --- crypto/hash/hmac_ossl.c | 1 - 1 file changed, 1 deletion(-) diff --git a/crypto/hash/hmac_ossl.c b/crypto/hash/hmac_ossl.c index b0a8d2bab..a2332fc0b 100644 --- a/crypto/hash/hmac_ossl.c +++ b/crypto/hash/hmac_ossl.c @@ -112,7 +112,6 @@ static srtp_err_status_t srtp_hmac_alloc(srtp_auth_t **a, *a = NULL; return srtp_err_status_alloc_fail; } - memset(hmac, 0, sizeof(srtp_hmac_ossl_ctx_t)); #ifdef SRTP_OSSL_USE_EVP_MAC hmac->mac = EVP_MAC_fetch(NULL, "HMAC", NULL); From 5d9c5fd8d24f58e222645ceca728a49cc957bfc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Wed, 14 Dec 2022 00:10:12 +0100 Subject: [PATCH 088/109] Add comment about the 3 flavours of OpenSSL HMAC --- crypto/hash/hmac_ossl.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crypto/hash/hmac_ossl.c b/crypto/hash/hmac_ossl.c index a2332fc0b..9f6ccc350 100644 --- a/crypto/hash/hmac_ossl.c +++ b/crypto/hash/hmac_ossl.c @@ -72,6 +72,19 @@ srtp_debug_module_t srtp_mod_hmac = { "hmac sha-1 openssl" /* printable name for module */ }; +/* + * There are three different behaviors of OpenSSL HMAC for different versions. + * + * 1. Pre-3.0 - Use HMAC API + * 2. 3.0.0 - 3.0.2 - EVP API is required, but doesn't support reinitialization, + * so we have to use EVP_MAC_CTX_dup + * 3. 3.0.3 and later - EVP API is required and supports reinitialization + * + * The distingtion between cases 2 & 3 needs to be made at runtime, because in a + * shared library context you might end up building against 3.0.3 and running + * against 3.0.2. + */ + typedef struct { #ifdef SRTP_OSSL_USE_EVP_MAC EVP_MAC *mac; From 131c0bba29d5a3b5d7590c173782a101fff139b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Wed, 14 Dec 2022 00:59:49 +0100 Subject: [PATCH 089/109] only run against the main branch this is just keeping consistent with the other work flows --- .github/workflows/cifuzz.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml index c07c7fc80..c065c043b 100644 --- a/.github/workflows/cifuzz.yml +++ b/.github/workflows/cifuzz.yml @@ -1,5 +1,11 @@ name: CIFuzz -on: [ push, pull_request ] + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + jobs: Fuzzing: runs-on: ubuntu-latest From c83812034ba97b8ec9555d2b3ee8a0d6fa75dfd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Thu, 15 Dec 2022 02:32:19 +0100 Subject: [PATCH 090/109] flip the logic as to which ctx is dup'd As suggested by @bifurcation, it is nicer to have the dup logic in the init phase and have the hash code consistent. --- crypto/hash/hmac_ossl.c | 50 ++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/crypto/hash/hmac_ossl.c b/crypto/hash/hmac_ossl.c index 9f6ccc350..fe55f7874 100644 --- a/crypto/hash/hmac_ossl.c +++ b/crypto/hash/hmac_ossl.c @@ -136,23 +136,31 @@ static srtp_err_status_t srtp_hmac_alloc(srtp_auth_t **a, } hmac->ctx = EVP_MAC_CTX_new(hmac->mac); + if (hmac->ctx == NULL) { + EVP_MAC_free(hmac->mac); + srtp_crypto_free(hmac); + srtp_crypto_free(*a); + *a = NULL; + return srtp_err_status_alloc_fail; + } hmac->use_dup = OpenSSL_version_num() < SRTP_OSSL_MIN_REINIT_VERSION ? 1 : 0; + if (hmac->use_dup) { + debug_print0(srtp_mod_hmac, "using EVP_MAC_CTX_dup"); + hmac->ctx_dup = hmac->ctx; + hmac->ctx = NULL; + } #else hmac->ctx = HMAC_CTX_new(); -#endif - if (hmac->ctx == NULL) { -#ifdef SRTP_OSSL_USE_EVP_MAC - EVP_MAC_free(hmac->mac); -#endif srtp_crypto_free(hmac); srtp_crypto_free(*a); *a = NULL; return srtp_err_status_alloc_fail; } +#endif /* set pointers */ (*a)->state = hmac; @@ -170,12 +178,12 @@ static srtp_err_status_t srtp_hmac_dealloc(srtp_auth_t *a) if (hmac) { #ifdef SRTP_OSSL_USE_EVP_MAC - if (hmac->ctx_dup) { - EVP_MAC_CTX_free(hmac->ctx_dup); - } - if (hmac->ctx) { + if (hmac->ctx != NULL) { EVP_MAC_CTX_free(hmac->ctx); } + if (hmac->ctx_dup != NULL) { + EVP_MAC_CTX_free(hmac->ctx_dup); + } EVP_MAC_free(hmac->mac); #else HMAC_CTX_free(hmac->ctx); @@ -201,11 +209,11 @@ static srtp_err_status_t srtp_hmac_start(void *statev) #ifdef SRTP_OSSL_USE_EVP_MAC if (hmac->use_dup) { - if (hmac->ctx_dup) { - EVP_MAC_CTX_free(hmac->ctx_dup); + if (hmac->ctx != NULL) { + EVP_MAC_CTX_free(hmac->ctx); } - hmac->ctx_dup = EVP_MAC_CTX_dup(hmac->ctx); - if (hmac->ctx_dup == NULL) { + hmac->ctx = EVP_MAC_CTX_dup(hmac->ctx_dup); + if (hmac->ctx == NULL) { return srtp_err_status_alloc_fail; } } else { @@ -232,8 +240,10 @@ static srtp_err_status_t srtp_hmac_init(void *statev, params[0] = OSSL_PARAM_construct_utf8_string("digest", "SHA1", 0); params[1] = OSSL_PARAM_construct_end(); - if (EVP_MAC_init(hmac->ctx, key, key_len, params) == 0) + if (EVP_MAC_init(hmac->use_dup ? hmac->ctx_dup : hmac->ctx, key, key_len, + params) == 0) { return srtp_err_status_auth_fail; + } #else if (HMAC_Init_ex(hmac->ctx, key, key_len, EVP_sha1(), NULL) == 0) return srtp_err_status_auth_fail; @@ -251,9 +261,9 @@ static srtp_err_status_t srtp_hmac_update(void *statev, srtp_octet_string_hex_string(message, msg_octets)); #ifdef SRTP_OSSL_USE_EVP_MAC - if (EVP_MAC_update(hmac->use_dup ? hmac->ctx_dup : hmac->ctx, message, - msg_octets) == 0) + if (EVP_MAC_update(hmac->ctx, message, msg_octets) == 0) { return srtp_err_status_auth_fail; + } #else if (HMAC_Update(hmac->ctx, message, msg_octets) == 0) return srtp_err_status_auth_fail; @@ -286,13 +296,13 @@ static srtp_err_status_t srtp_hmac_compute(void *statev, /* hash message, copy output into H */ #ifdef SRTP_OSSL_USE_EVP_MAC - if (EVP_MAC_update(hmac->use_dup ? hmac->ctx_dup : hmac->ctx, message, - msg_octets) == 0) + if (EVP_MAC_update(hmac->ctx, message, msg_octets) == 0) { return srtp_err_status_auth_fail; + } - if (EVP_MAC_final(hmac->use_dup ? hmac->ctx_dup : hmac->ctx, hash_value, - &len, sizeof hash_value) == 0) + if (EVP_MAC_final(hmac->ctx, hash_value, &len, sizeof hash_value) == 0) { return srtp_err_status_auth_fail; + } #else if (HMAC_Update(hmac->ctx, message, msg_octets) == 0) return srtp_err_status_auth_fail; From 3d640bfa7de18d4b2f558f0ed6f94175c594d871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Thu, 15 Dec 2022 03:49:33 +0100 Subject: [PATCH 091/109] Add android build to CI A single simple build, just to ensure it works and demonstrate how it can be done. --- .github/workflows/android.yml | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/android.yml diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml new file mode 100644 index 000000000..91fda9b86 --- /dev/null +++ b/.github/workflows/android.yml @@ -0,0 +1,44 @@ +name: Android CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + strategy: + fail-fast: false + + runs-on: ubuntu-20.04 + + steps: + + - uses: actions/checkout@v2 + + - name: Create Build Environment + run: cmake -E make_directory ${{github.workspace}}/build + + - name: Configure CMake + working-directory: ${{github.workspace}}/build + shell: bash + run: cmake $GITHUB_WORKSPACE -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a + + - name: Build + working-directory: ${{github.workspace}}/build + shell: bash + run: cmake --build . + + - name: Create Build Environment (Shared Library) + run: cmake -E make_directory ${{github.workspace}}/build_shared + + - name: Configure CMake (Shared Library) + working-directory: ${{github.workspace}}/build_shared + shell: bash + run: cmake $GITHUB_WORKSPACE -DBUILD_SHARED_LIBS=ON -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a + + - name: Build (Shared Library) + working-directory: ${{github.workspace}}/build_shared + shell: bash + run: cmake --build . From 5bceeabc46b83e4bcad580b9ad4f25e879a22848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Thu, 15 Dec 2022 04:48:02 +0100 Subject: [PATCH 092/109] update min openssl version to 1.1.0 As of commit #593 the minimal supported version is 1.1.0, this updates build files to check for that version. This also means the check for a broken openssl cleans function is obsolete so it is removed. #597 --- CMakeLists.txt | 2 +- config_in.h | 3 - configure | 335 ++++++++-------------------------------- configure.ac | 44 +----- crypto/math/datatypes.c | 2 +- meson.build | 2 +- 6 files changed, 77 insertions(+), 311 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index de0915fc3..3d9e4a9bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,7 @@ if(ENABLE_OPENSSL) if(ENABLE_NSS OR ENABLE_MBEDTLS) message(FATAL_ERROR "ssl conflict. can not enable openssl and mbedtls or nss simultaneously.") endif() - find_package(OpenSSL REQUIRED) + find_package(OpenSSL 1.1.0 REQUIRED) set(OPENSSL ${ENABLE_OPENSSL} CACHE BOOL INTERNAL) set(GCM ${ENABLE_OPENSSL} CACHE BOOL INTERNAL) endif() diff --git a/config_in.h b/config_in.h index 1a3737c5c..ee5393c48 100644 --- a/config_in.h +++ b/config_in.h @@ -141,9 +141,6 @@ /* Define this to use OpenSSL crypto. */ #undef OPENSSL -/* Define this if OPENSSL_cleanse is broken. */ -#undef OPENSSL_CLEANSE_BROKEN - /* Define this to use OpenSSL KDF for SRTP. */ #undef OPENSSL_KDF diff --git a/configure b/configure index 8c735bbb3..f0ba04293 100755 --- a/configure +++ b/configure @@ -685,6 +685,7 @@ infodir docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir @@ -775,6 +776,7 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -1027,6 +1029,15 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1164,7 +1175,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1317,6 +1328,7 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -3546,8 +3558,37 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu -# expand $ac_aux_dir to an absolute path -am_aux_dir=`cd $ac_aux_dir && pwd` +ac_aux_dir= +for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do + if test -f "$ac_dir/install-sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install-sh -c" + break + elif test -f "$ac_dir/install.sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install.sh -c" + break + elif test -f "$ac_dir/shtool"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/shtool install -c" + break + fi +done +if test -z "$ac_aux_dir"; then + as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5 +fi + +# These three variables are undocumented and unsupported, +# and are intended to be withdrawn in a future Autoconf release. +# They can cause serious problems if a builder's source tree is in a directory +# whose full name contains unusual characters. +ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. +ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. +ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. + + +# Expand $ac_aux_dir to an absolute path. +am_aux_dir=`cd "$ac_aux_dir" && pwd` if test -n "$ac_tool_prefix"; then @@ -3657,7 +3698,13 @@ $as_echo_n "checking the archiver ($AR) interface... " >&6; } if ${am_cv_ar_interface+:} false; then : $as_echo_n "(cached) " >&6 else - am_cv_ar_interface=ar + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + am_cv_ar_interface=ar cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int some_variable = 0; @@ -3688,6 +3735,11 @@ if ac_fn_c_try_compile "$LINENO"; then : fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_ar_interface" >&5 @@ -3802,35 +3854,6 @@ else RANLIB="$ac_cv_prog_RANLIB" fi -ac_aux_dir= -for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do - if test -f "$ac_dir/install-sh"; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install-sh -c" - break - elif test -f "$ac_dir/install.sh"; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install.sh -c" - break - elif test -f "$ac_dir/shtool"; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/shtool install -c" - break - fi -done -if test -z "$ac_aux_dir"; then - as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5 -fi - -# These three variables are undocumented and unsupported, -# and are intended to be withdrawn in a future Autoconf release. -# They can cause serious problems if a builder's source tree is in a directory -# whose full name contains unusual characters. -ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. -ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. -ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. - - # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: @@ -5497,71 +5520,12 @@ if test -n "$crypto_CFLAGS"; then pkg_cv_crypto_CFLAGS="$crypto_CFLAGS" elif test -n "$PKG_CONFIG"; then if test -n "$PKG_CONFIG" && \ - { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libcrypto >= 1.0.2i\""; } >&5 - ($PKG_CONFIG --exists --print-errors "libcrypto >= 1.0.2i") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; then - pkg_cv_crypto_CFLAGS=`$PKG_CONFIG --cflags "libcrypto >= 1.0.2i" 2>/dev/null` - test "x$?" != "x0" && pkg_failed=yes -else - pkg_failed=yes -fi - else - pkg_failed=untried -fi -if test -n "$crypto_LIBS"; then - pkg_cv_crypto_LIBS="$crypto_LIBS" - elif test -n "$PKG_CONFIG"; then - if test -n "$PKG_CONFIG" && \ - { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libcrypto >= 1.0.2i\""; } >&5 - ($PKG_CONFIG --exists --print-errors "libcrypto >= 1.0.2i") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; then - pkg_cv_crypto_LIBS=`$PKG_CONFIG --libs "libcrypto >= 1.0.2i" 2>/dev/null` - test "x$?" != "x0" && pkg_failed=yes -else - pkg_failed=yes -fi - else - pkg_failed=untried -fi - - - -if test $pkg_failed = yes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - -if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then - _pkg_short_errors_supported=yes -else - _pkg_short_errors_supported=no -fi - if test $_pkg_short_errors_supported = yes; then - crypto_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libcrypto >= 1.0.2i" 2>&1` - else - crypto_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libcrypto >= 1.0.2i" 2>&1` - fi - # Put the nasty error message in config.log where it belongs - echo "$crypto_PKG_ERRORS" >&5 - - -pkg_failed=no -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for crypto" >&5 -$as_echo_n "checking for crypto... " >&6; } - -if test -n "$crypto_CFLAGS"; then - pkg_cv_crypto_CFLAGS="$crypto_CFLAGS" - elif test -n "$PKG_CONFIG"; then - if test -n "$PKG_CONFIG" && \ - { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libcrypto >= 1.0.1\""; } >&5 - ($PKG_CONFIG --exists --print-errors "libcrypto >= 1.0.1") 2>&5 + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libcrypto >= 1.1.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libcrypto >= 1.1.0") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then - pkg_cv_crypto_CFLAGS=`$PKG_CONFIG --cflags "libcrypto >= 1.0.1" 2>/dev/null` + pkg_cv_crypto_CFLAGS=`$PKG_CONFIG --cflags "libcrypto >= 1.1.0" 2>/dev/null` test "x$?" != "x0" && pkg_failed=yes else pkg_failed=yes @@ -5573,12 +5537,12 @@ if test -n "$crypto_LIBS"; then pkg_cv_crypto_LIBS="$crypto_LIBS" elif test -n "$PKG_CONFIG"; then if test -n "$PKG_CONFIG" && \ - { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libcrypto >= 1.0.1\""; } >&5 - ($PKG_CONFIG --exists --print-errors "libcrypto >= 1.0.1") 2>&5 + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libcrypto >= 1.1.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libcrypto >= 1.1.0") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then - pkg_cv_crypto_LIBS=`$PKG_CONFIG --libs "libcrypto >= 1.0.1" 2>/dev/null` + pkg_cv_crypto_LIBS=`$PKG_CONFIG --libs "libcrypto >= 1.1.0" 2>/dev/null` test "x$?" != "x0" && pkg_failed=yes else pkg_failed=yes @@ -5599,14 +5563,14 @@ else _pkg_short_errors_supported=no fi if test $_pkg_short_errors_supported = yes; then - crypto_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libcrypto >= 1.0.1" 2>&1` + crypto_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libcrypto >= 1.1.0" 2>&1` else - crypto_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libcrypto >= 1.0.1" 2>&1` + crypto_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libcrypto >= 1.1.0" 2>&1` fi # Put the nasty error message in config.log where it belongs echo "$crypto_PKG_ERRORS" >&5 - as_fn_error $? "Package requirements (libcrypto >= 1.0.1) were not met: + as_fn_error $? "Package requirements (libcrypto >= 1.1.0) were not met: $crypto_PKG_ERRORS @@ -5631,111 +5595,6 @@ See the pkg-config man page for more details. To get pkg-config, see . See \`config.log' for more details" "$LINENO" 5; } -else - crypto_CFLAGS=$pkg_cv_crypto_CFLAGS - crypto_LIBS=$pkg_cv_crypto_LIBS - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - CFLAGS="$CFLAGS $crypto_CFLAGS" - LIBS="$crypto_LIBS $LIBS" - openssl_cleanse_broken=maybe -fi -elif test $pkg_failed = untried; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - -pkg_failed=no -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for crypto" >&5 -$as_echo_n "checking for crypto... " >&6; } - -if test -n "$crypto_CFLAGS"; then - pkg_cv_crypto_CFLAGS="$crypto_CFLAGS" - elif test -n "$PKG_CONFIG"; then - if test -n "$PKG_CONFIG" && \ - { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libcrypto >= 1.0.1\""; } >&5 - ($PKG_CONFIG --exists --print-errors "libcrypto >= 1.0.1") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; then - pkg_cv_crypto_CFLAGS=`$PKG_CONFIG --cflags "libcrypto >= 1.0.1" 2>/dev/null` - test "x$?" != "x0" && pkg_failed=yes -else - pkg_failed=yes -fi - else - pkg_failed=untried -fi -if test -n "$crypto_LIBS"; then - pkg_cv_crypto_LIBS="$crypto_LIBS" - elif test -n "$PKG_CONFIG"; then - if test -n "$PKG_CONFIG" && \ - { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libcrypto >= 1.0.1\""; } >&5 - ($PKG_CONFIG --exists --print-errors "libcrypto >= 1.0.1") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; then - pkg_cv_crypto_LIBS=`$PKG_CONFIG --libs "libcrypto >= 1.0.1" 2>/dev/null` - test "x$?" != "x0" && pkg_failed=yes -else - pkg_failed=yes -fi - else - pkg_failed=untried -fi - - - -if test $pkg_failed = yes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - -if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then - _pkg_short_errors_supported=yes -else - _pkg_short_errors_supported=no -fi - if test $_pkg_short_errors_supported = yes; then - crypto_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libcrypto >= 1.0.1" 2>&1` - else - crypto_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libcrypto >= 1.0.1" 2>&1` - fi - # Put the nasty error message in config.log where it belongs - echo "$crypto_PKG_ERRORS" >&5 - - as_fn_error $? "Package requirements (libcrypto >= 1.0.1) were not met: - -$crypto_PKG_ERRORS - -Consider adjusting the PKG_CONFIG_PATH environment variable if you -installed software in a non-standard prefix. - -Alternatively, you may set the environment variables crypto_CFLAGS -and crypto_LIBS to avoid the need to call pkg-config. -See the pkg-config man page for more details." "$LINENO" 5 -elif test $pkg_failed = untried; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it -is in your PATH or set the PKG_CONFIG environment variable to the full -path to pkg-config. - -Alternatively, you may set the environment variables crypto_CFLAGS -and crypto_LIBS to avoid the need to call pkg-config. -See the pkg-config man page for more details. - -To get pkg-config, see . -See \`config.log' for more details" "$LINENO" 5; } -else - crypto_CFLAGS=$pkg_cv_crypto_CFLAGS - crypto_LIBS=$pkg_cv_crypto_LIBS - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - CFLAGS="$CFLAGS $crypto_CFLAGS" - LIBS="$crypto_LIBS $LIBS" - openssl_cleanse_broken=maybe -fi else crypto_CFLAGS=$pkg_cv_crypto_CFLAGS crypto_LIBS=$pkg_cv_crypto_LIBS @@ -5743,7 +5602,6 @@ else $as_echo "yes" >&6; } CFLAGS="$CFLAGS $crypto_CFLAGS" LIBS="$crypto_LIBS $LIBS" - openssl_cleanse_broken=no fi else { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 @@ -5901,7 +5759,7 @@ if test "$ac_res" != no; then : else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error $? "can't find openssl >= 1.0.1 crypto lib +as_fn_error $? "can't find openssl >= 1.1.0 crypto lib See \`config.log' for more details" "$LINENO" 5; } fi @@ -5962,7 +5820,7 @@ if test "$ac_res" != no; then : else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error $? "can't find openssl >= 1.0.1 crypto lib +as_fn_error $? "can't find openssl >= 1.1.0 crypto lib See \`config.log' for more details" "$LINENO" 5; } fi @@ -6023,7 +5881,7 @@ if test "$ac_res" != no; then : else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error $? "can't find openssl >= 1.0.1 crypto lib +as_fn_error $? "can't find openssl >= 1.1.0 crypto lib See \`config.log' for more details" "$LINENO" 5; } fi @@ -6039,63 +5897,6 @@ $as_echo "#define OPENSSL 1" >>confdefs.h USE_EXTERNAL_CRYPTO=1 - if test "x$openssl_cleanse_broken" != "xno"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if OPENSSL_cleanse is broken" >&5 -$as_echo_n "checking if OPENSSL_cleanse is broken... " >&6; } - if test "$cross_compiling" = yes; then : - openssl_cleanse_broken=maybe -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - - #include - #include - -int -main () -{ - - #define BUFFER_SIZE (16) - char buffer[BUFFER_SIZE]; - int i; - for (i = 0; i < BUFFER_SIZE; i++) { - buffer[i] = i & 0xff; - } - OPENSSL_cleanse(buffer, BUFFER_SIZE); - for (i = 0; i < BUFFER_SIZE; i++) { - if (buffer[i]) { - printf("Buffer contents not zero at position %d (is %d)\n", i, - buffer[i]); - return 1; - } - } - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_run "$LINENO"; then : - openssl_cleanse_broken=no -else - openssl_cleanse_broken=yes -fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext -fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $openssl_cleanse_broken" >&5 -$as_echo "$openssl_cleanse_broken" >&6; } - if test "x$openssl_cleanse_broken" != "xno"; then : - - -$as_echo "#define OPENSSL_CLEANSE_BROKEN 1" >>confdefs.h - - -fi - -fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to leverage OpenSSL KDF algorithm" >&5 $as_echo_n "checking whether to leverage OpenSSL KDF algorithm... " >&6; } # Check whether --enable-openssl-kdf was given. diff --git a/configure.ac b/configure.ac index d2f7190ff..900720718 100644 --- a/configure.ac +++ b/configure.ac @@ -242,25 +242,20 @@ if test "$enable_openssl" = "yes"; then [AC_MSG_RESULT([no])]) if test "x$PKG_CONFIG" != "x"; then - PKG_CHECK_MODULES([crypto], [libcrypto >= 1.0.2i], + PKG_CHECK_MODULES([crypto], [libcrypto >= 1.1.0], [CFLAGS="$CFLAGS $crypto_CFLAGS" - LIBS="$crypto_LIBS $LIBS" - openssl_cleanse_broken=no], - [PKG_CHECK_MODULES([crypto], [libcrypto >= 1.0.1], - [CFLAGS="$CFLAGS $crypto_CFLAGS" - LIBS="$crypto_LIBS $LIBS" - openssl_cleanse_broken=maybe])]) + LIBS="$crypto_LIBS $LIBS"]) else AC_CHECK_LIB([dl], [dlopen], [], [AC_MSG_WARN([can't find libdl])]) AC_CHECK_LIB([z], [inflate], [], [AC_MSG_WARN([can't find libz])]) fi AC_SEARCH_LIBS([EVP_EncryptInit], [crypto], - [], [AC_MSG_FAILURE([can't find openssl >= 1.0.1 crypto lib])]) + [], [AC_MSG_FAILURE([can't find openssl >= 1.1.0 crypto lib])]) AC_SEARCH_LIBS([EVP_aes_128_ctr], [crypto], - [], [AC_MSG_FAILURE([can't find openssl >= 1.0.1 crypto lib])]) + [], [AC_MSG_FAILURE([can't find openssl >= 1.1.0 crypto lib])]) AC_SEARCH_LIBS([EVP_aes_128_gcm], [crypto], - [], [AC_MSG_FAILURE([can't find openssl >= 1.0.1 crypto lib])]) + [], [AC_MSG_FAILURE([can't find openssl >= 1.1.0 crypto lib])]) AC_DEFINE([GCM], [1], [Define this to use AES-GCM.]) AC_DEFINE([OPENSSL], [1], [Define this to use OpenSSL crypto.]) @@ -268,33 +263,6 @@ if test "$enable_openssl" = "yes"; then HMAC_OBJS=crypto/hash/hmac_ossl.o AC_SUBST([USE_EXTERNAL_CRYPTO], [1]) - AS_IF([test "x$openssl_cleanse_broken" != "xno"], [ - AC_MSG_CHECKING([if OPENSSL_cleanse is broken]) - AC_RUN_IFELSE([AC_LANG_PROGRAM([ - #include - #include - ], [ - #define BUFFER_SIZE (16) - char buffer[[BUFFER_SIZE]]; - int i; - for (i = 0; i < BUFFER_SIZE; i++) { - buffer[[i]] = i & 0xff; - } - OPENSSL_cleanse(buffer, BUFFER_SIZE); - for (i = 0; i < BUFFER_SIZE; i++) { - if (buffer[[i]]) { - printf("Buffer contents not zero at position %d (is %d)\n", i, - buffer[[i]]); - return 1; - } - } - ])], [openssl_cleanse_broken=no], [openssl_cleanse_broken=yes], [openssl_cleanse_broken=maybe]) - AC_MSG_RESULT([$openssl_cleanse_broken]) - AS_IF([test "x$openssl_cleanse_broken" != "xno"], [ - AC_DEFINE([OPENSSL_CLEANSE_BROKEN], [1], [Define this if OPENSSL_cleanse is broken.]) - ]) - ]) - AC_MSG_CHECKING([whether to leverage OpenSSL KDF algorithm]) AC_ARG_ENABLE([openssl-kdf], [AS_HELP_STRING([--enable-openssl-kdf], [Use OpenSSL KDF algorithm])], @@ -381,7 +349,7 @@ AS_IF([test "x$enable_pcap" != "xno"], [ AC_SUBST([HAVE_PCAP], [1])]) ]) AC_SUBST([PCAP_LIB]) - + AC_MSG_CHECKING([whether to redirect logging to stdout]) AC_ARG_ENABLE([log-stdout], [AS_HELP_STRING([--enable-log-stdout], [redirecting logging to stdout])], diff --git a/crypto/math/datatypes.c b/crypto/math/datatypes.c index 4b6f6f3f5..372f8d188 100644 --- a/crypto/math/datatypes.c +++ b/crypto/math/datatypes.c @@ -279,7 +279,7 @@ void srtp_cleanse(void *s, size_t len) void octet_string_set_to_zero(void *s, size_t len) { -#if defined(OPENSSL) && !defined(OPENSSL_CLEANSE_BROKEN) +#if defined(OPENSSL) OPENSSL_cleanse(s, len); #else srtp_cleanse(s, len); diff --git a/meson.build b/meson.build index a9ab7ca7d..646d32dcf 100644 --- a/meson.build +++ b/meson.build @@ -124,7 +124,7 @@ use_nss = false crypto_library = get_option('crypto-library') if crypto_library == 'openssl' - openssl_dep = dependency('openssl', version: '>= 1.0.1', required: true) + openssl_dep = dependency('openssl', version: '>= 1.1.0', required: true) srtp2_deps += [openssl_dep] cdata.set('GCM', true) cdata.set('OPENSSL', true) From 523c2a9cddc87b35053d6bce268308af6bc9174c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Thu, 15 Dec 2022 05:32:38 +0100 Subject: [PATCH 093/109] fix compile after merge --- srtp/srtp.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/srtp/srtp.c b/srtp/srtp.c index 39234fc09..7ae448014 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -149,9 +149,8 @@ unsigned int srtp_get_version(void) return rv; } -static srtp_err_status_t srtp_stream_dealloc( - srtp_stream_ctx_t *stream, - const srtp_stream_ctx_t *stream_template) +srtp_err_status_t srtp_stream_dealloc(srtp_stream_ctx_t *stream, + const srtp_stream_ctx_t *stream_template) { srtp_err_status_t status; unsigned int i = 0; From 77382a0d17d0007718bcfa2dd845e92721301506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Fri, 16 Dec 2022 10:13:16 +0100 Subject: [PATCH 094/109] remove unnecessary checks for null These api's are no op for null so no need. As mentioned by @bifurcation. --- crypto/hash/hmac_ossl.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/crypto/hash/hmac_ossl.c b/crypto/hash/hmac_ossl.c index fe55f7874..4bdfe53f6 100644 --- a/crypto/hash/hmac_ossl.c +++ b/crypto/hash/hmac_ossl.c @@ -178,12 +178,8 @@ static srtp_err_status_t srtp_hmac_dealloc(srtp_auth_t *a) if (hmac) { #ifdef SRTP_OSSL_USE_EVP_MAC - if (hmac->ctx != NULL) { - EVP_MAC_CTX_free(hmac->ctx); - } - if (hmac->ctx_dup != NULL) { - EVP_MAC_CTX_free(hmac->ctx_dup); - } + EVP_MAC_CTX_free(hmac->ctx); + EVP_MAC_CTX_free(hmac->ctx_dup); EVP_MAC_free(hmac->mac); #else HMAC_CTX_free(hmac->ctx); @@ -209,9 +205,7 @@ static srtp_err_status_t srtp_hmac_start(void *statev) #ifdef SRTP_OSSL_USE_EVP_MAC if (hmac->use_dup) { - if (hmac->ctx != NULL) { - EVP_MAC_CTX_free(hmac->ctx); - } + EVP_MAC_CTX_free(hmac->ctx); hmac->ctx = EVP_MAC_CTX_dup(hmac->ctx_dup); if (hmac->ctx == NULL) { return srtp_err_status_alloc_fail; From 0fc6310a262b4741261c70a7a5ffd75ba2827495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Fri, 16 Dec 2022 10:25:47 +0100 Subject: [PATCH 095/109] move to ubuntu-latest for workflows ubuntu-22.04 should now be supported --- .github/workflows/android.yml | 2 +- .github/workflows/autotools.yml | 16 ++++++++-------- .github/workflows/cmake.yml | 6 +++--- .github/workflows/coverity_scan.yml | 8 ++++---- .github/workflows/format_check.yml | 2 +- .github/workflows/fuzzer_build.yml | 8 ++++---- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 91fda9b86..70cbaa01b 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: diff --git a/.github/workflows/autotools.yml b/.github/workflows/autotools.yml index 92369c2db..3c8fe2ff0 100644 --- a/.github/workflows/autotools.yml +++ b/.github/workflows/autotools.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-20.04, macos-latest] + os: [ubuntu-latest, macos-latest] crypto: [internal, openssl, nss] include: - crypto: internal @@ -25,23 +25,23 @@ jobs: steps: - name: Setup Ubuntu - if: matrix.os == 'ubuntu-20.04' + if: matrix.os == 'ubuntu-latest' run: sudo apt-get install valgrind - name: Setup Ubuntu NSS - if: matrix.os == 'ubuntu-20.04' && matrix.crypto == 'nss' + if: matrix.os == 'ubuntu-latest' && matrix.crypto == 'nss' run: | sudo apt-get update sudo apt-get install libnss3-dev - + - name: Setup macOS OpenSSL if: matrix.os == 'macos-latest' && matrix.crypto == 'openssl' run: echo "configure-env=PKG_CONFIG_PATH=$(brew --prefix openssl@1.1)/lib/pkgconfig" >> $GITHUB_ENV - + - name: Setup macOS NSS if: matrix.os == 'macos-latest' && matrix.crypto == 'nss' run: brew install nss - + - uses: actions/checkout@v2 - name: Configure @@ -52,7 +52,7 @@ jobs: - name: Test run: make runtest - + - name: Test Valgrind - if: matrix.os == 'ubuntu-20.04' + if: matrix.os == 'ubuntu-latest' run: make runtest-valgrind diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index f15f00899..764be18b7 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-20.04, macos-latest, windows-latest] + os: [ubuntu-latest, macos-latest, windows-latest] crypto: [internal, openssl, openssl3, nss, mbedtls] exclude: - os: windows-latest @@ -43,13 +43,13 @@ jobs: steps: - name: Setup Ubuntu NSS - if: matrix.os == 'ubuntu-20.04' && matrix.crypto == 'nss' + if: matrix.os == 'ubuntu-latest' && matrix.crypto == 'nss' run: | sudo apt-get update sudo apt-get install libnss3-dev - name: Setup Ubuntu MbedTLS - if: matrix.os == 'ubuntu-20.04' && matrix.crypto == 'mbedtls' + if: matrix.os == 'ubuntu-latest' && matrix.crypto == 'mbedtls' run: sudo apt-get install libmbedtls-dev - name: Setup macOS OpenSSL diff --git a/.github/workflows/coverity_scan.yml b/.github/workflows/coverity_scan.yml index 26a83bbb5..262ef3363 100644 --- a/.github/workflows/coverity_scan.yml +++ b/.github/workflows/coverity_scan.yml @@ -6,7 +6,7 @@ on: jobs: coverity: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -17,15 +17,15 @@ jobs: tar xzf cov-analysis-linux64.tar.gz --strip 1 -C cov-analysis-linux64 env: TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} - + - name: Configure run: ./configure - + - name: Build with cov-build run: | export PATH=`pwd`/cov-analysis-linux64/bin:$PATH cov-build --dir cov-int make - + - name: Submit the result to Coverity Scan run: | tar czvf libsrtp.tgz cov-int diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml index bbbd0c65d..d2556a73c 100644 --- a/.github/workflows/format_check.yml +++ b/.github/workflows/format_check.yml @@ -8,7 +8,7 @@ on: jobs: format-check: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Install Clang Format diff --git a/.github/workflows/fuzzer_build.yml b/.github/workflows/fuzzer_build.yml index 610e8fa8f..837af8df0 100644 --- a/.github/workflows/fuzzer_build.yml +++ b/.github/workflows/fuzzer_build.yml @@ -10,15 +10,15 @@ on: jobs: fuzz: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - + - name: Install clang run: sudo apt install clang - + - name: Configure with fuzzing run: CC=clang CXX=clang++ CXXFLAGS="-fsanitize=fuzzer-no-link,address,undefined -g -O3" CFLAGS="-fsanitize=fuzzer-no-link,address,undefined -g -O3" LDFLAGS="-fsanitize=fuzzer-no-link,address,undefined" ./configure - + - name: Build run: LIBFUZZER="-fsanitize=fuzzer" make srtp-fuzzer From a0f8490dd0d221332d5b4fa330d16c18280e8a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Fri, 16 Dec 2022 11:13:53 +0100 Subject: [PATCH 096/109] remove more code checking openssl versions < 1.1.0 --- crypto/cipher/aes_gcm_ossl.c | 4 ---- crypto/cipher/aes_icm_ossl.c | 4 ---- 2 files changed, 8 deletions(-) diff --git a/crypto/cipher/aes_gcm_ossl.c b/crypto/cipher/aes_gcm_ossl.c index 1c900f207..23b5ba8ed 100644 --- a/crypto/cipher/aes_gcm_ossl.c +++ b/crypto/cipher/aes_gcm_ossl.c @@ -193,11 +193,7 @@ static srtp_err_status_t srtp_aes_gcm_openssl_context_init(void *cv, break; } -#if OPENSSL_VERSION_NUMBER < 0x10100000L - EVP_CIPHER_CTX_cleanup(c->ctx); -#else EVP_CIPHER_CTX_reset(c->ctx); -#endif if (!EVP_CipherInit_ex(c->ctx, evp, NULL, key, NULL, 0)) { return (srtp_err_status_init_fail); diff --git a/crypto/cipher/aes_icm_ossl.c b/crypto/cipher/aes_icm_ossl.c index b76c4fbc5..911e9f84f 100644 --- a/crypto/cipher/aes_icm_ossl.c +++ b/crypto/cipher/aes_icm_ossl.c @@ -250,11 +250,7 @@ static srtp_err_status_t srtp_aes_icm_openssl_context_init(void *cv, break; } -#if OPENSSL_VERSION_NUMBER < 0x10100000L - EVP_CIPHER_CTX_cleanup(c->ctx); -#else EVP_CIPHER_CTX_reset(c->ctx); -#endif if (!EVP_EncryptInit_ex(c->ctx, evp, NULL, key, NULL)) { return srtp_err_status_fail; From cba4c0c13621cc9553b4e512eced22f3a943d1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Fri, 16 Dec 2022 11:25:14 +0100 Subject: [PATCH 097/109] add checking for EVP_CIPHER_CTX_reset in configure This is a new symbol that is needed and part of the reason for updating the minimal version. --- configure | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 2 ++ 2 files changed, 63 insertions(+) diff --git a/configure b/configure index f0ba04293..ed78cce34 100755 --- a/configure +++ b/configure @@ -5885,6 +5885,67 @@ as_fn_error $? "can't find openssl >= 1.1.0 crypto lib See \`config.log' for more details" "$LINENO" 5; } fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing EVP_CIPHER_CTX_reset" >&5 +$as_echo_n "checking for library containing EVP_CIPHER_CTX_reset... " >&6; } +if ${ac_cv_search_EVP_CIPHER_CTX_reset+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char EVP_CIPHER_CTX_reset (); +int +main () +{ +return EVP_CIPHER_CTX_reset (); + ; + return 0; +} +_ACEOF +for ac_lib in '' crypto; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_EVP_CIPHER_CTX_reset=$ac_res +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext + if ${ac_cv_search_EVP_CIPHER_CTX_reset+:} false; then : + break +fi +done +if ${ac_cv_search_EVP_CIPHER_CTX_reset+:} false; then : + +else + ac_cv_search_EVP_CIPHER_CTX_reset=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_EVP_CIPHER_CTX_reset" >&5 +$as_echo "$ac_cv_search_EVP_CIPHER_CTX_reset" >&6; } +ac_res=$ac_cv_search_EVP_CIPHER_CTX_reset +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "can't find openssl >= 1.1.0 crypto lib +See \`config.log' for more details" "$LINENO" 5; } +fi + $as_echo "#define GCM 1" >>confdefs.h diff --git a/configure.ac b/configure.ac index 900720718..c0a44bac7 100644 --- a/configure.ac +++ b/configure.ac @@ -256,6 +256,8 @@ if test "$enable_openssl" = "yes"; then [], [AC_MSG_FAILURE([can't find openssl >= 1.1.0 crypto lib])]) AC_SEARCH_LIBS([EVP_aes_128_gcm], [crypto], [], [AC_MSG_FAILURE([can't find openssl >= 1.1.0 crypto lib])]) + AC_SEARCH_LIBS([EVP_CIPHER_CTX_reset], [crypto], + [], [AC_MSG_FAILURE([can't find openssl >= 1.1.0 crypto lib])]) AC_DEFINE([GCM], [1], [Define this to use AES-GCM.]) AC_DEFINE([OPENSSL], [1], [Define this to use OpenSSL crypto.]) From 07ca6ad289f7d5384f39265e1d5118881e1a375d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Fri, 6 Jan 2023 18:15:12 +0100 Subject: [PATCH 098/109] use ubuntu 20.04 when running with valgrind ubunutu 22.04 currently uses glibc 2.35 that has a memory leak that is triggered by nss. see: https://sourceware.org/bugzilla/show_bug.cgi?id=29062 This is fixed in glibc 2.36, so until that is available use ubunutu 20.04 --- .github/workflows/autotools.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/autotools.yml b/.github/workflows/autotools.yml index 3c8fe2ff0..a5ef77ae5 100644 --- a/.github/workflows/autotools.yml +++ b/.github/workflows/autotools.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-20.04, macos-latest] crypto: [internal, openssl, nss] include: - crypto: internal @@ -25,11 +25,11 @@ jobs: steps: - name: Setup Ubuntu - if: matrix.os == 'ubuntu-latest' + if: matrix.os == 'ubuntu-20.04' run: sudo apt-get install valgrind - name: Setup Ubuntu NSS - if: matrix.os == 'ubuntu-latest' && matrix.crypto == 'nss' + if: matrix.os == 'ubuntu-20.04' && matrix.crypto == 'nss' run: | sudo apt-get update sudo apt-get install libnss3-dev @@ -54,5 +54,5 @@ jobs: run: make runtest - name: Test Valgrind - if: matrix.os == 'ubuntu-latest' + if: matrix.os == 'ubuntu-20.04' run: make runtest-valgrind From 914cb552fbcc1854f5c88a969eaa34d22377e598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Fri, 23 Dec 2022 13:55:24 +0100 Subject: [PATCH 099/109] alternative stream list api and unit tests for the api Beside some small API rename the main difference is that the list implementation is not responsible for deallocating streams. Calling srtp_stream_list_dealloc() on a list that is not empty results in an error. This also changes the default implementation to be a double linked list making removing items faster. --- .github/workflows/cmake.yml | 8 ++ include/srtp_priv.h | 10 +- include/stream_list_priv.h | 34 ++--- srtp/srtp.c | 188 ++++++++++++++---------- test/srtp_driver.c | 280 ++++++++++++++++++++++++++++++++++-- 5 files changed, 404 insertions(+), 116 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index ed914a637..5018fd2af 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -77,3 +77,11 @@ jobs: working-directory: ${{github.workspace}}/build shell: bash run: ctest + + - name: Test Stream List Replacement + working-directory: ${{github.workspace}}/build + shell: bash + run: | + make clean + make C_FLAGS="-DSRTP_NO_STREAM_LIST -DSRTP_USE_TEST_STREAM_LIST" srtp_driver + ./srtp_driver -v diff --git a/include/srtp_priv.h b/include/srtp_priv.h index 90045942d..f74afddb5 100644 --- a/include/srtp_priv.h +++ b/include/srtp_priv.h @@ -97,15 +97,6 @@ srtp_err_status_t srtp_steam_init_all_master_keys( srtp_master_key_t **keys, const unsigned int max_master_keys); -/* - * srtp_stream_init(s, p) initializes the srtp_stream_t s to - * use the policy at the location p - */ -srtp_err_status_t srtp_stream_init(srtp_stream_t srtp, const srtp_policy_t *p); - -srtp_err_status_t srtp_stream_dealloc(srtp_stream_ctx_t *stream, - const srtp_stream_ctx_t *stream_template); - /* * libsrtp internal datatypes */ @@ -154,6 +145,7 @@ typedef struct srtp_stream_ctx_t_ { int enc_xtn_hdr_count; uint32_t pending_roc; struct srtp_stream_ctx_t_ *next; /* linked list of streams */ + struct srtp_stream_ctx_t_ *prev; /* linked list of streams */ } strp_stream_ctx_t_; /* diff --git a/include/stream_list_priv.h b/include/stream_list_priv.h index 0245126a4..b44ca91e3 100644 --- a/include/stream_list_priv.h +++ b/include/stream_list_priv.h @@ -58,8 +58,8 @@ extern "C" { * the API was extracted to allow downstreams to override its * implementation by defining the `SRTP_NO_STREAM_LIST` preprocessor * directive, which removes the default implementation of these - * functions. if this is done, the `next` field is free for the - * implementation to use. + * functions. if this is done, the `next` & `prev` fields are free for + * the implementation to use. * * this is still an internal interface; there is no stability * guarantee--downstreams should watch this file for changes in @@ -69,7 +69,14 @@ extern "C" { /** * allocate and initialize a stream list instance */ -srtp_err_status_t srtp_stream_list_create(srtp_stream_list_t *list); +srtp_err_status_t srtp_stream_list_alloc(srtp_stream_list_t *list_ptr); + +/** + * deallocate a stream list instance + * + * the list must be empty or else an error is returned. + */ +srtp_err_status_t srtp_stream_list_dealloc(srtp_stream_list_t list); /** * insert a stream into the list @@ -82,38 +89,33 @@ srtp_err_status_t srtp_stream_list_create(srtp_stream_list_t *list); * behavior is undefined. if the SSRC field is mutated while the * stream is inserted, further operations have undefined behavior */ -srtp_err_status_t srtp_stream_list_insert(srtp_stream_list_t *list, +srtp_err_status_t srtp_stream_list_insert(srtp_stream_list_t list, srtp_stream_t stream); /* * look up the stream corresponding to the specified SSRC and return it. * if no such SSRC is found, NULL is returned. */ -srtp_stream_t srtp_stream_list_get(srtp_stream_list_t *list, uint32_t ssrc); +srtp_stream_t srtp_stream_list_get(srtp_stream_list_t list, uint32_t ssrc); /** - * delete the stream associated to the specified SSRC. + * remove the stream from the list. * - * if a stream is found and removed, it's returned and ownership is - * transferred to the caller. if not found, NULL is returned. + * ownership is transferred to the caller. + * + * if the stream is not in the list the behavior is undefined. */ -srtp_stream_t srtp_stream_list_delete(srtp_stream_list_t *list, uint32_t ssrc); +void srtp_stream_list_remove(srtp_stream_list_t list, srtp_stream_t stream); /** * iterate through all stored streams. while iterating, it is allowed to delete * the current element; any other mutation to the list is undefined behavior. * returning non-zero from callback aborts the iteration. */ -void srtp_stream_list_for_each(srtp_stream_list_t *list, +void srtp_stream_list_for_each(srtp_stream_list_t list, int (*callback)(srtp_stream_t, void *), void *data); -/** - * deallocate a stream list instance and all streams inserted in it - */ -srtp_err_status_t srtp_stream_list_dealloc(srtp_stream_list_t *list, - srtp_stream_t template_); - #ifdef __cplusplus } #endif diff --git a/srtp/srtp.c b/srtp/srtp.c index 7ae448014..6ab5db476 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -149,8 +149,9 @@ unsigned int srtp_get_version(void) return rv; } -srtp_err_status_t srtp_stream_dealloc(srtp_stream_ctx_t *stream, - const srtp_stream_ctx_t *stream_template) +static srtp_err_status_t srtp_stream_dealloc( + srtp_stream_ctx_t *stream, + const srtp_stream_ctx_t *stream_template) { srtp_err_status_t status; unsigned int i = 0; @@ -280,7 +281,7 @@ srtp_err_status_t srtp_stream_dealloc(srtp_stream_ctx_t *stream, } /* try to insert stream in list or deallocate it */ -static srtp_err_status_t srtp_insert_or_dealloc_stream(srtp_stream_list_t *list, +static srtp_err_status_t srtp_insert_or_dealloc_stream(srtp_stream_list_t list, srtp_stream_t stream, srtp_stream_t template) { @@ -291,6 +292,34 @@ static srtp_err_status_t srtp_insert_or_dealloc_stream(srtp_stream_list_t *list, return status; } +struct remove_and_dealloc_streams_data { + srtp_err_status_t status; + srtp_stream_list_t list; + srtp_stream_t template; +}; + +static int remove_and_dealloc_streams_cb(srtp_stream_t stream, void *data) +{ + struct remove_and_dealloc_streams_data *d = + (struct remove_and_dealloc_streams_data *)data; + srtp_stream_list_remove(d->list, stream); + d->status = srtp_stream_dealloc(stream, d->template); + if (d->status) { + return 1; + } + return 0; +} + +static srtp_err_status_t srtp_remove_and_dealloc_streams( + srtp_stream_list_t list, + srtp_stream_t template) +{ + struct remove_and_dealloc_streams_data data = { srtp_err_status_ok, list, + template }; + srtp_stream_list_for_each(list, remove_and_dealloc_streams_cb, &data); + return data.status; +} + static srtp_err_status_t srtp_valid_policy(const srtp_policy_t *p) { if (p != NULL && p->deprecated_ekt != NULL) { @@ -565,6 +594,7 @@ static srtp_err_status_t srtp_stream_clone( /* defensive coding */ str->next = NULL; + str->prev = NULL; return srtp_err_status_ok; } @@ -1269,8 +1299,8 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, return srtp_err_status_ok; } -srtp_err_status_t srtp_stream_init(srtp_stream_ctx_t *srtp, - const srtp_policy_t *p) +static srtp_err_status_t srtp_stream_init(srtp_stream_ctx_t *srtp, + const srtp_policy_t *p) { srtp_err_status_t err; @@ -2071,7 +2101,7 @@ static srtp_err_status_t srtp_unprotect_aead(srtp_ctx_t *ctx, } /* add new stream to the list */ - status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, + status = srtp_insert_or_dealloc_stream(ctx->stream_list, new_stream, ctx->stream_template); if (status) return status; @@ -2164,8 +2194,8 @@ srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx, return status; /* add new stream to the list */ - status = srtp_insert_or_dealloc_stream( - &ctx->stream_list, new_stream, ctx->stream_template); + status = srtp_insert_or_dealloc_stream(ctx->stream_list, new_stream, + ctx->stream_template); if (status) return status; @@ -2765,7 +2795,7 @@ srtp_err_status_t srtp_unprotect_mki(srtp_ctx_t *ctx, return status; /* add new stream to the list */ - status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, + status = srtp_insert_or_dealloc_stream(ctx->stream_list, new_stream, ctx->stream_template); if (status) return status; @@ -2828,7 +2858,7 @@ srtp_err_status_t srtp_shutdown(void) srtp_stream_ctx_t *srtp_get_stream(srtp_t srtp, uint32_t ssrc) { - return srtp_stream_list_get(&srtp->stream_list, ssrc); + return srtp_stream_list_get(srtp->stream_list, ssrc); } srtp_err_status_t srtp_dealloc(srtp_t session) @@ -2842,8 +2872,8 @@ srtp_err_status_t srtp_dealloc(srtp_t session) */ /* deallocate streams */ - status = srtp_stream_list_dealloc(&session->stream_list, - session->stream_template); + status = srtp_remove_and_dealloc_streams(session->stream_list, + session->stream_template); if (status) return status; @@ -2854,6 +2884,12 @@ srtp_err_status_t srtp_dealloc(srtp_t session) return status; } + /* deallocate stream list */ + status = srtp_stream_list_dealloc(session->stream_list); + if (status) { + return status; + } + /* deallocate session context */ srtp_crypto_free(session); @@ -2914,7 +2950,7 @@ srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy) session->stream_template->direction = dir_srtp_receiver; break; case (ssrc_specific): - status = srtp_insert_or_dealloc_stream(&session->stream_list, tmp, + status = srtp_insert_or_dealloc_stream(session->stream_list, tmp, session->stream_template); if (status) return status; @@ -2954,7 +2990,7 @@ srtp_err_status_t srtp_create(srtp_t *session, /* handle for session */ ctx->user_data = NULL; /* allocate stream list */ - stat = srtp_stream_list_create(&ctx->stream_list); + stat = srtp_stream_list_alloc(&ctx->stream_list); if (stat) { /* clean up everything */ srtp_dealloc(*session); @@ -2992,9 +3028,11 @@ srtp_err_status_t srtp_remove_stream(srtp_t session, uint32_t ssrc) return srtp_err_status_bad_param; /* find and remove stream from the list */ - stream = srtp_stream_list_delete(&session->stream_list, ssrc); - if (stream == NULL) + stream = srtp_stream_list_get(session->stream_list, ssrc); + if (stream == NULL) { return srtp_err_status_no_ctx; + } + srtp_stream_list_remove(session->stream_list, stream); /* deallocate the stream */ status = srtp_stream_dealloc(stream, session->stream_template); @@ -3035,10 +3073,10 @@ struct update_template_stream_data { srtp_err_status_t status; srtp_t session; srtp_stream_t new_stream_template; - srtp_stream_list_t *new_stream_list; + srtp_stream_list_t new_stream_list; }; -static int update_template_stream(srtp_stream_t stream, void *raw_data) +static int update_template_stream_cb(srtp_stream_t stream, void *raw_data) { struct update_template_stream_data *data = (struct update_template_stream_data *)raw_data; @@ -3050,7 +3088,7 @@ static int update_template_stream(srtp_stream_t stream, void *raw_data) /* old / non-template streams are copied unchanged */ if (stream->session_keys[0].rtp_auth != session->stream_template->session_keys[0].rtp_auth) { - stream = srtp_stream_list_delete(&session->stream_list, ssrc); + srtp_stream_list_remove(session->stream_list, stream); data->status = srtp_insert_or_dealloc_stream( data->new_stream_list, stream, session->stream_template); if (data->status) @@ -3115,7 +3153,7 @@ static srtp_err_status_t update_template_streams(srtp_t session, } /* allocate new stream list */ - status = srtp_stream_list_create(&new_stream_list); + status = srtp_stream_list_alloc(&new_stream_list); if (status) { srtp_crypto_free(new_stream_template); return status; @@ -3124,18 +3162,21 @@ static srtp_err_status_t update_template_streams(srtp_t session, /* process streams */ struct update_template_stream_data data = { srtp_err_status_ok, session, new_stream_template, - &new_stream_list }; - srtp_stream_list_for_each(&session->stream_list, &update_template_stream, + new_stream_list }; + srtp_stream_list_for_each(session->stream_list, update_template_stream_cb, &data); if (data.status) { /* free new allocations */ - srtp_stream_list_dealloc(&new_stream_list, new_stream_template); + srtp_remove_and_dealloc_streams(new_stream_list, new_stream_template); + srtp_stream_list_dealloc(new_stream_list); srtp_stream_dealloc(new_stream_template, NULL); return data.status; } /* dealloc old list / template */ - srtp_stream_list_dealloc(&session->stream_list, session->stream_template); + srtp_remove_and_dealloc_streams(session->stream_list, + session->stream_template); + srtp_stream_list_dealloc(session->stream_list); srtp_stream_dealloc(session->stream_template, NULL); /* set new list / template */ session->stream_template = new_stream_template; @@ -3909,7 +3950,7 @@ static srtp_err_status_t srtp_unprotect_rtcp_aead( } /* add new stream to the list */ - status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, + status = srtp_insert_or_dealloc_stream(ctx->stream_list, new_stream, ctx->stream_template); if (status) return status; @@ -3977,8 +4018,8 @@ srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx, return status; /* add new stream to the list */ - status = srtp_insert_or_dealloc_stream( - &ctx->stream_list, new_stream, ctx->stream_template); + status = srtp_insert_or_dealloc_stream(ctx->stream_list, new_stream, + ctx->stream_template); if (status) return status; @@ -4426,7 +4467,7 @@ srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx, return status; /* add new stream to the list */ - status = srtp_insert_or_dealloc_stream(&ctx->stream_list, new_stream, + status = srtp_insert_or_dealloc_stream(ctx->stream_list, new_stream, ctx->stream_template); if (status) return status; @@ -4658,8 +4699,8 @@ srtp_err_status_t get_protect_trailer_length(srtp_t session, &data.length); } - srtp_stream_list_for_each(&session->stream_list, - &get_protect_trailer_length_cb, &data); + srtp_stream_list_for_each(session->stream_list, + get_protect_trailer_length_cb, &data); if (!data.valid) { return srtp_err_status_bad_param; @@ -4783,37 +4824,53 @@ srtp_err_status_t srtp_get_stream_roc(srtp_t session, #ifndef SRTP_NO_STREAM_LIST /* in the default implementation, we have an intrusive linked list */ -struct { - srtp_stream_ctx_t dummy; +struct srtp_stream_list_ctx_t_ { + srtp_stream_ctx_t data; } srtp_stream_list_ctx_t_; -srtp_err_status_t srtp_stream_list_create(srtp_stream_list_t *list) +srtp_err_status_t srtp_stream_list_alloc(srtp_stream_list_t *list_ptr) { - (*list) = NULL; + srtp_stream_list_t list = + srtp_crypto_alloc(sizeof(srtp_stream_list_ctx_t_)); + if (list == NULL) { + return srtp_err_status_alloc_fail; + } + *list_ptr = list; return srtp_err_status_ok; } -srtp_err_status_t srtp_stream_list_insert(srtp_stream_list_t *list_, - srtp_stream_t stream) +srtp_err_status_t srtp_stream_list_dealloc(srtp_stream_list_t list) { - srtp_stream_t *list = (srtp_stream_t *)list_; + /* list must be empty */ + if (list->data.next) { + return srtp_err_status_fail; + } + srtp_crypto_free(list); + return srtp_err_status_ok; +} +srtp_err_status_t srtp_stream_list_insert(srtp_stream_list_t list, + srtp_stream_t stream) +{ /* insert at the head of the list */ - stream->next = (*list); - (*list) = stream; + stream->next = list->data.next; + if (stream->next != NULL) { + stream->next->prev = stream; + } + list->data.next = stream; + stream->prev = &(list->data); return srtp_err_status_ok; } -srtp_stream_t srtp_stream_list_get(srtp_stream_list_t *list_, uint32_t ssrc) +srtp_stream_t srtp_stream_list_get(srtp_stream_list_t list, uint32_t ssrc) { - srtp_stream_t *list = (srtp_stream_t *)list_; - /* walk down list until ssrc is found */ - srtp_stream_t stream = (*list); + srtp_stream_t stream = list->data.next; while (stream != NULL) { - if (stream->ssrc == ssrc) + if (stream->ssrc == ssrc) { return stream; + } stream = stream->next; } @@ -4821,31 +4878,22 @@ srtp_stream_t srtp_stream_list_get(srtp_stream_list_t *list_, uint32_t ssrc) return NULL; } -srtp_stream_t srtp_stream_list_delete(srtp_stream_list_t *list_, uint32_t ssrc) +void srtp_stream_list_remove(srtp_stream_list_t list, + srtp_stream_t stream_to_remove) { - srtp_stream_t *list = (srtp_stream_t *)list_; + (void)list; - /* walk down list until ssrc is found */ - srtp_stream_t *stream = list; - while ((*stream) != NULL) { - if ((*stream)->ssrc == ssrc) { - srtp_stream_t tmp = (*stream); - (*stream) = tmp->next; - return tmp; - } - stream = &(*stream)->next; + stream_to_remove->prev->next = stream_to_remove->next; + if (stream_to_remove->next != NULL) { + stream_to_remove->next->prev = stream_to_remove->prev; } - - /* we haven't found our ssrc, so return a null */ - return NULL; } -void srtp_stream_list_for_each(srtp_stream_list_t *list_, +void srtp_stream_list_for_each(srtp_stream_list_t list, int (*callback)(srtp_stream_t, void *), void *data) { - srtp_stream_t *list = (srtp_stream_t *)list_; - srtp_stream_t stream = (*list); + srtp_stream_t stream = list->data.next; while (stream != NULL) { srtp_stream_t tmp = stream; stream = stream->next; @@ -4854,22 +4902,4 @@ void srtp_stream_list_for_each(srtp_stream_list_t *list_, } } -srtp_err_status_t srtp_stream_list_dealloc(srtp_stream_list_t *list_, - srtp_stream_t template) -{ - srtp_stream_t *list = (srtp_stream_t *)list_; - srtp_err_status_t status; - - /* walk list of streams, deallocating as we go */ - while ((*list) != NULL) { - srtp_stream_t next = (*list)->next; - status = srtp_stream_dealloc((*list), template); - if (status) - return status; - (*list) = next; - } - - return srtp_err_status_ok; -} - #endif diff --git a/test/srtp_driver.c b/test/srtp_driver.c index f6e395755..8ecf273a1 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -125,6 +125,8 @@ char *srtp_packet_to_string(srtp_hdr_t *hdr, int packet_len); double mips_estimate(int num_trials, int *ignore); +srtp_err_status_t srtp_stream_list_test(void); + #define TEST_MKI_ID_SIZE 4 extern uint8_t test_key[46]; @@ -154,15 +156,17 @@ srtp_master_key_t *test_keys[2] = { void usage(char *prog_name) { - printf("usage: %s [ -t ][ -c ][ -v ][ -o ][-d ]* [ -l ]\n" - " -t run timing test\n" - " -r run rejection timing test\n" - " -c run codec timing test\n" - " -v run validation tests\n" - " -o output logging to stdout\n" - " -d turn on debugging module \n" - " -l list debugging modules\n", - prog_name); + printf( + "usage: %s [ -t ][ -c ][ -v ][ -s ][ -o ][-d ]* [ -l ]\n" + " -t run timing test\n" + " -r run rejection timing test\n" + " -c run codec timing test\n" + " -v run validation tests\n" + " -s run stream list tests only\n" + " -o output logging to stdout\n" + " -d turn on debugging module \n" + " -l list debugging modules\n", + prog_name); exit(1); } @@ -218,6 +222,7 @@ int main(int argc, char *argv[]) unsigned do_rejection_test = 0; unsigned do_codec_timing = 0; unsigned do_validation = 0; + unsigned do_stream_list = 0; unsigned do_list_mods = 0; unsigned do_log_stdout = 0; srtp_err_status_t status; @@ -252,7 +257,7 @@ int main(int argc, char *argv[]) /* process input arguments */ while (1) { - q = getopt_s(argc, argv, "trcvold:"); + q = getopt_s(argc, argv, "trcvsold:"); if (q == -1) { break; } @@ -268,6 +273,10 @@ int main(int argc, char *argv[]) break; case 'v': do_validation = 1; + do_stream_list = 1; + break; + case 's': + do_stream_list = 1; break; case 'o': do_log_stdout = 1; @@ -288,7 +297,7 @@ int main(int argc, char *argv[]) } if (!do_validation && !do_timing_test && !do_codec_timing && - !do_list_mods && !do_rejection_test) { + !do_list_mods && !do_rejection_test && !do_stream_list) { usage(argv[0]); } @@ -598,6 +607,16 @@ int main(int argc, char *argv[]) } } + if (do_stream_list) { + printf("testing srtp_stream_list..."); + if (srtp_stream_list_test() == srtp_err_status_ok) { + printf("passed\n"); + } else { + printf("failed\n"); + exit(1); + } + } + if (do_timing_test) { const srtp_policy_t **policy = policy_array; @@ -1551,7 +1570,7 @@ srtp_err_status_t srtp_session_print_policy(srtp_t srtp) /* loop over streams in session, printing the policy of each */ data.is_template = 0; - srtp_stream_list_for_each(&srtp->stream_list, &srtp_session_print_stream, + srtp_stream_list_for_each(srtp->stream_list, srtp_session_print_stream, &data); return data.status; @@ -4280,3 +4299,240 @@ const srtp_policy_t wildcard_policy = { 0, /* list of encrypted extension headers is empty */ NULL }; + +static srtp_stream_t stream_list_test_create_stream(uint32_t ssrc) +{ + srtp_stream_t stream = calloc(1, sizeof(srtp_stream_ctx_t)); + stream->ssrc = ssrc; + return stream; +} + +static void stream_list_test_free_stream(srtp_stream_t stream) +{ + free(stream); +} + +int stream_list_test_count_cb(srtp_stream_t stream, void *data) +{ + int *count = (int *)data; + (*count)++; + (void)stream; + return 0; +} + +struct remove_one_data { + uint32_t ssrc; + srtp_stream_list_t list; +}; + +int stream_list_test_remove_one_cb(srtp_stream_t stream, void *data) +{ + struct remove_one_data *d = (struct remove_one_data *)data; + if (stream->ssrc == d->ssrc) { + srtp_stream_list_remove(d->list, stream); + stream_list_test_free_stream(stream); + return 1; + } + return 0; +} + +int stream_list_test_remove_all_cb(srtp_stream_t stream, void *data) +{ + srtp_stream_list_t *list = (srtp_stream_list_t *)data; + srtp_stream_list_remove(*list, stream); + stream_list_test_free_stream(stream); + return 0; +} + +srtp_err_status_t srtp_stream_list_test(void) +{ + srtp_stream_list_t list; + + if (srtp_stream_list_alloc(&list)) { + return srtp_err_status_fail; + } + + /* add 4 streams*/ + if (srtp_stream_list_insert(list, stream_list_test_create_stream(1))) { + return srtp_err_status_fail; + } + if (srtp_stream_list_insert(list, stream_list_test_create_stream(2))) { + return srtp_err_status_fail; + } + if (srtp_stream_list_insert(list, stream_list_test_create_stream(3))) { + return srtp_err_status_fail; + } + if (srtp_stream_list_insert(list, stream_list_test_create_stream(4))) { + return srtp_err_status_fail; + } + + /* find */ + if (srtp_stream_list_get(list, 3) == NULL) { + return srtp_err_status_fail; + } + if (srtp_stream_list_get(list, 1) == NULL) { + return srtp_err_status_fail; + } + if (srtp_stream_list_get(list, 2) == NULL) { + return srtp_err_status_fail; + } + if (srtp_stream_list_get(list, 4) == NULL) { + return srtp_err_status_fail; + } + + /* find not in list */ + if (srtp_stream_list_get(list, 5)) { + return srtp_err_status_fail; + } + + /* for each */ + int count = 0; + srtp_stream_list_for_each(list, stream_list_test_count_cb, &count); + if (count != 4) { + return srtp_err_status_fail; + } + + /* remove */ + srtp_stream_t stream = srtp_stream_list_get(list, 3); + if (stream == NULL) { + return srtp_err_status_fail; + } + srtp_stream_list_remove(list, stream); + stream_list_test_free_stream(stream); + + /* find after remove */ + if (srtp_stream_list_get(list, 3)) { + return srtp_err_status_fail; + } + + /* recount */ + count = 0; + srtp_stream_list_for_each(list, stream_list_test_count_cb, &count); + if (count != 3) { + return srtp_err_status_fail; + } + + /* remove one in for each */ + struct remove_one_data data = { 2, list }; + srtp_stream_list_for_each(list, stream_list_test_remove_one_cb, &data); + + /* find after remove */ + if (srtp_stream_list_get(list, 2)) { + return srtp_err_status_fail; + } + + /* recount */ + count = 0; + srtp_stream_list_for_each(list, stream_list_test_count_cb, &count); + if (count != 2) { + return srtp_err_status_fail; + } + + /* destroy non empty list */ + if (srtp_stream_list_dealloc(list) == srtp_err_status_ok) { + return srtp_err_status_fail; + } + + /* remove all in for each */ + srtp_stream_list_for_each(list, stream_list_test_remove_all_cb, &list); + + /* recount */ + count = 0; + srtp_stream_list_for_each(list, stream_list_test_count_cb, &count); + if (count != 0) { + return srtp_err_status_fail; + } + + /* destroy empty list */ + if (srtp_stream_list_dealloc(list)) { + return srtp_err_status_fail; + } + + return srtp_err_status_ok; +} + +#ifdef SRTP_USE_TEST_STREAM_LIST + +/* + * A srtp_stream_list_ctx_t implementation using a single linked list + * that does not use the internal next / prev fields. + */ + +struct test_list_node { + srtp_stream_t stream; + struct test_list_node *next; +}; +struct srtp_stream_list_ctx_t_ { + struct test_list_node *head; +}; + +srtp_err_status_t srtp_stream_list_alloc(srtp_stream_list_t *list_ptr) +{ + struct srtp_stream_list_ctx_t_ *l = + malloc(sizeof(struct srtp_stream_list_ctx_t_)); + l->head = NULL; + *list_ptr = l; + return srtp_err_status_ok; +} + +srtp_err_status_t srtp_stream_list_dealloc(srtp_stream_list_t list) +{ + struct test_list_node *node = list->head; + if (node) { + return srtp_err_status_fail; + } + free(list); + + return srtp_err_status_ok; +} + +srtp_err_status_t srtp_stream_list_insert(srtp_stream_list_t list, + srtp_stream_t stream) +{ + struct test_list_node *node = malloc(sizeof(struct test_list_node)); + node->stream = stream; + node->next = list->head; + list->head = node; + + return srtp_err_status_ok; +} + +srtp_stream_t srtp_stream_list_get(srtp_stream_list_t list, uint32_t ssrc) +{ + struct test_list_node *node = list->head; + while (node != NULL) { + if (node->stream->ssrc == ssrc) + return node->stream; + node = node->next; + } + return NULL; +} + +void srtp_stream_list_remove(srtp_stream_list_t list, srtp_stream_t stream) +{ + struct test_list_node **node = &(list->head); + while ((*node) != NULL) { + if ((*node)->stream->ssrc == stream->ssrc) { + struct test_list_node *tmp = (*node); + (*node) = tmp->next; + free(tmp); + return; + } + node = &(*node)->next; + } +} + +void srtp_stream_list_for_each(srtp_stream_list_t list, + int (*callback)(srtp_stream_t, void *), + void *data) +{ + struct test_list_node *node = list->head; + while (node != NULL) { + struct test_list_node *tmp = node; + node = node->next; + if (callback(tmp->stream, data)) + break; + } +} + +#endif From 8ef408485cee69e28a9e758f01696290dd94d059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Tue, 10 Jan 2023 12:17:14 +0100 Subject: [PATCH 100/109] use cmake to build and run test This does it in a cross platform manor. --- .github/workflows/cmake.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 5018fd2af..00a96a2a6 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -82,6 +82,6 @@ jobs: working-directory: ${{github.workspace}}/build shell: bash run: | - make clean - make C_FLAGS="-DSRTP_NO_STREAM_LIST -DSRTP_USE_TEST_STREAM_LIST" srtp_driver - ./srtp_driver -v + cmake $GITHUB_WORKSPACE -DBUILD_WITH_SANITIZERS=TRUE ${{ matrix.cmake-crypto-enable}} ${{env.cmake-crypto-dir}} -DCMAKE_C_FLAGS:STRING="-DSRTP_NO_STREAM_LIST -DSRTP_USE_TEST_STREAM_LIST" + cmake --build . --clean-first -t srtp_driver + ctest -R srtp_driver From 07334b277cb2cc9ca30f087f022f57e9f208e3a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Thu, 12 Jan 2023 18:20:11 +0100 Subject: [PATCH 101/109] move stream list replace test to own CI work flow --- .github/workflows/cmake.yml | 8 ------ .github/workflows/stream_list.yml | 41 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/stream_list.yml diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 00a96a2a6..ed914a637 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -77,11 +77,3 @@ jobs: working-directory: ${{github.workspace}}/build shell: bash run: ctest - - - name: Test Stream List Replacement - working-directory: ${{github.workspace}}/build - shell: bash - run: | - cmake $GITHUB_WORKSPACE -DBUILD_WITH_SANITIZERS=TRUE ${{ matrix.cmake-crypto-enable}} ${{env.cmake-crypto-dir}} -DCMAKE_C_FLAGS:STRING="-DSRTP_NO_STREAM_LIST -DSRTP_USE_TEST_STREAM_LIST" - cmake --build . --clean-first -t srtp_driver - ctest -R srtp_driver diff --git a/.github/workflows/stream_list.yml b/.github/workflows/stream_list.yml new file mode 100644 index 000000000..7da047b6b --- /dev/null +++ b/.github/workflows/stream_list.yml @@ -0,0 +1,41 @@ +name: Stream List CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + + runs-on: ${{ matrix.os }} + + env: + CTEST_OUTPUT_ON_FAILURE: 1 + + steps: + + - uses: actions/checkout@v2 + + - name: Create Build Environment + run: cmake -E make_directory ${{github.workspace}}/build + + - name: Configure CMake + working-directory: ${{github.workspace}}/build + shell: bash + run: cmake $GITHUB_WORKSPACE -DBUILD_WITH_SANITIZERS=TRUE -DCMAKE_C_FLAGS:STRING="-DSRTP_NO_STREAM_LIST -DSRTP_USE_TEST_STREAM_LIST" + + - name: Build + working-directory: ${{github.workspace}}/build + shell: bash + run: cmake --build . -t srtp_driver + + - name: Test + working-directory: ${{github.workspace}}/build + shell: bash + run: ctest -R srtp_driver From d1eb03abfe712f223e9cb3ded1c1392e827aa981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Thu, 12 Jan 2023 19:16:00 +0100 Subject: [PATCH 102/109] address comments from review, no function change --- include/srtp_priv.h | 10 ++++-- include/stream_list_priv.h | 7 ++-- srtp/srtp.c | 65 ++++++++++++++++++++++++++------------ test/srtp_driver.c | 2 +- 4 files changed, 56 insertions(+), 28 deletions(-) diff --git a/include/srtp_priv.h b/include/srtp_priv.h index f74afddb5..8e7848989 100644 --- a/include/srtp_priv.h +++ b/include/srtp_priv.h @@ -144,8 +144,14 @@ typedef struct srtp_stream_ctx_t_ { int *enc_xtn_hdr; int enc_xtn_hdr_count; uint32_t pending_roc; - struct srtp_stream_ctx_t_ *next; /* linked list of streams */ - struct srtp_stream_ctx_t_ *prev; /* linked list of streams */ + /* + The next and prev pointers are here to allow for a stream list to be + implemented as an intrusive doubly-linked list (the former being the + default). Other stream list implementations can ignore these fields or use + them for some other purpose specific to the stream list implementation. + */ + struct srtp_stream_ctx_t_ *next; + struct srtp_stream_ctx_t_ *prev; } strp_stream_ctx_t_; /* diff --git a/include/stream_list_priv.h b/include/stream_list_priv.h index b44ca91e3..f49cd551d 100644 --- a/include/stream_list_priv.h +++ b/include/stream_list_priv.h @@ -83,7 +83,6 @@ srtp_err_status_t srtp_stream_list_dealloc(srtp_stream_list_t list); * * returns srtp_err_status_alloc_fail if insertion failed due to unavailable * capacity in the list. if operation succeeds, srtp_err_status_ok is returned - * and ownership is transferred from caller into the list * * if another stream with the same SSRC already exists in the list, * behavior is undefined. if the SSRC field is mutated while the @@ -101,9 +100,9 @@ srtp_stream_t srtp_stream_list_get(srtp_stream_list_t list, uint32_t ssrc); /** * remove the stream from the list. * - * ownership is transferred to the caller. - * - * if the stream is not in the list the behavior is undefined. + * The stream to be removed is referenced "by value", i.e., by the pointer to be + * removed from the list. This pointer is obtained using `srtp_stream_list_get` + * or as callback parameter in `srtp_stream_list_for_each`. */ void srtp_stream_list_remove(srtp_stream_list_t list, srtp_stream_t stream); diff --git a/srtp/srtp.c b/srtp/srtp.c index 6ab5db476..933f58f96 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -287,8 +287,9 @@ static srtp_err_status_t srtp_insert_or_dealloc_stream(srtp_stream_list_t list, { srtp_err_status_t status = srtp_stream_list_insert(list, stream); /* on failure, ownership wasn't transferred and we need to deallocate */ - if (status) + if (status) { srtp_stream_dealloc(stream, template); + } return status; } @@ -2103,8 +2104,9 @@ static srtp_err_status_t srtp_unprotect_aead(srtp_ctx_t *ctx, /* add new stream to the list */ status = srtp_insert_or_dealloc_stream(ctx->stream_list, new_stream, ctx->stream_template); - if (status) + if (status) { return status; + } /* set stream (the pointer used in this function) */ stream = new_stream; @@ -2196,8 +2198,9 @@ srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx, /* add new stream to the list */ status = srtp_insert_or_dealloc_stream(ctx->stream_list, new_stream, ctx->stream_template); - if (status) + if (status) { return status; + } /* set direction to outbound */ new_stream->direction = dir_srtp_sender; @@ -2791,14 +2794,16 @@ srtp_err_status_t srtp_unprotect_mki(srtp_ctx_t *ctx, */ status = srtp_stream_clone(ctx->stream_template, hdr->ssrc, &new_stream); - if (status) + if (status) { return status; + } /* add new stream to the list */ status = srtp_insert_or_dealloc_stream(ctx->stream_list, new_stream, ctx->stream_template); - if (status) + if (status) { return status; + } /* set stream (the pointer used in this function) */ stream = new_stream; @@ -2874,14 +2879,16 @@ srtp_err_status_t srtp_dealloc(srtp_t session) /* deallocate streams */ status = srtp_remove_and_dealloc_streams(session->stream_list, session->stream_template); - if (status) + if (status) { return status; + } /* deallocate stream template, if there is one */ if (session->stream_template != NULL) { status = srtp_stream_dealloc(session->stream_template, NULL); - if (status) + if (status) { return status; + } } /* deallocate stream list */ @@ -2952,8 +2959,9 @@ srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy) case (ssrc_specific): status = srtp_insert_or_dealloc_stream(session->stream_list, tmp, session->stream_template); - if (status) + if (status) { return status; + } break; case (ssrc_undefined): default: @@ -3032,6 +3040,7 @@ srtp_err_status_t srtp_remove_stream(srtp_t session, uint32_t ssrc) if (stream == NULL) { return srtp_err_status_no_ctx; } + srtp_stream_list_remove(session->stream_list, stream); /* deallocate the stream */ @@ -3091,8 +3100,9 @@ static int update_template_stream_cb(srtp_stream_t stream, void *raw_data) srtp_stream_list_remove(session->stream_list, stream); data->status = srtp_insert_or_dealloc_stream( data->new_stream_list, stream, session->stream_template); - if (data->status) + if (data->status) { return 1; + } return 0; } @@ -3102,19 +3112,22 @@ static int update_template_stream_cb(srtp_stream_t stream, void *raw_data) /* remove stream */ data->status = srtp_remove_stream(session, ssrc); - if (data->status) + if (data->status) { return 1; + } /* allocate and initialize a new stream */ data->status = srtp_stream_clone(data->new_stream_template, ssrc, &stream); - if (data->status) + if (data->status) { return 1; + } /* add new stream to the head of the new_stream_list */ data->status = srtp_insert_or_dealloc_stream(data->new_stream_list, stream, data->new_stream_template); - if (data->status) + if (data->status) { return 1; + } /* restore old extended seq */ stream->rtp_rdbx.index = old_index; @@ -3178,6 +3191,7 @@ static srtp_err_status_t update_template_streams(srtp_t session, session->stream_template); srtp_stream_list_dealloc(session->stream_list); srtp_stream_dealloc(session->stream_template, NULL); + /* set new list / template */ session->stream_template = new_stream_template; session->stream_list = new_stream_list; @@ -3952,8 +3966,9 @@ static srtp_err_status_t srtp_unprotect_rtcp_aead( /* add new stream to the list */ status = srtp_insert_or_dealloc_stream(ctx->stream_list, new_stream, ctx->stream_template); - if (status) + if (status) { return status; + } /* set stream (the pointer used in this function) */ stream = new_stream; @@ -4020,8 +4035,9 @@ srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx, /* add new stream to the list */ status = srtp_insert_or_dealloc_stream(ctx->stream_list, new_stream, ctx->stream_template); - if (status) + if (status) { return status; + } /* set stream (the pointer used in this function) */ stream = new_stream; @@ -4469,8 +4485,9 @@ srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx, /* add new stream to the list */ status = srtp_insert_or_dealloc_stream(ctx->stream_list, new_stream, ctx->stream_template); - if (status) + if (status) { return status; + } /* set stream (the pointer used in this function) */ stream = new_stream; @@ -4652,8 +4669,8 @@ srtp_err_status_t stream_get_protect_trailer_length(srtp_stream_ctx_t *stream, } struct get_protect_trailer_length_data { - int valid; - uint32_t length; + uint32_t found_stream; /* whether at least one matching stream was found */ + uint32_t length; /* maximum trailer length found so far */ uint32_t is_rtp; uint32_t use_mki; uint32_t mki_index; @@ -4665,10 +4682,10 @@ static int get_protect_trailer_length_cb(srtp_stream_t stream, void *raw_data) (struct get_protect_trailer_length_data *)raw_data; uint32_t temp_length; - data->valid = 1; if (stream_get_protect_trailer_length(stream, data->is_rtp, data->use_mki, data->mki_index, &temp_length) == srtp_err_status_ok) { + data->found_stream = 1; if (temp_length > data->length) { data->length = temp_length; } @@ -4694,7 +4711,7 @@ srtp_err_status_t get_protect_trailer_length(srtp_t session, stream = session->stream_template; if (stream != NULL) { - data.valid = 1; + data.found_stream = 1; stream_get_protect_trailer_length(stream, is_rtp, use_mki, mki_index, &data.length); } @@ -4702,7 +4719,7 @@ srtp_err_status_t get_protect_trailer_length(srtp_t session, srtp_stream_list_for_each(session->stream_list, get_protect_trailer_length_cb, &data); - if (!data.valid) { + if (!data.found_stream) { return srtp_err_status_bad_param; } @@ -4823,8 +4840,10 @@ srtp_err_status_t srtp_get_stream_roc(srtp_t session, #ifndef SRTP_NO_STREAM_LIST -/* in the default implementation, we have an intrusive linked list */ +/* in the default implementation, we have an intrusive doubly-linked list */ struct srtp_stream_list_ctx_t_ { + /* a stub stream that just holds pointers to the beginning and end of the + * list */ srtp_stream_ctx_t data; } srtp_stream_list_ctx_t_; @@ -4835,6 +4854,10 @@ srtp_err_status_t srtp_stream_list_alloc(srtp_stream_list_t *list_ptr) if (list == NULL) { return srtp_err_status_alloc_fail; } + + list->data.next = NULL; + list->data.prev = NULL; + *list_ptr = list; return srtp_err_status_ok; } diff --git a/test/srtp_driver.c b/test/srtp_driver.c index 8ecf273a1..42229be78 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -4302,7 +4302,7 @@ const srtp_policy_t wildcard_policy = { static srtp_stream_t stream_list_test_create_stream(uint32_t ssrc) { - srtp_stream_t stream = calloc(1, sizeof(srtp_stream_ctx_t)); + srtp_stream_t stream = malloc(sizeof(srtp_stream_ctx_t)); stream->ssrc = ssrc; return stream; } From fec3449a3ebe22cc7b51694b9563965592e459c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Thu, 19 Jan 2023 10:13:41 +0100 Subject: [PATCH 103/109] do not use system include for srtp_priv.h Including srtp_priv.h should only be done form inside source tree. --- include/stream_list_priv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/stream_list_priv.h b/include/stream_list_priv.h index f49cd551d..b61af188e 100644 --- a/include/stream_list_priv.h +++ b/include/stream_list_priv.h @@ -45,7 +45,7 @@ #ifndef SRTP_STREAM_LIST_PRIV_H #define SRTP_STREAM_LIST_PRIV_H -#include +#include "srtp_priv.h" #ifdef __cplusplus extern "C" { From 70b28c69a2d8250c2c444f18b52f9f41844d2232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 23 Jan 2023 21:45:05 +0100 Subject: [PATCH 104/109] use snprintf instead sprintf sprintf is marked as deprecated in OSX 13.1 --- test/cutest.h | 2 +- test/srtp_driver.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cutest.h b/test/cutest.h index f64667143..ae2b22bff 100644 --- a/test/cutest.h +++ b/test/cutest.h @@ -467,7 +467,7 @@ static void test_run__(const struct test__ *test) signame = "SIGTERM"; break; default: - sprintf(tmp, "signal %d", WTERMSIG(exit_code)); + snprintf(tmp, sizeof(tmp), "signal %d", WTERMSIG(exit_code)); signame = tmp; break; } diff --git a/test/srtp_driver.c b/test/srtp_driver.c index 42229be78..bc245d063 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -1621,7 +1621,7 @@ char *srtp_packet_to_string(srtp_hdr_t *hdr, int pkt_octet_len) } /* write packet into string */ - sprintf(packet_string, + snprintf(packet_string, sizeof(packet_string), "(s)rtp packet: {\n" " version:\t%d\n" " p:\t\t%d\n" From a3150271bbb66fd284498ca0f061a81398764fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 23 Jan 2023 21:47:26 +0100 Subject: [PATCH 105/109] format --- test/cutest.h | 3 ++- test/srtp_driver.c | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/test/cutest.h b/test/cutest.h index ae2b22bff..94e1087e6 100644 --- a/test/cutest.h +++ b/test/cutest.h @@ -467,7 +467,8 @@ static void test_run__(const struct test__ *test) signame = "SIGTERM"; break; default: - snprintf(tmp, sizeof(tmp), "signal %d", WTERMSIG(exit_code)); + snprintf(tmp, sizeof(tmp), "signal %d", + WTERMSIG(exit_code)); signame = tmp; break; } diff --git a/test/srtp_driver.c b/test/srtp_driver.c index bc245d063..ad722bb6f 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -1622,21 +1622,21 @@ char *srtp_packet_to_string(srtp_hdr_t *hdr, int pkt_octet_len) /* write packet into string */ snprintf(packet_string, sizeof(packet_string), - "(s)rtp packet: {\n" - " version:\t%d\n" - " p:\t\t%d\n" - " x:\t\t%d\n" - " cc:\t\t%d\n" - " m:\t\t%d\n" - " pt:\t\t%x\n" - " seq:\t\t%x\n" - " ts:\t\t%x\n" - " ssrc:\t%x\n" - " data:\t%s\n" - "} (%d octets in total)\n", - hdr->version, hdr->p, hdr->x, hdr->cc, hdr->m, hdr->pt, hdr->seq, - hdr->ts, hdr->ssrc, octet_string_hex_string(data, hex_len), - pkt_octet_len); + "(s)rtp packet: {\n" + " version:\t%d\n" + " p:\t\t%d\n" + " x:\t\t%d\n" + " cc:\t\t%d\n" + " m:\t\t%d\n" + " pt:\t\t%x\n" + " seq:\t\t%x\n" + " ts:\t\t%x\n" + " ssrc:\t%x\n" + " data:\t%s\n" + "} (%d octets in total)\n", + hdr->version, hdr->p, hdr->x, hdr->cc, hdr->m, hdr->pt, hdr->seq, + hdr->ts, hdr->ssrc, octet_string_hex_string(data, hex_len), + pkt_octet_len); return packet_string; } From 68ef5c5f78373be161b008e9b7fb4f98b5941c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Mon, 23 Jan 2023 22:22:11 +0100 Subject: [PATCH 106/109] schedule cmake CI once a week A few times now CI builds have broken due to changes in the CI environment, but these are not picked up before the next PR / commit. This will try to detect CI breakage early so it can be fix independently of any other code change. --- .github/workflows/cmake.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 764be18b7..03f489cf5 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -5,6 +5,8 @@ on: branches: [ main ] pull_request: branches: [ main ] + schedule: + - cron: '20 4 * * 1' jobs: build: From bc16c317f1969e003de26ddc2152ce47cc35e605 Mon Sep 17 00:00:00 2001 From: Oliver Shenton Date: Mon, 23 Jan 2023 13:43:49 +0000 Subject: [PATCH 107/109] Make mbedtls hmac less restrictive in line with RFC and library capabilities. --- crypto/hash/hmac_mbedtls.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crypto/hash/hmac_mbedtls.c b/crypto/hash/hmac_mbedtls.c index f710be9c7..d109791fa 100644 --- a/crypto/hash/hmac_mbedtls.c +++ b/crypto/hash/hmac_mbedtls.c @@ -71,10 +71,6 @@ static srtp_err_status_t srtp_hmac_mbedtls_alloc(srtp_auth_t **a, debug_print(srtp_mod_hmac, " tag length %d", out_len); - /* check output length - should be less than 20 bytes */ - if (key_len > SHA1_DIGEST_SIZE) { - return srtp_err_status_bad_param; - } /* check output length - should be less than 20 bytes */ if (out_len > SHA1_DIGEST_SIZE) { return srtp_err_status_bad_param; From b3891a97e5415fabaf22318da6dbb0153e25462c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Tue, 31 Jan 2023 14:04:48 +0100 Subject: [PATCH 108/109] update change log preparing for 2.5.0 release --- CHANGES | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 88095aaec..4541aa772 100644 --- a/CHANGES +++ b/CHANGES @@ -1,12 +1,54 @@ Changelog +2.5.0 + +#636 - Make mbedtls hmac less restrictive in line with RFC and library capabilities + +#612 - Allow overriding stream list implementation + +#629 - update min openssl version to 1.1.0 + +#602 - Openssl 3 support for EVP MAC + +#628 - Add android build to CI + +#616 - add CIFuzz Github action to workflows + +#621 - Add policy_set_aes_cm_192_xxx symbols to def file + +#617 - Use current directions in stream update test + +#614 - Call `set_aad` and `get_tag` in AEAD performance tests + +#611 - Create alias for srtp2 as libSRTP::srtp2 + +#593 - Remove compatibility code for legacy OpenSSL to fix LibreSSL build + +#573 - Export CMake Targets + +#586 - Avoid initializing local char table when converting nibble to hex + +#591 - EVP_CIPHER_CTX_cleanup() is deprecated in OpenSSL 1.1.0 + +#589 - Correct null cipher key sizes and be more defensive + +#570 - Include directory should point to 'include' not to 'include/srtp2' + +#551 - Count blocks instead of bytes in AES-ICM limit computation + +#561 - Rtp decoder support ssrc and roc + +#559 - Use a full-length key even with null ciphers + +#558 - Fix set ROC functionality with gcm + 2.4.0 Major changes #529 - Remove EKT files, this was never completed and the draft has since changed. -#512 - Adds suport for Mbedtls as a crypto backend. +#512 - Adds support for Mbedtls as a crypto backend. #503 - Support apple silicon build. @@ -54,7 +96,7 @@ Major changes A fuzzer was added to the project based on libFuzzer. This is run as part of Google oss-fuzz, the current status can be found at https://oss-fuzz-build-logs.storage.googleapis.com/index.html#libsrtp . Details available in PR #442 and issue #393. -CMake support was added as an alternative build system. This was primarily added to replace the Visual Studio project files currently checked in but has been extend to support building on all platforms. Initial PR #449 and #455 but has been support has been continuously improved. +CMake support was added as an alternative build system. This was primarily added to replace the Visual Studio project files currently checked in but has been extend to support building on all platforms. Initial PR #449 and #455 but has been support has been continuously improved. NSS support for crypto backend was added. This is can be used as an alternative to openssl. Initial PR #413 but there has been numerous improvements. From a566a9cfcd619e8327784aa7cff4a1276dc1e895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BChler?= Date: Wed, 1 Feb 2023 08:25:02 +0100 Subject: [PATCH 109/109] create 2.5.0 release --- configure | 18 +++++++++--------- configure.ac | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/configure b/configure index ed78cce34..c60213773 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for libsrtp2 2.5.0-pre. +# Generated by GNU Autoconf 2.69 for libsrtp2 2.5.0. # # Report bugs to . # @@ -580,8 +580,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='libsrtp2' PACKAGE_TARNAME='libsrtp2' -PACKAGE_VERSION='2.5.0-pre' -PACKAGE_STRING='libsrtp2 2.5.0-pre' +PACKAGE_VERSION='2.5.0' +PACKAGE_STRING='libsrtp2 2.5.0' PACKAGE_BUGREPORT='https://github.com/cisco/libsrtp/issues' PACKAGE_URL='' @@ -1288,7 +1288,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures libsrtp2 2.5.0-pre to adapt to many kinds of systems. +\`configure' configures libsrtp2 2.5.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1354,7 +1354,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of libsrtp2 2.5.0-pre:";; + short | recursive ) echo "Configuration of libsrtp2 2.5.0:";; esac cat <<\_ACEOF @@ -1467,7 +1467,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -libsrtp2 configure 2.5.0-pre +libsrtp2 configure 2.5.0 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2020,7 +2020,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by libsrtp2 $as_me 2.5.0-pre, which was +It was created by libsrtp2 $as_me 2.5.0, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -6998,7 +6998,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by libsrtp2 $as_me 2.5.0-pre, which was +This file was extended by libsrtp2 $as_me 2.5.0, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -7060,7 +7060,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -libsrtp2 config.status 2.5.0-pre +libsrtp2 config.status 2.5.0 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index c0a44bac7..233954c29 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -AC_INIT([libsrtp2], [2.5.0-pre], [https://github.com/cisco/libsrtp/issues]) +AC_INIT([libsrtp2], [2.5.0], [https://github.com/cisco/libsrtp/issues]) dnl Must come before AC_PROG_CC EMPTY_CFLAGS="no"