-
Notifications
You must be signed in to change notification settings - Fork 2.1k
sys: add credman (D)TLS credential management module #11564
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
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.
Some initial review.
Regarding naming, what do you think about removing the credential
in most function names. It seems redundant to me and makes the names somewhat clunky.
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 I get this right, this is a sort of in-memory index to user supplied buffers. That is, it creates a mapping of (tag, type) -> (buffer with key) and except the data definitions, nothing seems to be specific to credentials.
I think this may be over-specialized. If the user must remember a (32 bit) numerical tag and this does not copy the buffers, how is this different from just remembering a pointer to the buffer.
Also, why mix the storage and validation logic. If what is needed is an int->pointer mapping (thread safe and all) why not make that a module and implement the validation and retrieval on top of it.
The design of this does not allow for persisting the credentials in any way.
If credentials are known at compile time, why not use constfs. And if they are dynamically added in run-time, where will they be allocated?
To use DTLS, users must first tell the DTLS sock which credential needs to be used for the credman handles both of these by providing a unified way to pass credential to the sock. Even though this adds few more steps to add a credential to a sock (add credential, register tag to use), it avoids having multiple ways to tell sock which credential to use depending on the use case, which could be confusing to a new user.
As there can be multiple credentials of the same type added into the system, the (tag, type) -> credential buffer mapping is used by credman to identify which credential to use with which sock. If this module are intended for more general usage, mixing the storage and validation logic may not be good here but for (D)TLS it is easier to check it once when added if the credential is valid than to check it later every time the credential will be used in the (D)TLS libraries. Also, I don't know if such module (int->pointer mapping) is needed currently other than here.
This is intentional. Copying the buffer into the system might use a larger amount of memory than needed e.g. credman reserves memory enough for a longer credential but the user only uses part of the buffer to save the credential. That is why I decided to only save pointer to the buffer.
I'm not aware of constfs before this. Thanks for pointing that out. I'll look into it. For the dynamically added in run-time, the users have to supply their own buffer for the credentials. [1]: sock_dtls is a wrapper around libraries that implements DTLS e.g. tinyDTLS, wolfSSL. |
@miri64 @jcarrano I updated my comment and the PR description. I hope it is easier to understand now. Also fixed requested changes. As for constfs, credman may need to handle dynamically added credentials during runtime if something like 1 is implemented in the future. So I think it is better to not make the assumption that the credentials is known at compile-time. |
Rebased to current master. |
Thanks for the review @miri64. I pushed some commits addressing the review comments. |
Had a look at your changes. Code design looks good now. |
|
I ran the unittests for
All tests except the noted one on For |
Please squash. I will look at style and documentation later. |
Rebased and squashed. |
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.
My doc and style review
Only #11564 (comment) left. |
@miri64 if you noticed, I removed
But while trying to explain it, I noticed that doing it that way may not be scalable if there is other application like gcoap using it in the future. Basically, my idea was a list of reserved That means, this PR (+ sock_dtls PR which is coming) will only enable support for the first use case:
If you're okay with that, I'll proceed with rebasing and squashing the commits. |
Good. Another reason why doc is important. Trying to explain stuff oftentimes helps me rethink stuff :-).
Yepp. In case it is needed later it can always be re-added. I give this a final round of tests, and then I'll ACK [edit for the pedantics]when they succeed[/edit]. You may squash in the meantime. |
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 repeated my tests from #11564 (comment) for native
, samr21-xpro
, and z1
. All succeeded. ACK
Rebased and squashed. |
ACK holds |
Just noticed I messed up the commit a bit. Fixed and re-pushed the commits. |
I noticed it already when I ACK'd :-) |
And go! |
I'm trying to understand the idea behind the credman tag. |
Contribution description
This PR is the first part to add sock_dtls module for (D)TLS support in RIOT. credman can also be used
to handle credentials for TLS if TLS is supported in RIOT in the future.
To use DTLS, users must first tell the DTLS sock which credential needs to be used for the
encryption and decryption process. There are two use cases here, 1) the user has direct access to the
DTLS sock and can actually give the pointer of the credential buffer to the sock, 2) the user does not have access to the sock because it is located in a lower leveled library used by user application (e.g. gcoap + DTLS).
credman handles both of these by providing a unified way to pass credential to the sock. Even though this adds few more steps to add a credential to a sock (add credential, register tag to use), it avoids having multiple ways to tell sock which credential to use depending on the use case, which could be confusing to a new user.
As there can be multiple credentials of the same type added into the system, the (tag, type) -> credential buffer mapping is used by credman to identify which credential to use with which sock.
Testing procedure
Added unit tests under
tests/unittests/tests-credman
.Issues/PRs references
See also #10897