Skip to content

net/sock/dtls: allow using multiple credentials#16179

Merged
PeterKietzmann merged 10 commits intoRIOT-OS:masterfrom
leandrolanzieri:dev/net/sock/dtls_multi_cred
Apr 6, 2021
Merged

net/sock/dtls: allow using multiple credentials#16179
PeterKietzmann merged 10 commits intoRIOT-OS:masterfrom
leandrolanzieri:dev/net/sock/dtls_multi_cred

Conversation

@leandrolanzieri
Copy link
Copy Markdown
Contributor

Contribution description

Currently only one credential can be associated to each DTLS sock. This limits certain use cases that need to establish multiple connections on a single sock using potentially multiple credentials.

This PR proposes an extension of the sock DTLS API to allow registering multiple credentials to be used on a single sock. An application may register callbacks to specify a certain credential from the list based on the session information (and, when using PSK, based on the hint that may have been sent).

Additionally, now a server can send a PSK Identity hint to a client during the handshake, to help deciding on the PSK Identity that should be used.

Finally, the example application has been extended to show these functionalities.

Testing procedure

  • The example application should be working both when using PSK and ECC (for more information enable the debug messages in the sock_dtls.c file).
  • Check that the correct hint is being sent in PSK
  • Check that the correct RPK is being used in ECC
  • Read the documentation
  • A single credential use case should still work seamlessly

Issues/PRs references

None so far

@leandrolanzieri leandrolanzieri added Area: network Area: Networking Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: security Area: Security-related libraries and subsystems labels Mar 10, 2021
@leandrolanzieri leandrolanzieri force-pushed the dev/net/sock/dtls_multi_cred branch 2 times, most recently from d47f275 to 198c519 Compare March 10, 2021 13:08
@leandrolanzieri leandrolanzieri force-pushed the dev/net/sock/dtls_multi_cred branch from 198c519 to aaecc9c Compare March 15, 2021 12:14
@leandrolanzieri
Copy link
Copy Markdown
Contributor Author

@janosbrodbeck the new definitions are not split into their own header, this should avoid the issues when using Sock Async.

Copy link
Copy Markdown
Contributor

@pokgak pokgak left a comment

Choose a reason for hiding this comment

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

Looks good overall.

Copy link
Copy Markdown
Member

@janosbrodbeck janosbrodbeck left a comment

Choose a reason for hiding this comment

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

It works now with async sockets!
tests/pkg_tinydtls_sock_async/dtls-server.c needs one change, because the PSK matching changed. The server in the test does not provide an identity for the credential. Don't know why the ID is missing but now it leads with the current changes to not being able to find a matching credential, since it compares with an empty identity.

static const uint8_t psk_id_0[] = PSK_DEFAULT_IDENTITY; needs to be added to pkg_tinydtls_sock_async/dtls-server.c. And the ID then needs to be added to the credential.

@janosbrodbeck
Copy link
Copy Markdown
Member

janosbrodbeck commented Mar 16, 2021

Looks good to me. Existing code is still working (except the test, but I'll leave that out) and the API is easy to use. Already have a WIP build for my gcoap-dtls running which supports the new functionality.

However, I am for a small extension in sock_dtls_create() as I found a small issue:

When creating a new DTLS socket it is mandatory to provide a credman tag, as it includes sock_dtls_add_credential(). That was okay when there could only be one credential per socket. For gcoap I defined a pre-defined tag and the user could add their credential and tag it with the gcoap tag. But now there is no need for that anymore, I would prefer to have the possibility to create a socket with an empty tag list. The user has to create the credential anyway, and I see no reason to make the usage of a pre-defined tag mandatory. I would like to leave the tag creation up to the user.

But the current API does not provide that functionality. It should be fairly easy to achieve, since CREDMAN_TAG_EMPTY already exists. We should parse this option in sock_dtls_create() to allow the creation of a socket with an empty credential list. And should also add this possibility to the documentation.

@leandrolanzieri
Copy link
Copy Markdown
Contributor Author

static const uint8_t psk_id_0[] = PSK_DEFAULT_IDENTITY; needs to be added to pkg_tinydtls_sock_async/dtls-server.c. And the ID then needs to be added to the credential.

Added in 26cf8cf.

But the current API does not provide that functionality. It should be fairly easy to achieve, since CREDMAN_TAG_EMPTY already exists. We should parse this option in sock_dtls_create() to allow the creation of a socket with an empty credential list. And should also add this possibility to the documentation.

Added in b051dae.

Copy link
Copy Markdown
Contributor

@pokgak pokgak left a comment

Choose a reason for hiding this comment

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

Almost done. Just need to update the docs.

* registering a callback with @ref sock_dtls_set_client_psk_cb. If no callback is registered the
* credential is chosen as follows: if a hint is sent by the server, all credentials registered to
* the sock are checked for a matching @ref psk_params_t::hint "hint". A credential is select on
* matching hint. If no credential matches the hint or no hint is provided, the first PSK credential
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure what exactly needs to change here. I made some adaptions to the doc in 74ea508. Could you take a look?

Copy link
Copy Markdown
Member

@janosbrodbeck janosbrodbeck left a comment

Choose a reason for hiding this comment

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

Besides the documentation updates that pokgak suggested, I am very happy.

Tested it again with examples/dtls-sock, tests/pkg_tinydtls_sock_async and my gcoap-dtls PR without adaption changes and with some first integration changes. The right credentials are used, and existing single credential use cases are also working without changes.

@leandrolanzieri
Copy link
Copy Markdown
Contributor Author

I added another function to get a read-only array of the registered credentials on a sock.

Copy link
Copy Markdown
Contributor

@pokgak pokgak left a comment

Choose a reason for hiding this comment

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

You can squash now.

@leandrolanzieri leandrolanzieri force-pushed the dev/net/sock/dtls_multi_cred branch 2 times, most recently from 6187e42 to 1f6e68c Compare March 19, 2021 10:06
@leandrolanzieri
Copy link
Copy Markdown
Contributor Author

Any maintainer that would like to take a look? @miri64? @cgundogan?

@PeterKietzmann
Copy link
Copy Markdown
Member

@leandrolanzieri thanks, looks better! Maybe introduce PSK and RPK as abbreviations. Mention that the hint (string) could also be changed, you could also explain that it is printed on the client (for verification by the user). I leave this up to you... Please squash directly

@PeterKietzmann PeterKietzmann added Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Mar 30, 2021
@leandrolanzieri leandrolanzieri force-pushed the dev/net/sock/dtls_multi_cred branch from 4a153ea to f2dda22 Compare March 31, 2021 09:31
@leandrolanzieri
Copy link
Copy Markdown
Contributor Author

@leandrolanzieri thanks, looks better! Maybe introduce PSK and RPK as abbreviations. Mention that the hint (string) could also be changed, you could also explain that it is printed on the client (for verification by the user). I leave this up to you... Please squash directly

Added the suggestions and squashed directly!

@leandrolanzieri leandrolanzieri added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 31, 2021
@leandrolanzieri leandrolanzieri force-pushed the dev/net/sock/dtls_multi_cred branch from f2dda22 to a5ccb9a Compare March 31, 2021 11:25
Copy link
Copy Markdown
Member

@PeterKietzmann PeterKietzmann left a comment

Choose a reason for hiding this comment

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

ACK from my side. Anyone else who wants to give this PR a look before merge?

@leandrolanzieri leandrolanzieri force-pushed the dev/net/sock/dtls_multi_cred branch from a5ccb9a to 835589a Compare April 1, 2021 07:48
@fjmolinas fjmolinas added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 1, 2021
@PeterKietzmann
Copy link
Copy Markdown
Member

Well then, go!

@PeterKietzmann PeterKietzmann merged commit f348207 into RIOT-OS:master Apr 6, 2021
@leandrolanzieri leandrolanzieri deleted the dev/net/sock/dtls_multi_cred branch April 6, 2021 08:07
@kaspar030 kaspar030 added this to the Release 2021.04 milestone Apr 23, 2021
@leandrolanzieri leandrolanzieri added the Release notes: added Set on PRs that have been processed into the release notes for the current release. label Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: network Area: Networking Area: security Area: Security-related libraries and subsystems CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Release notes: added Set on PRs that have been processed into the release notes for the current release. Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants