From eec73412dfa410456c486d1840fc1868f5b03f96 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Fri, 7 Apr 2023 10:22:28 -0700 Subject: [PATCH 01/38] linux-integration-tests.yml --- codebuild/linux-integration-tests.yml | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 codebuild/linux-integration-tests.yml diff --git a/codebuild/linux-integration-tests.yml b/codebuild/linux-integration-tests.yml new file mode 100644 index 000000000..947ffffab --- /dev/null +++ b/codebuild/linux-integration-tests.yml @@ -0,0 +1,32 @@ +version: 0.2 +env: + shell: bash +#this buildspec assumes the ubuntu 14 image +phases: + install: + commands: + - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + - sudo add-apt-repository ppa:ubuntu-toolchain-r/test + - sudo apt-add-repository "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main" + - sudo apt-get update -y + - sudo apt-get install clang-6.0 cmake3 clang-tidy-6.0 clang-format-6.0 -y -f + - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "/tmp/awscliv2.zip" + - unzip -q -d /tmp /tmp/awscliv2.zip + - sudo /tmp/aws/install + + pre_build: + commands: + - export CC=clang-6.0 + - export CXX=clang++-6.0 + build: + commands: + - echo Build started on `date` + # - aws s3 cp s3://aws-crt-test-stuff/setup_proxy_test_env.sh /tmp/setup_proxy_test_env.sh + # - sudo chmod a+xr /tmp/setup_proxy_test_env.sh + # # Setup Mqtt5 test environment + # - source ./codebuild/mqtt5_test_setup.sh s3://aws-crt-test-stuff/CodeBuildIotProdMQTT5EnvironmentVariables_v2.txt us-east-1 + # - ./codebuild/common-posix.sh -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DENABLE_FUZZ_TESTS=ON -DENABLE_MQTT5_TEST=ON + post_build: + commands: + - echo Build completed on `date` + From 51f9eb4ebd696a6e6ab8c340f27e4cd8b533be19 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Fri, 7 Apr 2023 13:53:56 -0700 Subject: [PATCH 02/38] yml update --- codebuild/linux-integration-tests.yml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/codebuild/linux-integration-tests.yml b/codebuild/linux-integration-tests.yml index 947ffffab..99b27a7a0 100644 --- a/codebuild/linux-integration-tests.yml +++ b/codebuild/linux-integration-tests.yml @@ -5,19 +5,23 @@ env: phases: install: commands: - - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - - sudo add-apt-repository ppa:ubuntu-toolchain-r/test - - sudo apt-add-repository "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main" - - sudo apt-get update -y - - sudo apt-get install clang-6.0 cmake3 clang-tidy-6.0 clang-format-6.0 -y -f - - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "/tmp/awscliv2.zip" - - unzip -q -d /tmp /tmp/awscliv2.zip - - sudo /tmp/aws/install + # - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + # - sudo add-apt-repository ppa:ubuntu-toolchain-r/test + # - sudo apt-add-repository "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main" + # - sudo apt-get update -y + # - sudo apt-get install clang-6.0 cmake3 clang-tidy-6.0 clang-format-6.0 -y -f + # - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "/tmp/awscliv2.zip" + # - unzip -q -d /tmp /tmp/awscliv2.zip + # - sudo /tmp/aws/install + - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - + - add-apt-repository ppa:ubuntu-toolchain-r/test + - apt-add-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main" + - apt-get update -y pre_build: commands: - - export CC=clang-6.0 - - export CXX=clang++-6.0 + # - export CC=clang-6.0 + # - export CXX=clang++-6.0 build: commands: - echo Build started on `date` From ff6e2bc0349c509446137d05b0553cbcafbfe462 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Fri, 7 Apr 2023 13:58:49 -0700 Subject: [PATCH 03/38] run setup-linux.sh --- codebuild/linux-integration-tests.yml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/codebuild/linux-integration-tests.yml b/codebuild/linux-integration-tests.yml index 99b27a7a0..9b04f9408 100644 --- a/codebuild/linux-integration-tests.yml +++ b/codebuild/linux-integration-tests.yml @@ -5,26 +5,15 @@ env: phases: install: commands: - # - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - # - sudo add-apt-repository ppa:ubuntu-toolchain-r/test - # - sudo apt-add-repository "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main" - # - sudo apt-get update -y - # - sudo apt-get install clang-6.0 cmake3 clang-tidy-6.0 clang-format-6.0 -y -f - # - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "/tmp/awscliv2.zip" - # - unzip -q -d /tmp /tmp/awscliv2.zip - # - sudo /tmp/aws/install - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - - add-apt-repository ppa:ubuntu-toolchain-r/test - apt-add-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main" - apt-get update -y - pre_build: - commands: - # - export CC=clang-6.0 - # - export CXX=clang++-6.0 build: commands: - echo Build started on `date` + - $CODEBUILD_SRC_DIR/codebuild/samples/setup-linux.sh # - aws s3 cp s3://aws-crt-test-stuff/setup_proxy_test_env.sh /tmp/setup_proxy_test_env.sh # - sudo chmod a+xr /tmp/setup_proxy_test_env.sh # # Setup Mqtt5 test environment From d780a0f26fa38edbf98737aadf998d468963ca69 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Fri, 7 Apr 2023 14:09:14 -0700 Subject: [PATCH 04/38] install cmake --- codebuild/linux-integration-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/codebuild/linux-integration-tests.yml b/codebuild/linux-integration-tests.yml index 9b04f9408..bc4b6d723 100644 --- a/codebuild/linux-integration-tests.yml +++ b/codebuild/linux-integration-tests.yml @@ -9,6 +9,7 @@ phases: - add-apt-repository ppa:ubuntu-toolchain-r/test - apt-add-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main" - apt-get update -y + - apt-get install cmake -y -f build: commands: From 270d94c4d0f3082db23335ee1f7eaebc7c6851a5 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Fri, 7 Apr 2023 14:50:36 -0700 Subject: [PATCH 05/38] notes --- codebuild/linux-integration-tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codebuild/linux-integration-tests.yml b/codebuild/linux-integration-tests.yml index bc4b6d723..d974f59f1 100644 --- a/codebuild/linux-integration-tests.yml +++ b/codebuild/linux-integration-tests.yml @@ -14,7 +14,9 @@ phases: build: commands: - echo Build started on `date` + # Building of dependencies happens in setup-linux - $CODEBUILD_SRC_DIR/codebuild/samples/setup-linux.sh + # - aws s3 cp s3://aws-crt-test-stuff/setup_proxy_test_env.sh /tmp/setup_proxy_test_env.sh # - sudo chmod a+xr /tmp/setup_proxy_test_env.sh # # Setup Mqtt5 test environment From b30a7bcb3bbd3a828e631ddb9adb34072eb47c48 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Fri, 7 Apr 2023 15:01:41 -0700 Subject: [PATCH 06/38] test --- codebuild/linux-integration-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/codebuild/linux-integration-tests.yml b/codebuild/linux-integration-tests.yml index d974f59f1..a0fc562bf 100644 --- a/codebuild/linux-integration-tests.yml +++ b/codebuild/linux-integration-tests.yml @@ -16,7 +16,6 @@ phases: - echo Build started on `date` # Building of dependencies happens in setup-linux - $CODEBUILD_SRC_DIR/codebuild/samples/setup-linux.sh - # - aws s3 cp s3://aws-crt-test-stuff/setup_proxy_test_env.sh /tmp/setup_proxy_test_env.sh # - sudo chmod a+xr /tmp/setup_proxy_test_env.sh # # Setup Mqtt5 test environment From ab108c9b3208022e6fbdfb4977ed192a3277db0a Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Fri, 7 Apr 2023 15:16:00 -0700 Subject: [PATCH 07/38] test --- codebuild/linux-integration-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/codebuild/linux-integration-tests.yml b/codebuild/linux-integration-tests.yml index a0fc562bf..d974f59f1 100644 --- a/codebuild/linux-integration-tests.yml +++ b/codebuild/linux-integration-tests.yml @@ -16,6 +16,7 @@ phases: - echo Build started on `date` # Building of dependencies happens in setup-linux - $CODEBUILD_SRC_DIR/codebuild/samples/setup-linux.sh + # - aws s3 cp s3://aws-crt-test-stuff/setup_proxy_test_env.sh /tmp/setup_proxy_test_env.sh # - sudo chmod a+xr /tmp/setup_proxy_test_env.sh # # Setup Mqtt5 test environment From 67a0018a0a6f80e9cc5fb24dace05ea458ba2f35 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Fri, 7 Apr 2023 16:26:05 -0700 Subject: [PATCH 08/38] integration-tests.sh --- codebuild/integration-tests.sh | 11 +++++++++++ codebuild/linux-integration-tests.yml | 3 +++ 2 files changed, 14 insertions(+) create mode 100644 codebuild/integration-tests.sh diff --git a/codebuild/integration-tests.sh b/codebuild/integration-tests.sh new file mode 100644 index 000000000..14428d6b2 --- /dev/null +++ b/codebuild/integration-tests.sh @@ -0,0 +1,11 @@ +env + +pushd $CODEBUILD_SRC_DIR/secure_tunneling/tests + +aws iotsecuretunneling open-tunnel --destination-config thingName=,services=ssh --timeout-config maxLifeTimeOutMinutes = 10 + +# mkdir _build +# cd _build +# cmake -DCMAKE_PREFIX_PATH=/tmp/install .. +# make -j + diff --git a/codebuild/linux-integration-tests.yml b/codebuild/linux-integration-tests.yml index d974f59f1..d3efa70ad 100644 --- a/codebuild/linux-integration-tests.yml +++ b/codebuild/linux-integration-tests.yml @@ -17,6 +17,9 @@ phases: # Building of dependencies happens in setup-linux - $CODEBUILD_SRC_DIR/codebuild/samples/setup-linux.sh + # Run the integration tests + - $CODEBUILD_SRC_DIR/codebuild/integration-tests.sh + # - aws s3 cp s3://aws-crt-test-stuff/setup_proxy_test_env.sh /tmp/setup_proxy_test_env.sh # - sudo chmod a+xr /tmp/setup_proxy_test_env.sh # # Setup Mqtt5 test environment From 508a73462219d8801eae761f151f28c08cb1c039 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Mon, 10 Apr 2023 10:03:21 -0700 Subject: [PATCH 09/38] chmod integration-tests.sh --- codebuild/integration-tests.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 codebuild/integration-tests.sh diff --git a/codebuild/integration-tests.sh b/codebuild/integration-tests.sh old mode 100644 new mode 100755 From 7f344283e486f537580e2e3b303c6d20e7edf6d3 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Mon, 10 Apr 2023 10:09:59 -0700 Subject: [PATCH 10/38] check what's set --- codebuild/integration-tests.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/codebuild/integration-tests.sh b/codebuild/integration-tests.sh index 14428d6b2..250ac3230 100755 --- a/codebuild/integration-tests.sh +++ b/codebuild/integration-tests.sh @@ -1,9 +1,13 @@ +set -e + env pushd $CODEBUILD_SRC_DIR/secure_tunneling/tests aws iotsecuretunneling open-tunnel --destination-config thingName=,services=ssh --timeout-config maxLifeTimeOutMinutes = 10 +printenv + # mkdir _build # cd _build # cmake -DCMAKE_PREFIX_PATH=/tmp/install .. From 66241bed761edd1dcda0851104b9bc8ef1f79b89 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Mon, 10 Apr 2023 10:13:20 -0700 Subject: [PATCH 11/38] secure tunneling tests directory --- secure_tunneling/tests/CMakeLists.txt | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 secure_tunneling/tests/CMakeLists.txt diff --git a/secure_tunneling/tests/CMakeLists.txt b/secure_tunneling/tests/CMakeLists.txt new file mode 100644 index 000000000..489c0a4b8 --- /dev/null +++ b/secure_tunneling/tests/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.1) +# note: cxx-17 requires cmake 3.8, cxx-20 requires cmake 3.12 +project(secure-tunnel CXX) + +file(GLOB SRC_FILES + "*.cpp" + "../../utils/CommandLineUtils.cpp" + "../../utils/CommandLineUtils.h" +) + +add_executable(${PROJECT_NAME} ${SRC_FILES}) + +set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_STANDARD 14) + +#set warnings +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX) +else () + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror) +endif () + +find_package(aws-crt-cpp REQUIRED) +find_package(IotDeviceCommon-cpp REQUIRED) +find_package(IotSecureTunneling-cpp REQUIRED) + +install(TARGETS ${PROJECT_NAME} DESTINATION bin) + +target_link_libraries(${PROJECT_NAME} AWS::aws-crt-cpp AWS::IotDeviceCommon-cpp AWS::IotSecureTunneling-cpp) From 138e26219d83ea852567b8e8394f735b599db044 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Mon, 10 Apr 2023 10:21:53 -0700 Subject: [PATCH 12/38] print first --- codebuild/integration-tests.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/codebuild/integration-tests.sh b/codebuild/integration-tests.sh index 250ac3230..73a389b57 100755 --- a/codebuild/integration-tests.sh +++ b/codebuild/integration-tests.sh @@ -4,9 +4,11 @@ env pushd $CODEBUILD_SRC_DIR/secure_tunneling/tests +printenv + aws iotsecuretunneling open-tunnel --destination-config thingName=,services=ssh --timeout-config maxLifeTimeOutMinutes = 10 -printenv + # mkdir _build # cd _build From 686f20f20a20aad0c880ad9b13429d83439aaf36 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Mon, 10 Apr 2023 10:26:50 -0700 Subject: [PATCH 13/38] open secure tunnel --- codebuild/integration-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codebuild/integration-tests.sh b/codebuild/integration-tests.sh index 73a389b57..912fdd484 100755 --- a/codebuild/integration-tests.sh +++ b/codebuild/integration-tests.sh @@ -6,7 +6,7 @@ pushd $CODEBUILD_SRC_DIR/secure_tunneling/tests printenv -aws iotsecuretunneling open-tunnel --destination-config thingName=,services=ssh --timeout-config maxLifeTimeOutMinutes = 10 +aws iotsecuretunneling open-tunnel --destination-config services=ssh,ssh2,ssh3 --timeout-config maxLifetimeTimeoutMinutes=10 From 6552a2ac79bbad7836461d88c3ab51d6b1084d46 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Mon, 10 Apr 2023 14:19:57 -0700 Subject: [PATCH 14/38] open and store tunnel tokens --- codebuild/integration-tests.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/codebuild/integration-tests.sh b/codebuild/integration-tests.sh index 912fdd484..295ba60ad 100755 --- a/codebuild/integration-tests.sh +++ b/codebuild/integration-tests.sh @@ -4,11 +4,16 @@ env pushd $CODEBUILD_SRC_DIR/secure_tunneling/tests +printf "Currently set env variables\n" printenv -aws iotsecuretunneling open-tunnel --destination-config services=ssh,ssh2,ssh3 --timeout-config maxLifetimeTimeoutMinutes=10 - +tunnel_info=$(aws iotsecuretunneling open-tunnel --destination-config services=ssh,ssh2,ssh3 --timeout-config maxLifetimeTimeoutMinutes=10) && echo -e "$tunnel_info" > /tmp/tunnel_info.pem +source_access_token=$(sed '4!d' /tmp/tunnel_info.pem | cut -d'"' -f4) && echo -e "$source_access_token" > /tmp/source_access_token.pem +destination_access_token=$(sed '5!d' /tmp/tunnel_info.pem | cut -d'"' -f4) && echo -e "$destination_access_token" > /tmp/destination_access_token.pem +cat /tmp/tunnel_info.pem +cat /tmp/source_access_token.pem +cat /tmp/destination_access_token.pem # mkdir _build # cd _build From cdedf37f3b7f7aa4fa3a8a8085756bad54b23624 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Mon, 10 Apr 2023 15:54:29 -0700 Subject: [PATCH 15/38] work on integration test --- codebuild/integration-tests.sh | 9 ++++++++- secure_tunneling/tests/CMakeLists.txt | 6 +++--- secure_tunneling/tests/main.cpp | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 secure_tunneling/tests/main.cpp diff --git a/codebuild/integration-tests.sh b/codebuild/integration-tests.sh index 295ba60ad..8983dbba4 100755 --- a/codebuild/integration-tests.sh +++ b/codebuild/integration-tests.sh @@ -4,6 +4,11 @@ env pushd $CODEBUILD_SRC_DIR/secure_tunneling/tests +mkdir _build +cd _build +cmake -DCMAKE_PREFIX_PATH=/tmp/install .. +make -j + printf "Currently set env variables\n" printenv @@ -15,8 +20,10 @@ cat /tmp/tunnel_info.pem cat /tmp/source_access_token.pem cat /tmp/destination_access_token.pem +echo "Secure Tunnel Test" +./secure_tunnel_test + # mkdir _build # cd _build # cmake -DCMAKE_PREFIX_PATH=/tmp/install .. # make -j - diff --git a/secure_tunneling/tests/CMakeLists.txt b/secure_tunneling/tests/CMakeLists.txt index 489c0a4b8..c4ddfecc6 100644 --- a/secure_tunneling/tests/CMakeLists.txt +++ b/secure_tunneling/tests/CMakeLists.txt @@ -1,11 +1,11 @@ cmake_minimum_required(VERSION 3.1) # note: cxx-17 requires cmake 3.8, cxx-20 requires cmake 3.12 -project(secure-tunnel CXX) +project(secure_tunnel_test CXX) file(GLOB SRC_FILES "*.cpp" - "../../utils/CommandLineUtils.cpp" - "../../utils/CommandLineUtils.h" + # "../../utils/CommandLineUtils.cpp" + # "../../utils/CommandLineUtils.h" ) add_executable(${PROJECT_NAME} ${SRC_FILES}) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp new file mode 100644 index 000000000..2aa6d5456 --- /dev/null +++ b/secure_tunneling/tests/main.cpp @@ -0,0 +1,19 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include +#include + +int main(int argc, char *argv[]) +{ + fprintf(stdout, "Secure Tunnel Test Starting\n"); + struct aws_allocator *allocator = aws_default_allocator(); + ApiHandle apiHandle; + aws_iotdevice_library_init(allocator); + + fprintf(stdout, "Secure Tunnel Test Completed\n"); + + return 0; +} From 5ef64ad690b7052fbd422c076af5ccf5a7d1a4a4 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Mon, 10 Apr 2023 16:09:45 -0700 Subject: [PATCH 16/38] update --- codebuild/integration-tests.sh | 5 ----- secure_tunneling/tests/main.cpp | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/codebuild/integration-tests.sh b/codebuild/integration-tests.sh index 8983dbba4..85ea71195 100755 --- a/codebuild/integration-tests.sh +++ b/codebuild/integration-tests.sh @@ -22,8 +22,3 @@ cat /tmp/destination_access_token.pem echo "Secure Tunnel Test" ./secure_tunnel_test - -# mkdir _build -# cd _build -# cmake -DCMAKE_PREFIX_PATH=/tmp/install .. -# make -j diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 2aa6d5456..91725531a 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -3,9 +3,14 @@ * SPDX-License-Identifier: Apache-2.0. */ +#include #include +#include +#include #include +using namespace Aws::Crt; + int main(int argc, char *argv[]) { fprintf(stdout, "Secure Tunnel Test Starting\n"); From 598e1d118be17a17573e6be940adb863ab68ddc3 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 09:47:32 -0700 Subject: [PATCH 17/38] wip --- codebuild/integration-tests.sh | 3 + .../secure_tunneling/secure_tunnel/main.cpp | 2 +- secure_tunneling/tests/main.cpp | 177 ++++++++++++++++++ 3 files changed, 181 insertions(+), 1 deletion(-) diff --git a/codebuild/integration-tests.sh b/codebuild/integration-tests.sh index 85ea71195..291adfecc 100755 --- a/codebuild/integration-tests.sh +++ b/codebuild/integration-tests.sh @@ -16,6 +16,9 @@ tunnel_info=$(aws iotsecuretunneling open-tunnel --destination-config services=s source_access_token=$(sed '4!d' /tmp/tunnel_info.pem | cut -d'"' -f4) && echo -e "$source_access_token" > /tmp/source_access_token.pem destination_access_token=$(sed '5!d' /tmp/tunnel_info.pem | cut -d'"' -f4) && echo -e "$destination_access_token" > /tmp/destination_access_token.pem +export SECTUN_ENDPOINT=$source_access_token + + cat /tmp/tunnel_info.pem cat /tmp/source_access_token.pem cat /tmp/destination_access_token.pem diff --git a/samples/secure_tunneling/secure_tunnel/main.cpp b/samples/secure_tunneling/secure_tunnel/main.cpp index b9dc634cc..4cb4ba8c5 100644 --- a/samples/secure_tunneling/secure_tunnel/main.cpp +++ b/samples/secure_tunneling/secure_tunnel/main.cpp @@ -558,7 +558,7 @@ int main(int argc, char *argv[]) /* Set the Secure Tunnel Client to desire a stopped state */ if (secureTunnel->Stop() == AWS_OP_ERR) { - fprintf(stderr, "Secure Tunnel Close call failed: %s\n", ErrorDebugString(LastError())); + fprintf(stderr, "Secure Tunnel Stop call failed: %s\n", ErrorDebugString(LastError())); exit(-1); } diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 91725531a..99678dec0 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -4,12 +4,20 @@ */ #include +#include #include #include #include #include using namespace Aws::Crt; +using namespace Aws::Iotsecuretunneling; +using namespace Aws::Crt::Io; +using namespace std::chrono_literals; + +AWS_STATIC_STRING_FROM_LITERAL(SECTUN_ENDPOINT, "SECTUN_ENDPOINT"); +// AWS_STATIC_STRING_FROM_LITERAL(SECTUN_SOURCE_TOKEN, "SECTUN_SOURCE_TOKEN"); +// AWS_STATIC_STRING_FROM_LITERAL(SECTUN_DESTINATION_TOKEN, "SECTUN_DESTINATION_TOKEN"); int main(int argc, char *argv[]) { @@ -18,6 +26,175 @@ int main(int argc, char *argv[]) ApiHandle apiHandle; aws_iotdevice_library_init(allocator); + /* service id storage for use in test */ + Aws::Crt::ByteBuf m_serviceIdStorage; + AWS_ZERO_STRUCT(m_serviceIdStorage); + Aws::Crt::Optional m_serviceId; + + /* + * In a real world application you probably don't want to enforce synchronous behavior + * but this is a sample console application, so we'll just do that with a condition variable. + */ + std::promise clientStoppedPromise; + + String endpoint; + String accessToken; + String clientToken; + aws_secure_tunneling_local_proxy_mode localProxyMode = AWS_SECURE_TUNNELING_DESTINATION_MODE; + /* Connection Id is used for Simultaneous HTTP Connections (Protocl V3) */ + uint32_t connectionId = 1; + + aws_string *aws_string_endpoint = NULL; + + aws_get_environment_value(allocator, SECTUN_ENDPOINT, &aws_string_endpoint); + endpoint = aws_string_endpoint == nullptr ? "" : aws_string_c_str(aws_string_endpoint); + aws_string_destroy(aws_string_endpoint); + + if (apiHandle.GetOrCreateStaticDefaultClientBootstrap()->LastError() != AWS_ERROR_SUCCESS) + { + fprintf( + stderr, + "ClientBootstrap failed with error %s\n", + ErrorDebugString(apiHandle.GetOrCreateStaticDefaultClientBootstrap()->LastError())); + exit(-1); + } + + /* Use a SecureTunnelBuilder to set up and build the secure tunnel client */ + SecureTunnelBuilder builder = SecureTunnelBuilder(allocator, accessToken.c_str(), localProxyMode, endpoint.c_str()); + + // builder.WithClientToken(clientToket.c_str()); + + builder.WithOnMessageReceived([&](SecureTunnel *secureTunnel, const MessageReceivedEventData &eventData) { + { + (void)secureTunnel; + (void)eventData; + } + }); + + builder.WithOnSendMessageComplete( + [&](SecureTunnel *secureTunnel, int errorCode, const SendMessageCompleteEventData &eventData) { + (void)secureTunnel; + (void)eventData; + + if (!errorCode) + { + fprintf( + stdout, + "Message of type '" PRInSTR "' sent successfully\n", + AWS_BYTE_CURSOR_PRI(eventData.sendMessageCompleteData->getMessageType())); + } + else + { + fprintf(stdout, "Send Message failed with error code %d(%s)\n", errorCode, ErrorDebugString(errorCode)); + } + }); + + builder.WithOnConnectionSuccess([&](SecureTunnel *secureTunnel, const ConnectionSuccessEventData &eventData) { + (void)secureTunnel; + (void)eventData; + + /* Stream Start can only be called from Source Mode */ + if (localProxyMode == AWS_SECURE_TUNNELING_SOURCE_MODE) + { + /* Use a Multiplexing (Service Id) if available on this Secure Tunnel */ + if (eventData.connectionData->getServiceId1().has_value()) + { + /* Store the service id for future use */ + aws_byte_buf_clean_up(&m_serviceIdStorage); + AWS_ZERO_STRUCT(m_serviceIdStorage); + aws_byte_buf_init_copy_from_cursor( + &m_serviceIdStorage, allocator, eventData.connectionData->getServiceId1().value()); + m_serviceId = aws_byte_cursor_from_buf(&m_serviceIdStorage); + secureTunnel->SendStreamStart(eventData.connectionData->getServiceId1().value(), connectionId); + } + else + { + fprintf(stdout, "Sending Stream Start request\n"); + secureTunnel->SendStreamStart(); + } + } + }); + + builder.WithOnStreamStarted( + [&](SecureTunnel *secureTunnel, int errorCode, const StreamStartedEventData &eventData) { + (void)secureTunnel; + (void)eventData; + if (!errorCode) + { + // logStreamStartData(eventData); + } + else + { + fprintf(stdout, "Stream Start failed with error code %d(%s)\n", errorCode, ErrorDebugString(errorCode)); + } + }); + + builder.WithOnConnectionStarted([&](SecureTunnel *secureTunnel, + int errorCode, + const ConnectionStartedEventData &eventData) { + (void)secureTunnel; + (void)eventData; + if (!errorCode) + { + // logConnectionStartedData(eventData); + } + else + { + fprintf(stdout, "Connection Start failed with error code %d(%s)\n", errorCode, ErrorDebugString(errorCode)); + } + }); + + builder.WithOnStreamStopped([&](SecureTunnel *secureTunnel, const StreamStoppedEventData &eventData) { + (void)secureTunnel; + + // logStreamStoppedData(eventData); + }); + + builder.WithOnConnectionShutdown([&]() { fprintf(stdout, "Connection Shutdown\n"); }); + + builder.WithOnStopped([&](SecureTunnel *secureTunnel) { + (void)secureTunnel; + fprintf(stdout, "Secure Tunnel has entered Stopped State\n"); + clientStoppedPromise.set_value(true); + }); + + /* Create Secure Tunnel using the options set with the builder */ + std::shared_ptr secureTunnel = builder.Build(); + + if (!secureTunnel) + { + fprintf(stderr, "Secure Tunnel Creation failed: %s\n", ErrorDebugString(LastError())); + exit(-1); + } + + fprintf(stdout, "Secure Tunnel Created\n"); + + /* Set the Secure Tunnel Client to desire a connected state */ + if (secureTunnel->Start()) + { + fprintf(stderr, "Secure Tunnel Connect call failed: %s\n", ErrorDebugString(LastError())); + exit(-1); + } + + std::this_thread::sleep_for(3000ms); + + fprintf(stdout, "Closing Connection\n"); + /* Set the Secure Tunnel Client to desire a stopped state */ + if (secureTunnel->Stop() == AWS_OP_ERR) + { + fprintf(stderr, "Secure Tunnel Stop call failed: %s\n", ErrorDebugString(LastError())); + exit(-1); + } + + /* The Secure Tunnel Client at this point will report they are stopped and can be safely removed. */ + if (clientStoppedPromise.get_future().get()) + { + secureTunnel = nullptr; + } + + /* Clean Up */ + aws_byte_buf_clean_up(&m_serviceIdStorage); + fprintf(stdout, "Secure Tunnel Test Completed\n"); return 0; From 40a17a3ef74b22509aef360bf4018040ee5df312 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 09:59:10 -0700 Subject: [PATCH 18/38] remove sleep --- secure_tunneling/tests/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 99678dec0..5ff5432f4 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -176,7 +176,7 @@ int main(int argc, char *argv[]) exit(-1); } - std::this_thread::sleep_for(3000ms); + // std::this_thread::sleep_for(3000ms); fprintf(stdout, "Closing Connection\n"); /* Set the Secure Tunnel Client to desire a stopped state */ From 43451252f3154a58adf9ad3c7eaa81235d754c70 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 10:37:02 -0700 Subject: [PATCH 19/38] testing --- secure_tunneling/tests/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 5ff5432f4..9765ad640 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -50,6 +50,12 @@ int main(int argc, char *argv[]) endpoint = aws_string_endpoint == nullptr ? "" : aws_string_c_str(aws_string_endpoint); aws_string_destroy(aws_string_endpoint); + fprintf(stdout, "endpoint:%s\n", endpoint.c_str()); + + // STEVE DEBUG + endpoint = "test endpoint"; + accessToken = "test token"; + if (apiHandle.GetOrCreateStaticDefaultClientBootstrap()->LastError() != AWS_ERROR_SUCCESS) { fprintf( From 73d76cf03a7c06d96f5d0011b0deaccb89db168f Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 11:07:59 -0700 Subject: [PATCH 20/38] test --- secure_tunneling/tests/main.cpp | 41 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 9765ad640..26a0290fe 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -24,6 +24,9 @@ int main(int argc, char *argv[]) fprintf(stdout, "Secure Tunnel Test Starting\n"); struct aws_allocator *allocator = aws_default_allocator(); ApiHandle apiHandle; + // Logging + // apiHandle.InitializeLogging(Aws::Crt::LogLevel::Trace, stderr); + aws_iotdevice_library_init(allocator); /* service id storage for use in test */ @@ -176,27 +179,29 @@ int main(int argc, char *argv[]) fprintf(stdout, "Secure Tunnel Created\n"); /* Set the Secure Tunnel Client to desire a connected state */ - if (secureTunnel->Start()) - { - fprintf(stderr, "Secure Tunnel Connect call failed: %s\n", ErrorDebugString(LastError())); - exit(-1); - } + // if (secureTunnel->Start()) + // { + // fprintf(stderr, "Secure Tunnel Connect call failed: %s\n", ErrorDebugString(LastError())); + // exit(-1); + // } // std::this_thread::sleep_for(3000ms); - fprintf(stdout, "Closing Connection\n"); - /* Set the Secure Tunnel Client to desire a stopped state */ - if (secureTunnel->Stop() == AWS_OP_ERR) - { - fprintf(stderr, "Secure Tunnel Stop call failed: %s\n", ErrorDebugString(LastError())); - exit(-1); - } - - /* The Secure Tunnel Client at this point will report they are stopped and can be safely removed. */ - if (clientStoppedPromise.get_future().get()) - { - secureTunnel = nullptr; - } + // fprintf(stdout, "Closing Connection\n"); + // /* Set the Secure Tunnel Client to desire a stopped state */ + // if (secureTunnel->Stop() == AWS_OP_ERR) + // { + // fprintf(stderr, "Secure Tunnel Stop call failed: %s\n", ErrorDebugString(LastError())); + // exit(-1); + // } + + // /* The Secure Tunnel Client at this point will report they are stopped and can be safely removed. */ + // if (clientStoppedPromise.get_future().get()) + // { + // secureTunnel = nullptr; + // } + + secureTunnel = nullptr; /* Clean Up */ aws_byte_buf_clean_up(&m_serviceIdStorage); From c63a9b5e0f6889eea3fb7e79cbeefad182b9c0d9 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 13:18:23 -0700 Subject: [PATCH 21/38] test --- codebuild/integration-tests.sh | 6 ++++-- secure_tunneling/tests/main.cpp | 36 ++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/codebuild/integration-tests.sh b/codebuild/integration-tests.sh index 291adfecc..e693b2ec1 100755 --- a/codebuild/integration-tests.sh +++ b/codebuild/integration-tests.sh @@ -13,10 +13,12 @@ printf "Currently set env variables\n" printenv tunnel_info=$(aws iotsecuretunneling open-tunnel --destination-config services=ssh,ssh2,ssh3 --timeout-config maxLifetimeTimeoutMinutes=10) && echo -e "$tunnel_info" > /tmp/tunnel_info.pem -source_access_token=$(sed '4!d' /tmp/tunnel_info.pem | cut -d'"' -f4) && echo -e "$source_access_token" > /tmp/source_access_token.pem +# source_access_token=$(sed '4!d' /tmp/tunnel_info.pem | cut -d'"' -f4) && echo -e "$source_access_token" > /tmp/source_access_token.pem destination_access_token=$(sed '5!d' /tmp/tunnel_info.pem | cut -d'"' -f4) && echo -e "$destination_access_token" > /tmp/destination_access_token.pem -export SECTUN_ENDPOINT=$source_access_token +export SECTUN_SOURCE_TOKEN=$(sed '4!d' /tmp/tunnel_info.pem | cut -d'"' -f4) +export SECTUN_DESTINATION_TOKEN=$(sed '5!d' /tmp/tunnel_info.pem | cut -d'"' -f4) +export SECTUN_ENDPOINT="data.tunneling.iot.us-east-1.amazonaws.com" cat /tmp/tunnel_info.pem diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 26a0290fe..413fbd809 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -16,8 +16,16 @@ using namespace Aws::Crt::Io; using namespace std::chrono_literals; AWS_STATIC_STRING_FROM_LITERAL(SECTUN_ENDPOINT, "SECTUN_ENDPOINT"); -// AWS_STATIC_STRING_FROM_LITERAL(SECTUN_SOURCE_TOKEN, "SECTUN_SOURCE_TOKEN"); -// AWS_STATIC_STRING_FROM_LITERAL(SECTUN_DESTINATION_TOKEN, "SECTUN_DESTINATION_TOKEN"); +AWS_STATIC_STRING_FROM_LITERAL(SECTUN_SOURCE_TOKEN, "SECTUN_SOURCE_TOKEN"); +AWS_STATIC_STRING_FROM_LITERAL(SECTUN_DESTINATION_TOKEN, "SECTUN_DESTINATION_TOKEN"); + +void setEnvVariable(struct aws_allocator *allocator, const struct aws_string *variable_name, String stringToSet) +{ + aws_string *awsStringToSet = NULL; + aws_get_environment_value(allocator, variable_name, &awsStringToSet); + stringToSet = awsStringToSet == nullptr ? "" : aws_string_c_str(awsStringToSet); + aws_string_destroy(awsStringToSet); +} int main(int argc, char *argv[]) { @@ -42,22 +50,25 @@ int main(int argc, char *argv[]) String endpoint; String accessToken; - String clientToken; + String destinationToken; + String sourceToken; aws_secure_tunneling_local_proxy_mode localProxyMode = AWS_SECURE_TUNNELING_DESTINATION_MODE; /* Connection Id is used for Simultaneous HTTP Connections (Protocl V3) */ uint32_t connectionId = 1; - aws_string *aws_string_endpoint = NULL; + setEnvVariable(allocator, SECTUN_DESTINATION_TOKEN, destinationToken); + setEnvVariable(allocator, SECTUN_SOURCE_TOKEN, sourceToken); + setEnvVariable(allocator, SECTUN_ENDPOINT, endpoint); - aws_get_environment_value(allocator, SECTUN_ENDPOINT, &aws_string_endpoint); - endpoint = aws_string_endpoint == nullptr ? "" : aws_string_c_str(aws_string_endpoint); - aws_string_destroy(aws_string_endpoint); + // aws_string *aws_string_endpoint = NULL; - fprintf(stdout, "endpoint:%s\n", endpoint.c_str()); + // aws_get_environment_value(allocator, SECTUN_ENDPOINT, &aws_string_endpoint); + // endpoint = aws_string_endpoint == nullptr ? "" : aws_string_c_str(aws_string_endpoint); + // aws_string_destroy(aws_string_endpoint); - // STEVE DEBUG - endpoint = "test endpoint"; - accessToken = "test token"; + fprintf(stdout, "endpoint:%s\n", endpoint.c_str()); + fprintf(stdout, "source token:%s\n", sourceToken.c_str()); + fprintf(stdout, "destination token:%s\n", destinationToken.c_str()); if (apiHandle.GetOrCreateStaticDefaultClientBootstrap()->LastError() != AWS_ERROR_SUCCESS) { @@ -69,7 +80,8 @@ int main(int argc, char *argv[]) } /* Use a SecureTunnelBuilder to set up and build the secure tunnel client */ - SecureTunnelBuilder builder = SecureTunnelBuilder(allocator, accessToken.c_str(), localProxyMode, endpoint.c_str()); + SecureTunnelBuilder builder = + SecureTunnelBuilder(allocator, destinationToken.c_str(), localProxyMode, endpoint.c_str()); // builder.WithClientToken(clientToket.c_str()); From f699b7c1f85fda2a9ca0b860cda37269e8fda110 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 13:24:30 -0700 Subject: [PATCH 22/38] setup fix --- codebuild/integration-tests.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/codebuild/integration-tests.sh b/codebuild/integration-tests.sh index e693b2ec1..8bcbbeb58 100755 --- a/codebuild/integration-tests.sh +++ b/codebuild/integration-tests.sh @@ -14,16 +14,11 @@ printenv tunnel_info=$(aws iotsecuretunneling open-tunnel --destination-config services=ssh,ssh2,ssh3 --timeout-config maxLifetimeTimeoutMinutes=10) && echo -e "$tunnel_info" > /tmp/tunnel_info.pem # source_access_token=$(sed '4!d' /tmp/tunnel_info.pem | cut -d'"' -f4) && echo -e "$source_access_token" > /tmp/source_access_token.pem -destination_access_token=$(sed '5!d' /tmp/tunnel_info.pem | cut -d'"' -f4) && echo -e "$destination_access_token" > /tmp/destination_access_token.pem +# destination_access_token=$(sed '5!d' /tmp/tunnel_info.pem | cut -d'"' -f4) && echo -e "$destination_access_token" > /tmp/destination_access_token.pem export SECTUN_SOURCE_TOKEN=$(sed '4!d' /tmp/tunnel_info.pem | cut -d'"' -f4) export SECTUN_DESTINATION_TOKEN=$(sed '5!d' /tmp/tunnel_info.pem | cut -d'"' -f4) export SECTUN_ENDPOINT="data.tunneling.iot.us-east-1.amazonaws.com" - -cat /tmp/tunnel_info.pem -cat /tmp/source_access_token.pem -cat /tmp/destination_access_token.pem - echo "Secure Tunnel Test" ./secure_tunnel_test From 3eb3ed4b745c8c024e7f9e8424fcb9e898a90191 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 13:34:46 -0700 Subject: [PATCH 23/38] test fix --- secure_tunneling/tests/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 413fbd809..977944f86 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -19,10 +19,12 @@ AWS_STATIC_STRING_FROM_LITERAL(SECTUN_ENDPOINT, "SECTUN_ENDPOINT"); AWS_STATIC_STRING_FROM_LITERAL(SECTUN_SOURCE_TOKEN, "SECTUN_SOURCE_TOKEN"); AWS_STATIC_STRING_FROM_LITERAL(SECTUN_DESTINATION_TOKEN, "SECTUN_DESTINATION_TOKEN"); -void setEnvVariable(struct aws_allocator *allocator, const struct aws_string *variable_name, String stringToSet) +void setEnvVariable(struct aws_allocator *allocator, const struct aws_string *variable_name, String &stringToSet) { aws_string *awsStringToSet = NULL; aws_get_environment_value(allocator, variable_name, &awsStringToSet); + // Steve TODO debug + // awsStringToSet = aws_string_new_from_c_str(allocator, "test string"); stringToSet = awsStringToSet == nullptr ? "" : aws_string_c_str(awsStringToSet); aws_string_destroy(awsStringToSet); } From 926c99fc420a129f0a93448a62cc3336fed6d847 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 14:10:56 -0700 Subject: [PATCH 24/38] sleep test --- secure_tunneling/tests/main.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 977944f86..d0580b2fb 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -62,16 +62,6 @@ int main(int argc, char *argv[]) setEnvVariable(allocator, SECTUN_SOURCE_TOKEN, sourceToken); setEnvVariable(allocator, SECTUN_ENDPOINT, endpoint); - // aws_string *aws_string_endpoint = NULL; - - // aws_get_environment_value(allocator, SECTUN_ENDPOINT, &aws_string_endpoint); - // endpoint = aws_string_endpoint == nullptr ? "" : aws_string_c_str(aws_string_endpoint); - // aws_string_destroy(aws_string_endpoint); - - fprintf(stdout, "endpoint:%s\n", endpoint.c_str()); - fprintf(stdout, "source token:%s\n", sourceToken.c_str()); - fprintf(stdout, "destination token:%s\n", destinationToken.c_str()); - if (apiHandle.GetOrCreateStaticDefaultClientBootstrap()->LastError() != AWS_ERROR_SUCCESS) { fprintf( @@ -192,6 +182,8 @@ int main(int argc, char *argv[]) fprintf(stdout, "Secure Tunnel Created\n"); + std::this_thread::sleep_for(std::chrono::milliseconds(1 * 1000)); + /* Set the Secure Tunnel Client to desire a connected state */ // if (secureTunnel->Start()) // { From 46ac3f686304c98835c7ab5dac9213e4f7cd1371 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 14:21:06 -0700 Subject: [PATCH 25/38] fix sleep --- codebuild/linux-integration-tests.yml | 6 ------ secure_tunneling/tests/main.cpp | 24 +++++++++++------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/codebuild/linux-integration-tests.yml b/codebuild/linux-integration-tests.yml index d3efa70ad..1ae3cbe22 100644 --- a/codebuild/linux-integration-tests.yml +++ b/codebuild/linux-integration-tests.yml @@ -19,12 +19,6 @@ phases: # Run the integration tests - $CODEBUILD_SRC_DIR/codebuild/integration-tests.sh - - # - aws s3 cp s3://aws-crt-test-stuff/setup_proxy_test_env.sh /tmp/setup_proxy_test_env.sh - # - sudo chmod a+xr /tmp/setup_proxy_test_env.sh - # # Setup Mqtt5 test environment - # - source ./codebuild/mqtt5_test_setup.sh s3://aws-crt-test-stuff/CodeBuildIotProdMQTT5EnvironmentVariables_v2.txt us-east-1 - # - ./codebuild/common-posix.sh -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DENABLE_FUZZ_TESTS=ON -DENABLE_MQTT5_TEST=ON post_build: commands: - echo Build completed on `date` diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index d0580b2fb..dd192fbfa 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -9,6 +9,7 @@ #include #include #include +#include using namespace Aws::Crt; using namespace Aws::Iotsecuretunneling; @@ -54,7 +55,6 @@ int main(int argc, char *argv[]) String accessToken; String destinationToken; String sourceToken; - aws_secure_tunneling_local_proxy_mode localProxyMode = AWS_SECURE_TUNNELING_DESTINATION_MODE; /* Connection Id is used for Simultaneous HTTP Connections (Protocl V3) */ uint32_t connectionId = 1; @@ -72,10 +72,8 @@ int main(int argc, char *argv[]) } /* Use a SecureTunnelBuilder to set up and build the secure tunnel client */ - SecureTunnelBuilder builder = - SecureTunnelBuilder(allocator, destinationToken.c_str(), localProxyMode, endpoint.c_str()); - - // builder.WithClientToken(clientToket.c_str()); + SecureTunnelBuilder builder = SecureTunnelBuilder( + allocator, destinationToken.c_str(), AWS_SECURE_TUNNELING_DESTINATION_MODE, endpoint.c_str()); builder.WithOnMessageReceived([&](SecureTunnel *secureTunnel, const MessageReceivedEventData &eventData) { { @@ -172,7 +170,7 @@ int main(int argc, char *argv[]) }); /* Create Secure Tunnel using the options set with the builder */ - std::shared_ptr secureTunnel = builder.Build(); + std::shared_ptr secureTunnelDestination = builder.Build(); if (!secureTunnel) { @@ -180,18 +178,18 @@ int main(int argc, char *argv[]) exit(-1); } - fprintf(stdout, "Secure Tunnel Created\n"); + fprintf(stdout, "Destination Secure Tunnel Created\n"); std::this_thread::sleep_for(std::chrono::milliseconds(1 * 1000)); /* Set the Secure Tunnel Client to desire a connected state */ - // if (secureTunnel->Start()) - // { - // fprintf(stderr, "Secure Tunnel Connect call failed: %s\n", ErrorDebugString(LastError())); - // exit(-1); - // } + if (secureTunnelDestination->Start()) + { + fprintf(stderr, "Secure Tunnel Connect call failed: %s\n", ErrorDebugString(LastError())); + exit(-1); + } - // std::this_thread::sleep_for(3000ms); + std::this_thread::sleep_for(std::chrono::milliseconds(3 * 1000)); // fprintf(stdout, "Closing Connection\n"); // /* Set the Secure Tunnel Client to desire a stopped state */ From ad9e0976e78ab8188357a9e9e694457f32082a23 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 14:28:16 -0700 Subject: [PATCH 26/38] separate destination secure tunnel --- secure_tunneling/tests/main.cpp | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index dd192fbfa..412e4e835 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -105,25 +105,25 @@ int main(int argc, char *argv[]) (void)eventData; /* Stream Start can only be called from Source Mode */ - if (localProxyMode == AWS_SECURE_TUNNELING_SOURCE_MODE) - { - /* Use a Multiplexing (Service Id) if available on this Secure Tunnel */ - if (eventData.connectionData->getServiceId1().has_value()) - { - /* Store the service id for future use */ - aws_byte_buf_clean_up(&m_serviceIdStorage); - AWS_ZERO_STRUCT(m_serviceIdStorage); - aws_byte_buf_init_copy_from_cursor( - &m_serviceIdStorage, allocator, eventData.connectionData->getServiceId1().value()); - m_serviceId = aws_byte_cursor_from_buf(&m_serviceIdStorage); - secureTunnel->SendStreamStart(eventData.connectionData->getServiceId1().value(), connectionId); - } - else - { - fprintf(stdout, "Sending Stream Start request\n"); - secureTunnel->SendStreamStart(); - } - } + // if (localProxyMode == AWS_SECURE_TUNNELING_SOURCE_MODE) + // { + // /* Use a Multiplexing (Service Id) if available on this Secure Tunnel */ + // if (eventData.connectionData->getServiceId1().has_value()) + // { + // /* Store the service id for future use */ + // aws_byte_buf_clean_up(&m_serviceIdStorage); + // AWS_ZERO_STRUCT(m_serviceIdStorage); + // aws_byte_buf_init_copy_from_cursor( + // &m_serviceIdStorage, allocator, eventData.connectionData->getServiceId1().value()); + // m_serviceId = aws_byte_cursor_from_buf(&m_serviceIdStorage); + // secureTunnel->SendStreamStart(eventData.connectionData->getServiceId1().value(), connectionId); + // } + // else + // { + // fprintf(stdout, "Sending Stream Start request\n"); + // secureTunnel->SendStreamStart(); + // } + // } }); builder.WithOnStreamStarted( @@ -172,7 +172,7 @@ int main(int argc, char *argv[]) /* Create Secure Tunnel using the options set with the builder */ std::shared_ptr secureTunnelDestination = builder.Build(); - if (!secureTunnel) + if (!secureTunnelDestination) { fprintf(stderr, "Secure Tunnel Creation failed: %s\n", ErrorDebugString(LastError())); exit(-1); @@ -205,7 +205,7 @@ int main(int argc, char *argv[]) // secureTunnel = nullptr; // } - secureTunnel = nullptr; + secureTunnelDestination = nullptr; /* Clean Up */ aws_byte_buf_clean_up(&m_serviceIdStorage); From 6c0a65178e93819ede44db9f5c2e82eb3dc61399 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 14:34:30 -0700 Subject: [PATCH 27/38] start/stop --- secure_tunneling/tests/main.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 412e4e835..a9bfbe989 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) String destinationToken; String sourceToken; /* Connection Id is used for Simultaneous HTTP Connections (Protocl V3) */ - uint32_t connectionId = 1; + // uint32_t connectionId = 1; setEnvVariable(allocator, SECTUN_DESTINATION_TOKEN, destinationToken); setEnvVariable(allocator, SECTUN_SOURCE_TOKEN, sourceToken); @@ -183,27 +183,29 @@ int main(int argc, char *argv[]) std::this_thread::sleep_for(std::chrono::milliseconds(1 * 1000)); /* Set the Secure Tunnel Client to desire a connected state */ + if (secureTunnelDestination->Start()) { fprintf(stderr, "Secure Tunnel Connect call failed: %s\n", ErrorDebugString(LastError())); exit(-1); } - std::this_thread::sleep_for(std::chrono::milliseconds(3 * 1000)); + std::this_thread::sleep_for(std::chrono::milliseconds(5 * 1000)); // fprintf(stdout, "Closing Connection\n"); // /* Set the Secure Tunnel Client to desire a stopped state */ - // if (secureTunnel->Stop() == AWS_OP_ERR) - // { - // fprintf(stderr, "Secure Tunnel Stop call failed: %s\n", ErrorDebugString(LastError())); - // exit(-1); - // } - - // /* The Secure Tunnel Client at this point will report they are stopped and can be safely removed. */ - // if (clientStoppedPromise.get_future().get()) - // { - // secureTunnel = nullptr; - // } + if (secureTunnel->Stop() == AWS_OP_ERR) + { + fprintf(stderr, "Secure Tunnel Stop call failed: %s\n", ErrorDebugString(LastError())); + exit(-1); + } + + /* The Secure Tunnel Client at this point will report they are stopped and can be safely removed. */ + if (clientStoppedPromise.get_future().get()) + { + fprintf(stdout, "Destinatino Secure Tunnel Stopped\n"); + secureTunnel = nullptr; + } secureTunnelDestination = nullptr; From 294f4652721da3321c82d7ae2f3fa0382fcaa098 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 14:40:58 -0700 Subject: [PATCH 28/38] fix --- secure_tunneling/tests/main.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index a9bfbe989..7262f81b4 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -194,7 +194,7 @@ int main(int argc, char *argv[]) // fprintf(stdout, "Closing Connection\n"); // /* Set the Secure Tunnel Client to desire a stopped state */ - if (secureTunnel->Stop() == AWS_OP_ERR) + if (secureTunnelDestination->Stop() == AWS_OP_ERR) { fprintf(stderr, "Secure Tunnel Stop call failed: %s\n", ErrorDebugString(LastError())); exit(-1); @@ -204,11 +204,9 @@ int main(int argc, char *argv[]) if (clientStoppedPromise.get_future().get()) { fprintf(stdout, "Destinatino Secure Tunnel Stopped\n"); - secureTunnel = nullptr; + secureTunnelDestination = nullptr; } - secureTunnelDestination = nullptr; - /* Clean Up */ aws_byte_buf_clean_up(&m_serviceIdStorage); From 7f3075bb7c40230508eb92a9a6e0d2f2a72cd18b Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 15:15:54 -0700 Subject: [PATCH 29/38] two clients --- secure_tunneling/tests/main.cpp | 177 ++++++++++++++++++++++---------- 1 file changed, 122 insertions(+), 55 deletions(-) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 7262f81b4..fd7f5c7f6 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -45,18 +45,17 @@ int main(int argc, char *argv[]) AWS_ZERO_STRUCT(m_serviceIdStorage); Aws::Crt::Optional m_serviceId; - /* - * In a real world application you probably don't want to enforce synchronous behavior - * but this is a sample console application, so we'll just do that with a condition variable. - */ - std::promise clientStoppedPromise; + std::promise promiseDestinationConnected; + std::promise promiseSourceConnected; + std::promise promiseDestinationStopped; + std::promise promiseSourceStopped; String endpoint; String accessToken; String destinationToken; String sourceToken; /* Connection Id is used for Simultaneous HTTP Connections (Protocl V3) */ - // uint32_t connectionId = 1; + uint32_t connectionId = 1; setEnvVariable(allocator, SECTUN_DESTINATION_TOKEN, destinationToken); setEnvVariable(allocator, SECTUN_SOURCE_TOKEN, sourceToken); @@ -71,18 +70,46 @@ int main(int argc, char *argv[]) exit(-1); } - /* Use a SecureTunnelBuilder to set up and build the secure tunnel client */ - SecureTunnelBuilder builder = SecureTunnelBuilder( + /* Use a SecureTunnelBuilder to set up and build the secure tunnel clients */ + SecureTunnelBuilder builderDestination = SecureTunnelBuilder( allocator, destinationToken.c_str(), AWS_SECURE_TUNNELING_DESTINATION_MODE, endpoint.c_str()); + SecureTunnelBuilder builderSource = + SecureTunnelBuilder(allocator, sourceToken.c_str(), AWS_SECURE_TUNNELING_SOURCE_MODE, endpoint.c_str()); - builder.WithOnMessageReceived([&](SecureTunnel *secureTunnel, const MessageReceivedEventData &eventData) { + builderDestination.WithOnMessageReceived( + [&](SecureTunnel *secureTunnel, const MessageReceivedEventData &eventData) { + { + (void)secureTunnel; + (void)eventData; + } + }); + + builderSource.WithOnMessageReceived([&](SecureTunnel *secureTunnel, const MessageReceivedEventData &eventData) { { (void)secureTunnel; (void)eventData; } }); - builder.WithOnSendMessageComplete( + builderDestination.WithOnSendMessageComplete( + [&](SecureTunnel *secureTunnel, int errorCode, const SendMessageCompleteEventData &eventData) { + (void)secureTunnel; + (void)eventData; + + if (!errorCode) + { + fprintf( + stdout, + "Message of type '" PRInSTR "' sent successfully\n", + AWS_BYTE_CURSOR_PRI(eventData.sendMessageCompleteData->getMessageType())); + } + else + { + fprintf(stdout, "Send Message failed with error code %d(%s)\n", errorCode, ErrorDebugString(errorCode)); + } + }); + + builderSource.WithOnSendMessageComplete( [&](SecureTunnel *secureTunnel, int errorCode, const SendMessageCompleteEventData &eventData) { (void)secureTunnel; (void)eventData; @@ -100,39 +127,45 @@ int main(int argc, char *argv[]) } }); - builder.WithOnConnectionSuccess([&](SecureTunnel *secureTunnel, const ConnectionSuccessEventData &eventData) { + builderDestination.WithOnConnectionSuccess( + [&](SecureTunnel *secureTunnel, const ConnectionSuccessEventData &eventData) { + (void)secureTunnel; + (void)eventData; + promiseDestinationConnected.set_value(true); + }); + + builderSource.WithOnConnectionSuccess([&](SecureTunnel *secureTunnel, const ConnectionSuccessEventData &eventData) { (void)secureTunnel; (void)eventData; - /* Stream Start can only be called from Source Mode */ - // if (localProxyMode == AWS_SECURE_TUNNELING_SOURCE_MODE) - // { - // /* Use a Multiplexing (Service Id) if available on this Secure Tunnel */ - // if (eventData.connectionData->getServiceId1().has_value()) - // { - // /* Store the service id for future use */ - // aws_byte_buf_clean_up(&m_serviceIdStorage); - // AWS_ZERO_STRUCT(m_serviceIdStorage); - // aws_byte_buf_init_copy_from_cursor( - // &m_serviceIdStorage, allocator, eventData.connectionData->getServiceId1().value()); - // m_serviceId = aws_byte_cursor_from_buf(&m_serviceIdStorage); - // secureTunnel->SendStreamStart(eventData.connectionData->getServiceId1().value(), connectionId); - // } - // else - // { - // fprintf(stdout, "Sending Stream Start request\n"); - // secureTunnel->SendStreamStart(); - // } - // } + /* Use a Multiplexing (Service Id) if available on this Secure Tunnel */ + if (eventData.connectionData->getServiceId1().has_value()) + { + /* Store the service id for future use */ + aws_byte_buf_clean_up(&m_serviceIdStorage); + AWS_ZERO_STRUCT(m_serviceIdStorage); + aws_byte_buf_init_copy_from_cursor( + &m_serviceIdStorage, allocator, eventData.connectionData->getServiceId1().value()); + m_serviceId = aws_byte_cursor_from_buf(&m_serviceIdStorage); + secureTunnel->SendStreamStart(eventData.connectionData->getServiceId1().value(), connectionId); + fprintf(stdout, "Stream Start sent from Source Client.\n"); + } + else + { + fprintf(stdout, "Sending Stream Start request\n"); + secureTunnel->SendStreamStart(); + } + + promiseSourceConnected.set_value(true); }); - builder.WithOnStreamStarted( + builderDestination.WithOnStreamStarted( [&](SecureTunnel *secureTunnel, int errorCode, const StreamStartedEventData &eventData) { (void)secureTunnel; (void)eventData; if (!errorCode) { - // logStreamStartData(eventData); + fprintf(stdout, "Stream Started on Destination Client.\n") } else { @@ -140,14 +173,14 @@ int main(int argc, char *argv[]) } }); - builder.WithOnConnectionStarted([&](SecureTunnel *secureTunnel, - int errorCode, - const ConnectionStartedEventData &eventData) { + builderDestination.WithOnConnectionStarted([&](SecureTunnel *secureTunnel, + int errorCode, + const ConnectionStartedEventData &eventData) { (void)secureTunnel; (void)eventData; if (!errorCode) { - // logConnectionStartedData(eventData); + fprintf(stdout, "Connection Started on Destination Client.\n") } else { @@ -155,58 +188,92 @@ int main(int argc, char *argv[]) } }); - builder.WithOnStreamStopped([&](SecureTunnel *secureTunnel, const StreamStoppedEventData &eventData) { - (void)secureTunnel; + builderDestination.WithOnConnectionShutdown([&]() { fprintf(stdout, "Destination Connection Shutdown\n"); }); - // logStreamStoppedData(eventData); - }); + builderSource.WithOnConnectionShutdown([&]() { fprintf(stdout, "Source Connection Shutdown\n"); }); - builder.WithOnConnectionShutdown([&]() { fprintf(stdout, "Connection Shutdown\n"); }); + builderDestination.WithOnStopped([&](SecureTunnel *secureTunnel) { + (void)secureTunnel; + fprintf(stdout, "Destination entered Stopped State\n"); + promiseDestinationStopped.set_value(true); + }); - builder.WithOnStopped([&](SecureTunnel *secureTunnel) { + builderSource.WithOnStopped([&](SecureTunnel *secureTunnel) { (void)secureTunnel; - fprintf(stdout, "Secure Tunnel has entered Stopped State\n"); - clientStoppedPromise.set_value(true); + fprintf(stdout, "Source has entered Stopped State\n"); + promiseSourceStopped.set_value(true); }); /* Create Secure Tunnel using the options set with the builder */ - std::shared_ptr secureTunnelDestination = builder.Build(); + std::shared_ptr secureTunnelDestination = builderDestination.Build(); if (!secureTunnelDestination) { - fprintf(stderr, "Secure Tunnel Creation failed: %s\n", ErrorDebugString(LastError())); + fprintf(stderr, "Secure Tunnel Destination Creation failed: %s\n", ErrorDebugString(LastError())); exit(-1); } - fprintf(stdout, "Destination Secure Tunnel Created\n"); + std::shared_ptr secureTunnelSource = builderSource.Build(); + if (!secureTunnelSource) + { + fprintf(stderr, "Secure Tunnel Source Creation failed: %s\n", ErrorDebugString(LastError())); + exit(-1); + } - std::this_thread::sleep_for(std::chrono::milliseconds(1 * 1000)); + fprintf(stdout, "Secure Tunnels Created\n"); /* Set the Secure Tunnel Client to desire a connected state */ if (secureTunnelDestination->Start()) { - fprintf(stderr, "Secure Tunnel Connect call failed: %s\n", ErrorDebugString(LastError())); + fprintf(stderr, "Secure Tunnel Destination Connect call failed: %s\n", ErrorDebugString(LastError())); + exit(-1); + } + + if (promiseDestinationConnected.get_future().get()) + { + fprintf(stdout, "Destination sucessfully connected\n"); + } + + if (secureTunnelSource->Start()) + { + fprintf(stderr, "Secure Tunnel Source Connect call failed: %s\n", ErrorDebugString(LastError())); exit(-1); } + if (promiseSourceConnected.get_future().get()) + { + fprintf(stdout, "Source sucessfully connected\n"); + } + std::this_thread::sleep_for(std::chrono::milliseconds(5 * 1000)); - // fprintf(stdout, "Closing Connection\n"); - // /* Set the Secure Tunnel Client to desire a stopped state */ if (secureTunnelDestination->Stop() == AWS_OP_ERR) { - fprintf(stderr, "Secure Tunnel Stop call failed: %s\n", ErrorDebugString(LastError())); + fprintf(stderr, "Secure Tunnel Destination Stop call failed: %s\n", ErrorDebugString(LastError())); exit(-1); } /* The Secure Tunnel Client at this point will report they are stopped and can be safely removed. */ - if (clientStoppedPromise.get_future().get()) + if (promiseDestinationStopped.get_future().get()) { - fprintf(stdout, "Destinatino Secure Tunnel Stopped\n"); + fprintf(stdout, "Destination Stopped\n"); secureTunnelDestination = nullptr; } + if (secureTunnelSource->Stop() == AWS_OP_ERR) + { + fprintf(stderr, "Secure Tunnel Source Stop call failed: %s\n", ErrorDebugString(LastError())); + exit(-1); + } + + /* The Secure Tunnel Client at this point will report they are stopped and can be safely removed. */ + if (promiseSourceStopped.get_future().get()) + { + fprintf(stdout, "Source Stopped\n"); + secureTunnelSource = nullptr; + } + /* Clean Up */ aws_byte_buf_clean_up(&m_serviceIdStorage); From 436685374f2b46773831157c5dad267c19dca9be Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 15:24:38 -0700 Subject: [PATCH 30/38] fix --- secure_tunneling/tests/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index fd7f5c7f6..390ea2c36 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -165,7 +165,7 @@ int main(int argc, char *argv[]) (void)eventData; if (!errorCode) { - fprintf(stdout, "Stream Started on Destination Client.\n") + fprintf(stdout, "Stream Started on Destination Client.\n"); } else { @@ -180,7 +180,7 @@ int main(int argc, char *argv[]) (void)eventData; if (!errorCode) { - fprintf(stdout, "Connection Started on Destination Client.\n") + fprintf(stdout, "Connection Started on Destination Client.\n"); } else { From f604a4786545cd3bdfa9836090cd28848c4bdaf9 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 16:09:59 -0700 Subject: [PATCH 31/38] more testing --- secure_tunneling/tests/main.cpp | 60 +++++++++++++++++---------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 390ea2c36..5eb27cb6d 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -45,10 +45,12 @@ int main(int argc, char *argv[]) AWS_ZERO_STRUCT(m_serviceIdStorage); Aws::Crt::Optional m_serviceId; - std::promise promiseDestinationConnected; - std::promise promiseSourceConnected; - std::promise promiseDestinationStopped; - std::promise promiseSourceStopped; + std::promise promiseDestinationConnected; + std::promise promiseSourceConnected; + std::promise promiseDestinationStreamStarted; + std::promise promiseDestinationConnectionStarted; + std::promise promiseDestinationStopped; + std::promise promiseSourceStopped; String endpoint; String accessToken; @@ -56,6 +58,7 @@ int main(int argc, char *argv[]) String sourceToken; /* Connection Id is used for Simultaneous HTTP Connections (Protocl V3) */ uint32_t connectionId = 1; + uint32_t connectionId2 = 2; setEnvVariable(allocator, SECTUN_DESTINATION_TOKEN, destinationToken); setEnvVariable(allocator, SECTUN_SOURCE_TOKEN, sourceToken); @@ -131,13 +134,16 @@ int main(int argc, char *argv[]) [&](SecureTunnel *secureTunnel, const ConnectionSuccessEventData &eventData) { (void)secureTunnel; (void)eventData; - promiseDestinationConnected.set_value(true); + fprintf(stdout, "Destination Client Connection Success\n"); + promiseDestinationConnected.set_value(); }); builderSource.WithOnConnectionSuccess([&](SecureTunnel *secureTunnel, const ConnectionSuccessEventData &eventData) { (void)secureTunnel; (void)eventData; + fprintf(stdout, "Source Client Connection Success\n"); + /* Use a Multiplexing (Service Id) if available on this Secure Tunnel */ if (eventData.connectionData->getServiceId1().has_value()) { @@ -156,7 +162,7 @@ int main(int argc, char *argv[]) secureTunnel->SendStreamStart(); } - promiseSourceConnected.set_value(true); + promiseSourceConnected.set_value(); }); builderDestination.WithOnStreamStarted( @@ -165,11 +171,13 @@ int main(int argc, char *argv[]) (void)eventData; if (!errorCode) { - fprintf(stdout, "Stream Started on Destination Client.\n"); + fprintf(stdout, "Destination Client Stream Started with Source Client\n"); + promiseDestinationStreamStarted.set_value(); } else { fprintf(stdout, "Stream Start failed with error code %d(%s)\n", errorCode, ErrorDebugString(errorCode)); + exit(-1); } }); @@ -181,10 +189,12 @@ int main(int argc, char *argv[]) if (!errorCode) { fprintf(stdout, "Connection Started on Destination Client.\n"); + promiseDestinationConnectionStarted.set_value(); } else { fprintf(stdout, "Connection Start failed with error code %d(%s)\n", errorCode, ErrorDebugString(errorCode)); + exit(-1); } }); @@ -195,13 +205,13 @@ int main(int argc, char *argv[]) builderDestination.WithOnStopped([&](SecureTunnel *secureTunnel) { (void)secureTunnel; fprintf(stdout, "Destination entered Stopped State\n"); - promiseDestinationStopped.set_value(true); + promiseDestinationStopped.set_value(); }); builderSource.WithOnStopped([&](SecureTunnel *secureTunnel) { (void)secureTunnel; fprintf(stdout, "Source has entered Stopped State\n"); - promiseSourceStopped.set_value(true); + promiseSourceStopped.set_value(); }); /* Create Secure Tunnel using the options set with the builder */ @@ -230,10 +240,7 @@ int main(int argc, char *argv[]) exit(-1); } - if (promiseDestinationConnected.get_future().get()) - { - fprintf(stdout, "Destination sucessfully connected\n"); - } + promiseDestinationConnected.get_future().wait(); if (secureTunnelSource->Start()) { @@ -241,10 +248,13 @@ int main(int argc, char *argv[]) exit(-1); } - if (promiseSourceConnected.get_future().get()) - { - fprintf(stdout, "Source sucessfully connected\n"); - } + promiseSourceConnected.get_future().wait(); + + promiseDestinationStreamStarted.get_future().wait(); + + secureTunnelSource->SendConnectionStart(m_serviceId.value(), connectionId2); + + promiseDestinationConnectionStarted.get_future().wait(); std::this_thread::sleep_for(std::chrono::milliseconds(5 * 1000)); @@ -254,12 +264,8 @@ int main(int argc, char *argv[]) exit(-1); } - /* The Secure Tunnel Client at this point will report they are stopped and can be safely removed. */ - if (promiseDestinationStopped.get_future().get()) - { - fprintf(stdout, "Destination Stopped\n"); - secureTunnelDestination = nullptr; - } + promiseDestinationStopped.get_future().wait(); + secureTunnelDestination = nullptr; if (secureTunnelSource->Stop() == AWS_OP_ERR) { @@ -267,12 +273,8 @@ int main(int argc, char *argv[]) exit(-1); } - /* The Secure Tunnel Client at this point will report they are stopped and can be safely removed. */ - if (promiseSourceStopped.get_future().get()) - { - fprintf(stdout, "Source Stopped\n"); - secureTunnelSource = nullptr; - } + promiseSourceStopped.get_future().wait(); + secureTunnelSource = nullptr; /* Clean Up */ aws_byte_buf_clean_up(&m_serviceIdStorage); From 7162fb803dab8ec956bee7e283ec8139b9c95f03 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 16:20:52 -0700 Subject: [PATCH 32/38] logging --- secure_tunneling/tests/main.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 5eb27cb6d..89bae18be 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -24,8 +24,6 @@ void setEnvVariable(struct aws_allocator *allocator, const struct aws_string *va { aws_string *awsStringToSet = NULL; aws_get_environment_value(allocator, variable_name, &awsStringToSet); - // Steve TODO debug - // awsStringToSet = aws_string_new_from_c_str(allocator, "test string"); stringToSet = awsStringToSet == nullptr ? "" : aws_string_c_str(awsStringToSet); aws_string_destroy(awsStringToSet); } @@ -36,7 +34,7 @@ int main(int argc, char *argv[]) struct aws_allocator *allocator = aws_default_allocator(); ApiHandle apiHandle; // Logging - // apiHandle.InitializeLogging(Aws::Crt::LogLevel::Trace, stderr); + apiHandle.InitializeLogging(Aws::Crt::LogLevel::Trace, stderr); aws_iotdevice_library_init(allocator); @@ -153,13 +151,13 @@ int main(int argc, char *argv[]) aws_byte_buf_init_copy_from_cursor( &m_serviceIdStorage, allocator, eventData.connectionData->getServiceId1().value()); m_serviceId = aws_byte_cursor_from_buf(&m_serviceIdStorage); - secureTunnel->SendStreamStart(eventData.connectionData->getServiceId1().value(), connectionId); + secureTunnel->SendStreamStart(m_serviceId.value(), connectionId); fprintf(stdout, "Stream Start sent from Source Client.\n"); } else { - fprintf(stdout, "Sending Stream Start request\n"); - secureTunnel->SendStreamStart(); + fprintf(stdout, "Secure Tunnel should have service ids set for proper testing\n"); + exit(-1); } promiseSourceConnected.set_value(); From a6a96fd614fa9040d87ffb36baabc9a807252362 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 11 Apr 2023 16:28:40 -0700 Subject: [PATCH 33/38] segfault check --- secure_tunneling/tests/main.cpp | 36 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 89bae18be..7d543c4bb 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -254,30 +254,30 @@ int main(int argc, char *argv[]) promiseDestinationConnectionStarted.get_future().wait(); - std::this_thread::sleep_for(std::chrono::milliseconds(5 * 1000)); + return 0; - if (secureTunnelDestination->Stop() == AWS_OP_ERR) - { - fprintf(stderr, "Secure Tunnel Destination Stop call failed: %s\n", ErrorDebugString(LastError())); - exit(-1); - } + // if (secureTunnelDestination->Stop() == AWS_OP_ERR) + // { + // fprintf(stderr, "Secure Tunnel Destination Stop call failed: %s\n", ErrorDebugString(LastError())); + // exit(-1); + // } - promiseDestinationStopped.get_future().wait(); - secureTunnelDestination = nullptr; + // promiseDestinationStopped.get_future().wait(); + // secureTunnelDestination = nullptr; - if (secureTunnelSource->Stop() == AWS_OP_ERR) - { - fprintf(stderr, "Secure Tunnel Source Stop call failed: %s\n", ErrorDebugString(LastError())); - exit(-1); - } + // if (secureTunnelSource->Stop() == AWS_OP_ERR) + // { + // fprintf(stderr, "Secure Tunnel Source Stop call failed: %s\n", ErrorDebugString(LastError())); + // exit(-1); + // } - promiseSourceStopped.get_future().wait(); - secureTunnelSource = nullptr; + // promiseSourceStopped.get_future().wait(); + // secureTunnelSource = nullptr; - /* Clean Up */ - aws_byte_buf_clean_up(&m_serviceIdStorage); + // /* Clean Up */ + // aws_byte_buf_clean_up(&m_serviceIdStorage); - fprintf(stdout, "Secure Tunnel Test Completed\n"); + // fprintf(stdout, "Secure Tunnel Test Completed\n"); return 0; } From 96aa7cc7d9a54fafd4f4d0751601bd24e9334a71 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Wed, 12 Apr 2023 10:23:26 -0700 Subject: [PATCH 34/38] updates --- codebuild/integration-tests.sh | 2 -- secure_tunneling/tests/main.cpp | 55 +++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/codebuild/integration-tests.sh b/codebuild/integration-tests.sh index 8bcbbeb58..14da8f338 100755 --- a/codebuild/integration-tests.sh +++ b/codebuild/integration-tests.sh @@ -13,8 +13,6 @@ printf "Currently set env variables\n" printenv tunnel_info=$(aws iotsecuretunneling open-tunnel --destination-config services=ssh,ssh2,ssh3 --timeout-config maxLifetimeTimeoutMinutes=10) && echo -e "$tunnel_info" > /tmp/tunnel_info.pem -# source_access_token=$(sed '4!d' /tmp/tunnel_info.pem | cut -d'"' -f4) && echo -e "$source_access_token" > /tmp/source_access_token.pem -# destination_access_token=$(sed '5!d' /tmp/tunnel_info.pem | cut -d'"' -f4) && echo -e "$destination_access_token" > /tmp/destination_access_token.pem export SECTUN_SOURCE_TOKEN=$(sed '4!d' /tmp/tunnel_info.pem | cut -d'"' -f4) export SECTUN_DESTINATION_TOKEN=$(sed '5!d' /tmp/tunnel_info.pem | cut -d'"' -f4) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 7d543c4bb..37bc7a67a 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -19,6 +19,8 @@ using namespace std::chrono_literals; AWS_STATIC_STRING_FROM_LITERAL(SECTUN_ENDPOINT, "SECTUN_ENDPOINT"); AWS_STATIC_STRING_FROM_LITERAL(SECTUN_SOURCE_TOKEN, "SECTUN_SOURCE_TOKEN"); AWS_STATIC_STRING_FROM_LITERAL(SECTUN_DESTINATION_TOKEN, "SECTUN_DESTINATION_TOKEN"); +AWS_STATIC_STRING_FROM_LITERAL(SECTUN_SOURCE_CLIENT_TOKEN, "SECTUN_SOURCE_CLIENT_TOKEN"); +AWS_STATIC_STRING_FROM_LITERAL(SECTUN_DESTINATION_CLIENT_TOKEN, "SECTUN_DESTINATION_CLIENT_TOKEN"); void setEnvVariable(struct aws_allocator *allocator, const struct aws_string *variable_name, String &stringToSet) { @@ -33,7 +35,9 @@ int main(int argc, char *argv[]) fprintf(stdout, "Secure Tunnel Test Starting\n"); struct aws_allocator *allocator = aws_default_allocator(); ApiHandle apiHandle; - // Logging + + // DEBUG + // LOGGING apiHandle.InitializeLogging(Aws::Crt::LogLevel::Trace, stderr); aws_iotdevice_library_init(allocator); @@ -51,15 +55,18 @@ int main(int argc, char *argv[]) std::promise promiseSourceStopped; String endpoint; - String accessToken; String destinationToken; String sourceToken; + String destinationClientToken; + String sourceClientToken; /* Connection Id is used for Simultaneous HTTP Connections (Protocl V3) */ uint32_t connectionId = 1; uint32_t connectionId2 = 2; setEnvVariable(allocator, SECTUN_DESTINATION_TOKEN, destinationToken); setEnvVariable(allocator, SECTUN_SOURCE_TOKEN, sourceToken); + setEnvVariable(allocator, SECTUN_DESTINATION_CLIENT_TOKEN, destinationClientToken); + setEnvVariable(allocator, SECTUN_SOURCE_CLIENT_TOKEN, sourceClientToken); setEnvVariable(allocator, SECTUN_ENDPOINT, endpoint); if (apiHandle.GetOrCreateStaticDefaultClientBootstrap()->LastError() != AWS_ERROR_SUCCESS) @@ -77,6 +84,15 @@ int main(int argc, char *argv[]) SecureTunnelBuilder builderSource = SecureTunnelBuilder(allocator, sourceToken.c_str(), AWS_SECURE_TUNNELING_SOURCE_MODE, endpoint.c_str()); + if (destinationClientToken.length() > 0) + { + builderDestination.WithClientToken(destinationClientToken.c_str()); + } + if (sourceClientToken.length() > 0) + { + builderSource.WithClientToken(sourceClientToken.c_str()); + } + builderDestination.WithOnMessageReceived( [&](SecureTunnel *secureTunnel, const MessageReceivedEventData &eventData) { { @@ -254,30 +270,29 @@ int main(int argc, char *argv[]) promiseDestinationConnectionStarted.get_future().wait(); - return 0; + if (secureTunnelDestination->Stop() == AWS_OP_ERR) + { + fprintf(stderr, "Secure Tunnel Destination Stop call failed: %s\n", ErrorDebugString(LastError())); + exit(-1); + } - // if (secureTunnelDestination->Stop() == AWS_OP_ERR) - // { - // fprintf(stderr, "Secure Tunnel Destination Stop call failed: %s\n", ErrorDebugString(LastError())); - // exit(-1); - // } + promiseDestinationStopped.get_future().wait(); - // promiseDestinationStopped.get_future().wait(); - // secureTunnelDestination = nullptr; + if (secureTunnelSource->Stop() == AWS_OP_ERR) + { + fprintf(stderr, "Secure Tunnel Source Stop call failed: %s\n", ErrorDebugString(LastError())); + exit(-1); + } - // if (secureTunnelSource->Stop() == AWS_OP_ERR) - // { - // fprintf(stderr, "Secure Tunnel Source Stop call failed: %s\n", ErrorDebugString(LastError())); - // exit(-1); - // } + promiseSourceStopped.get_future().wait(); - // promiseSourceStopped.get_future().wait(); - // secureTunnelSource = nullptr; + secureTunnelDestination = nullptr; + secureTunnelSource = nullptr; - // /* Clean Up */ - // aws_byte_buf_clean_up(&m_serviceIdStorage); + /* Clean Up */ + aws_byte_buf_clean_up(&m_serviceIdStorage); - // fprintf(stdout, "Secure Tunnel Test Completed\n"); + fprintf(stdout, "Secure Tunnel Test Completed\n"); return 0; } From 584eecf4e04ecad252df2aeb0316122c1aecc179 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Wed, 12 Apr 2023 13:46:33 -0700 Subject: [PATCH 35/38] fixed segfault --- secure_tunneling/source/SecureTunnel.cpp | 1 - secure_tunneling/tests/main.cpp | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/secure_tunneling/source/SecureTunnel.cpp b/secure_tunneling/source/SecureTunnel.cpp index b749929d5..4ae025a4d 100644 --- a/secure_tunneling/source/SecureTunnel.cpp +++ b/secure_tunneling/source/SecureTunnel.cpp @@ -185,7 +185,6 @@ namespace Aws Crt::Allocator *allocator) noexcept : m_allocator(allocator) { - aws_byte_buf_clean_up(&m_messageTypeStorage); AWS_ZERO_STRUCT(m_messageTypeStorage); struct aws_byte_buf typeBuf = aws_byte_buf_from_c_str(aws_secure_tunnel_message_type_to_c_string(type)); diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 37bc7a67a..3843895ab 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -277,6 +277,7 @@ int main(int argc, char *argv[]) } promiseDestinationStopped.get_future().wait(); + secureTunnelDestination = nullptr; if (secureTunnelSource->Stop() == AWS_OP_ERR) { @@ -285,8 +286,6 @@ int main(int argc, char *argv[]) } promiseSourceStopped.get_future().wait(); - - secureTunnelDestination = nullptr; secureTunnelSource = nullptr; /* Clean Up */ From 31873c5e4bf7ed009886d53c9753140723084b95 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Wed, 12 Apr 2023 14:19:26 -0700 Subject: [PATCH 36/38] message sending checks --- secure_tunneling/tests/main.cpp | 34 ++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index 3843895ab..f81e68b67 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -21,6 +21,7 @@ AWS_STATIC_STRING_FROM_LITERAL(SECTUN_SOURCE_TOKEN, "SECTUN_SOURCE_TOKEN"); AWS_STATIC_STRING_FROM_LITERAL(SECTUN_DESTINATION_TOKEN, "SECTUN_DESTINATION_TOKEN"); AWS_STATIC_STRING_FROM_LITERAL(SECTUN_SOURCE_CLIENT_TOKEN, "SECTUN_SOURCE_CLIENT_TOKEN"); AWS_STATIC_STRING_FROM_LITERAL(SECTUN_DESTINATION_CLIENT_TOKEN, "SECTUN_DESTINATION_CLIENT_TOKEN"); +AWS_STATIC_STRING_FROM_LITERAL(SECTUN_PAYLOAD_MESSAGE, "Payload Message"); void setEnvVariable(struct aws_allocator *allocator, const struct aws_string *variable_name, String &stringToSet) { @@ -36,9 +37,8 @@ int main(int argc, char *argv[]) struct aws_allocator *allocator = aws_default_allocator(); ApiHandle apiHandle; - // DEBUG - // LOGGING - apiHandle.InitializeLogging(Aws::Crt::LogLevel::Trace, stderr); + /* Uncomment to produce logs in codebuild */ + // apiHandle.InitializeLogging(Aws::Crt::LogLevel::Trace, stderr); aws_iotdevice_library_init(allocator); @@ -51,6 +51,10 @@ int main(int argc, char *argv[]) std::promise promiseSourceConnected; std::promise promiseDestinationStreamStarted; std::promise promiseDestinationConnectionStarted; + + std::promise promiseDestinationReceivedMessage; + std::promise promiseSourceReceivedMessage; + std::promise promiseDestinationStopped; std::promise promiseSourceStopped; @@ -98,6 +102,8 @@ int main(int argc, char *argv[]) { (void)secureTunnel; (void)eventData; + fprintf(stdout, "Destination Client Received Message\n"); + promiseDestinationReceivedMessage.set_value(); } }); @@ -105,6 +111,8 @@ int main(int argc, char *argv[]) { (void)secureTunnel; (void)eventData; + fprintf(stdout, "Source Client Received Message\n"); + promiseSourceReceivedMessage.set_value(); } }); @@ -123,6 +131,7 @@ int main(int argc, char *argv[]) else { fprintf(stdout, "Send Message failed with error code %d(%s)\n", errorCode, ErrorDebugString(errorCode)); + exit(-1); } }); @@ -141,6 +150,7 @@ int main(int argc, char *argv[]) else { fprintf(stdout, "Send Message failed with error code %d(%s)\n", errorCode, ErrorDebugString(errorCode)); + exit(-1); } }); @@ -270,6 +280,24 @@ int main(int argc, char *argv[]) promiseDestinationConnectionStarted.get_future().wait(); + std::shared_ptr message1 = + std::make_shared(ByteCursorFromCString(aws_string_c_str(SECTUN_PAYLOAD_MESSAGE))); + message1->withServiceId(m_serviceId.value()); + message1->withConnectionId(connectionId2); + secureTunnelSource->SendMessage(message1); + fprintf(stdout, "Source Client Sent Message\n"); + + promiseDestinationReceivedMessage.get_future().wait(); + + std::shared_ptr message2 = + std::make_shared(ByteCursorFromCString(aws_string_c_str(SECTUN_PAYLOAD_MESSAGE))); + message2->withServiceId(m_serviceId.value()); + message2->withConnectionId(connectionId); + secureTunnelDestination->SendMessage(message2); + fprintf(stdout, "Destination Client Sent Message\n"); + + promiseSourceReceivedMessage.get_future().wait(); + if (secureTunnelDestination->Stop() == AWS_OP_ERR) { fprintf(stderr, "Secure Tunnel Destination Stop call failed: %s\n", ErrorDebugString(LastError())); From d043cdd127b426a0ddbfecf1665b927e6495c4ff Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Wed, 12 Apr 2023 15:04:11 -0700 Subject: [PATCH 37/38] comments --- codebuild/integration-tests.sh | 5 +---- secure_tunneling/tests/main.cpp | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/codebuild/integration-tests.sh b/codebuild/integration-tests.sh index 14da8f338..d0852c7cc 100755 --- a/codebuild/integration-tests.sh +++ b/codebuild/integration-tests.sh @@ -9,14 +9,11 @@ cd _build cmake -DCMAKE_PREFIX_PATH=/tmp/install .. make -j -printf "Currently set env variables\n" -printenv - tunnel_info=$(aws iotsecuretunneling open-tunnel --destination-config services=ssh,ssh2,ssh3 --timeout-config maxLifetimeTimeoutMinutes=10) && echo -e "$tunnel_info" > /tmp/tunnel_info.pem export SECTUN_SOURCE_TOKEN=$(sed '4!d' /tmp/tunnel_info.pem | cut -d'"' -f4) export SECTUN_DESTINATION_TOKEN=$(sed '5!d' /tmp/tunnel_info.pem | cut -d'"' -f4) export SECTUN_ENDPOINT="data.tunneling.iot.us-east-1.amazonaws.com" -echo "Secure Tunnel Test" +echo "Running Secure Tunnel Test" ./secure_tunnel_test diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index f81e68b67..f73b8be17 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -49,6 +49,7 @@ int main(int argc, char *argv[]) std::promise promiseDestinationConnected; std::promise promiseSourceConnected; + std::promise promiseDestinationStreamStarted; std::promise promiseDestinationConnectionStarted; From e5ba5a96e7e753851cc85f757e226704288b87e4 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Wed, 12 Apr 2023 16:54:35 -0700 Subject: [PATCH 38/38] clean up service id storage on error --- secure_tunneling/tests/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/secure_tunneling/tests/main.cpp b/secure_tunneling/tests/main.cpp index f73b8be17..b255bfbbc 100644 --- a/secure_tunneling/tests/main.cpp +++ b/secure_tunneling/tests/main.cpp @@ -132,6 +132,7 @@ int main(int argc, char *argv[]) else { fprintf(stdout, "Send Message failed with error code %d(%s)\n", errorCode, ErrorDebugString(errorCode)); + aws_byte_buf_clean_up(&m_serviceIdStorage); exit(-1); } }); @@ -151,6 +152,7 @@ int main(int argc, char *argv[]) else { fprintf(stdout, "Send Message failed with error code %d(%s)\n", errorCode, ErrorDebugString(errorCode)); + aws_byte_buf_clean_up(&m_serviceIdStorage); exit(-1); } }); @@ -202,6 +204,7 @@ int main(int argc, char *argv[]) else { fprintf(stdout, "Stream Start failed with error code %d(%s)\n", errorCode, ErrorDebugString(errorCode)); + aws_byte_buf_clean_up(&m_serviceIdStorage); exit(-1); } }); @@ -219,6 +222,7 @@ int main(int argc, char *argv[]) else { fprintf(stdout, "Connection Start failed with error code %d(%s)\n", errorCode, ErrorDebugString(errorCode)); + aws_byte_buf_clean_up(&m_serviceIdStorage); exit(-1); } }); @@ -302,6 +306,7 @@ int main(int argc, char *argv[]) if (secureTunnelDestination->Stop() == AWS_OP_ERR) { fprintf(stderr, "Secure Tunnel Destination Stop call failed: %s\n", ErrorDebugString(LastError())); + aws_byte_buf_clean_up(&m_serviceIdStorage); exit(-1); } @@ -311,6 +316,7 @@ int main(int argc, char *argv[]) if (secureTunnelSource->Stop() == AWS_OP_ERR) { fprintf(stderr, "Secure Tunnel Source Stop call failed: %s\n", ErrorDebugString(LastError())); + aws_byte_buf_clean_up(&m_serviceIdStorage); exit(-1); }