From f39e6c3cf31bef0e2a0b80229119187107241ce4 Mon Sep 17 00:00:00 2001 From: Shubham Patil Date: Sat, 2 Dec 2023 00:07:01 +0530 Subject: [PATCH 01/14] [ESP32] Fix adding NDEBUG flag to CPPFLAGS (#30763) In esp-idf, NDEBUG flag is added to CPPFLAGS only if assertions are disabled. Making this inline to that. --- config/esp32/components/chip/CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/config/esp32/components/chip/CMakeLists.txt b/config/esp32/components/chip/CMakeLists.txt index b2058fe75df41c..e32588db436e2c 100644 --- a/config/esp32/components/chip/CMakeLists.txt +++ b/config/esp32/components/chip/CMakeLists.txt @@ -38,12 +38,9 @@ if(NOT "${IDF_TARGET}" STREQUAL "esp32h2") endif() if (NOT CMAKE_BUILD_EARLY_EXPANSION) - if (CONFIG_COMPILER_OPTIMIZATION_DEFAULT OR CONFIG_COMPILER_OPTIMIZATION_NONE) + if (CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE) set(is_debug TRUE) else() - if (NOT CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE) - message(FATAL_ERROR "CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE shall be set") - endif() set(is_debug FALSE) endif() endif() From 6000c145329106e6edf42f1e139928d630cdcb75 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Fri, 1 Dec 2023 12:38:11 -0800 Subject: [PATCH 02/14] Revert "Update Java8 Optional handling in JniReferences (#30071)" (#30769) This reverts commit 4e438d69c63d259dafdc3fc3bb1748d7de27e044. --- src/lib/support/JniReferences.cpp | 108 ++++++++++-------------------- src/lib/support/JniReferences.h | 4 -- 2 files changed, 37 insertions(+), 75 deletions(-) diff --git a/src/lib/support/JniReferences.cpp b/src/lib/support/JniReferences.cpp index b6919f8c076b4a..f07837ade467bd 100644 --- a/src/lib/support/JniReferences.cpp +++ b/src/lib/support/JniReferences.cpp @@ -21,7 +21,6 @@ #include #include #include -#include namespace chip { @@ -36,7 +35,7 @@ void JniReferences::SetJavaVm(JavaVM * jvm, const char * clsType) JNIEnv * env = GetEnvForCurrentThread(); // Any chip.devicecontroller.* class will work here - just need something to call getClassLoader() on. jclass chipClass = env->FindClass(clsType); - VerifyOrReturn(chipClass != nullptr, ChipLogError(Support, "clsType can not be found")); + VerifyOrReturn(chipClass != nullptr, ChipLogError(Support, "clsType can not found")); jclass classClass = env->FindClass("java/lang/Class"); jclass classLoaderClass = env->FindClass("java/lang/ClassLoader"); @@ -48,36 +47,6 @@ void JniReferences::SetJavaVm(JavaVM * jvm, const char * clsType) chip::JniReferences::GetInstance().GetClassRef(env, "java/util/List", mListClass); chip::JniReferences::GetInstance().GetClassRef(env, "java/util/ArrayList", mArrayListClass); chip::JniReferences::GetInstance().GetClassRef(env, "java/util/HashMap", mHashMapClass); - - // Determine if the Java code has proper Java 8 support or not. - // The class and method chosen here are arbitrary, all we care about is - // looking up any method that has an Optional parameter. - jclass controllerParamsClass = env->FindClass("chip/devicecontroller/ControllerParams"); - VerifyOrReturn(controllerParamsClass != nullptr, ChipLogError(Support, "controllerParamsClass is nullptr")); - - jmethodID getCountryCodeMethod = env->GetMethodID(controllerParamsClass, "getCountryCode", "()Ljava/util/Optional;"); - if (getCountryCodeMethod == nullptr) - { - // GetMethodID will have thrown an exception previously if it returned nullptr. - env->ExceptionClear(); - VerifyOrReturn(env->GetMethodID(controllerParamsClass, "getCountryCode", "()Lj$/util/Optional;") != nullptr, - ChipLogError(Support, "Method getCountryCode can not be found")); - use_java8_optional = false; - } - else - { - use_java8_optional = true; - } - - if (use_java8_optional) - { - chip::JniReferences::GetInstance().GetClassRef(env, "java/util/Optional", mOptionalClass); - } - else - { - chip::JniReferences::GetInstance().GetClassRef(env, "j$/util/Optional", mOptionalClass); - } - VerifyOrReturn(mOptionalClass != nullptr, ChipLogError(Support, "mOptionalClass is nullptr")); } JNIEnv * JniReferences::GetEnvForCurrentThread() @@ -121,11 +90,11 @@ CHIP_ERROR JniReferences::GetLocalClassRef(JNIEnv * env, const char * clsType, j { jclass cls = nullptr; - // Try `j$/util/Optional` when enabling Java8. Check whether mOptionalClass - // is null because this method is used to originally set mOptionalClass. - if (mOptionalClass != nullptr && (strcmp(clsType, "java/util/Optional") == 0 || strcmp(clsType, "j$/util/Optional") == 0)) + // Try `j$/util/Optional` when enabling Java8. + if (strcmp(clsType, "java/util/Optional") == 0) { - cls = mOptionalClass; + cls = env->FindClass("j$/util/Optional"); + env->ExceptionClear(); } if (cls == nullptr) @@ -160,18 +129,6 @@ CHIP_ERROR JniReferences::N2J_ByteArray(JNIEnv * env, const uint8_t * inArray, j return err; } -static std::string StrReplaceAll(const std::string & source, const std::string & from, const std::string & to) -{ - std::string newString = source; - size_t pos = 0; - while ((pos = newString.find(from, pos)) != std::string::npos) - { - newString.replace(pos, from.length(), to); - pos += to.length(); - } - return newString; -} - CHIP_ERROR JniReferences::FindMethod(JNIEnv * env, jobject object, const char * methodName, const char * methodSignature, jmethodID * methodId) { @@ -189,14 +146,21 @@ CHIP_ERROR JniReferences::FindMethod(JNIEnv * env, jobject object, const char * return CHIP_NO_ERROR; } - std::string method_signature = methodSignature; - if (!use_java8_optional) + // Try `j$` when enabling Java8. + std::string methodSignature_java8_str(methodSignature); + size_t pos = methodSignature_java8_str.find("java/util/Optional"); + if (pos != std::string::npos) { - method_signature = StrReplaceAll(method_signature, "java/util/Optional", "j$/util/Optional"); + // Replace all "java/util/Optional" with "j$/util/Optional". + while (pos != std::string::npos) + { + methodSignature_java8_str.replace(pos, strlen("java/util/Optional"), "j$/util/Optional"); + pos = methodSignature_java8_str.find("java/util/Optional"); + } + *methodId = env->GetMethodID(javaClass, methodName, methodSignature_java8_str.c_str()); + env->ExceptionClear(); } - *methodId = env->GetMethodID(javaClass, methodName, method_signature.data()); - VerifyOrReturnError(*methodId != nullptr, CHIP_JNI_ERROR_METHOD_NOT_FOUND); return CHIP_NO_ERROR; @@ -262,23 +226,24 @@ void JniReferences::ThrowError(JNIEnv * env, jclass exceptionCls, CHIP_ERROR err CHIP_ERROR JniReferences::CreateOptional(jobject objectToWrap, jobject & outOptional) { - VerifyOrReturnError(mOptionalClass != nullptr, CHIP_JNI_ERROR_TYPE_NOT_FOUND); + JNIEnv * env = GetEnvForCurrentThread(); + jclass optionalCls; + chip::JniReferences::GetInstance().GetClassRef(env, "java/util/Optional", optionalCls); + VerifyOrReturnError(optionalCls != nullptr, CHIP_JNI_ERROR_TYPE_NOT_FOUND); + chip::JniClass jniClass(optionalCls); - JNIEnv * const env = GetEnvForCurrentThread(); - VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV); + jmethodID ofMethod = env->GetStaticMethodID(optionalCls, "ofNullable", "(Ljava/lang/Object;)Ljava/util/Optional;"); + env->ExceptionClear(); - jmethodID ofMethod = nullptr; - if (use_java8_optional) + // Try `Lj$/util/Optional;` when enabling Java8. + if (ofMethod == nullptr) { - ofMethod = env->GetStaticMethodID(mOptionalClass, "ofNullable", "(Ljava/lang/Object;)Ljava/util/Optional;"); - } - else - { - ofMethod = env->GetStaticMethodID(mOptionalClass, "ofNullable", "(Ljava/lang/Object;)Lj$/util/Optional;"); + ofMethod = env->GetStaticMethodID(optionalCls, "ofNullable", "(Ljava/lang/Object;)Lj$/util/Optional;"); + env->ExceptionClear(); } - VerifyOrReturnError(ofMethod != nullptr, CHIP_JNI_ERROR_METHOD_NOT_FOUND); - outOptional = env->CallStaticObjectMethod(mOptionalClass, ofMethod, objectToWrap); + VerifyOrReturnError(ofMethod != nullptr, CHIP_JNI_ERROR_METHOD_NOT_FOUND); + outOptional = env->CallStaticObjectMethod(optionalCls, ofMethod, objectToWrap); VerifyOrReturnError(!env->ExceptionCheck(), CHIP_JNI_ERROR_EXCEPTION_THROWN); @@ -287,12 +252,13 @@ CHIP_ERROR JniReferences::CreateOptional(jobject objectToWrap, jobject & outOpti CHIP_ERROR JniReferences::GetOptionalValue(jobject optionalObj, jobject & optionalValue) { - VerifyOrReturnError(mOptionalClass != nullptr, CHIP_JNI_ERROR_TYPE_NOT_FOUND); - - JNIEnv * const env = GetEnvForCurrentThread(); - VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV); + JNIEnv * env = GetEnvForCurrentThread(); + jclass optionalCls; + chip::JniReferences::GetInstance().GetClassRef(env, "java/util/Optional", optionalCls); + VerifyOrReturnError(optionalCls != nullptr, CHIP_JNI_ERROR_TYPE_NOT_FOUND); + chip::JniClass jniClass(optionalCls); - jmethodID isPresentMethod = env->GetMethodID(mOptionalClass, "isPresent", "()Z"); + jmethodID isPresentMethod = env->GetMethodID(optionalCls, "isPresent", "()Z"); VerifyOrReturnError(isPresentMethod != nullptr, CHIP_JNI_ERROR_METHOD_NOT_FOUND); jboolean isPresent = optionalObj && env->CallBooleanMethod(optionalObj, isPresentMethod); @@ -302,7 +268,7 @@ CHIP_ERROR JniReferences::GetOptionalValue(jobject optionalObj, jobject & option return CHIP_NO_ERROR; } - jmethodID getMethod = env->GetMethodID(mOptionalClass, "get", "()Ljava/lang/Object;"); + jmethodID getMethod = env->GetMethodID(optionalCls, "get", "()Ljava/lang/Object;"); VerifyOrReturnError(getMethod != nullptr, CHIP_JNI_ERROR_METHOD_NOT_FOUND); optionalValue = env->CallObjectMethod(optionalObj, getMethod); return CHIP_NO_ERROR; diff --git a/src/lib/support/JniReferences.h b/src/lib/support/JniReferences.h index 4abef990822b0c..9a0fea52019040 100644 --- a/src/lib/support/JniReferences.h +++ b/src/lib/support/JniReferences.h @@ -190,12 +190,8 @@ class JniReferences jobject mClassLoader = nullptr; jmethodID mFindClassMethod = nullptr; - // These are global refs and therefore safe to persist. jclass mHashMapClass = nullptr; jclass mListClass = nullptr; jclass mArrayListClass = nullptr; - jclass mOptionalClass = nullptr; - - bool use_java8_optional = false; }; } // namespace chip From 516f918c1282978e68fc0ff2d7ddf69f825ff0c6 Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Fri, 1 Dec 2023 16:22:42 -0500 Subject: [PATCH 03/14] Remove updateLCDStatusScreen from the onPlatformEvent (#30768) --- examples/platform/silabs/BaseApplication.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index 9cf51e8917315a..e0789f0d0d0071 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -744,10 +744,6 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t) { BaseApplication::sIsProvisioned = event->ServiceProvisioningChange.IsServiceProvisioned; } - -#ifdef DISPLAY_ENABLED - UpdateLCDStatusScreen(); -#endif } void BaseApplication::OutputQrCode(bool refreshLCD) From 2a4a2cada95a8cf0d8447996d47b8cbd77ebd73e Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Fri, 1 Dec 2023 14:35:14 -0800 Subject: [PATCH 04/14] Fix length in DefaultICDStorage (#30767) Add VerifyEndOfContainer for DefaultICDClientStorage::Load and DefaultICDClientStorage::LoadCounter, existing test would fail, the fix is to set right length for TLV::ScopedBufferTLVReader --- src/app/icd/client/DefaultICDClientStorage.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/icd/client/DefaultICDClientStorage.cpp b/src/app/icd/client/DefaultICDClientStorage.cpp index b7fa634064826f..47319f6c874659 100644 --- a/src/app/icd/client/DefaultICDClientStorage.cpp +++ b/src/app/icd/client/DefaultICDClientStorage.cpp @@ -188,7 +188,7 @@ CHIP_ERROR DefaultICDClientStorage::LoadCounter(FabricIndex fabricIndex, size_t } ReturnErrorOnFailure(err); - TLV::ScopedBufferTLVReader reader(std::move(backingBuffer), len); + TLV::ScopedBufferTLVReader reader(std::move(backingBuffer), length); ReturnErrorOnFailure(reader.Next(TLV::kTLVType_Structure, TLV::AnonymousTag())); TLV::TLVType structType; ReturnErrorOnFailure(reader.EnterContainer(structType)); @@ -203,7 +203,7 @@ CHIP_ERROR DefaultICDClientStorage::LoadCounter(FabricIndex fabricIndex, size_t clientInfoSize = static_cast(tempClientInfoSize); ReturnErrorOnFailure(reader.ExitContainer(structType)); - return CHIP_NO_ERROR; + return reader.VerifyEndOfContainer(); } CHIP_ERROR DefaultICDClientStorage::Load(FabricIndex fabricIndex, std::vector & clientInfoVector, @@ -224,7 +224,7 @@ CHIP_ERROR DefaultICDClientStorage::Load(FabricIndex fabricIndex, std::vector Date: Mon, 4 Dec 2023 12:53:58 +0100 Subject: [PATCH 05/14] Replace usage of ERROR_EMPTY with ERROR_NOT_FOUND (#30761) --- docs/ERROR_CODES.md | 1 - src/lib/address_resolve/AddressResolve.h | 2 +- src/lib/address_resolve/AddressResolve_DefaultImpl.cpp | 2 +- src/lib/core/CHIPError.cpp | 3 --- src/lib/core/CHIPError.h | 9 +-------- src/lib/core/tests/TestCHIPErrorStr.cpp | 1 - src/lib/shell/commands/Dns.cpp | 2 +- 7 files changed, 4 insertions(+), 16 deletions(-) diff --git a/docs/ERROR_CODES.md b/docs/ERROR_CODES.md index d828eef779b69f..787ea58659c460 100644 --- a/docs/ERROR_CODES.md +++ b/docs/ERROR_CODES.md @@ -43,7 +43,6 @@ This file was **AUTOMATICALLY** generated by | 26 | 0x1A | `CHIP_ERROR_DUPLICATE_KEY_ID` | | 27 | 0x1B | `CHIP_ERROR_WRONG_KEY_TYPE` | | 28 | 0x1C | `CHIP_ERROR_UNINITIALIZED` | -| 29 | 0x1D | `CHIP_ERROR_EMPTY` | | 30 | 0x1E | `CHIP_ERROR_INVALID_STRING_LENGTH` | | 31 | 0x1F | `CHIP_ERROR_INVALID_LIST_LENGTH` | | 33 | 0x21 | `CHIP_ERROR_END_OF_TLV` | diff --git a/src/lib/address_resolve/AddressResolve.h b/src/lib/address_resolve/AddressResolve.h index 5e2ad1a09bc0e8..bcfdc9c551356a 100644 --- a/src/lib/address_resolve/AddressResolve.h +++ b/src/lib/address_resolve/AddressResolve.h @@ -225,7 +225,7 @@ class Resolver /// This method will return CHIP_ERROR_INCORRECT_STATE if the handle is /// still active. /// - /// This method will return CHIP_ERROR_EMPTY if there are no more + /// This method will return CHIP_ERROR_NOT_FOUND if there are no more /// results. /// /// This method may return other errors in some cases. diff --git a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp index 0b1fdeadfde829..07c3559af66ded 100644 --- a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp +++ b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp @@ -195,7 +195,7 @@ CHIP_ERROR Resolver::LookupNode(const NodeLookupRequest & request, Impl::NodeLoo CHIP_ERROR Resolver::TryNextResult(Impl::NodeLookupHandle & handle) { VerifyOrReturnError(!mActiveLookups.Contains(&handle), CHIP_ERROR_INCORRECT_STATE); - VerifyOrReturnError(handle.HasLookupResult(), CHIP_ERROR_EMPTY); + VerifyOrReturnError(handle.HasLookupResult(), CHIP_ERROR_NOT_FOUND); auto listener = handle.GetListener(); auto peerId = handle.GetRequest().GetPeerId(); diff --git a/src/lib/core/CHIPError.cpp b/src/lib/core/CHIPError.cpp index 9e15fa11673b75..a3bdd148253cfb 100644 --- a/src/lib/core/CHIPError.cpp +++ b/src/lib/core/CHIPError.cpp @@ -143,9 +143,6 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, CHIP_ERROR err) case CHIP_ERROR_UNINITIALIZED.AsInteger(): desc = "Uninitialized"; break; - case CHIP_ERROR_EMPTY.AsInteger(): - desc = "Empty"; - break; case CHIP_ERROR_INVALID_STRING_LENGTH.AsInteger(): desc = "Invalid string length"; break; diff --git a/src/lib/core/CHIPError.h b/src/lib/core/CHIPError.h index acfb2cef9cd72f..593e3e2d6d984d 100644 --- a/src/lib/core/CHIPError.h +++ b/src/lib/core/CHIPError.h @@ -674,14 +674,7 @@ using CHIP_ERROR = ::chip::ChipError; */ #define CHIP_ERROR_UNINITIALIZED CHIP_CORE_ERROR(0x1c) -/** - * @def CHIP_ERROR_EMPTY - * - * @brief - * A requested object is empty. - * - */ -#define CHIP_ERROR_EMPTY CHIP_CORE_ERROR(0x1d) +// AVAILABLE: 0x1d /** * @def CHIP_ERROR_INVALID_STRING_LENGTH diff --git a/src/lib/core/tests/TestCHIPErrorStr.cpp b/src/lib/core/tests/TestCHIPErrorStr.cpp index cb94abe6589988..2a5300b380ff58 100644 --- a/src/lib/core/tests/TestCHIPErrorStr.cpp +++ b/src/lib/core/tests/TestCHIPErrorStr.cpp @@ -77,7 +77,6 @@ static const CHIP_ERROR kTestElements[] = CHIP_ERROR_DUPLICATE_KEY_ID, CHIP_ERROR_WRONG_KEY_TYPE, CHIP_ERROR_UNINITIALIZED, - CHIP_ERROR_EMPTY, CHIP_ERROR_INVALID_STRING_LENGTH, CHIP_ERROR_INVALID_LIST_LENGTH, CHIP_END_OF_TLV, diff --git a/src/lib/shell/commands/Dns.cpp b/src/lib/shell/commands/Dns.cpp index 5ae2ddc484e5cf..badd6681fceec3 100644 --- a/src/lib/shell/commands/Dns.cpp +++ b/src/lib/shell/commands/Dns.cpp @@ -67,7 +67,7 @@ class DnsShellResolverDelegate : public Dnssd::CommissioningResolveDelegate, pub // Schedule a retry. Not called directly so we do not recurse in OnNodeAddressResolved DeviceLayer::SystemLayer().ScheduleLambda([this] { CHIP_ERROR err = AddressResolve::Resolver::Instance().TryNextResult(Handle()); - if (err != CHIP_NO_ERROR && err != CHIP_ERROR_EMPTY) + if (err != CHIP_NO_ERROR && err != CHIP_ERROR_NOT_FOUND) { ChipLogError(Discovery, "Failed to list next result: %" CHIP_ERROR_FORMAT, err.Format()); } From 7ee2b47d921fc456e699d4e18b6a258f58b0fd1e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 08:42:30 -0500 Subject: [PATCH 06/14] Bump third_party/imgui/repo from `bce4db0` to `5288687` (#30788) Bumps [third_party/imgui/repo](https://github.com/ocornut/imgui) from `bce4db0` to `5288687`. - [Release notes](https://github.com/ocornut/imgui/releases) - [Commits](https://github.com/ocornut/imgui/compare/bce4db00bcccef072cd5a596b2f123395561e869...52886872f10656b299af4b90487e1036f582b812) --- updated-dependencies: - dependency-name: third_party/imgui/repo dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- third_party/imgui/repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/imgui/repo b/third_party/imgui/repo index bce4db00bcccef..52886872f10656 160000 --- a/third_party/imgui/repo +++ b/third_party/imgui/repo @@ -1 +1 @@ -Subproject commit bce4db00bcccef072cd5a596b2f123395561e869 +Subproject commit 52886872f10656b299af4b90487e1036f582b812 From 4bf0795dd7a5fcdd25731cd40740b35f44564b46 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 08:42:55 -0500 Subject: [PATCH 07/14] Bump third_party/mbedtls/repo from `60dcdd1` to `7655fd2` (#30786) Bumps [third_party/mbedtls/repo](https://github.com/ARMmbed/mbedtls) from `60dcdd1` to `7655fd2`. - [Release notes](https://github.com/ARMmbed/mbedtls/releases) - [Commits](https://github.com/ARMmbed/mbedtls/compare/60dcdd1686dbde47f2a8dfbe177a372541c37111...7655fd2d93d20df1b975773fa8da917d6b5207a9) --- updated-dependencies: - dependency-name: third_party/mbedtls/repo dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- third_party/mbedtls/repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/mbedtls/repo b/third_party/mbedtls/repo index 60dcdd1686dbde..7655fd2d93d20d 160000 --- a/third_party/mbedtls/repo +++ b/third_party/mbedtls/repo @@ -1 +1 @@ -Subproject commit 60dcdd1686dbde47f2a8dfbe177a372541c37111 +Subproject commit 7655fd2d93d20df1b975773fa8da917d6b5207a9 From c4f377df3a12ed5d5e1450dc72309ebbdafe6a79 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 08:43:09 -0500 Subject: [PATCH 08/14] Bump third_party/ot-br-posix/repo from `86cb36e` to `03132d3` (#30789) Bumps [third_party/ot-br-posix/repo](https://github.com/openthread/ot-br-posix) from `86cb36e` to `03132d3`. - [Release notes](https://github.com/openthread/ot-br-posix/releases) - [Commits](https://github.com/openthread/ot-br-posix/compare/86cb36e8d5a20fb20a23ab9857faae125efca11d...03132d34368f6403b12d63df740dd8a69f73483d) --- updated-dependencies: - dependency-name: third_party/ot-br-posix/repo dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- third_party/ot-br-posix/repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/ot-br-posix/repo b/third_party/ot-br-posix/repo index 86cb36e8d5a20f..03132d34368f64 160000 --- a/third_party/ot-br-posix/repo +++ b/third_party/ot-br-posix/repo @@ -1 +1 @@ -Subproject commit 86cb36e8d5a20fb20a23ab9857faae125efca11d +Subproject commit 03132d34368f6403b12d63df740dd8a69f73483d From 2b965b491b09406133c5a70f6f9feccec5617c0f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 08:44:44 -0500 Subject: [PATCH 09/14] Bump third_party/libwebsockets/repo from `a4a7e0a` to `b391e11` (#30784) Bumps [third_party/libwebsockets/repo](https://github.com/warmcat/libwebsockets) from `a4a7e0a` to `b391e11`. - [Commits](https://github.com/warmcat/libwebsockets/compare/a4a7e0a49b1e464e09caf78257df3be8ab92fc4a...b391e1141abdb1f46621a67a8f00f0884bf6595a) --- updated-dependencies: - dependency-name: third_party/libwebsockets/repo dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- third_party/libwebsockets/repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/libwebsockets/repo b/third_party/libwebsockets/repo index a4a7e0a49b1e46..b391e1141abdb1 160000 --- a/third_party/libwebsockets/repo +++ b/third_party/libwebsockets/repo @@ -1 +1 @@ -Subproject commit a4a7e0a49b1e464e09caf78257df3be8ab92fc4a +Subproject commit b391e1141abdb1f46621a67a8f00f0884bf6595a From 1f5e515272bf98af0e349b9c6980d17c923eb13c Mon Sep 17 00:00:00 2001 From: Jaehoon-You <55170115+Jaehoon-You@users.noreply.github.com> Date: Mon, 4 Dec 2023 22:45:18 +0900 Subject: [PATCH 10/14] [Android] virtual-device-app: Implement door lock view (#30778) * virtual-device-app: Implement common layout Signed-off-by: Jaehoon You Signed-off-by: Charles Kim * virtual-device-app: Implement doorlock view Signed-off-by: Jaehoon You Signed-off-by: Charles Kim --------- Signed-off-by: Jaehoon You Signed-off-by: Charles Kim --- .../common/src/main/res/values/strings.xml | 1 + .../app/core/model/databinding/SeekbarData.kt | 5 ++ .../round_radio_button_checked_24.xml | 6 ++ .../main/res/drawable/round_settings_24.xml | 5 ++ .../layout_item_title_value_seekbar.xml | 54 +++++++++++++ .../layout_item_title_value_simple_button.xml | 44 +++++++++++ .../core/ui/src/main/res/values/strings.xml | 8 +- .../app/feature/closure/DoorLockFragment.kt | 75 ++++++++++++++++++- .../app/feature/closure/DoorLockViewModel.kt | 15 +--- .../main/res/layout/fragment_door_lock.xml | 31 +++++++- .../closure/src/main/res/values/strings.xml | 5 ++ .../setup/src/main/res/values/strings.xml | 1 - 12 files changed, 233 insertions(+), 17 deletions(-) create mode 100644 examples/virtual-device-app/android/App/core/model/src/main/java/com/matter/virtual/device/app/core/model/databinding/SeekbarData.kt create mode 100644 examples/virtual-device-app/android/App/core/ui/src/main/res/drawable/round_radio_button_checked_24.xml create mode 100644 examples/virtual-device-app/android/App/core/ui/src/main/res/drawable/round_settings_24.xml create mode 100644 examples/virtual-device-app/android/App/core/ui/src/main/res/layout/layout_item_title_value_seekbar.xml create mode 100644 examples/virtual-device-app/android/App/core/ui/src/main/res/layout/layout_item_title_value_simple_button.xml create mode 100644 examples/virtual-device-app/android/App/feature/closure/src/main/res/values/strings.xml diff --git a/examples/virtual-device-app/android/App/core/common/src/main/res/values/strings.xml b/examples/virtual-device-app/android/App/core/common/src/main/res/values/strings.xml index 7afe5953bf2dfd..896c9d0fcae7fe 100644 --- a/examples/virtual-device-app/android/App/core/common/src/main/res/values/strings.xml +++ b/examples/virtual-device-app/android/App/core/common/src/main/res/values/strings.xml @@ -1,6 +1,7 @@ Matter OnOff Switch + Matter Door Lock Matter Device icon \ No newline at end of file diff --git a/examples/virtual-device-app/android/App/core/model/src/main/java/com/matter/virtual/device/app/core/model/databinding/SeekbarData.kt b/examples/virtual-device-app/android/App/core/model/src/main/java/com/matter/virtual/device/app/core/model/databinding/SeekbarData.kt new file mode 100644 index 00000000000000..1c705277210c50 --- /dev/null +++ b/examples/virtual-device-app/android/App/core/model/src/main/java/com/matter/virtual/device/app/core/model/databinding/SeekbarData.kt @@ -0,0 +1,5 @@ +package com.matter.virtual.device.app.core.model.databinding + +import androidx.lifecycle.LiveData + +data class SeekbarData(val progress: LiveData, val min: Int = 0, val max: Int = 100) diff --git a/examples/virtual-device-app/android/App/core/ui/src/main/res/drawable/round_radio_button_checked_24.xml b/examples/virtual-device-app/android/App/core/ui/src/main/res/drawable/round_radio_button_checked_24.xml new file mode 100644 index 00000000000000..51d6c60882ff8a --- /dev/null +++ b/examples/virtual-device-app/android/App/core/ui/src/main/res/drawable/round_radio_button_checked_24.xml @@ -0,0 +1,6 @@ + + + + diff --git a/examples/virtual-device-app/android/App/core/ui/src/main/res/drawable/round_settings_24.xml b/examples/virtual-device-app/android/App/core/ui/src/main/res/drawable/round_settings_24.xml new file mode 100644 index 00000000000000..6828a1e8db4507 --- /dev/null +++ b/examples/virtual-device-app/android/App/core/ui/src/main/res/drawable/round_settings_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/examples/virtual-device-app/android/App/core/ui/src/main/res/layout/layout_item_title_value_seekbar.xml b/examples/virtual-device-app/android/App/core/ui/src/main/res/layout/layout_item_title_value_seekbar.xml new file mode 100644 index 00000000000000..ea1ce4ea2ec124 --- /dev/null +++ b/examples/virtual-device-app/android/App/core/ui/src/main/res/layout/layout_item_title_value_seekbar.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/virtual-device-app/android/App/core/ui/src/main/res/layout/layout_item_title_value_simple_button.xml b/examples/virtual-device-app/android/App/core/ui/src/main/res/layout/layout_item_title_value_simple_button.xml new file mode 100644 index 00000000000000..95677bcd9eaa3f --- /dev/null +++ b/examples/virtual-device-app/android/App/core/ui/src/main/res/layout/layout_item_title_value_simple_button.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/virtual-device-app/android/App/core/ui/src/main/res/values/strings.xml b/examples/virtual-device-app/android/App/core/ui/src/main/res/values/strings.xml index 70fd88fd75a365..feab13c39647af 100644 --- a/examples/virtual-device-app/android/App/core/ui/src/main/res/values/strings.xml +++ b/examples/virtual-device-app/android/App/core/ui/src/main/res/values/strings.xml @@ -1,12 +1,18 @@ button + seekbar + Reset "The Matter device app will be reset and closed. Continue?" "The commissioning was not completed. The Matter device app will be reset and closed. Continue?" - "The fabric was removed. The Matter device app will be reset and closed." + "The fabric was removed. The Matter device app will be reset and closed." + + Battery + %d <small><small>%%</small></small> + Cancel On Off \ No newline at end of file diff --git a/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockFragment.kt b/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockFragment.kt index 8cfe6a403f53ed..7e0553b7653223 100644 --- a/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockFragment.kt +++ b/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockFragment.kt @@ -1,7 +1,12 @@ package com.matter.virtual.device.app.feature.closure +import android.text.Html +import android.widget.SeekBar +import androidx.appcompat.app.AlertDialog import androidx.fragment.app.viewModels import androidx.navigation.fragment.navArgs +import com.matter.virtual.device.app.core.model.databinding.SeekbarData +import com.matter.virtual.device.app.core.model.matter.LockState import com.matter.virtual.device.app.core.ui.BaseFragment import com.matter.virtual.device.app.core.ui.databinding.LayoutAppbarBinding import com.matter.virtual.device.app.feature.closure.databinding.FragmentDoorLockBinding @@ -16,6 +21,7 @@ class DoorLockFragment : BaseFragment(R.layout.fragment_door_lock) { override val viewModel: DoorLockViewModel by viewModels() + private var lockState: LockState = LockState.LOCKED @OptIn(ExperimentalSerializationApi::class) override fun setupNavArgs() { @@ -25,9 +31,55 @@ class DoorLockFragment : override fun setupAppbar(): LayoutAppbarBinding = binding.appbar - override fun setupUi() {} + override fun setupUi() { + /** title text */ + binding.appbar.toolbarTitle.text = getString(R.string.matter_door_lock) - override fun setupObservers() {} + /** LockState layout */ + binding.doorLockLockStateLayout.titleText.text = getString(R.string.door_lock_lock_state) + binding.doorLockLockStateLayout.button.setImageResource(R.drawable.round_settings_24) + binding.doorLockLockStateLayout.button.setOnClickListener { showLockStatePopup() } + + /** Send alarm layout */ + binding.doorLockSendAlarmLayout.valueText.text = + getString(R.string.door_lock_send_lock_alarm_event) + binding.doorLockSendAlarmLayout.button.setImageResource( + R.drawable.round_radio_button_checked_24 + ) + binding.doorLockSendAlarmLayout.button.setOnClickListener { + viewModel.onClickSendLockAlarmEventButton() + } + + /** Battery layout */ + binding.doorLockBatteryLayout.titleText.text = getString(R.string.battery) + binding.doorLockBatteryLayout.seekbarData = + SeekbarData(progress = viewModel.batteryRemainingPercentage) + binding.doorLockBatteryLayout.seekbar.setOnSeekBarChangeListener( + object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { + viewModel.updateBatterySeekbarProgress(progress) + } + + override fun onStartTrackingTouch(seekBar: SeekBar) {} + + override fun onStopTrackingTouch(seekBar: SeekBar) { + viewModel.updateBatteryStatusToCluster(seekBar.progress) + } + } + ) + } + + override fun setupObservers() { + viewModel.lockState.observe(viewLifecycleOwner) { + this.lockState = it + binding.doorLockLockStateLayout.valueText.text = it.toString() + } + + viewModel.batteryRemainingPercentage.observe(viewLifecycleOwner) { + val text: String = getString(R.string.battery_format, it) + binding.doorLockBatteryLayout.valueText.text = Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY) + } + } override fun onResume() { Timber.d("onResume()") @@ -38,4 +90,23 @@ class DoorLockFragment : Timber.d("onDestroy()") super.onDestroy() } + + private fun showLockStatePopup() { + val list = + arrayOf( + LockState.NOT_FULLY_LOCKED.toString(), + LockState.LOCKED.toString(), + LockState.UNLOCKED.toString(), + LockState.UNLATCHED.toString() + ) + + AlertDialog.Builder(requireContext()) + .setTitle(R.string.door_lock_lock_state) + .setSingleChoiceItems(list, list.indexOf(this.lockState.toString())) { dialog, which -> + viewModel.setLockState(enumValueOf(list[which])) + dialog.dismiss() + } + .setNegativeButton(R.string.cancel, null) + .show() + } } diff --git a/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockViewModel.kt b/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockViewModel.kt index 4f9b0b3a48ce55..f5d430b0e669c3 100644 --- a/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockViewModel.kt +++ b/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockViewModel.kt @@ -61,18 +61,9 @@ constructor( super.onCleared() } - fun onClickButton() { - Timber.d("onClickButton()") - viewModelScope.launch { - Timber.d("current lockState value = ${_lockState.value}") - if (_lockState.value == LockState.LOCKED) { - Timber.d("set value = unlocked") - setLockStateUseCase(LockState.UNLOCKED) - } else { - Timber.d("set value = locked") - setLockStateUseCase(LockState.LOCKED) - } - } + fun setLockState(lockState: LockState) { + Timber.d("setLockState():new:$lockState") + viewModelScope.launch { setLockStateUseCase(lockState) } } fun onClickSendLockAlarmEventButton() { diff --git a/examples/virtual-device-app/android/App/feature/closure/src/main/res/layout/fragment_door_lock.xml b/examples/virtual-device-app/android/App/feature/closure/src/main/res/layout/fragment_door_lock.xml index d726e82e616348..9caa1a2b67a48b 100644 --- a/examples/virtual-device-app/android/App/feature/closure/src/main/res/layout/fragment_door_lock.xml +++ b/examples/virtual-device-app/android/App/feature/closure/src/main/res/layout/fragment_door_lock.xml @@ -1,5 +1,6 @@ + @@ -15,6 +16,34 @@ android:layout_height="match_parent" android:layout_marginTop="?attr/actionBarSize"> + + + + + + + + + + + + + + + - \ No newline at end of file + diff --git a/examples/virtual-device-app/android/App/feature/closure/src/main/res/values/strings.xml b/examples/virtual-device-app/android/App/feature/closure/src/main/res/values/strings.xml new file mode 100644 index 00000000000000..5f0ec3d4e84114 --- /dev/null +++ b/examples/virtual-device-app/android/App/feature/closure/src/main/res/values/strings.xml @@ -0,0 +1,5 @@ + + + Lock state + Send Alarm + \ No newline at end of file diff --git a/examples/virtual-device-app/android/App/feature/setup/src/main/res/values/strings.xml b/examples/virtual-device-app/android/App/feature/setup/src/main/res/values/strings.xml index e8ae1eb4677b47..75f4022f6ebef9 100644 --- a/examples/virtual-device-app/android/App/feature/setup/src/main/res/values/strings.xml +++ b/examples/virtual-device-app/android/App/feature/setup/src/main/res/values/strings.xml @@ -11,7 +11,6 @@ Make sure your Mobile/Hub/Device App are connected to the same Wi-Fi network. Save Invalid input value - Cancel Start Wi-Fi : %1$s %1$s : %2$s From 6ba3e609a11cd36dab7f543218c7fb77156280c1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 13:54:51 +0000 Subject: [PATCH 11/14] Bump third_party/pigweed/repo from `8b5d45a` to `e35aa3a` (#30783) Bumps [third_party/pigweed/repo](https://github.com/google/pigweed) from `8b5d45a` to `e35aa3a`. - [Commits](https://github.com/google/pigweed/compare/8b5d45a34aa2d4b30a8624a6df946077c879b892...e35aa3aecf78ae4914e9559b77c57885a548a23d) --- updated-dependencies: - dependency-name: third_party/pigweed/repo dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- third_party/pigweed/repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/pigweed/repo b/third_party/pigweed/repo index 8b5d45a34aa2d4..e35aa3aecf78ae 160000 --- a/third_party/pigweed/repo +++ b/third_party/pigweed/repo @@ -1 +1 @@ -Subproject commit 8b5d45a34aa2d4b30a8624a6df946077c879b892 +Subproject commit e35aa3aecf78ae4914e9559b77c57885a548a23d From b9ff894760bd01953deb0bc8188931415500d908 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 08:55:56 -0500 Subject: [PATCH 12/14] Bump actions/setup-java from 3 to 4 (#30791) Bumps [actions/setup-java](https://github.com/actions/setup-java) from 3 to 4. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/kotlin-style.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/kotlin-style.yaml b/.github/workflows/kotlin-style.yaml index c3b15250a907ef..08bade12d21963 100644 --- a/.github/workflows/kotlin-style.yaml +++ b/.github/workflows/kotlin-style.yaml @@ -35,7 +35,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-java@v3 + - uses: actions/setup-java@v4 with: distribution: 'adopt' java-version: '17' From 16f8d7a619bb24e2dcd137986f3b8481c3af2388 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 4 Dec 2023 19:21:41 -0500 Subject: [PATCH 13/14] Fix session eviction handling of eviction hints. (#30806) When we establish a session as a CASE responder, we try to allocate a new session to listen to session establishments, and use the just-established-session's peer ID as the eviction hint. If we had a bunch of active sessions on a fabric, all to different nodes, this would cause the just-established session to be evicted, since it matched the hint. The fix is to only consider sessions for eviction based on the hint if they are either non-active or not unique sessions to the peer (at which point, the just-established session should be last in priority order for eviction). Fixes https://github.com/project-chip/connectedhomeip/issues/30728 --- src/transport/SecureSessionTable.cpp | 27 ++++- src/transport/SecureSessionTable.h | 2 +- .../tests/TestSecureSessionTable.cpp | 107 +++++++++++++++++- 3 files changed, 127 insertions(+), 9 deletions(-) diff --git a/src/transport/SecureSessionTable.cpp b/src/transport/SecureSessionTable.cpp index aa98637345e9e5..bc201b33007094 100644 --- a/src/transport/SecureSessionTable.cpp +++ b/src/transport/SecureSessionTable.cpp @@ -265,8 +265,31 @@ void SecureSessionTable::DefaultEvictionPolicy(EvictionPolicyContext & evictionC return a.mNumMatchingOnPeer > b.mNumMatchingOnPeer; } - int doesAMatchSessionHint = a.mSession->GetPeer() == evictionContext.GetSessionEvictionHint(); - int doesBMatchSessionHint = b.mSession->GetPeer() == evictionContext.GetSessionEvictionHint(); + // We have an evicton hint in two cases: + // + // 1) When we just established CASE as a responder, the hint is the node + // we just established CASE to. + // 2) When starting to establish CASE as an initiator, the hint is the + // node we are going to establish CASE to. + // + // In case 2, we should not end up here if there is an active session to + // the peer at all (because that session should have been used instead + // of establishing a new one). + // + // In case 1, we know we have a session matching the hint, but we don't + // want to pick that one for eviction, because we just established it. + // So we should not consider a session as matching a hint if it's active + // and is the only session to our peer. + // + // Checking for the "active" state in addition to the "only session to + // peer" state allows us to prioritize evicting defuct sessions that + // match the hint against other defunct sessions. + auto sessionMatchesEvictionHint = [&evictionContext](const SortableSession & session) -> int { + return session.mSession->GetPeer() == evictionContext.GetSessionEvictionHint() && + (!session.mSession->IsActiveSession() || session.mNumMatchingOnPeer > 0); + }; + int doesAMatchSessionHint = sessionMatchesEvictionHint(a); + int doesBMatchSessionHint = sessionMatchesEvictionHint(b); // // Sorting on Key4 diff --git a/src/transport/SecureSessionTable.h b/src/transport/SecureSessionTable.h index aff58c4e5fe0b0..7f8a072a03a2fe 100644 --- a/src/transport/SecureSessionTable.h +++ b/src/transport/SecureSessionTable.h @@ -206,7 +206,7 @@ class SecureSessionTable * the session that is most ahead as the best candidate for eviction: * * - Key1: Sessions on fabrics that have more sessions in the table are placed ahead of sessions on fabrics - * with lesser sessions. We conclusively know that if a particular fabric has more sessions in the table + * with fewer sessions. We conclusively know that if a particular fabric has more sessions in the table * than another, then that fabric is definitely over minimas (assuming a minimally sized session table * conformant to spec minimas). * diff --git a/src/transport/tests/TestSecureSessionTable.cpp b/src/transport/tests/TestSecureSessionTable.cpp index 980e07e955015f..7dbbeba654117f 100644 --- a/src/transport/tests/TestSecureSessionTable.cpp +++ b/src/transport/tests/TestSecureSessionTable.cpp @@ -120,10 +120,14 @@ void TestSecureSessionTable::CreateSessionTable(std::vector & ScopedNodeId(1, sessionParams[i].mPeer.GetFabricIndex()), sessionParams[i].mPeer, CATValues(), static_cast(i), ReliableMessageProtocolConfig(System::Clock::Milliseconds32(0), System::Clock::Milliseconds32(0), System::Clock::Milliseconds16(0))); - session.Value()->AsSecureSession()->mLastActivityTime = sessionParams[i].mLastActivityTime; - session.Value()->AsSecureSession()->mState = sessionParams[i].mState; + // Make sure we set up our holder _before_ the session goes into a state + // other than active, because holders refuse to hold non-active + // sessions. mSessionList.push_back(Platform::MakeUnique(session.Value())); + + session.Value()->AsSecureSession()->mLastActivityTime = sessionParams[i].mLastActivityTime; + session.Value()->AsSecureSession()->mState = sessionParams[i].mState; } } @@ -279,12 +283,44 @@ void TestSecureSessionTable::ValidateSessionSorting(nlTestSuite * inSuite, void // This validates evicting from a table with equally loaded fabrics. In this scenario, // bias is given to the fabric that matches that of the eviction hint. // - // There are equal sessions to Node 2 as well as Node 3 in that fabric, so the Node - // that matches the session eviction hint will be selected, and in that, the older session. + // There is an equal number sessions to nodes 1, 2, and 3 in that fabric, so the Node + // that matches the session eviction hint will be selected. + // + // All the sessions in the table are defunct, because for unique active + // sessions eviction hints are ignored. // { - ChipLogProgress(SecureChannel, - "-------- Equal Fabrics Eviction (Equal # Sessions to Nodes, Hint Match On Fabric & Node) ---------"); + ChipLogProgress( + SecureChannel, + "-------- Equal Fabrics Eviction (Single equal # Sessions to Nodes, Hint Match On Fabric & Node) ---------"); + + std::vector sessionParamList = { + { { 1, kFabric1 }, System::Clock::Timestamp(9), SecureSession::State::kDefunct }, + { { 1, kFabric2 }, System::Clock::Timestamp(3), SecureSession::State::kDefunct }, + { { 2, kFabric1 }, System::Clock::Timestamp(2), SecureSession::State::kDefunct }, + { { 3, kFabric1 }, System::Clock::Timestamp(7), SecureSession::State::kDefunct }, + { { 3, kFabric2 }, System::Clock::Timestamp(1), SecureSession::State::kDefunct }, + { { 4, kFabric2 }, System::Clock::Timestamp(2), SecureSession::State::kDefunct }, + }; + + _this->CreateSessionTable(sessionParamList); + _this->AllocateSession(ScopedNodeId(3, kFabric1), sessionParamList, 3); + } + + // + // This validates evicting from a table with equally loaded fabrics. In this scenario, + // bias is given to the fabric that matches that of the eviction hint. + // + // There is an equal number sessions to nodes 1, 2, and 3 in that fabric, so the Node + // that matches the session eviction hint will be selected. + // + // All the peers in this table have two sessions to them, so that we pay + // attention to the eviction hint. The older of the two should be selected. + // + { + ChipLogProgress( + SecureChannel, + "-------- Equal Fabrics Eviction (Multiple equal # Sessions to Nodes, Hint Match On Fabric & Node) ---------"); std::vector sessionParamList = { { { 1, kFabric1 }, System::Clock::Timestamp(9), SecureSession::State::kActive }, @@ -293,12 +329,71 @@ void TestSecureSessionTable::ValidateSessionSorting(nlTestSuite * inSuite, void { { 3, kFabric1 }, System::Clock::Timestamp(7), SecureSession::State::kActive }, { { 3, kFabric2 }, System::Clock::Timestamp(1), SecureSession::State::kActive }, { { 4, kFabric2 }, System::Clock::Timestamp(2), SecureSession::State::kActive }, + { { 1, kFabric1 }, System::Clock::Timestamp(10), SecureSession::State::kActive }, + { { 1, kFabric2 }, System::Clock::Timestamp(4), SecureSession::State::kActive }, + { { 2, kFabric1 }, System::Clock::Timestamp(3), SecureSession::State::kActive }, + { { 3, kFabric1 }, System::Clock::Timestamp(8), SecureSession::State::kActive }, + { { 3, kFabric2 }, System::Clock::Timestamp(2), SecureSession::State::kActive }, + { { 4, kFabric2 }, System::Clock::Timestamp(3), SecureSession::State::kActive }, }; _this->CreateSessionTable(sessionParamList); _this->AllocateSession(ScopedNodeId(3, kFabric1), sessionParamList, 3); } + // + // This validates evicting from a table with equally loaded fabrics. In this scenario, + // bias is given to the fabric that matches that of the eviction hint. + // + // There is an equal sessions to nodes 1, 2, and 3 in that fabric, and only + // one per node. Since all the sessions are active, the eviction hint's + // node id will be ignored and the oldest session on the fabric will be selected. + // + { + ChipLogProgress(SecureChannel, + "-------- Equal Fabrics Eviction (Equal # Sessions to Nodes, Hint Match On Fabric & Node, hint node " + "ignored) ---------"); + + std::vector sessionParamList = { + { { 1, kFabric1 }, System::Clock::Timestamp(9), SecureSession::State::kActive }, + { { 1, kFabric2 }, System::Clock::Timestamp(3), SecureSession::State::kActive }, + { { 2, kFabric1 }, System::Clock::Timestamp(2), SecureSession::State::kActive }, + { { 3, kFabric1 }, System::Clock::Timestamp(7), SecureSession::State::kActive }, + { { 3, kFabric2 }, System::Clock::Timestamp(1), SecureSession::State::kActive }, + { { 4, kFabric2 }, System::Clock::Timestamp(2), SecureSession::State::kActive }, + }; + + _this->CreateSessionTable(sessionParamList); + _this->AllocateSession(ScopedNodeId(3, kFabric1), sessionParamList, 2); + } + + // + // This validates evicting from a table with equally loaded fabrics. In this scenario, + // bias is given to the fabric that matches that of the eviction hint. + // + // There is an equal sessions to nodes 1, 2, and 3 in that fabric, and only + // one per node. Since the hinted session is active, the eviction hint's + // node id will be ignored and the defunct session will be selected, even + // though it's the newest one. + // + { + ChipLogProgress(SecureChannel, + "-------- Equal Fabrics Eviction (Equal # Sessions to Nodes, Hint Match On Fabric & Node, hint node " + "ignored and state wins) ---------"); + + std::vector sessionParamList = { + { { 1, kFabric1 }, System::Clock::Timestamp(9), SecureSession::State::kDefunct }, + { { 1, kFabric2 }, System::Clock::Timestamp(3), SecureSession::State::kActive }, + { { 2, kFabric1 }, System::Clock::Timestamp(2), SecureSession::State::kActive }, + { { 3, kFabric1 }, System::Clock::Timestamp(7), SecureSession::State::kActive }, + { { 3, kFabric2 }, System::Clock::Timestamp(1), SecureSession::State::kActive }, + { { 4, kFabric2 }, System::Clock::Timestamp(2), SecureSession::State::kActive }, + }; + + _this->CreateSessionTable(sessionParamList); + _this->AllocateSession(ScopedNodeId(3, kFabric1), sessionParamList, 0); + } + // // Similar to above, except that the eviction hint matches a given fabric (kFabric1) in the // session table, but not any nodes. In this case, the oldest session in that fabric is selected From db06afc6084b26a62259f8561035ca3df23f4fdf Mon Sep 17 00:00:00 2001 From: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com> Date: Mon, 4 Dec 2023 23:36:22 -0500 Subject: [PATCH 14/14] [Crypto] Rename aes key byte array to symmetric key byte array (#30802) * Rename aes key byte array to symmetric key byte array * Restyled by clang-format --------- Co-authored-by: Restyled.io --- src/app/icd/ICDCheckInSender.cpp | 4 ++-- src/app/icd/ICDMonitoringTable.cpp | 21 +++++++++--------- .../icd/client/DefaultICDClientStorage.cpp | 13 ++++++----- src/app/icd/client/DefaultICDClientStorage.h | 2 +- src/app/icd/client/ICDClientInfo.h | 5 +++-- src/credentials/GroupDataProviderImpl.h | 8 +++---- src/crypto/CHIPCryptoPAL.h | 2 +- src/crypto/CHIPCryptoPALOpenSSL.cpp | 12 +++++----- src/crypto/CHIPCryptoPALmbedTLS.cpp | 6 +++-- src/crypto/PSASessionKeystore.cpp | 5 +++-- src/crypto/PSASessionKeystore.h | 2 +- src/crypto/RawKeySessionKeystore.cpp | 14 ++++++------ src/crypto/RawKeySessionKeystore.h | 2 +- src/crypto/SessionKeystore.h | 2 +- src/crypto/tests/CHIPCryptoPALTest.cpp | 2 +- src/crypto/tests/TestSessionKeystore.cpp | 2 +- .../common/crypto/CHIPCryptoPALTinyCrypt.cpp | 6 +++-- .../nxp/crypto/se05x/CHIPCryptoPALHost.cpp | 6 +++-- .../crypto/CHIPCryptoPALNXPUltrafastP256.cpp | 6 +++-- .../nxp/k32w/k32w1/CHIPCryptoPalK32W1.cpp | 6 +++-- .../silabs/SiWx917/CHIPCryptoPALTinyCrypt.cpp | 6 +++-- .../silabs/efr32/CHIPCryptoPALPsaEfr32.cpp | 22 ++++++++++--------- .../secure_channel/CheckinMessage.cpp | 4 ++-- .../secure_channel/tests/TestCheckinMsg.cpp | 8 +++---- 24 files changed, 92 insertions(+), 74 deletions(-) diff --git a/src/app/icd/ICDCheckInSender.cpp b/src/app/icd/ICDCheckInSender.cpp index 9781069b2c743d..173a1df50ac037 100644 --- a/src/app/icd/ICDCheckInSender.cpp +++ b/src/app/icd/ICDCheckInSender.cpp @@ -89,8 +89,8 @@ CHIP_ERROR ICDCheckInSender::RequestResolve(ICDMonitoringEntry & entry, FabricTa AddressResolve::NodeLookupRequest request(peerId); - memcpy(mKey.AsMutable(), entry.key.As(), - sizeof(Crypto::Aes128KeyByteArray)); + memcpy(mKey.AsMutable(), entry.key.As(), + sizeof(Crypto::Symmetric128BitsKeyByteArray)); CHIP_ERROR err = AddressResolve::Resolver::Instance().LookupNode(request, mAddressLookupHandle); diff --git a/src/app/icd/ICDMonitoringTable.cpp b/src/app/icd/ICDMonitoringTable.cpp index fe8c959983a714..83a06c4f35ad80 100644 --- a/src/app/icd/ICDMonitoringTable.cpp +++ b/src/app/icd/ICDMonitoringTable.cpp @@ -42,7 +42,7 @@ CHIP_ERROR ICDMonitoringEntry::Serialize(TLV::TLVWriter & writer) const ReturnErrorOnFailure(writer.Put(TLV::ContextTag(Fields::kCheckInNodeID), checkInNodeID)); ReturnErrorOnFailure(writer.Put(TLV::ContextTag(Fields::kMonitoredSubject), monitoredSubject)); - ByteSpan buf(key.As()); + ByteSpan buf(key.As()); ReturnErrorOnFailure(writer.Put(TLV::ContextTag(Fields::kKey), buf)); ReturnErrorOnFailure(writer.EndContainer(outer)); return CHIP_NO_ERROR; @@ -70,13 +70,14 @@ CHIP_ERROR ICDMonitoringEntry::Deserialize(TLV::TLVReader & reader) ReturnErrorOnFailure(reader.Get(monitoredSubject)); break; case to_underlying(Fields::kKey): { - ByteSpan buf(key.AsMutable()); + ByteSpan buf(key.AsMutable()); ReturnErrorOnFailure(reader.Get(buf)); // Since we are storing either the raw key or a key ID, we must // simply copy the data as is in the keyHandle. // Calling SetKey here would create another key in storage and will cause // key leakage in some implementation. - memcpy(key.AsMutable(), buf.data(), sizeof(Crypto::Aes128KeyByteArray)); + memcpy(key.AsMutable(), buf.data(), + sizeof(Crypto::Symmetric128BitsKeyByteArray)); keyHandleValid = true; } break; @@ -100,12 +101,12 @@ void ICDMonitoringEntry::Clear() CHIP_ERROR ICDMonitoringEntry::SetKey(ByteSpan keyData) { - VerifyOrReturnError(keyData.size() == sizeof(Crypto::Aes128KeyByteArray), CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(keyData.size() == sizeof(Crypto::Symmetric128BitsKeyByteArray), CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnError(symmetricKeystore != nullptr, CHIP_ERROR_INTERNAL); VerifyOrReturnError(!keyHandleValid, CHIP_ERROR_INTERNAL); - Crypto::Aes128KeyByteArray keyMaterial; - memcpy(keyMaterial, keyData.data(), sizeof(Crypto::Aes128KeyByteArray)); + Crypto::Symmetric128BitsKeyByteArray keyMaterial; + memcpy(keyMaterial, keyData.data(), sizeof(Crypto::Symmetric128BitsKeyByteArray)); ReturnErrorOnFailure(symmetricKeystore->CreateKey(keyMaterial, key)); keyHandleValid = true; @@ -174,8 +175,8 @@ ICDMonitoringEntry & ICDMonitoringEntry::operator=(const ICDMonitoringEntry & ic index = icdMonitoringEntry.index; keyHandleValid = icdMonitoringEntry.keyHandleValid; symmetricKeystore = icdMonitoringEntry.symmetricKeystore; - memcpy(key.AsMutable(), icdMonitoringEntry.key.As(), - sizeof(Crypto::Aes128KeyByteArray)); + memcpy(key.AsMutable(), icdMonitoringEntry.key.As(), + sizeof(Crypto::Symmetric128BitsKeyByteArray)); return *this; } @@ -214,8 +215,8 @@ CHIP_ERROR ICDMonitoringTable::Set(uint16_t index, const ICDMonitoringEntry & en e.checkInNodeID = entry.checkInNodeID; e.monitoredSubject = entry.monitoredSubject; e.index = index; - memcpy(e.key.AsMutable(), entry.key.As(), - sizeof(Crypto::Aes128KeyByteArray)); + memcpy(e.key.AsMutable(), entry.key.As(), + sizeof(Crypto::Symmetric128BitsKeyByteArray)); return e.Save(this->mStorage); } diff --git a/src/app/icd/client/DefaultICDClientStorage.cpp b/src/app/icd/client/DefaultICDClientStorage.cpp index 47319f6c874659..add4923e16f5fb 100644 --- a/src/app/icd/client/DefaultICDClientStorage.cpp +++ b/src/app/icd/client/DefaultICDClientStorage.cpp @@ -262,8 +262,9 @@ CHIP_ERROR DefaultICDClientStorage::Load(FabricIndex fabricIndex, std::vector(), buf.data(), sizeof(Crypto::Aes128KeyByteArray)); + VerifyOrReturnError(buf.size() == sizeof(Crypto::Symmetric128BitsKeyByteArray), CHIP_ERROR_INTERNAL); + memcpy(clientInfo.shared_key.AsMutable(), buf.data(), + sizeof(Crypto::Symmetric128BitsKeyByteArray)); ReturnErrorOnFailure(reader.ExitContainer(ICDClientInfoType)); clientInfoVector.push_back(clientInfo); } @@ -279,10 +280,10 @@ CHIP_ERROR DefaultICDClientStorage::Load(FabricIndex fabricIndex, std::vectorCreateKey(keyMaterial, clientInfo.shared_key); } @@ -300,7 +301,7 @@ CHIP_ERROR DefaultICDClientStorage::SerializeToTlv(TLV::TLVWriter & writer, cons ReturnErrorOnFailure(writer.Put(TLV::ContextTag(ClientInfoTag::kStartICDCounter), clientInfo.start_icd_counter)); ReturnErrorOnFailure(writer.Put(TLV::ContextTag(ClientInfoTag::kOffset), clientInfo.offset)); ReturnErrorOnFailure(writer.Put(TLV::ContextTag(ClientInfoTag::kMonitoredSubject), clientInfo.monitored_subject)); - ByteSpan buf(clientInfo.shared_key.As()); + ByteSpan buf(clientInfo.shared_key.As()); ReturnErrorOnFailure(writer.Put(TLV::ContextTag(ClientInfoTag::kSharedKey), buf)); ReturnErrorOnFailure(writer.EndContainer(ICDClientInfoContainerType)); } diff --git a/src/app/icd/client/DefaultICDClientStorage.h b/src/app/icd/client/DefaultICDClientStorage.h index adc8c69113a700..3637221df0c7f1 100644 --- a/src/app/icd/client/DefaultICDClientStorage.h +++ b/src/app/icd/client/DefaultICDClientStorage.h @@ -100,7 +100,7 @@ class DefaultICDClientStorage : public ICDClientStorage { // All the fields added together return TLV::EstimateStructOverhead(sizeof(NodeId), sizeof(FabricIndex), sizeof(uint32_t), sizeof(uint32_t), - sizeof(uint64_t), sizeof(Crypto::Aes128KeyByteArray)); + sizeof(uint64_t), sizeof(Crypto::Symmetric128BitsKeyByteArray)); } static constexpr size_t MaxICDCounterSize() diff --git a/src/app/icd/client/ICDClientInfo.h b/src/app/icd/client/ICDClientInfo.h index 4ab2aeec6dc8e5..f7863b61798148 100644 --- a/src/app/icd/client/ICDClientInfo.h +++ b/src/app/icd/client/ICDClientInfo.h @@ -44,8 +44,9 @@ struct ICDClientInfo start_icd_counter = other.start_icd_counter; offset = other.offset; monitored_subject = other.monitored_subject; - ByteSpan buf(other.shared_key.As()); - memcpy(shared_key.AsMutable(), buf.data(), sizeof(Crypto::Aes128KeyByteArray)); + ByteSpan buf(other.shared_key.As()); + memcpy(shared_key.AsMutable(), buf.data(), + sizeof(Crypto::Symmetric128BitsKeyByteArray)); return *this; } }; diff --git a/src/credentials/GroupDataProviderImpl.h b/src/credentials/GroupDataProviderImpl.h index fad1d87471bc4a..c06165b59ea6a3 100644 --- a/src/credentials/GroupDataProviderImpl.h +++ b/src/credentials/GroupDataProviderImpl.h @@ -156,16 +156,16 @@ class GroupDataProviderImpl : public GroupDataProvider public: GroupKeyContext(GroupDataProviderImpl & provider) : mProvider(provider) {} - GroupKeyContext(GroupDataProviderImpl & provider, const Crypto::Aes128KeyByteArray & encryptionKey, uint16_t hash, - const Crypto::Aes128KeyByteArray & privacyKey) : + GroupKeyContext(GroupDataProviderImpl & provider, const Crypto::Symmetric128BitsKeyByteArray & encryptionKey, uint16_t hash, + const Crypto::Symmetric128BitsKeyByteArray & privacyKey) : mProvider(provider) { Initialize(encryptionKey, hash, privacyKey); } - void Initialize(const Crypto::Aes128KeyByteArray & encryptionKey, uint16_t hash, - const Crypto::Aes128KeyByteArray & privacyKey) + void Initialize(const Crypto::Symmetric128BitsKeyByteArray & encryptionKey, uint16_t hash, + const Crypto::Symmetric128BitsKeyByteArray & privacyKey) { ReleaseKeys(); mKeyHash = hash; diff --git a/src/crypto/CHIPCryptoPAL.h b/src/crypto/CHIPCryptoPAL.h index 60c88b5e399d49..150f86fecf4b49 100644 --- a/src/crypto/CHIPCryptoPAL.h +++ b/src/crypto/CHIPCryptoPAL.h @@ -562,7 +562,7 @@ class P256Keypair : public P256KeypairBase bool mInitialized = false; }; -using Aes128KeyByteArray = uint8_t[CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BYTES]; +using Symmetric128BitsKeyByteArray = uint8_t[CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BYTES]; /** * @brief Platform-specific AES key diff --git a/src/crypto/CHIPCryptoPALOpenSSL.cpp b/src/crypto/CHIPCryptoPALOpenSSL.cpp index f31911e3b3cbd7..25041654331ac7 100644 --- a/src/crypto/CHIPCryptoPALOpenSSL.cpp +++ b/src/crypto/CHIPCryptoPALOpenSSL.cpp @@ -204,7 +204,7 @@ CHIP_ERROR AES_CCM_encrypt(const uint8_t * plaintext, size_t plaintext_length, c #if CHIP_CRYPTO_BORINGSSL aead = EVP_aead_aes_128_ccm_matter(); - context = EVP_AEAD_CTX_new(aead, key.As(), sizeof(Aes128KeyByteArray), tag_length); + context = EVP_AEAD_CTX_new(aead, key.As(), sizeof(Symmetric128BitsKeyByteArray), tag_length); VerifyOrExit(context != nullptr, error = CHIP_ERROR_NO_MEMORY); result = EVP_AEAD_CTX_seal_scatter(context, ciphertext, tag, &written_tag_len, tag_length, nonce, nonce_length, plaintext, @@ -231,8 +231,8 @@ CHIP_ERROR AES_CCM_encrypt(const uint8_t * plaintext, size_t plaintext_length, c VerifyOrExit(result == 1, error = CHIP_ERROR_INTERNAL); // Pass in key + nonce - static_assert(kAES_CCM128_Key_Length == sizeof(Aes128KeyByteArray), "Unexpected key length"); - result = EVP_EncryptInit_ex(context, nullptr, nullptr, key.As(), Uint8::to_const_uchar(nonce)); + static_assert(kAES_CCM128_Key_Length == sizeof(Symmetric128BitsKeyByteArray), "Unexpected key length"); + result = EVP_EncryptInit_ex(context, nullptr, nullptr, key.As(), Uint8::to_const_uchar(nonce)); VerifyOrExit(result == 1, error = CHIP_ERROR_INTERNAL); // Pass in plain text length @@ -336,7 +336,7 @@ CHIP_ERROR AES_CCM_decrypt(const uint8_t * ciphertext, size_t ciphertext_length, #if CHIP_CRYPTO_BORINGSSL aead = EVP_aead_aes_128_ccm_matter(); - context = EVP_AEAD_CTX_new(aead, key.As(), sizeof(Aes128KeyByteArray), tag_length); + context = EVP_AEAD_CTX_new(aead, key.As(), sizeof(Symmetric128BitsKeyByteArray), tag_length); VerifyOrExit(context != nullptr, error = CHIP_ERROR_NO_MEMORY); result = EVP_AEAD_CTX_open_gather(context, plaintext, nonce, nonce_length, ciphertext, ciphertext_length, tag, tag_length, aad, @@ -366,8 +366,8 @@ CHIP_ERROR AES_CCM_decrypt(const uint8_t * ciphertext, size_t ciphertext_length, VerifyOrExit(result == 1, error = CHIP_ERROR_INTERNAL); // Pass in key + nonce - static_assert(kAES_CCM128_Key_Length == sizeof(Aes128KeyByteArray), "Unexpected key length"); - result = EVP_DecryptInit_ex(context, nullptr, nullptr, key.As(), Uint8::to_const_uchar(nonce)); + static_assert(kAES_CCM128_Key_Length == sizeof(Symmetric128BitsKeyByteArray), "Unexpected key length"); + result = EVP_DecryptInit_ex(context, nullptr, nullptr, key.As(), Uint8::to_const_uchar(nonce)); VerifyOrExit(result == 1, error = CHIP_ERROR_INTERNAL); // Pass in cipher text length diff --git a/src/crypto/CHIPCryptoPALmbedTLS.cpp b/src/crypto/CHIPCryptoPALmbedTLS.cpp index 3981ff30575d00..209573c6a99253 100644 --- a/src/crypto/CHIPCryptoPALmbedTLS.cpp +++ b/src/crypto/CHIPCryptoPALmbedTLS.cpp @@ -96,7 +96,8 @@ CHIP_ERROR AES_CCM_encrypt(const uint8_t * plaintext, size_t plaintext_length, c } // Size of key is expressed in bits, hence the multiplication by 8. - result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), sizeof(Aes128KeyByteArray) * 8); + result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), + sizeof(Symmetric128BitsKeyByteArray) * 8); VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL); // Encrypt @@ -133,7 +134,8 @@ CHIP_ERROR AES_CCM_decrypt(const uint8_t * ciphertext, size_t ciphertext_len, co } // Size of key is expressed in bits, hence the multiplication by 8. - result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), sizeof(Aes128KeyByteArray) * 8); + result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), + sizeof(Symmetric128BitsKeyByteArray) * 8); VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL); // Decrypt diff --git a/src/crypto/PSASessionKeystore.cpp b/src/crypto/PSASessionKeystore.cpp index 0b8a237a9d405b..8a85d2c6fa8eaf 100644 --- a/src/crypto/PSASessionKeystore.cpp +++ b/src/crypto/PSASessionKeystore.cpp @@ -49,13 +49,14 @@ class AesKeyAttributes } // namespace -CHIP_ERROR PSASessionKeystore::CreateKey(const Aes128KeyByteArray & keyMaterial, Aes128KeyHandle & key) +CHIP_ERROR PSASessionKeystore::CreateKey(const Symmetric128BitsKeyByteArray & keyMaterial, Aes128KeyHandle & key) { // Destroy the old key if already allocated psa_destroy_key(key.As()); AesKeyAttributes attrs; - psa_status_t status = psa_import_key(&attrs.Get(), keyMaterial, sizeof(Aes128KeyByteArray), &key.AsMutable()); + psa_status_t status = + psa_import_key(&attrs.Get(), keyMaterial, sizeof(Symmetric128BitsKeyByteArray), &key.AsMutable()); VerifyOrReturnError(status == PSA_SUCCESS, CHIP_ERROR_INTERNAL); return CHIP_NO_ERROR; diff --git a/src/crypto/PSASessionKeystore.h b/src/crypto/PSASessionKeystore.h index c448d7923a6575..db1ce671e45cbc 100644 --- a/src/crypto/PSASessionKeystore.h +++ b/src/crypto/PSASessionKeystore.h @@ -25,7 +25,7 @@ namespace Crypto { class PSASessionKeystore : public SessionKeystore { public: - CHIP_ERROR CreateKey(const Aes128KeyByteArray & keyMaterial, Aes128KeyHandle & key) override; + CHIP_ERROR CreateKey(const Symmetric128BitsKeyByteArray & keyMaterial, Aes128KeyHandle & key) override; CHIP_ERROR DeriveKey(const P256ECDHDerivedSecret & secret, const ByteSpan & salt, const ByteSpan & info, Aes128KeyHandle & key) override; CHIP_ERROR DeriveSessionKeys(const ByteSpan & secret, const ByteSpan & salt, const ByteSpan & info, Aes128KeyHandle & i2rKey, diff --git a/src/crypto/RawKeySessionKeystore.cpp b/src/crypto/RawKeySessionKeystore.cpp index 7db2c0c8b28962..80f391ac1a4a6c 100644 --- a/src/crypto/RawKeySessionKeystore.cpp +++ b/src/crypto/RawKeySessionKeystore.cpp @@ -24,9 +24,9 @@ namespace Crypto { using HKDF_sha_crypto = HKDF_sha; -CHIP_ERROR RawKeySessionKeystore::CreateKey(const Aes128KeyByteArray & keyMaterial, Aes128KeyHandle & key) +CHIP_ERROR RawKeySessionKeystore::CreateKey(const Symmetric128BitsKeyByteArray & keyMaterial, Aes128KeyHandle & key) { - memcpy(key.AsMutable(), keyMaterial, sizeof(Aes128KeyByteArray)); + memcpy(key.AsMutable(), keyMaterial, sizeof(Symmetric128BitsKeyByteArray)); return CHIP_NO_ERROR; } @@ -36,7 +36,7 @@ CHIP_ERROR RawKeySessionKeystore::DeriveKey(const P256ECDHDerivedSecret & secret HKDF_sha_crypto hkdf; return hkdf.HKDF_SHA256(secret.ConstBytes(), secret.Length(), salt.data(), salt.size(), info.data(), info.size(), - key.AsMutable(), sizeof(Aes128KeyByteArray)); + key.AsMutable(), sizeof(Symmetric128BitsKeyByteArray)); } CHIP_ERROR RawKeySessionKeystore::DeriveSessionKeys(const ByteSpan & secret, const ByteSpan & salt, const ByteSpan & info, @@ -44,22 +44,22 @@ CHIP_ERROR RawKeySessionKeystore::DeriveSessionKeys(const ByteSpan & secret, con AttestationChallenge & attestationChallenge) { HKDF_sha_crypto hkdf; - uint8_t keyMaterial[2 * sizeof(Aes128KeyByteArray) + AttestationChallenge::Capacity()]; + uint8_t keyMaterial[2 * sizeof(Symmetric128BitsKeyByteArray) + AttestationChallenge::Capacity()]; ReturnErrorOnFailure(hkdf.HKDF_SHA256(secret.data(), secret.size(), salt.data(), salt.size(), info.data(), info.size(), keyMaterial, sizeof(keyMaterial))); Encoding::LittleEndian::Reader reader(keyMaterial, sizeof(keyMaterial)); - return reader.ReadBytes(i2rKey.AsMutable(), sizeof(Aes128KeyByteArray)) - .ReadBytes(r2iKey.AsMutable(), sizeof(Aes128KeyByteArray)) + return reader.ReadBytes(i2rKey.AsMutable(), sizeof(Symmetric128BitsKeyByteArray)) + .ReadBytes(r2iKey.AsMutable(), sizeof(Symmetric128BitsKeyByteArray)) .ReadBytes(attestationChallenge.Bytes(), AttestationChallenge::Capacity()) .StatusCode(); } void RawKeySessionKeystore::DestroyKey(Aes128KeyHandle & key) { - ClearSecretData(key.AsMutable()); + ClearSecretData(key.AsMutable()); } } // namespace Crypto diff --git a/src/crypto/RawKeySessionKeystore.h b/src/crypto/RawKeySessionKeystore.h index c8db3eda069518..21ecc630543151 100644 --- a/src/crypto/RawKeySessionKeystore.h +++ b/src/crypto/RawKeySessionKeystore.h @@ -25,7 +25,7 @@ namespace Crypto { class RawKeySessionKeystore : public SessionKeystore { public: - CHIP_ERROR CreateKey(const Aes128KeyByteArray & keyMaterial, Aes128KeyHandle & key) override; + CHIP_ERROR CreateKey(const Symmetric128BitsKeyByteArray & keyMaterial, Aes128KeyHandle & key) override; CHIP_ERROR DeriveKey(const P256ECDHDerivedSecret & secret, const ByteSpan & salt, const ByteSpan & info, Aes128KeyHandle & key) override; CHIP_ERROR DeriveSessionKeys(const ByteSpan & secret, const ByteSpan & salt, const ByteSpan & info, Aes128KeyHandle & i2rKey, diff --git a/src/crypto/SessionKeystore.h b/src/crypto/SessionKeystore.h index edc31dc788dbea..00107b385d37af 100644 --- a/src/crypto/SessionKeystore.h +++ b/src/crypto/SessionKeystore.h @@ -45,7 +45,7 @@ class SessionKeystore * If the method returns no error, the application is responsible for destroying the handle * using DestroyKey() method when the key is no longer needed. */ - virtual CHIP_ERROR CreateKey(const Aes128KeyByteArray & keyMaterial, Aes128KeyHandle & key) = 0; + virtual CHIP_ERROR CreateKey(const Symmetric128BitsKeyByteArray & keyMaterial, Aes128KeyHandle & key) = 0; /** * @brief Derive key from a shared secret. diff --git a/src/crypto/tests/CHIPCryptoPALTest.cpp b/src/crypto/tests/CHIPCryptoPALTest.cpp index 38343a60d52e5c..3519d31fc15ec6 100644 --- a/src/crypto/tests/CHIPCryptoPALTest.cpp +++ b/src/crypto/tests/CHIPCryptoPALTest.cpp @@ -183,7 +183,7 @@ struct TestAesKey public: TestAesKey(nlTestSuite * inSuite, const uint8_t * keyBytes, size_t keyLength) { - Crypto::Aes128KeyByteArray keyMaterial; + Crypto::Symmetric128BitsKeyByteArray keyMaterial; memcpy(&keyMaterial, keyBytes, keyLength); CHIP_ERROR err = keystore.CreateKey(keyMaterial, key); diff --git a/src/crypto/tests/TestSessionKeystore.cpp b/src/crypto/tests/TestSessionKeystore.cpp index a1f786d51a3dc1..025cd5c9233cbe 100644 --- a/src/crypto/tests/TestSessionKeystore.cpp +++ b/src/crypto/tests/TestSessionKeystore.cpp @@ -110,7 +110,7 @@ void TestBasicImport(nlTestSuite * inSuite, void * inContext) { const ccm_128_test_vector & test = *testPtr; - Aes128KeyByteArray keyMaterial; + Symmetric128BitsKeyByteArray keyMaterial; memcpy(keyMaterial, test.key, test.key_len); Aes128KeyHandle keyHandle; diff --git a/src/platform/nxp/common/crypto/CHIPCryptoPALTinyCrypt.cpp b/src/platform/nxp/common/crypto/CHIPCryptoPALTinyCrypt.cpp index b8e0101cdacea9..db5dbada3d00e8 100644 --- a/src/platform/nxp/common/crypto/CHIPCryptoPALTinyCrypt.cpp +++ b/src/platform/nxp/common/crypto/CHIPCryptoPALTinyCrypt.cpp @@ -145,7 +145,8 @@ CHIP_ERROR AES_CCM_encrypt(const uint8_t * plaintext, size_t plaintext_length, c } // Size of key is expressed in bits, hence the multiplication by 8. - result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), sizeof(Aes128KeyByteArray) * 8); + result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), + sizeof(Symmetric128BitsKeyByteArray) * 8); VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL); // Encrypt @@ -182,7 +183,8 @@ CHIP_ERROR AES_CCM_decrypt(const uint8_t * ciphertext, size_t ciphertext_len, co } // Size of key is expressed in bits, hence the multiplication by 8. - result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), sizeof(Aes128KeyByteArray) * 8); + result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), + sizeof(Symmetric128BitsKeyByteArray) * 8); VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL); // Decrypt diff --git a/src/platform/nxp/crypto/se05x/CHIPCryptoPALHost.cpp b/src/platform/nxp/crypto/se05x/CHIPCryptoPALHost.cpp index 525d3e32ba654f..ffc626c201d373 100644 --- a/src/platform/nxp/crypto/se05x/CHIPCryptoPALHost.cpp +++ b/src/platform/nxp/crypto/se05x/CHIPCryptoPALHost.cpp @@ -130,7 +130,8 @@ CHIP_ERROR AES_CCM_encrypt(const uint8_t * plaintext, size_t plaintext_length, c } // Size of key is expressed in bits, hence the multiplication by 8. - result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), sizeof(Aes128KeyByteArray) * 8); + result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), + sizeof(Symmetric128BitsKeyByteArray) * 8); VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL); // Encrypt @@ -167,7 +168,8 @@ CHIP_ERROR AES_CCM_decrypt(const uint8_t * ciphertext, size_t ciphertext_len, co } // Size of key is expressed in bits, hence the multiplication by 8. - result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), sizeof(Aes128KeyByteArray) * 8); + result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), + sizeof(Symmetric128BitsKeyByteArray) * 8); VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL); // Decrypt diff --git a/src/platform/nxp/k32w/k32w0/crypto/CHIPCryptoPALNXPUltrafastP256.cpp b/src/platform/nxp/k32w/k32w0/crypto/CHIPCryptoPALNXPUltrafastP256.cpp index 68ae897de2917e..31156e735232d4 100644 --- a/src/platform/nxp/k32w/k32w0/crypto/CHIPCryptoPALNXPUltrafastP256.cpp +++ b/src/platform/nxp/k32w/k32w0/crypto/CHIPCryptoPALNXPUltrafastP256.cpp @@ -136,7 +136,8 @@ CHIP_ERROR AES_CCM_encrypt(const uint8_t * plaintext, size_t plaintext_length, c } // Size of key is expressed in bits, hence the multiplication by 8. - result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), sizeof(Aes128KeyByteArray) * 8); + result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), + sizeof(Symmetric128BitsKeyByteArray) * 8); VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL); // Encrypt @@ -173,7 +174,8 @@ CHIP_ERROR AES_CCM_decrypt(const uint8_t * ciphertext, size_t ciphertext_len, co } // Size of key is expressed in bits, hence the multiplication by 8. - result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), sizeof(Aes128KeyByteArray) * 8); + result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), + sizeof(Symmetric128BitsKeyByteArray) * 8); VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL); // Decrypt diff --git a/src/platform/nxp/k32w/k32w1/CHIPCryptoPalK32W1.cpp b/src/platform/nxp/k32w/k32w1/CHIPCryptoPalK32W1.cpp index 609c0efa8d6e47..b22feed6e10d80 100644 --- a/src/platform/nxp/k32w/k32w1/CHIPCryptoPalK32W1.cpp +++ b/src/platform/nxp/k32w/k32w1/CHIPCryptoPalK32W1.cpp @@ -143,7 +143,8 @@ CHIP_ERROR AES_CCM_encrypt(const uint8_t * plaintext, size_t plaintext_length, c } // Size of key is expressed in bits, hence the multiplication by 8. - result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), sizeof(Aes128KeyByteArray) * 8); + result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), + sizeof(Symmetric128BitsKeyByteArray) * 8); VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL); // Encrypt @@ -180,7 +181,8 @@ CHIP_ERROR AES_CCM_decrypt(const uint8_t * ciphertext, size_t ciphertext_len, co } // Size of key is expressed in bits, hence the multiplication by 8. - result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), sizeof(Aes128KeyByteArray) * 8); + result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), + sizeof(Symmetric128BitsKeyByteArray) * 8); VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL); // Decrypt diff --git a/src/platform/silabs/SiWx917/CHIPCryptoPALTinyCrypt.cpp b/src/platform/silabs/SiWx917/CHIPCryptoPALTinyCrypt.cpp index e15237b042285d..bd678ba17e09e7 100644 --- a/src/platform/silabs/SiWx917/CHIPCryptoPALTinyCrypt.cpp +++ b/src/platform/silabs/SiWx917/CHIPCryptoPALTinyCrypt.cpp @@ -135,7 +135,8 @@ CHIP_ERROR AES_CCM_encrypt(const uint8_t * plaintext, size_t plaintext_length, c } // multiplying by 8 to convert key from bits to byte - result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), sizeof(Aes128KeyByteArray) * 8); + result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), + sizeof(Symmetric128BitsKeyByteArray) * 8); VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL); // Encrypt @@ -172,7 +173,8 @@ CHIP_ERROR AES_CCM_decrypt(const uint8_t * ciphertext, size_t ciphertext_len, co } // multiplying by 8 to convert key from bits to byte - result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), sizeof(Aes128KeyByteArray) * 8); + result = mbedtls_ccm_setkey(&context, MBEDTLS_CIPHER_ID_AES, key.As(), + sizeof(Symmetric128BitsKeyByteArray) * 8); VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL); // Decrypt diff --git a/src/platform/silabs/efr32/CHIPCryptoPALPsaEfr32.cpp b/src/platform/silabs/efr32/CHIPCryptoPALPsaEfr32.cpp index 0ad35de132f940..6d3d05910943ce 100644 --- a/src/platform/silabs/efr32/CHIPCryptoPALPsaEfr32.cpp +++ b/src/platform/silabs/efr32/CHIPCryptoPALPsaEfr32.cpp @@ -185,14 +185,15 @@ CHIP_ERROR AES_CCM_encrypt(const uint8_t * plaintext, size_t plaintext_length, c psa_crypto_init(); psa_set_key_type(&attr, PSA_KEY_TYPE_AES); - psa_set_key_bits(&attr, sizeof(Aes128KeyByteArray) * 8); + psa_set_key_bits(&attr, sizeof(Symmetric128BitsKeyByteArray) * 8); psa_set_key_algorithm(&attr, PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(PSA_ALG_CCM, 8)); psa_set_key_usage_flags(&attr, PSA_KEY_USAGE_ENCRYPT); - status = psa_driver_wrapper_aead_encrypt( - &attr, key.As(), sizeof(Aes128KeyByteArray), PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, tag_length), - Uint8::to_const_uchar(nonce), nonce_length, Uint8::to_const_uchar(aad), aad_length, Uint8::to_const_uchar(plaintext), - plaintext_length, allocated_buffer ? buffer : ciphertext, plaintext_length + tag_length, &output_length); + status = psa_driver_wrapper_aead_encrypt(&attr, key.As(), sizeof(Symmetric128BitsKeyByteArray), + PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, tag_length), Uint8::to_const_uchar(nonce), + nonce_length, Uint8::to_const_uchar(aad), aad_length, Uint8::to_const_uchar(plaintext), + plaintext_length, allocated_buffer ? buffer : ciphertext, + plaintext_length + tag_length, &output_length); VerifyOrExit(status == PSA_SUCCESS, error = CHIP_ERROR_INTERNAL); VerifyOrExit(output_length == plaintext_length + tag_length, error = CHIP_ERROR_INTERNAL); @@ -240,7 +241,7 @@ CHIP_ERROR AES_CCM_decrypt(const uint8_t * ciphertext, size_t ciphertext_len, co psa_crypto_init(); psa_set_key_type(&attr, PSA_KEY_TYPE_AES); - psa_set_key_bits(&attr, sizeof(Aes128KeyByteArray) * 8); + psa_set_key_bits(&attr, sizeof(Symmetric128BitsKeyByteArray) * 8); psa_set_key_algorithm(&attr, PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(PSA_ALG_CCM, 8)); psa_set_key_usage_flags(&attr, PSA_KEY_USAGE_DECRYPT); @@ -250,10 +251,11 @@ CHIP_ERROR AES_CCM_decrypt(const uint8_t * ciphertext, size_t ciphertext_len, co memcpy(buffer + ciphertext_len, tag, tag_length); } - status = psa_driver_wrapper_aead_decrypt( - &attr, key.As(), sizeof(Aes128KeyByteArray), PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, tag_length), - Uint8::to_const_uchar(nonce), nonce_length, Uint8::to_const_uchar(aad), aad_len, allocated_buffer ? buffer : ciphertext, - ciphertext_len + tag_length, plaintext, ciphertext_len, &output_length); + status = + psa_driver_wrapper_aead_decrypt(&attr, key.As(), sizeof(Symmetric128BitsKeyByteArray), + PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, tag_length), Uint8::to_const_uchar(nonce), + nonce_length, Uint8::to_const_uchar(aad), aad_len, allocated_buffer ? buffer : ciphertext, + ciphertext_len + tag_length, plaintext, ciphertext_len, &output_length); if (allocated_buffer) { diff --git a/src/protocols/secure_channel/CheckinMessage.cpp b/src/protocols/secure_channel/CheckinMessage.cpp index 358133a42b81b1..5e63feb3428aa0 100644 --- a/src/protocols/secure_channel/CheckinMessage.cpp +++ b/src/protocols/secure_channel/CheckinMessage.cpp @@ -43,8 +43,8 @@ CHIP_ERROR CheckinMessage::GenerateCheckinMessagePayload(Crypto::Aes128KeyHandle chip::Crypto::HMAC_sha shaHandler; uint8_t nonceWorkBuffer[CHIP_CRYPTO_HASH_LEN_BYTES] = { 0 }; - ReturnErrorOnFailure(shaHandler.HMAC_SHA256(key.As(), sizeof(Aes128KeyByteArray), appDataStartPtr, - sizeof(CounterType), nonceWorkBuffer, CHIP_CRYPTO_HASH_LEN_BYTES)); + ReturnErrorOnFailure(shaHandler.HMAC_SHA256(key.As(), sizeof(Symmetric128BitsKeyByteArray), + appDataStartPtr, sizeof(CounterType), nonceWorkBuffer, CHIP_CRYPTO_HASH_LEN_BYTES)); static_assert(sizeof(nonceWorkBuffer) >= CHIP_CRYPTO_AEAD_NONCE_LENGTH_BYTES, "We're reading off the end of our buffer."); memcpy(output.data(), nonceWorkBuffer, CHIP_CRYPTO_AEAD_NONCE_LENGTH_BYTES); diff --git a/src/protocols/secure_channel/tests/TestCheckinMsg.cpp b/src/protocols/secure_channel/tests/TestCheckinMsg.cpp index 37f7c765729dd3..6310cf38c05494 100644 --- a/src/protocols/secure_channel/tests/TestCheckinMsg.cpp +++ b/src/protocols/secure_channel/tests/TestCheckinMsg.cpp @@ -56,7 +56,7 @@ void TestCheckin_Generate(nlTestSuite * inSuite, void * inContext) { const ccm_128_test_vector & test = *testPtr; - Aes128KeyByteArray keyMaterial; + Symmetric128BitsKeyByteArray keyMaterial; memcpy(keyMaterial, test.key, test.key_len); Aes128KeyHandle keyHandle; @@ -87,7 +87,7 @@ void TestCheckin_Generate(nlTestSuite * inSuite, void * inContext) const ccm_128_test_vector & test = *ccm_128_test_vectors[0]; uint8_t gargantuaBuffer[2 * CheckinMessage::sMaxAppDataSize] = { 0 }; - Aes128KeyByteArray keyMaterial; + Symmetric128BitsKeyByteArray keyMaterial; memcpy(keyMaterial, test.key, test.key_len); Aes128KeyHandle keyHandle; @@ -137,7 +137,7 @@ void TestCheckin_Parse(nlTestSuite * inSuite, void * inContext) userData = chip::ByteSpan(data); const ccm_128_test_vector & test = *ccm_128_test_vectors[0]; - Aes128KeyByteArray keyMaterial; + Symmetric128BitsKeyByteArray keyMaterial; memcpy(keyMaterial, test.key, test.key_len); Aes128KeyHandle keyHandle; @@ -180,7 +180,7 @@ void TestCheckin_GenerateParse(nlTestSuite * inSuite, void * inContext) { const ccm_128_test_vector & test = *testPtr; - Aes128KeyByteArray keyMaterial; + Symmetric128BitsKeyByteArray keyMaterial; memcpy(keyMaterial, test.key, test.key_len); Aes128KeyHandle keyHandle;