Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message counter implementation #5389

Merged
merged 10 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions examples/shell/shell_common/cmd_ping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <messaging/ExchangeMgr.h>
#include <platform/CHIPDeviceLayer.h>
#include <protocols/echo/Echo.h>
#include <protocols/secure_channel/MessageCounterManager.h>
#include <protocols/secure_channel/PASESession.h>
#include <system/SystemPacketBuffer.h>
#include <transport/SecureSessionMgr.h>
Expand Down Expand Up @@ -269,7 +270,8 @@ void StartPinging(streamer_t * stream, char * destination)
{
peerAddress = Transport::PeerAddress::TCP(gDestAddr, gPingArguments.GetEchoPort());

err = gSessionManager.Init(kTestControllerNodeId, &DeviceLayer::SystemLayer, &gTCPManager, &admins);
err =
gSessionManager.Init(kTestControllerNodeId, &DeviceLayer::SystemLayer, &gTCPManager, &admins, &gMessageCounterManager);
SuccessOrExit(err);

err = gExchangeManager.Init(&gSessionManager);
Expand All @@ -280,13 +282,17 @@ void StartPinging(streamer_t * stream, char * destination)
{
peerAddress = Transport::PeerAddress::UDP(gDestAddr, gPingArguments.GetEchoPort(), INET_NULL_INTERFACEID);

err = gSessionManager.Init(kTestControllerNodeId, &DeviceLayer::SystemLayer, &gUDPManager, &admins);
err =
gSessionManager.Init(kTestControllerNodeId, &DeviceLayer::SystemLayer, &gUDPManager, &admins, &gMessageCounterManager);
SuccessOrExit(err);

err = gExchangeManager.Init(&gSessionManager);
SuccessOrExit(err);
}

err = gMessageCounterManager.Init(&gExchangeManager);
SuccessOrExit(err);

// Start the CHIP connection to the CHIP echo responder.
err = EstablishSecureSession(stream, peerAddress);
SuccessOrExit(err);
Expand Down
18 changes: 10 additions & 8 deletions examples/shell/shell_common/cmd_send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,24 +256,26 @@ void ProcessCommand(streamer_t * stream, char * destination)
{
peerAddress = Transport::PeerAddress::TCP(gDestAddr, gSendArguments.GetPort());

err = gSessionManager.Init(kTestControllerNodeId, &DeviceLayer::SystemLayer, &gTCPManager, &admins);
SuccessOrExit(err);

err = gExchangeManager.Init(&gSessionManager);
err =
gSessionManager.Init(kTestControllerNodeId, &DeviceLayer::SystemLayer, &gTCPManager, &admins, &gMessageCounterManager);
SuccessOrExit(err);
}
else
#endif
{
peerAddress = Transport::PeerAddress::UDP(gDestAddr, gSendArguments.GetPort(), INET_NULL_INTERFACEID);

err = gSessionManager.Init(kTestControllerNodeId, &DeviceLayer::SystemLayer, &gUDPManager, &admins);
SuccessOrExit(err);

err = gExchangeManager.Init(&gSessionManager);
err =
gSessionManager.Init(kTestControllerNodeId, &DeviceLayer::SystemLayer, &gUDPManager, &admins, &gMessageCounterManager);
SuccessOrExit(err);
}

err = gExchangeManager.Init(&gSessionManager);
SuccessOrExit(err);

err = gMessageCounterManager.Init(&gExchangeManager);
SuccessOrExit(err);

// Start the CHIP connection to the CHIP server.
err = EstablishSecureSession(stream, peerAddress);
SuccessOrExit(err);
Expand Down
1 change: 1 addition & 0 deletions examples/shell/shell_common/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <Globals.h>

chip::secure_channel::MessageCounterManager gMessageCounterManager;
chip::Messaging::ExchangeManager gExchangeManager;
chip::SecureSessionMgr gSessionManager;
chip::Inet::IPAddress gDestAddr;
Expand Down
2 changes: 2 additions & 0 deletions examples/shell/shell_common/include/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <lib/core/CHIPCore.h>
#include <messaging/ExchangeMgr.h>
#include <protocols/secure_channel/MessageCounterManager.h>
#include <transport/SecureSessionMgr.h>
#include <transport/raw/TCP.h>
#include <transport/raw/UDP.h>
Expand All @@ -30,6 +31,7 @@ constexpr size_t kMaxTcpPendingPackets = 4;
constexpr size_t kMaxPayloadSize = 1280;
constexpr size_t kResponseTimeOut = 1000;

extern chip::secure_channel::MessageCounterManager gMessageCounterManager;
extern chip::Messaging::ExchangeManager gExchangeManager;
extern chip::SecureSessionMgr gSessionManager;
extern chip::Inet::IPAddress gDestAddr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ bool emberAfOperationalCredentialsClusterSetFabricCallback(chip::app::Command *

SuccessOrExit(err = commandObj->PrepareCommand(&cmdParams));
writer = commandObj->GetCommandDataElementTLVWriter();
SuccessOrExit(
err = writer->Put(TLV::ContextTag(0), commandObj->GetExchangeContext()->GetSecureSessionHandle().GetPeerNodeId()));
SuccessOrExit(err = writer->Put(TLV::ContextTag(0), commandObj->GetExchangeContext()->GetSecureSession().GetPeerNodeId()));
SuccessOrExit(err = commandObj->FinishCommand());
}

Expand Down
7 changes: 6 additions & 1 deletion src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <messaging/ExchangeMgr.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/KeyValueStoreManager.h>
#include <protocols/secure_channel/MessageCounterManager.h>
#include <setup_payload/SetupPayload.h>
#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
Expand Down Expand Up @@ -397,6 +398,7 @@ class ServerCallback : public ExchangeDelegate
SecureSessionMgr * mSessionMgr = nullptr;
};

