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

Use exchange for session establishment and provisioning #5938

Merged
merged 18 commits into from
Apr 14, 2021

Conversation

pan-apple
Copy link
Contributor

Problem

Session establishment doesn't use exchange or reliable messaging.

Summary of Changes

  • Add concept of ExchangeTransport to distinguish between encrypted
    and unencrypted message exchanges
  • Update PASE to use exchange manager to send/receive messages
  • Update network provisioning code to use exchange manager

Fixes #2240, Fixes #2243

@todo
Copy link

todo bot commented Apr 10, 2021

This is needed for time being, as ServiceProvisioning is used for opening pairing window.

// TODO: This is needed for time being, as ServiceProvisioning is used for opening pairing window.
err = gExchangeMgr.RegisterUnsolicitedMessageHandlerForProtocol(Protocols::ServiceProvisioning::Id, &gCallbacks);
SuccessOrExit(err);
#if defined(CHIP_APP_USE_ECHO)
err = InitEchoHandler(&gExchangeMgr);
SuccessOrExit(err);


This comment was generated by todo based on a TODO comment in 33af7ef in #5938. cc @pan-apple.

@todo
Copy link

todo bot commented Apr 10, 2021

Change this check to only include the protocol and message types that are allowed

// TODO: Change this check to only include the protocol and message types that are allowed
switch (protocol)
{
case Protocols::SecureChannel::Id.GetProtocolId():
switch (static_cast<Protocols::SecureChannel::MsgType>(type))
{
case Protocols::SecureChannel::MsgType::PBKDFParamRequest:
case Protocols::SecureChannel::MsgType::PBKDFParamResponse:
case Protocols::SecureChannel::MsgType::PASE_Spake2p1:
case Protocols::SecureChannel::MsgType::PASE_Spake2p2:
case Protocols::SecureChannel::MsgType::PASE_Spake2p3:


This comment was generated by todo based on a TODO comment in 33af7ef in #5938. cc @pan-apple.

@todo
Copy link

todo bot commented Apr 10, 2021

Figure out which channel to use for the received message

// TODO: Figure out which channel to use for the received message
ec = AllocContext(payloadHeader.GetExchangeID(), session, !payloadHeader.IsInitiator(), nullptr);
}
else


This comment was generated by todo based on a TODO comment in 33af7ef in #5938. cc @pan-apple.

@todo
Copy link

todo bot commented Apr 10, 2021

Register for specific message types, as CASE and PASE share the same protocol ID

// TODO: Register for specific message types, as CASE and PASE share the same protocol ID
return mExchangeMgr->RegisterUnsolicitedMessageHandlerForProtocol(Protocols::SecureChannel::Id, this);
}
void MessageCounterSyncMgr::Shutdown()


This comment was generated by todo based on a TODO comment in 33af7ef in #5938. cc @pan-apple.

@pan-apple pan-apple force-pushed the pase-over-exchange branch 2 times, most recently from 2972729 to b84ebb7 Compare April 12, 2021 23:38
@pan-apple
Copy link
Contributor Author

rebased

src/messaging/ApplicationExchangeTransport.cpp Outdated Show resolved Hide resolved
src/messaging/ApplicationExchangeTransport.cpp Outdated Show resolved Hide resolved
src/messaging/ExchangeTransport.cpp Outdated Show resolved Hide resolved
src/messaging/ExchangeTransport.cpp Outdated Show resolved Hide resolved
src/messaging/ExchangeTransport.cpp Outdated Show resolved Hide resolved
src/protocols/secure_channel/NetworkProvisioning.cpp Outdated Show resolved Hide resolved
src/protocols/secure_channel/NetworkProvisioning.cpp Outdated Show resolved Hide resolved
src/protocols/secure_channel/NetworkProvisioning.h Outdated Show resolved Hide resolved
src/transport/PairingSession.h Outdated Show resolved Hide resolved
@yunhanw-google
Copy link
Contributor

@pan-apple the im cirque test is faling after sending several im commands, in case you wanna locally reproduce it, you can use
To start the Server, run the built executable.

$ ./chip-im-responder
To start the Client, run the built executable and pass it the IP address of the server to talk to.

$ ./chip-im-initiator <Server's IPv4 address>

