-
Notifications
You must be signed in to change notification settings - Fork 1.4k
treewide: cellular: add support for debug sectags #21727
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
Conversation
7661466 to
ab6606b
Compare
CI InformationTo view the history of this post, clich the 'edited' button above Inputs:Sources:sdk-nrf: PR head: 6697b984aeaff775a267bca29e6b4ddf904b86e5 more detailssdk-nrf:
Github labels
List of changed files detected by CI (8)Outputs:ToolchainVersion: 7cbc0036f4 Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped;
|
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.
Knowing that the normal sectag range is from 0 to 2147483647 and for enabling debugging is 0x80000000 - 0x8000000F, this condition will always be valid.
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.
modem_shell works fine with debug sec_tags without this change, but this change breaks the functionality with all sec_tags. Also, using -1 with an unsigned integer does not look nice.
BTW, the last sec_tag reserved for debugging is 2147483667, i.e. 0x80000013.
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.
right, I got the condition the wrong way around. is if (sec_tag == -1) { okay?
The current check does nothing, with the change, you check if the parameter was set.
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.
That works, but I would rather not use -1 with an unsigned integer. The variable can not be made signed (32-bit) integer either, because the debug sec_tag values are larger than it can represent.
Because 0 is also a valid value, I think it would be best to use 0xFFFFFFFF to indicate that no sec_tag value was given. Maybe add a define for that as well.
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.
@tokangas I added a new macro for invalid sec tags with value 0xFFFFFFFF to libmodem, hopefully this will help addressing the current limitations.
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.
@MirkoCovizzi Thanks, I think that's a good idea.
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.
@MirkoCovizzi Did you confirm with the modem team that 0xFFFFFFFF is not used internally for other things? I see that 0xFFFFFFFE is in use for DEV_ID_PUB_KEY.
|
You can find the documentation preview for this PR here. |
MarkusLassila
left a comment
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.
SLM
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.
modem_shell works fine with debug sec_tags without this change, but this change breaks the functionality with all sec_tags. Also, using -1 with an unsigned integer does not look nice.
BTW, the last sec_tag reserved for debugging is 2147483667, i.e. 0x80000013.
nRF91 modems support special sectags to trace TLS ephemeral keys, but these checks mark those as invalid. This patch removes checks and changes some of them to check for -1, which is not one of the debug sectags. Signed-off-by: Maximilian Deubel <[email protected]>
ab6606b to
6697b98
Compare
|
There are several places where the |
| } | ||
|
|
||
| if (sec_tag < 0) { | ||
| if (sec_tag == -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.
I would also recommend to validate if the sec_tag is out of range
if (sec_tag > 0x8000000F) { mosh_error("Invalid security tag"); }
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.
If the check is added, the correct value is 2147483667 (0x80000013).
Transport Layer Security (TLS) traffic can be decrypted with Nordic tools if the TLS
session is created using certificates stored to <sec_tag>s 2147483648– 2147483667.
These <sec_tag>s shall be used only for test and development purposes.
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.
You are right, the maximum value is up to 0x80000013
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.
Range check in modem_shell is not absolutely needed because we do allow testing for some invalid inputs to test other parts of the SW. In this case, I'll leave it to you to decide if it would still be better to have it 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.
For modem_shell I'll vote for not having this check, because from modem fw any sec_tag is valid.
SeppoTakalo
left a comment
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.
I would propose that we don't fix the code like this.
Seems like on may locations we have used -1 to mark a sec_tag that has not been set.
However, as now found out by, this have introduced bugs.
On some run-time checks the sec_tag < 0 offcourse always fails as sec_tag_t is unsigned, as it should be.
If we want to continue like this, we MUST be using only sec_tag_t to store sec tags. Not int and uint32_t mix and max.
So if we refactor, I would accept that we refactor every API to use proper sec_tag_t.
Then runtime checks, if we use (-1) it should ONLY be (sec_tag_t)(-1) and the check can ONLY be if (sec_tag = INVALID_SEC_TAG) .
Only then we can expect that -1 conversion is always the same.
| const char *file; | ||
| int sec_tag = SEC_TAG; | ||
| uint8_t sec_tag_count = sec_tag < 0 ? 0 : 1; | ||
| uint8_t sec_tag_count = 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.
This introduces a bug.
Now it sets as sec_tag count to one, even if sec_tag is not configured.
This file needs refactoring. Usage of HTTPS is controlled by CONFIG_USE_HTTPS but in the code, it uses runtime check if sec_tag is (-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.
Do we need to count the amount of sec_tags or should we just need to know that there is a sec_tag? Seems to me that is more than enough to know the presence of a sec_tag
| if (param_count > 4) { | ||
| if (at_parser_num_get(parser, 4, &proxy.sec_tag) | ||
| || proxy.sec_tag == INVALID_SEC_TAG || proxy.sec_tag < 0) { | ||
| || proxy.sec_tag == INVALID_SEC_TAG) { |
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.
Seem to be an existing bug in this file.
proxy.sec_tag is unsigned, and therefore cannot be < 0.
| const char *file; | ||
| int sec_tag = SEC_TAG; | ||
| uint8_t sec_tag_count = sec_tag < 0 ? 0 : 1; | ||
| uint8_t sec_tag_count = 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.
This introduces a bug.
Now it sets as sec_tag count to one, even if sec_tag is not configured.
This file needs refactoring. Usage of HTTPS is controlled by CONFIG_USE_HTTPS but in the code, it uses runtime check if sec_tag is (-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.
What about checking CONFIG_USE_HTTPS here instead of setting SEC_TAG to -1 (in top of the file)?
| } | ||
|
|
||
| if (sec_tag < 0) { | ||
| if (sec_tag == -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.
This is a bug.
sec_tag is unsigned and therefore this check has always bee false.
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, seems that also this has been broken. 0 can not be used because that's a valid value, so I guess UINT32_MAX should be used to indicate a missing value.
| int arg_pdn_cid = 0; | ||
| bool arg_secure = false; | ||
| uint32_t arg_sec_tag = 0; | ||
| uint32_t arg_sec_tag = -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.
uint32_t cannot be -1 so this is silently converting the integer to unsigned. Seems extremely weird and prone to bugs.
| { | ||
| int sec_tag_list[1] = { sec_tag }; | ||
| uint8_t sec_tag_count = sec_tag < 0 ? 0 : 1; | ||
| uint8_t sec_tag_count = 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.
New bug.
sec_tag_count cannot always be one.
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.
I currently use uint8_t sec_tag_count = sec_tag == -1 ? 0 : 1; in my development branch, but I think the best solution is to use sec_tag_t and introduce UNUSED_SEC_TAG or INVALID_SEC_TAG.
| { | ||
| int sec_tag_list[1] = { sec_tag }; | ||
| uint8_t sec_tag_count = sec_tag < 0 ? 0 : 1; | ||
| uint8_t sec_tag_count = 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.
same.
|
Thanks for the input, folks! How should we proceed? Changing |
MirkoCovizzi
left a comment
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.
@MirkoCovizzi Yes, I saw that. What point did you want to make? |
|
Waiting for the next libmodem release which will include a define for an invalid sectag. Feel free to tend to any discovered bugs in the meantime. |
|
Do we need to wait for a new define from a library to be able to fix an existing bug? @SeppoTakalo proposed to use |
nRF91 modems support special sectags to trace TLS ephemeral keys,
but these checks mark those as invalid.
This patch removes checks and changes some of them to check for -1,
which is not one of the debug sectags.