diff --git a/.github/build.sh b/.github/build.sh index 1ed24bd18..c3ed42471 100755 --- a/.github/build.sh +++ b/.github/build.sh @@ -125,17 +125,12 @@ case $compileMode in cd .. if [ "$stMode" = true ]; then # Set CMake flags for ST mode - # Fix for the Cmake executing build of the sdk which errors out linking incorrectly to openssl - cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-armhf.cmake -DBUILD_SDK=ON -DEXCLUDE_JOBS=ON -DEXCLUDE_DD=ON -DEXCLUDE_FP=ON -DDISABLE_MQTT=ON ../ || true cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-armhf.cmake -DBUILD_SDK=ON -DEXCLUDE_JOBS=ON -DEXCLUDE_DD=ON -DEXCLUDE_FP=ON -DDISABLE_MQTT=ON ../ elif [ "$sharedLibs" = true ]; then - cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-armhf.cmake -DBUILD_SDK=ON ../ || true cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-armhf.cmake -DBUILD_SDK=ON ../ make install DESTDIR=./shared_install_dir chmod 0777 ./shared_install_dir else - # Fix for the Cmake executing build of the sdk which errors out linking incorrectly to openssl - cmake -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-armhf.cmake ../ || true cmake -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-armhf.cmake ../ fi cmake --build . --target aws-iot-device-client @@ -161,15 +156,12 @@ case $compileMode in make -j 4 make install cd .. - # Fix for the Cmake executing build of the sdk which errors out linking incorrectly to openssl if [ "$sharedLibs" = true ]; then - cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-mips.cmake ../ || true - cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-mips.cmake ../ + cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-mips.cmake -DS2N_NO_PQ=ON ../ make install DESTDIR=./shared_install_dir chmod 0777 ./shared_install_dir else - cmake -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-mips.cmake ../ || true - cmake -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-mips.cmake ../ + cmake -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-mips.cmake -DS2N_NO_PQ=ON ../ fi cmake --build . --target aws-iot-device-client cmake --build . --target test-aws-iot-device-client @@ -196,17 +188,12 @@ case $compileMode in cd .. if [ "$stMode" = true ]; then # Set CMake flags for ST mode - # Fix for the Cmake executing build of the sdk which errors out linking incorrectly to openssl - cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-aarch64.cmake -DBUILD_SDK=ON -DEXCLUDE_JOBS=ON -DEXCLUDE_DD=ON -DEXCLUDE_FP=ON -DDISABLE_MQTT=ON ../ || true cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-aarch64.cmake -DBUILD_SDK=ON -DEXCLUDE_JOBS=ON -DEXCLUDE_DD=ON -DEXCLUDE_FP=ON -DDISABLE_MQTT=ON ../ elif [ "$sharedLibs" = true ]; then - cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-aarch64.cmake -DBUILD_SDK=ON ../ || true cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-aarch64.cmake -DBUILD_SDK=ON ../ make install DESTDIR=./shared_install_dir chmod 0777 ./shared_install_dir else - # Fix for the Cmake executing build of the sdk which errors out linking incorrectly to openssl - cmake -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-aarch64.cmake ../ || true cmake -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/Toolchain-aarch64.cmake ../ fi cmake --build . --target aws-iot-device-client diff --git a/.github/docker-images/amazonlinux/Dockerfile b/.github/docker-images/amazonlinux/Dockerfile index c06341943..5e6a1afcd 100755 --- a/.github/docker-images/amazonlinux/Dockerfile +++ b/.github/docker-images/amazonlinux/Dockerfile @@ -84,7 +84,7 @@ RUN mkdir sdk-cpp-workspace \ && cd sdk-cpp-workspace \ && git clone https://github.com/aws/aws-iot-device-sdk-cpp-v2.git \ && cd aws-iot-device-sdk-cpp-v2 \ - && git checkout 975dcefbd422604b939ff916751bf7b11ac05d14 \ + && git checkout ac3ba3774b031dde1b988e698880d6064d53b9d9 \ && git submodule update --init --recursive \ && cd .. \ && mkdir aws-iot-device-sdk-cpp-v2-build \ diff --git a/.github/docker-images/ubi8/Dockerfile b/.github/docker-images/ubi8/Dockerfile index c48c446b6..092c9018a 100644 --- a/.github/docker-images/ubi8/Dockerfile +++ b/.github/docker-images/ubi8/Dockerfile @@ -96,7 +96,7 @@ RUN mkdir sdk-cpp-workspace \ && cd sdk-cpp-workspace \ && git clone https://github.com/aws/aws-iot-device-sdk-cpp-v2.git \ && cd aws-iot-device-sdk-cpp-v2 \ - && git checkout 975dcefbd422604b939ff916751bf7b11ac05d14 \ + && git checkout ac3ba3774b031dde1b988e698880d6064d53b9d9 \ && git submodule update --init --recursive \ && cd .. \ && mkdir aws-iot-device-sdk-cpp-v2-build \ diff --git a/.github/docker-images/ubuntu-18-x64/Dockerfile b/.github/docker-images/ubuntu-18-x64/Dockerfile index b3e780280..83aa389e9 100644 --- a/.github/docker-images/ubuntu-18-x64/Dockerfile +++ b/.github/docker-images/ubuntu-18-x64/Dockerfile @@ -73,7 +73,7 @@ RUN mkdir sdk-cpp-workspace \ && cd sdk-cpp-workspace \ && git clone https://github.com/aws/aws-iot-device-sdk-cpp-v2.git \ && cd aws-iot-device-sdk-cpp-v2 \ - && git checkout 975dcefbd422604b939ff916751bf7b11ac05d14 \ + && git checkout ac3ba3774b031dde1b988e698880d6064d53b9d9 \ && git submodule update --init --recursive \ && cd .. \ && mkdir aws-iot-device-sdk-cpp-v2-build \ diff --git a/.version b/.version index d3ef87965..87226c2ab 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -v1.6.0-31d162e*v1.6*1*6*0*0*31d162e +v1.6.0-31d162e*v1.6*1*6*0*0*31d162e \ No newline at end of file diff --git a/CMakeLists.txt.awssdk b/CMakeLists.txt.awssdk index 4bf1a42a6..c1dbc21be 100644 --- a/CMakeLists.txt.awssdk +++ b/CMakeLists.txt.awssdk @@ -5,7 +5,7 @@ project(aws-iot-device-sdk-cpp-v2-download NONE) include(ExternalProject) ExternalProject_Add(aws-iot-device-sdk-cpp-v2 GIT_REPOSITORY https://github.com/aws/aws-iot-device-sdk-cpp-v2.git - GIT_TAG 975dcefbd422604b939ff916751bf7b11ac05d14 + GIT_TAG ac3ba3774b031dde1b988e698880d6064d53b9d9 SOURCE_DIR "${CMAKE_BINARY_DIR}/aws-iot-device-sdk-cpp-v2-src" BINARY_DIR "${CMAKE_BINARY_DIR}/aws-iot-device-sdk-cpp-v2-build" CONFIGURE_COMMAND "" diff --git a/docs/PERMISSIONS.md b/docs/PERMISSIONS.md index 3ef4f0796..85f5cbf8e 100644 --- a/docs/PERMISSIONS.md +++ b/docs/PERMISSIONS.md @@ -36,6 +36,7 @@ Directory Storing CSR File | 700 | **Yes** Directory Storing Log File | 745 | **Yes** Directory Storing Config Files | 745 | **Recommended** Directory Storing PubSub File | 745 | **Yes** +Directory Storing Sensor Publish Pathname Socket | 700 | **Yes** Directory Storing PKCS11 Library File | 700 | **Yes** *Note: It is worth noting here that files are directories storing these files created by AWS IoT Device Client will have the above mentioned permissions set by default* diff --git a/setup.sh b/setup.sh index 645a0015f..8bce1e156 100755 --- a/setup.sh +++ b/setup.sh @@ -187,7 +187,7 @@ if [ "$BUILD_CONFIG" = "y" ]; then read -r PUB_TOPIC printf ${PMPT} "Specify the path of a file for the feature to publish (if no path is provided, will default to ${PUB_FILE}):" read -r PUB_FILE_TMP - if [ "$PUB_FILE_TMP"]; then + if [ "$PUB_FILE_TMP" ]; then PUB_FILE=$PUB_FILE_TMP PUB_FILE_PROVIDED="y" fi @@ -195,7 +195,7 @@ if [ "$BUILD_CONFIG" = "y" ]; then read -r SUB_TOPIC printf ${PMPT} "Specify the path of a file for the feature to write to (if no path is provided, will default to ${SUB_FILE}):" read -r SUB_FILE_TMP - if [ "$SUB_FILE_TMP"]; then + if [ "$SUB_FILE_TMP" ]; then SUB_FILE=$SUB_FILE_TMP SUB_FILE_PROVIDED="y" fi @@ -374,6 +374,7 @@ if [ "$INSTALL_SERVICE" = "y" ]; then printf ${PMPT} "Installing AWS IoT Device Client..." if command -v "systemctl" &>/dev/null; then systemctl stop aws-iot-device-client.service || true + sed -i "s#/etc/.aws-iot-device-client/aws-iot-device-client.conf#$CONF_OUTPUT_PATH#g" $SERVICE_FILE cp "$SERVICE_FILE" /etc/systemd/system/aws-iot-device-client.service if [ "$SERVICE_DEBUG" = "y" ]; then echo "$DEBUG_SCRIPT" | tee /sbin/aws-iot-device-client >/dev/null diff --git a/setup/aws-iot-device-client.service b/setup/aws-iot-device-client.service index c6f7a466d..bffe7f124 100644 --- a/setup/aws-iot-device-client.service +++ b/setup/aws-iot-device-client.service @@ -4,7 +4,8 @@ Wants=network-online.target After=network.target network-online.target [Service] -ExecStart=/sbin/aws-iot-device-client --config-file /etc/.aws-iot-device-client/aws-iot-device-client.conf +Environment="CONF_PATH=/etc/.aws-iot-device-client/aws-iot-device-client.conf" +ExecStart=/sbin/aws-iot-device-client --config-file $CONF_PATH [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=multi-user.target diff --git a/source/config/Config.cpp b/source/config/Config.cpp index 5898125db..cc27f905f 100644 --- a/source/config/Config.cpp +++ b/source/config/Config.cpp @@ -20,6 +20,7 @@ #include "../util/FileUtils.h" #include "../util/MqttUtils.h" #include "../util/StringUtils.h" +#include "Version.h" #include #include @@ -1828,7 +1829,7 @@ bool PlainConfig::SensorPublish::Validate() const // If the path does not point to an existing file, // then check the parent directory exists and has required permissions. auto addrParentDir = FileUtils::ExtractParentDirectory(setting.addr.value()); - if (!FileUtils::ValidateFilePermissions(addrParentDir, Permissions::SENSOR_PUBLISH_ADDR_FILE)) + if (!FileUtils::ValidateFilePermissions(addrParentDir, Permissions::SENSOR_PUBLISH_ADDR_DIR)) { setting.enabled = false; } @@ -1978,6 +1979,7 @@ constexpr char Config::DEFAULT_CONFIG_DIR[]; constexpr char Config::DEFAULT_KEY_DIR[]; constexpr char Config::DEFAULT_CONFIG_FILE[]; constexpr char Config::CLI_HELP[]; +constexpr char Config::CLI_VERSION[]; constexpr char Config::CLI_EXPORT_DEFAULT_SETTINGS[]; constexpr char Config::CLI_CONFIG_FILE[]; constexpr char Config::DEFAULT_FLEET_PROVISIONING_RUNTIME_CONFIG_FILE[]; @@ -1995,6 +1997,7 @@ bool Config::ParseCliArgs(int argc, char **argv, CliArgs &cliArgs) }; ArgumentDefinition argumentDefinitions[] = { {CLI_HELP, false, true, [](const string &additionalArg) { PrintHelpMessage(); }}, + {CLI_VERSION, false, true, [](const string &additionalArg) { PrintVersion(); }}, {CLI_EXPORT_DEFAULT_SETTINGS, true, true, @@ -2252,6 +2255,7 @@ void Config::PrintHelpMessage() "Available sub-commands:\n" "\n" "%s:\t\t\t\t\t\t\t\t\tGet more help on commands\n" + "%s:\t\t\t\t\t\t\t\tOutput current version\n" "%s :\t\t\t\tExport default settings for the AWS IoT Device Client binary to the specified " "file " "and exit " @@ -2268,14 +2272,14 @@ void Config::PrintHelpMessage() "%s [true|false]:\t\t\t\t\tEnables/Disables Device Defender feature\n" "%s [true|false]:\t\t\t\tEnables/Disables Fleet Provisioning feature\n" "%s [true|false]:\t\t\t\t\t\tEnables/Disables Pub/Sub Sample feature\n" - "%s [true|false]:\t\t\t\t\t\tEnables/Disables Sample Shadow feature\n" - "%s [true|false]:\t\t\t\t\t\tEnables/Disables Config Shadow feature\n" + "%s [true|false]:\t\t\t\t\tEnables/Disables Sample Shadow feature\n" + "%s [true|false]:\t\t\t\t\tEnables/Disables Config Shadow feature\n" "%s [true|false]:\t\t\t\t\t\tEnables/Disables Secure Element Configuration\n" "%s :\t\t\t\t\t\tUse Specified Endpoint\n" "%s :\t\t\t\t\t\t\tUse Specified Cert file\n" "%s :\t\t\t\t\t\t\tUse Specified Key file\n" "%s :\t\t\t\t\t\tUse Specified Root-CA file\n" - "%s :\t\t\t\t\tUse Specified Thing Name (Also used as Client ID)\n" + "%s :\t\t\tUse Specified Thing Name (Also used as Client ID)\n" "%s :\t\t\t\tUse specified directory to find job handlers\n" "%s :\t\t\t\t\t\tUse Specified AWS Region for Secure Tunneling\n" "%s :\t\t\t\t\t\tConnect secure tunnel to specific service\n" @@ -2295,9 +2299,9 @@ void Config::PrintHelpMessage() "%s :\t\t\t\t\tThe file the Pub/Sub sample feature will read from when publishing\n" "%s :\t\t\t\t\tThe topic the Pub/Sub sample feature will receive messages on\n" "%s :\t\t\t\t\tThe file the Pub/Sub sample feature will write received messaged to\n" - "%s :\t\t\t\t\tThe name of shadow SampleShadow feature will create or update\n" - "%s :\t\t\t\t\tThe file the Sample Shadow feature will read from when updating shadow data\n" - "%s :\t\t\t\t\tThe file the Sample Shadow feature will write the latest shadow document " + "%s :\t\t\t\t\t\tThe name of shadow SampleShadow feature will create or update\n" + "%s :\t\t\t\tThe file the Sample Shadow feature will read from when updating shadow data\n" + "%s :\t\t\t\tThe file the Sample Shadow feature will write the latest shadow document " "to\n" "%s :\t\t\t\t\tThe file path to PKCS#11 library\n" "%s :\t\t\t\t\tThe user PIN for logging into PKCS#11 token.\n" @@ -2308,6 +2312,7 @@ void Config::PrintHelpMessage() cout << FormatMessage( helpMessageTemplate, CLI_HELP, + CLI_VERSION, CLI_EXPORT_DEFAULT_SETTINGS, CLI_CONFIG_FILE, PlainConfig::LogConfig::CLI_LOG_LEVEL, @@ -2352,6 +2357,11 @@ void Config::PrintHelpMessage() PlainConfig::SecureElement::CLI_SECURE_ELEMENT_TOKEN_LABEL); } +void Config::PrintVersion() +{ + cout << DEVICE_CLIENT_VERSION_FULL << endl; +} + bool Config::ExportDefaultSetting(const string &file) { string jsonTemplate = R"({ diff --git a/source/config/Config.h b/source/config/Config.h index f86dc35ba..8f98b3a9c 100644 --- a/source/config/Config.h +++ b/source/config/Config.h @@ -58,6 +58,7 @@ namespace Aws static constexpr int PUB_SUB_FILES = 600; static constexpr int SAMPLE_SHADOW_FILES = 600; static constexpr int SENSOR_PUBLISH_ADDR_FILE = 660; + static constexpr int SENSOR_PUBLISH_ADDR_DIR = 700; static constexpr int PKCS11_LIB_FILE = 640; }; @@ -441,6 +442,7 @@ namespace Aws static constexpr char DEFAULT_SAMPLE_SHADOW_OUTPUT_DIR[] = "~/.aws-iot-device-client/sample-shadow/"; static constexpr char CLI_HELP[] = "--help"; + static constexpr char CLI_VERSION[] = "--version"; static constexpr char CLI_EXPORT_DEFAULT_SETTINGS[] = "--export-default-settings"; static constexpr char CLI_CONFIG_FILE[] = "--config-file"; @@ -469,6 +471,7 @@ namespace Aws private: static void PrintHelpMessage(); + static void PrintVersion(); static bool ExportDefaultSetting(const std::string &file); }; } // namespace DeviceClient diff --git a/source/tunneling/SecureTunnelingContext.cpp b/source/tunneling/SecureTunnelingContext.cpp index bd336196a..dfd5507fa 100644 --- a/source/tunneling/SecureTunnelingContext.cpp +++ b/source/tunneling/SecureTunnelingContext.cpp @@ -35,12 +35,17 @@ namespace Aws SecureTunnelingContext::~SecureTunnelingContext() { - if (mSecureTunnel) + LOG_DEBUG(TAG, "SecureTunnelingContext::~SecureTunnelingContext"); + if (mSecureTunnel->IsValid()) { mSecureTunnel->Close(); } } - + void SecureTunnelingContext::StopSecureTunnel() + { + LOG_DEBUG(TAG, "SecureTunnelingContext::StopSecureTunnel"); + mSecureTunnel->Shutdown(); + } template static bool operator==(const Aws::Crt::Optional &lhs, const Aws::Crt::Optional &rhs) { diff --git a/source/tunneling/SecureTunnelingContext.h b/source/tunneling/SecureTunnelingContext.h index b08379dc2..cc6b79687 100644 --- a/source/tunneling/SecureTunnelingContext.h +++ b/source/tunneling/SecureTunnelingContext.h @@ -72,6 +72,11 @@ namespace Aws */ virtual bool ConnectToSecureTunnel(); + /** + * \brief Stop and close secure tunnel + */ + void StopSecureTunnel(); + private: /** * \brief Connect to local TCP forward diff --git a/source/tunneling/SecureTunnelingFeature.cpp b/source/tunneling/SecureTunnelingFeature.cpp index e06405e37..bfe98ba07 100644 --- a/source/tunneling/SecureTunnelingFeature.cpp +++ b/source/tunneling/SecureTunnelingFeature.cpp @@ -59,9 +59,10 @@ namespace Aws int SecureTunnelingFeature::stop() { + LOG_DEBUG(TAG, "SecureTunnelingFeature::stop"); for (auto &c : mContexts) { - c.reset(); + c->StopSecureTunnel(); } auto self = static_cast(this); @@ -276,13 +277,6 @@ namespace Aws return c.get() == contextToRemove; }); mContexts.erase(std::remove(mContexts.begin(), mContexts.end(), *it)); - -#if defined(DISABLE_MQTT) - if (mContexts.empty()) - { - stop(); - } -#endif } } // namespace SecureTunneling diff --git a/test/config/TestConfig.cpp b/test/config/TestConfig.cpp index b65b8f750..469a25845 100644 --- a/test/config/TestConfig.cpp +++ b/test/config/TestConfig.cpp @@ -50,7 +50,7 @@ class ConfigTestFixture : public ::testing::Test // Ensure invalid-file does not exist std::remove(invalidFilePath.c_str()); - mode_t validPerms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; + mode_t validPerms = S_IRUSR | S_IWUSR | S_IXUSR; FileUtils::CreateDirectoryWithPermissions(addrPathValid.c_str(), validPerms); mode_t invalidPerms = validPerms | S_IRWXO; @@ -1578,4 +1578,4 @@ TEST(Config, MemoryTrace) ASSERT_TRUE(config.LoadFromEnvironment()) << "read AWS_CRT_MEMORY_TRACING=" << level; ASSERT_EQ(config.memTraceLevel, level); } -} \ No newline at end of file +}