-
-
Notifications
You must be signed in to change notification settings - Fork 116
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
Add support for DTLS 1.2 Connection IDs #473
Conversation
Nice. Is it possible to extend the example by resuming the connection? |
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.
@jkralik absolutely 👍🏻 will get this updated once the referenced PR in the replace
statement is merged!
995e122
to
8e43def
Compare
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.
@jkralik updated with examples, as well as logs and a capture of the behavior 👍🏻
// wrappedListener wraps a net.Listener and implements a go-coap DTLS | ||
// server.Listener. | ||
// NOTE: this utility is for example purposes only. Context should be handled | ||
// properly in meaningful scenarios. | ||
type wrappedListener struct { | ||
l net.Listener | ||
closed atomic.Bool | ||
} |
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.
@jkralik I'm not sure if there is appetite to do so, but I would be interested in go-coap
defining a common ContextListener
and utility wrappers to allow for the passing of net.Listener
. For now, consumers of this functionality will need to use a custom listener as demonstrated in this example.
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, I see the point. But one thing - Has handshaking been moved to Conn.Read/Write
from listener.Accept
? If not, we need to incorporate it with https://github.com/plgd-dev/go-coap/blob/master/net/dtlslistener.go#L37.
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.
But one thing - Has handshaking been moved to Conn.Read/Write from listener.Accept? If not, we need to incorporate it with https://github.com/plgd-dev/go-coap/blob/master/net/dtlslistener.go#L37.
@jkralik I'm not sure I'm following your suggestion here. Handshaking has not moved -- from the perspective of the existing DTLSListener
nothing has changed. In fact, setting the connectionIDGenerator
on the pion/dtls
config passed to NewDTLSListener
would enable connection ID support. The issue is that the underlying pion/transport/udp
package being used does not support routing based on Connection ID. A replacement has been introduced in https://github.com/pion/dtls/tree/master/internal/net/udp, which is in internal
for now so that it can be iterated upon prior to folks taking a direct dependency on its API. It can be consumed by using the pion/dtls.Listen
function.
I do think it would be good for the functionality to become the default in go-coap
, but right now the DTLSListener
is restrictive about the behavior it allows (anecdotally, we use a different implementation of the DTLSListener
internally so introduce additional functionality). This PR maintains the existing go-coap
functionality, while also demonstrating how a consumer can provide their own listener for custom functionality (including connection IDs).
It seems like previously the pion/dtls.Listener
was used, but then was moved away from in order to introduce parallel handshakes. My understanding of this functionality is that the DTLSListener
essentially just continuously accepts connections so that the handshake can begin and complete, perhaps before the DTLS Server
calls AcceptWithContext()
. It seems the major blocker from using the pion/dtls.Listener
is the [starting of the pion/dtls.Server
in a go pool. My question is whether this could be functionality introduced in pion/dtls
instead (i.e. stop blocking Accept()
on completion of the handshake), which would allow go-coap
to treat the DTLS listener as just a net.Listener
(with the generic wrapping to support context handling).
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.
(Note: this is what I would like to do long term, but the changes in this PR enable folks to implement custom behavior to enable connection ID support, while keeping the previous behavior of go-coap
unchanged when using the provided DTLSListener
implementation. This feels like a good intermediate step to me as it does not introduce any breaking changes in go-coap
, but I am open to discussion and happy to explore other avenues 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.
It seems like previously the pion/dtls.Listener was used, but then was moved away from in order to introduce parallel handshakes. My understanding of this functionality is that the DTLSListener essentially just continuously accepts connections so that the handshake can begin and complete, perhaps before the DTLS Server calls AcceptWithContext(). It seems the major blocker from using the pion/dtls.Listener is the [starting of the pion/dtls.Server in a go pool. My question is whether this could be functionality introduced in pion/dtls instead (i.e. stop blocking Accept() on completion of the handshake), which would allow go-coap to treat the DTLS listener as just a net.Listener (with the generic wrapping to support context handling).
There is a discussion (pion/dtls#279) about moving the handshake, as it is in the golang/crypto
package, to the Read/Write
functions.
I agree with you; we can proceed step by step.
8e43def
to
dc1228e
Compare
dc1228e
to
30d59ce
Compare
4d62dd3
to
e86c1a0
Compare
@@ -5,8 +5,8 @@ go 1.18 | |||
require ( |
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.
Looks like linter is stuck on replace
statement, but it has been removed and required functionality has been merged upstream 👍🏻
Updates pion/dtls dependency to bring in support for DTLS 1.2 Connection IDs. Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
Adds a server example for DTLS Connection IDs. Random 8 byte CIDs are used. Note that the built-in go-coap DTLS listener does not support this functionality presently as it uses a UDP listener from pion/transport that does not support routing datagrams based on attributes other than remote address. Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
Adds a DTLS Connection ID client example. Two different "connections" are used with the second resuming using the state from the first, allowing it to bypass performing a second DTLS handshake. Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
pion/dtls uses net.ListenUDP under the hood to allow for changing remote addresses. Therefore, if there is a mismatch between IPv4 and IPv6 between the client and server then they are unable to communicate. Additionally, writing to 0.0.0.0 fails on Windows, so 127.0.0.1 is specified explicitly. Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
Thx for contribution :). |
Thank you for all the time and effort you have invested in this library @jkralik! We are always willing to contribute where we can :) |
resolves #472 |
Updates pion/dtls dependency to bring in support for DTLS 1.2 Connection IDs.
Fixes #467
Wireshark capture of provided example:
I also ran with
pion/dtls
trace logging enabled, which demonstrates the continuation of the connection.server
client