secure_channel::MessageCounterManager gMessageCounterManager;
ServerCallback gCallbacks;
SecurePairingUsingTestSecret gTestPairing;

Expand Down Expand Up @@ -507,11 +509,14 @@ void InitServer(AppDelegate * delegate)

SuccessOrExit(err);

err = gSessions.Init(chip::kTestDeviceNodeId, &DeviceLayer::SystemLayer, &gTransports, &gAdminPairings);
err =
gSessions.Init(chip::kTestDeviceNodeId, &DeviceLayer::SystemLayer, &gTransports, &gAdminPairings, &gMessageCounterManager);
SuccessOrExit(err);

err = gExchangeMgr.Init(&gSessions);
SuccessOrExit(err);
err = gMessageCounterManager.Init(&gExchangeMgr);
SuccessOrExit(err);

err = chip::app::InteractionModelEngine::GetInstance()->Init(&gExchangeMgr, nullptr);
SuccessOrExit(err);
Expand Down
8 changes: 7 additions & 1 deletion src/app/tests/TestCommandInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <messaging/ExchangeMgr.h>
#include <messaging/Flags.h>
#include <platform/CHIPDeviceLayer.h>
#include <protocols/secure_channel/MessageCounterManager.h>
#include <protocols/secure_channel/PASESession.h>
#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
Expand All @@ -49,6 +50,7 @@ static System::Layer gSystemLayer;
static SecureSessionMgr gSessionManager;
static Messaging::ExchangeManager gExchangeManager;
static TransportMgr<Transport::UDP> gTransportManager;
static secure_channel::MessageCounterManager gMessageCounterManager;
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
static Transport::AdminId gAdminId = 0;

