Skip to content

Commit

Permalink
[Android]Return CHIP_ERROR_INVALID_IPK when providing the invalid IPK…
Browse files Browse the repository at this point in the history
… from and… (project-chip#31491)

* Return CHIP_ERROR_INVALID_IPK when providing the invalid IPK from android application

* gen updated error code
  • Loading branch information
yunhanw-google authored Jan 18, 2024
1 parent e59fd33 commit 71a1ce3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/ERROR_CODES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
6 changes: 5 additions & 1 deletion src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/lib/core/CHIPError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/lib/core/CHIPError.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 71a1ce3

Please sign in to comment.