Skip to content

Commit

Permalink
Resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kghost committed Mar 17, 2022
1 parent fc02b0d commit 4ef2ea7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
5 changes: 2 additions & 3 deletions src/app/tests/TestWriteInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,9 @@ int Test_Setup(void * inContext)
TestContext & ctx = *static_cast<TestContext *>(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;
Expand Down
5 changes: 3 additions & 2 deletions src/credentials/FabricTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,15 +809,16 @@ 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();

ReturnErrorOnFailure(SetRootCert(rootCert));
ReturnErrorOnFailure(SetICACert(icacCert));
ReturnErrorOnFailure(SetNOCCert(nocCert));

// NOTE: this requres ENABLE_HSM_CASE_OPS_KEY is not defined
P256SerializedKeypair opKeysSerialized;
memcpy(static_cast<uint8_t *>(opKeysSerialized), nodePubKey.data(), nodePubKey.size());
memcpy(static_cast<uint8_t *>(opKeysSerialized) + nodePubKey.size(), nodePrivateKey.data(), nodePrivateKey.size());
Expand Down
3 changes: 2 additions & 1 deletion src/credentials/FabricTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
22 changes: 12 additions & 10 deletions src/messaging/tests/MessagingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 4ef2ea7

Please sign in to comment.