Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
nanocoap: follow-up fixes #17950
nanocoap: follow-up fixes #17950
Changes from all commits
a5bc3cc
3ac258c
c22b124
e2fe9d0
bd7fe3b
85833ab
b20f899
bb4c597
5deea31
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Seems like we should actually be setting the token (which is 0 right now) to maybe
num
and then check on that instead ofelse if (coap_get_id(pkt) != id)
, would that be correct @maribu?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.
Note that a zero length token is still a valid token. The standard asks for 32 bit of entropy in the Token if a device is connected to the Internet, though:
https://datatracker.ietf.org/doc/html/rfc7252#section-5.3.1
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.
Yep
In that case, the default token length should at least be 4bytes, thinking of gcoap default
RIOT/sys/include/net/gcoap.h
Lines 482 to 490 in e64b1bd
Although for this specific use-case, I guess if a block option is set it could check that the blknum matches what is expected, keeping the token field to 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 the individual blocks require different tokens or is this considered a single transfer, so the same token for all blocks?
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.
It would be different tokens for each block request, but I think you could leave it empty and check in the
nanocoap_sock_request_cb
callcoap_get_block2(pkt, &block2);
on the request and response, and if its there is a block option and theblknum
does not match retry reception. But this optimization is maybe a bit of a hack to save the token bytes...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.
It is up to the client and needs to aid the client to identify the right response. With NSTART=1 only duplicates (trivial to detect with blockwise) and spoofed responses are needed to be told apart from the right one. In case of UDP transport, one cannot really defend against spoofed responses, but having same entropy in the Token at least requires the adversary to be able to listen to the requests. The standard specifically says 32 bits of randomness and not reusing Tokens for the same source and destination endpoints is what SHOULD be done.
The common strategy is to just use a properly seeded PRNG for generating the token and hope for the best.
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.
Since we don't include a token yet in the request, how about we move this to a follow-up PR?