Skip to content
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

feat: dtls connection using mbedtls #10

Merged
merged 46 commits into from
Aug 13, 2024
Merged

feat: dtls connection using mbedtls #10

merged 46 commits into from
Aug 13, 2024

Conversation

lchenut
Copy link
Collaborator

@lchenut lchenut commented Mar 8, 2024

Presentation

This PR is part of the stack to create the nim-libp2p webrtc-direct transport (defined here: https://github.com/libp2p/specs/blob/master/webrtc/webrtc-direct.md).
For this PR, we do not implement the full DTLS protocol, we are using the library MBed-TLS (nim wrapper: https://github.com/status-im/nim-mbedtls / C-library https://github.com/Mbed-TLS/mbedtls) to create and use a DTLS connection.

DTLS

DTLS is a protocol designed to provide the same security features as TLS, but for UDP applications. It secures communications over UDP, which is inherently unreliable and connectionless. By using DTLS, WebRTC ensures that all data streams are encrypted and secure from potential eavesdropping, tampering, and other security threats.

webrtc/dtls/dtls.nim Outdated Show resolved Hide resolved
webrtc/dtls/dtls.nim Outdated Show resolved Hide resolved
webrtc/dtls/dtls.nim Outdated Show resolved Hide resolved
@lchenut lchenut self-assigned this Jul 26, 2024
@diegomrsantos
Copy link
Contributor

Could you also create issues for the TODOs described in https://github.com/status-im/nim-mbedtls? It seems to me they need to be worked on before we say this work has been completed.

tests/testdtls.nim Outdated Show resolved Hide resolved
@diegomrsantos
Copy link
Contributor

What DTLS version is https://github.com/status-im/nim-mbedtls using?

# Mbed-TLS contexts
ctx: MbedTLSCtx

proc verify(ctx: pointer, pcert: ptr mbedtls_x509_crt,
Copy link
Contributor

@diegomrsantos diegomrsantos Aug 9, 2024

Choose a reason for hiding this comment

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

Reading the implementation, I find it unclear how it verifies the certificate's validity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hum... it's because the name verify is wrong. We use this callback because we need to retrieve the remote certificate from the peer (for the DataChannel). It's the solution I found to retrieve it, after this callback, the certificate is not stored.

I change the name to make it clearer!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

of AddressFamily.IPv6:
mb_ssl_set_client_transport_id(self.ctx.ssl, self.raddr.address_v6)
else:
doAssert(false, "Should never happen")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
doAssert(false, "Should never happen")
raiseAssert("Remote address must be IPv4 or IPv6")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@diegomrsantos diegomrsantos left a comment

Choose a reason for hiding this comment

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

Thank you, great job.

@lchenut lchenut merged commit d75e328 into master Aug 13, 2024
8 checks passed
@lchenut lchenut deleted the dtls-protocol branch August 13, 2024 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

2 participants