namespace app {
Expand Down Expand Up @@ -311,12 +313,16 @@ void InitializeChip(nlTestSuite * apSuite)

chip::gSystemLayer.Init(nullptr);

err = chip::gSessionManager.Init(chip::kTestDeviceNodeId, &chip::gSystemLayer, &chip::gTransportManager, &admins);
err = chip::gSessionManager.Init(chip::kTestDeviceNodeId, &chip::gSystemLayer, &chip::gTransportManager, &admins,
&chip::gMessageCounterManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = chip::gExchangeManager.Init(&chip::gSessionManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = chip::gMessageCounterManager.Init(&chip::gExchangeManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = chip::app::InteractionModelEngine::GetInstance()->Init(&chip::gExchangeManager, nullptr);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
}
Expand Down
7 changes: 6 additions & 1 deletion src/app/tests/TestEventLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <messaging/ExchangeMgr.h>
#include <messaging/Flags.h>
#include <platform/CHIPDeviceLayer.h>
#include <protocols/secure_channel/MessageCounterManager.h>
#include <protocols/secure_channel/PASESession.h>
#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
Expand Down Expand Up @@ -63,6 +64,7 @@ static chip::app::CircularEventBuffer gCircularEventBuffer[3];

chip::SecureSessionMgr gSessionManager;
chip::Messaging::ExchangeManager gExchangeManager;
chip::secure_channel::MessageCounterManager gMessageCounterManager;

void InitializeChip(nlTestSuite * apSuite)
{
Expand All @@ -78,11 +80,14 @@ void InitializeChip(nlTestSuite * apSuite)

gSystemLayer.Init(nullptr);

err = gSessionManager.Init(chip::kTestDeviceNodeId, &gSystemLayer, &gTransportManager, &admins);
err = gSessionManager.Init(chip::kTestDeviceNodeId, &gSystemLayer, &gTransportManager, &admins, &gMessageCounterManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = gExchangeManager.Init(&gSessionManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = gMessageCounterManager.Init(&gExchangeManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
}

void InitializeEventLogging()
Expand Down
7 changes: 6 additions & 1 deletion src/app/tests/TestInteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <messaging/ExchangeMgr.h>
#include <messaging/Flags.h>
#include <platform/CHIPDeviceLayer.h>
#include <protocols/secure_channel/MessageCounterManager.h>
#include <protocols/secure_channel/PASESession.h>
#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
Expand All @@ -45,6 +46,7 @@ namespace {
static chip::System::Layer gSystemLayer;
static chip::SecureSessionMgr gSessionManager;
static chip::Messaging::ExchangeManager gExchangeManager;
static chip::secure_channel::MessageCounterManager gMessageCounterManager;
static chip::TransportMgr<chip::Transport::UDP> gTransportManager;
static const chip::Transport::AdminId gAdminId = 0;
} // namespace
Expand Down Expand Up @@ -117,11 +119,14 @@ void InitializeChip(nlTestSuite * apSuite)

gSystemLayer.Init(nullptr);

err = gSessionManager.Init(chip::kTestDeviceNodeId, &gSystemLayer, &gTransportManager, &admins);
err = gSessionManager.Init(chip::kTestDeviceNodeId, &gSystemLayer, &gTransportManager, &admins, &gMessageCounterManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = gExchangeManager.Init(&gSessionManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = gMessageCounterManager.Init(&gExchangeManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
}

// clang-format off
Expand Down
8 changes: 7 additions & 1 deletion src/app/tests/TestReadInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <messaging/ExchangeMgr.h>
#include <messaging/Flags.h>
#include <platform/CHIPDeviceLayer.h>
#include <protocols/secure_channel/MessageCounterManager.h>
#include <protocols/secure_channel/PASESession.h>
#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
Expand All @@ -47,6 +48,7 @@ SecureSessionMgr gSessionManager;
Messaging::ExchangeManager gExchangeManager;
TransportMgr<Transport::UDP> gTransportManager;
const Transport::AdminId gAdminId = 0;
secure_channel::MessageCounterManager gMessageCounterManager;
kghost marked this conversation as resolved.
Show resolved Hide resolved

namespace app {
class TestReadInteraction
Expand Down Expand Up @@ -157,11 +159,15 @@ void InitializeChip(nlTestSuite * apSuite)

chip::gSystemLayer.Init(nullptr);

err = chip::gSessionManager.Init(chip::kTestDeviceNodeId, &chip::gSystemLayer, &chip::gTransportManager, &admins);
err = chip::gSessionManager.Init(chip::kTestDeviceNodeId, &chip::gSystemLayer, &chip::gTransportManager, &admins,
&chip::gMessageCounterManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = chip::gExchangeManager.Init(&chip::gSessionManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = chip::gMessageCounterManager.Init(&chip::gExchangeManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/app/tests/TestReportingEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <messaging/ExchangeMgr.h>
#include <messaging/Flags.h>
#include <platform/CHIPDeviceLayer.h>
#include <protocols/secure_channel/MessageCounterManager.h>
#include <protocols/secure_channel/PASESession.h>
#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
Expand All @@ -47,6 +48,7 @@ static System::Layer gSystemLayer;
static SecureSessionMgr gSessionManager;
static Messaging::ExchangeManager gExchangeManager;
static TransportMgr<Transport::UDP> gTransportManager;
static secure_channel::MessageCounterManager gMessageCounterManager;
kghost marked this conversation as resolved.
Show resolved Hide resolved
static const Transport::AdminId gAdminId = 0;
constexpr ClusterId kTestClusterId = 6;
constexpr EndpointId kTestEndpointId = 1;
Expand Down Expand Up @@ -153,11 +155,15 @@ void InitializeChip(nlTestSuite * apSuite)

chip::gSystemLayer.Init(nullptr);

err = chip::gSessionManager.Init(chip::kTestDeviceNodeId, &chip::gSystemLayer, &chip::gTransportManager, &admins);
err = chip::gSessionManager.Init(chip::kTestDeviceNodeId, &chip::gSystemLayer, &chip::gTransportManager, &admins,
&chip::gMessageCounterManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = chip::gExchangeManager.Init(&chip::gSessionManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = chip::gMessageCounterManager.Init(&chip::gExchangeManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
}

// clang-format off
Expand Down
9 changes: 7 additions & 2 deletions src/app/tests/integration/chip_im_initiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <core/CHIPCore.h>
#include <mutex>
#include <platform/CHIPDeviceLayer.h>
#include <protocols/secure_channel/MessageCounterManager.h>
#include <protocols/secure_channel/PASESession.h>
#include <support/ErrorStr.h>
#include <system/SystemPacketBuffer.h>
Expand All @@ -56,8 +57,8 @@ chip::app::CommandSender * gpCommandSender = nullptr;
chip::app::ReadClient * gpReadClient = nullptr;

chip::TransportMgr<chip::Transport::UDP> gTransportManager;

chip::SecureSessionMgr gSessionManager;
chip::secure_channel::MessageCounterManager gMessageCounterManager;
kghost marked this conversation as resolved.
Show resolved Hide resolved

chip::Inet::IPAddress gDestAddr;

Expand Down Expand Up @@ -317,12 +318,16 @@ int main(int argc, char * argv[])
.SetListenPort(IM_CLIENT_PORT));
SuccessOrExit(err);

err = gSessionManager.Init(chip::kTestControllerNodeId, &chip::DeviceLayer::SystemLayer, &gTransportManager, &admins);
err = gSessionManager.Init(chip::kTestControllerNodeId, &chip::DeviceLayer::SystemLayer, &gTransportManager, &admins,
&gMessageCounterManager);
SuccessOrExit(err);

err = gExchangeManager.Init(&gSessionManager);
SuccessOrExit(err);

err = gMessageCounterManager.Init(&gExchangeManager);
SuccessOrExit(err);

err = chip::app::InteractionModelEngine::GetInstance()->Init(&gExchangeManager, &mockDelegate);
SuccessOrExit(err);

Expand Down
8 changes: 7 additions & 1 deletion src/app/tests/integration/chip_im_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <messaging/ExchangeMgr.h>
#include <messaging/Flags.h>
#include <platform/CHIPDeviceLayer.h>
#include <protocols/secure_channel/MessageCounterManager.h>
#include <protocols/secure_channel/PASESession.h>
#include <support/ErrorStr.h>
#include <system/SystemPacketBuffer.h>
Expand Down Expand Up @@ -125,6 +126,7 @@ namespace {
chip::TransportMgr<chip::Transport::UDP> gTransportManager;
chip::SecureSessionMgr gSessionManager;
chip::SecurePairingUsingTestSecret gTestPairing;
chip::secure_channel::MessageCounterManager gMessageCounterManager;
kghost marked this conversation as resolved.
Show resolved Hide resolved
LivenessEventGenerator gLivenessGenerator;

uint8_t gDebugEventBuffer[2048];
Expand Down Expand Up @@ -162,12 +164,16 @@ int main(int argc, char * argv[])
chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer).SetAddressType(chip::Inet::kIPAddressType_IPv4));
SuccessOrExit(err);

err = gSessionManager.Init(chip::kTestDeviceNodeId, &chip::DeviceLayer::SystemLayer, &gTransportManager, &admins);
err = gSessionManager.Init(chip::kTestDeviceNodeId, &chip::DeviceLayer::SystemLayer, &gTransportManager, &admins,
&gMessageCounterManager);
SuccessOrExit(err);

err = gExchangeManager.Init(&gSessionManager);
SuccessOrExit(err);

err = gMessageCounterManager.Init(&gExchangeManager);
SuccessOrExit(err);

err = chip::app::InteractionModelEngine::GetInstance()->Init(&gExchangeManager, &mockDelegate);
SuccessOrExit(err);

Expand Down
Loading