From 4ef2ea7f02fa00576befac8b8b1d194763b98954 Mon Sep 17 00:00:00 2001 From: Zang MingJie Date: Thu, 17 Mar 2022 15:14:07 +0800 Subject: [PATCH] Resolve comments --- src/app/tests/TestWriteInteraction.cpp | 5 ++--- src/credentials/FabricTable.cpp | 5 +++-- src/credentials/FabricTable.h | 3 ++- src/messaging/tests/MessagingContext.cpp | 22 ++++++++++++---------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/app/tests/TestWriteInteraction.cpp b/src/app/tests/TestWriteInteraction.cpp index 5663a4c2c93804..4e9c5eac95f81b 100644 --- a/src/app/tests/TestWriteInteraction.cpp +++ b/src/app/tests/TestWriteInteraction.cpp @@ -482,10 +482,9 @@ int Test_Setup(void * inContext) TestContext & ctx = *static_cast(inContext); VerifyOrReturnError(CHIP_NO_ERROR == chip::GroupTesting::InitProvider(), FAILURE); - chip::CompressedFabricId compressedFabricId = ctx.GetBobFabric()->GetCompressedId(); - uint8_t buf[sizeof(compressedFabricId)]; + uint8_t buf[sizeof(chip::CompressedFabricId)]; chip::MutableByteSpan span(buf); - chip::Encoding::BigEndian::Put64(span.data(), span.size()); + VerifyOrReturnError(CHIP_NO_ERROR == ctx.GetBobFabric()->GetCompressedId(span), FAILURE); VerifyOrReturnError(CHIP_NO_ERROR == chip::GroupTesting::InitData(ctx.GetBobFabricIndex(), span), FAILURE); return SUCCESS; diff --git a/src/credentials/FabricTable.cpp b/src/credentials/FabricTable.cpp index 4b0acf4c1aa672..4f584437ba05d7 100644 --- a/src/credentials/FabricTable.cpp +++ b/src/credentials/FabricTable.cpp @@ -809,8 +809,8 @@ CHIP_ERROR formatKey(FabricIndex fabricIndex, MutableCharSpan formattedKey, cons return err; } -CHIP_ERROR FabricInfo::BuildFabric(ByteSpan rootCert, ByteSpan icacCert, ByteSpan nocCert, ByteSpan nodePubKey, - ByteSpan nodePrivateKey) +CHIP_ERROR FabricInfo::TestOnlyBuildFabric(ByteSpan rootCert, ByteSpan icacCert, ByteSpan nocCert, ByteSpan nodePubKey, + ByteSpan nodePrivateKey) { Reset(); @@ -818,6 +818,7 @@ CHIP_ERROR FabricInfo::BuildFabric(ByteSpan rootCert, ByteSpan icacCert, ByteSpa ReturnErrorOnFailure(SetICACert(icacCert)); ReturnErrorOnFailure(SetNOCCert(nocCert)); + // NOTE: this requres ENABLE_HSM_CASE_OPS_KEY is not defined P256SerializedKeypair opKeysSerialized; memcpy(static_cast(opKeysSerialized), nodePubKey.data(), nodePubKey.size()); memcpy(static_cast(opKeysSerialized) + nodePubKey.size(), nodePrivateKey.data(), nodePrivateKey.size()); diff --git a/src/credentials/FabricTable.h b/src/credentials/FabricTable.h index adc3c58fa8e24d..45d1163643e03f 100644 --- a/src/credentials/FabricTable.h +++ b/src/credentials/FabricTable.h @@ -209,7 +209,8 @@ class DLL_EXPORT FabricInfo friend class FabricTable; // Test-only, build a fabric using given root cert and NOC - CHIP_ERROR BuildFabric(ByteSpan rootCert, ByteSpan icacCert, ByteSpan nocCert, ByteSpan nodePubKey, ByteSpan nodePrivateKey); + CHIP_ERROR TestOnlyBuildFabric(ByteSpan rootCert, ByteSpan icacCert, ByteSpan nocCert, ByteSpan nodePubKey, + ByteSpan nodePrivateKey); private: static constexpr size_t MetadataTLVMaxSize() diff --git a/src/messaging/tests/MessagingContext.cpp b/src/messaging/tests/MessagingContext.cpp index a1221fa17874ef..273a98d18cc828 100644 --- a/src/messaging/tests/MessagingContext.cpp +++ b/src/messaging/tests/MessagingContext.cpp @@ -44,18 +44,20 @@ CHIP_ERROR MessagingContext::Init(TransportMgrBase * transport, IOContext * ioCo FabricInfo aliceFabric; FabricInfo bobFabric; - aliceFabric.BuildFabric(ByteSpan(TestCerts::sTestCert_Root01_Chip, TestCerts::sTestCert_Root01_Chip_Len), - ByteSpan(TestCerts::sTestCert_ICA01_Chip, TestCerts::sTestCert_ICA01_Chip_Len), - ByteSpan(TestCerts::sTestCert_Node01_01_Chip, TestCerts::sTestCert_Node01_01_Chip_Len), - ByteSpan(TestCerts::sTestCert_Node01_01_PublicKey, TestCerts::sTestCert_Node01_01_PublicKey_Len), - ByteSpan(TestCerts::sTestCert_Node01_01_PrivateKey, TestCerts::sTestCert_Node01_01_PrivateKey_Len)); + aliceFabric.TestOnlyBuildFabric( + ByteSpan(TestCerts::sTestCert_Root01_Chip, TestCerts::sTestCert_Root01_Chip_Len), + ByteSpan(TestCerts::sTestCert_ICA01_Chip, TestCerts::sTestCert_ICA01_Chip_Len), + ByteSpan(TestCerts::sTestCert_Node01_01_Chip, TestCerts::sTestCert_Node01_01_Chip_Len), + ByteSpan(TestCerts::sTestCert_Node01_01_PublicKey, TestCerts::sTestCert_Node01_01_PublicKey_Len), + ByteSpan(TestCerts::sTestCert_Node01_01_PrivateKey, TestCerts::sTestCert_Node01_01_PrivateKey_Len)); ReturnErrorOnFailure(mFabricTable.AddNewFabric(aliceFabric, &mAliceFabricIndex)); - bobFabric.BuildFabric(ByteSpan(TestCerts::sTestCert_Root02_Chip, TestCerts::sTestCert_Root02_Chip_Len), - ByteSpan(TestCerts::sTestCert_ICA02_Chip, TestCerts::sTestCert_ICA02_Chip_Len), - ByteSpan(TestCerts::sTestCert_Node02_01_Chip, TestCerts::sTestCert_Node02_01_Chip_Len), - ByteSpan(TestCerts::sTestCert_Node02_01_PublicKey, TestCerts::sTestCert_Node02_01_PublicKey_Len), - ByteSpan(TestCerts::sTestCert_Node02_01_PrivateKey, TestCerts::sTestCert_Node02_01_PrivateKey_Len)); + bobFabric.TestOnlyBuildFabric( + ByteSpan(TestCerts::sTestCert_Root02_Chip, TestCerts::sTestCert_Root02_Chip_Len), + ByteSpan(TestCerts::sTestCert_ICA02_Chip, TestCerts::sTestCert_ICA02_Chip_Len), + ByteSpan(TestCerts::sTestCert_Node02_01_Chip, TestCerts::sTestCert_Node02_01_Chip_Len), + ByteSpan(TestCerts::sTestCert_Node02_01_PublicKey, TestCerts::sTestCert_Node02_01_PublicKey_Len), + ByteSpan(TestCerts::sTestCert_Node02_01_PrivateKey, TestCerts::sTestCert_Node02_01_PrivateKey_Len)); ReturnErrorOnFailure(mFabricTable.AddNewFabric(bobFabric, &mBobFabricIndex)); ReturnErrorOnFailure(CreateSessionBobToAlice());