From 71a1ce3a80da6b149afc9587fbde3e5abc944ce9 Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Thu, 18 Jan 2024 00:37:03 -0800 Subject: [PATCH] =?UTF-8?q?[Android]Return=20CHIP=5FERROR=5FINVALID=5FIPK?= =?UTF-8?q?=20when=20providing=20the=20invalid=20IPK=20from=20and=E2=80=A6?= =?UTF-8?q?=20(#31491)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Return CHIP_ERROR_INVALID_IPK when providing the invalid IPK from android application * gen updated error code --- docs/ERROR_CODES.md | 1 + src/controller/java/CHIPDeviceController-JNI.cpp | 6 +++++- src/lib/core/CHIPError.cpp | 3 +++ src/lib/core/CHIPError.h | 9 ++++++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/ERROR_CODES.md b/docs/ERROR_CODES.md index 35dcd05d5bff07..8cd4a4c80940e3 100644 --- a/docs/ERROR_CODES.md +++ b/docs/ERROR_CODES.md @@ -44,6 +44,7 @@ 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_INVALID_IPK` | | 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/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 9b3e67b6bf253b..adde00b6cfb4a5 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -228,7 +228,11 @@ JNI_METHOD(jint, onNOCChainGeneration) { JniByteArray jByteArrayIpk(env, ipk); - VerifyOrReturnValue(jByteArrayIpk.byteSpan().size() == sizeof(ipkValue), CHIP_ERROR_INTERNAL.AsInteger()); + if (jByteArrayIpk.byteSpan().size() != sizeof(ipkValue)) + { + ChipLogError(Controller, "Invalid IPK size %ld and expect %ld", jByteArrayIpk.byteSpan().size(), sizeof(ipkValue)); + return CHIP_ERROR_INVALID_IPK.AsInteger(); + } memcpy(&ipkValue[0], jByteArrayIpk.byteSpan().data(), jByteArrayIpk.byteSpan().size()); ipkOptional.SetValue(ipkTempSpan); diff --git a/src/lib/core/CHIPError.cpp b/src/lib/core/CHIPError.cpp index a3bdd148253cfb..565e1b065b5c4c 100644 --- a/src/lib/core/CHIPError.cpp +++ b/src/lib/core/CHIPError.cpp @@ -143,6 +143,9 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, CHIP_ERROR err) case CHIP_ERROR_UNINITIALIZED.AsInteger(): desc = "Uninitialized"; break; + case CHIP_ERROR_INVALID_IPK.AsInteger(): + desc = "Invalid IPK"; + 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 3844bf53516b86..da3af4c29e681d 100644 --- a/src/lib/core/CHIPError.h +++ b/src/lib/core/CHIPError.h @@ -681,7 +681,14 @@ using CHIP_ERROR = ::chip::ChipError; */ #define CHIP_ERROR_UNINITIALIZED CHIP_CORE_ERROR(0x1c) -// AVAILABLE: 0x1d +/** + * @def CHIP_ERROR_INVALID_IPK + * + * @brief + * The IPK is invalid + * + */ +#define CHIP_ERROR_INVALID_IPK CHIP_CORE_ERROR(0x1d) /** * @def CHIP_ERROR_INVALID_STRING_LENGTH