src/app/server/Server.cpp Outdated Show resolved Hide resolved
src/messaging/ExchangeContext.h Show resolved Hide resolved
src/messaging/ExchangeContext.h Outdated Show resolved Hide resolved
src/messaging/ExchangeContext.h Outdated Show resolved Hide resolved
src/messaging/ExchangeDelegate.h Show resolved Hide resolved
src/messaging/ExchangeMgr.cpp Show resolved Hide resolved
src/messaging/ExchangeMgr.cpp Show resolved Hide resolved
src/messaging/ExchangeMgr.cpp Show resolved Hide resolved
src/messaging/ExchangeTransport.h Outdated Show resolved Hide resolved
Comment on lines +45 to +46
// TODO: Register for specific message types, as CASE and PASE share the same protocol ID
return mExchangeMgr->RegisterUnsolicitedMessageHandlerForProtocol(Protocols::SecureChannel::Id, this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use RegisterUnsolicitedMessageHandlerForType here now to register only MCSP messages, otherwise, all PASE/CASE messages will be received by MessageCounterSync class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing code is registering for the protocol type. I tried changing to only MCSP messages, but some tests are failing. That's why I added TODO so this can be tracked in an issue and fixed in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that indicates a problem, by design, each protocol should only have one protocol delegate, since the message is moved not copied.

Now, there are two entities both register to receive SecureChannel message, it is really depending on registration order, the first one will be overridden by the second one.

Registering by different message type is also a workaround, but it should works, ideally, we should use SecureChannel protocol delegate to dispatch the messages, but we can leave it later as TODO

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets have an issue ticket to follow up here if the PASE messages are consumed by MCSP first, then PASE protocol should not receive the message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, TODO bot will file the ticket once this PR is merged.

@yufengwangca
Copy link
Contributor

I noticed there are more than 300 bytes increase on BSS after this refactor, I guess this is mainly caused by moving Transport to ExchangeContext, it should go back to normal if we keep the transport handling all within ExchangeMgr.

src/messaging/ExchangeContext.cpp Show resolved Hide resolved
src/messaging/ExchangeTransport.h Outdated Show resolved Hide resolved
src/messaging/ExchangeTransport.cpp Outdated Show resolved Hide resolved
src/messaging/ExchangeContext.cpp Outdated Show resolved Hide resolved
#endif
}

if (!IsTransportReliable() && reliableMessageContext.AutoRequestAck() && mReliableMessageMgr != nullptr &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks isReliableTransmission is just translated from it is requested, we should also check the low level Transport type. CRMP is not needed for TCP

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expectation is that IsTransportReliable() method for TCP based exchange transport (e.g. SessionEstablishmentExchangeTransportTCP) will return True.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ApplicationExchangeDispatch should support both TCP and UDP right? if I run chip-shell ping -t , the message should also go through ApplicationExchangeDispatch, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ApplicationExchangeDispatch will be used by IM messages. Those should all be UDP only.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets have a ticket to follow up here, since all of our examples still support TCP option now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/messaging/ExchangeMgr.h Outdated Show resolved Hide resolved
src/messaging/ExchangeContext.h Outdated Show resolved Hide resolved
@yufengwangca yufengwangca merged commit 362c5f2 into project-chip:master Apr 14, 2021
@github-actions
Copy link

Size increase report for "nrfconnect-example-build" from 6130e4a

File Section File VM
chip-lighting.elf text 1016 1016
chip-lighting.elf rodata 584 584
chip-lighting.elf bss 0 137
chip-lighting.elf [LOAD #3 [RW]] 0 23
chip-lighting.elf devices 4 4
chip-lighting.elf device_handles -8 -8
chip-lighting.elf datas -12 -12
chip-shell.elf text 1316 1316
chip-shell.elf rodata 784 788
chip-shell.elf [LOAD #3 [RW]] 0 23
chip-shell.elf bss 0 9
chip-shell.elf device_handles -4 -4
chip-lock.elf text 1016 1016
chip-lock.elf rodata 584 584
chip-lock.elf bss 0 129
chip-lock.elf [LOAD #3 [RW]] 0 31
chip-lock.elf devices -4 -4
chip-lock.elf device_handles -8 -8
chip-lock.elf datas -12 -12
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-lighting.elf and ./pull_artifact/chip-lighting.elf:

sections,vmsize,filesize
.debug_info,0,179495
.debug_line,0,15953
.debug_abbrev,0,12056
.debug_str,0,5217
.strtab,0,3281
.symtab,0,1456
text,1016,1016
.debug_frame,0,996
.debug_loc,0,699
rodata,584,584
.debug_ranges,0,512
.debug_aranges,0,344
bss,137,0
[LOAD #3 [RW]],23,0
devices,4,4
.shstrtab,0,3
device_handles,-8,-8
datas,-12,-12

Comparing ./master_artifact/chip-shell.elf and ./pull_artifact/chip-shell.elf:

sections,vmsize,filesize
.debug_info,0,129412
.debug_line,0,14575
.debug_abbrev,0,11101
.debug_str,0,4857
.debug_loc,0,4091
.strtab,0,3035
.symtab,0,1424
text,1316,1316
.debug_frame,0,1068
.debug_ranges,0,1024
rodata,788,784
.debug_aranges,0,376
[LOAD #3 [RW]],23,0
bss,9,0
.shstrtab,0,1
device_handles,-4,-4

Comparing ./master_artifact/chip-lock.elf and ./pull_artifact/chip-lock.elf:

sections,vmsize,filesize
.debug_info,0,179459
.debug_line,0,15937
.debug_abbrev,0,12056
.debug_str,0,5206
.strtab,0,3281
.symtab,0,1456
text,1016,1016
.debug_frame,0,996
.debug_loc,0,698
rodata,584,584
.debug_ranges,0,512
.debug_aranges,0,344
bss,129,0
[LOAD #3 [RW]],31,0
.shstrtab,0,-1
devices,-4,-4
device_handles,-8,-8
datas,-12,-12


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants