RIOT icon indicating copy to clipboard operation
RIOT copied to clipboard

net/sock_dtls: add public key verification

Open leandrolanzieri opened this issue 1 year ago • 7 comments

Contribution description

This adds a pseudomodule to enable public key verification of peers. When sock_dtls_verify_public_key is enabled the public key sent by the peer is checked against the registered keys on the corresponding sock. The implementation for tinydtls is added, as well as the corresponding changes to use it on the dtls-sock example.

Testing procedure

Run examples/dtls-sock with ECC enabled, the public key should be verified. You can try removing the server's public key from the client, the connection should be aborted.

Issues/PRs references

Loosely related to #19838

leandrolanzieri avatar Nov 04 '23 16:11 leandrolanzieri

I'm wondering whether this feature should actually be opt-out instead.

leandrolanzieri avatar Nov 06 '23 09:11 leandrolanzieri

Murdock results

:heavy_check_mark: PASSED

6d9a9a35a75e4f2bce12b61ae0e1f4c6d0f91adc examples/dtls-sock: cleanup credentials

Success Failures Total Runtime
10009 0 10009 07m:27s

Artifacts

riot-ci avatar Jan 31 '24 23:01 riot-ci

I found the code in the example to be confusing due to naming of the key variables and lack of comments. If you want to go the extra mile and and a bit of ✨ that would be neat but totally optional for this PR.

I gave it a try. It's still not perfect, but I think much clearer. I tried clearly splitting both sets of credentials. A bonus: now the client can actively use the PSK hint to decide on the key to use.

leandrolanzieri avatar Feb 01 '24 16:02 leandrolanzieri

This needs a rebase

benpicco avatar Feb 01 '24 19:02 benpicco

Rebased. I also modified a bit the example: the server only stores one client public key, but has two key pairs. It allows the user to select which one to use on the handshake. As the client knows both public keys form the server, any will work. I think this showcases a bit better the usage of the callbacks and multiple credentials. I also updated the docs including this and the new command.

leandrolanzieri avatar Feb 01 '24 22:02 leandrolanzieri

This is great! Way easier to understand! Could you fix the format issues in the *credentials.h files? Don't forget to squash!

Teufelchen1 avatar Feb 09 '24 10:02 Teufelchen1

Fixed and squashed!

leandrolanzieri avatar Feb 09 '24 10:02 leandrolanzieri

Ping?

leandrolanzieri avatar Mar 15 '24 10:03 leandrolanzieri

Thanks for the review!

leandrolanzieri avatar Mar 19 '24 14:03 leandrolanzieri