-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
API SecureManager::SendMessage, use SecureSessoinHandle instead NodeId #3728
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -334,24 +334,57 @@ CHIP_ERROR DeviceController::ServiceEventSignal() | |
return err; | ||
} | ||
|
||
void DeviceController::OnNewConnection(const Transport::PeerConnectionState * peerConnection, SecureSessionMgr * mgr) {} | ||
void DeviceController::OnNewConnection(SecureSessionHandle session, SecureSessionMgr * mgr) | ||
{ | ||
CHIP_ERROR err = CHIP_NO_ERROR; | ||
uint16_t index = 0; | ||
|
||
VerifyOrExit(mState == State::Initialized, err = CHIP_ERROR_INCORRECT_STATE); | ||
|
||
index = FindDeviceIndex(mgr->GetPeerConnectionState(session)->GetPeerNodeId()); | ||
VerifyOrExit(index < kNumMaxActiveDevices, err = CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR); | ||
|
||
mActiveDevices[index].OnNewConnection(session, mgr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes the device object use the secure session corresponding to the keyID that was derived during pairing (which is based on SPAKE2P handshake). How will it switch to using the key derived by SIGMA handshake (which is more secure, and should typically be used for all communication once pairing process is complete). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I'm not quite understand your question, but IMHO, If the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, let me rephrase the question. It's two parts.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have created another PR to address the problem (#4171), Let's continue the discussion on that PR. |
||
|
||
exit: | ||
if (err != CHIP_NO_ERROR) | ||
{ | ||
ChipLogError(Controller, "Failed to process received message: err %d", err); | ||
} | ||
} | ||
|
||
void DeviceController::OnConnectionExpired(SecureSessionHandle session, SecureSessionMgr * mgr) | ||
{ | ||
CHIP_ERROR err = CHIP_NO_ERROR; | ||
uint16_t index = 0; | ||
|
||
VerifyOrExit(mState == State::Initialized, err = CHIP_ERROR_INCORRECT_STATE); | ||
|
||
index = FindDeviceIndex(session); | ||
VerifyOrExit(index < kNumMaxActiveDevices, err = CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR); | ||
|
||
mActiveDevices[index].OnConnectionExpired(session, mgr); | ||
|
||
exit: | ||
if (err != CHIP_NO_ERROR) | ||
{ | ||
ChipLogError(Controller, "Failed to process received message: err %d", err); | ||
} | ||
} | ||
|
||
void DeviceController::OnMessageReceived(const PacketHeader & header, const PayloadHeader & payloadHeader, | ||
const Transport::PeerConnectionState * state, System::PacketBufferHandle msgBuf, | ||
SecureSessionMgr * mgr) | ||
SecureSessionHandle session, System::PacketBufferHandle msgBuf, SecureSessionMgr * mgr) | ||
{ | ||
CHIP_ERROR err = CHIP_NO_ERROR; | ||
uint16_t index = 0; | ||
NodeId peer; | ||
|
||
VerifyOrExit(mState == State::Initialized, err = CHIP_ERROR_INCORRECT_STATE); | ||
VerifyOrExit(header.GetSourceNodeId().HasValue(), err = CHIP_ERROR_INVALID_ARGUMENT); | ||
|
||
peer = header.GetSourceNodeId().Value(); | ||
index = FindDeviceIndex(peer); | ||
index = FindDeviceIndex(session); | ||
VerifyOrExit(index < kNumMaxActiveDevices, err = CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR); | ||
|
||
mActiveDevices[index].OnMessageReceived(header, payloadHeader, state, std::move(msgBuf), mgr); | ||
mActiveDevices[index].OnMessageReceived(header, payloadHeader, session, std::move(msgBuf), mgr); | ||
|
||
exit: | ||
if (err != CHIP_NO_ERROR) | ||
|
@@ -395,6 +428,20 @@ void DeviceController::ReleaseAllDevices() | |
} | ||
} | ||
|
||
uint16_t DeviceController::FindDeviceIndex(SecureSessionHandle session) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is what the code used to look like with node id, but is there a reason this is not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While audit the usage of We can refactor it in another PR. but here I want to keep it consistent with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, followup is fine. Just file an issue, please. |
||
{ | ||
uint16_t i = 0; | ||
while (i < kNumMaxActiveDevices) | ||
{ | ||
if (mActiveDevices[i].IsActive() && mActiveDevices[i].IsSecureConnected() && mActiveDevices[i].MatchesSession(session)) | ||
{ | ||
return i; | ||
} | ||
i++; | ||
} | ||
return i; | ||
} | ||
|
||
uint16_t DeviceController::FindDeviceIndex(NodeId id) | ||
{ | ||
uint16_t i = 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we expect
SecureSessionHandle
to always be copyable? Or are we likely to switch to move semantics on it at some point? Put another way, should there be anstd::move()
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll expect that the handle is POD, and always be copyable. In the future, only messaging layer will use the handle, the handle class won't be exposed to applications or controller API.