From f388de65812878d8d26d0b74d331cbf5a19984e2 Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Thu, 25 Jul 2024 11:24:45 -0400 Subject: [PATCH] Update module github.com/pion/dtls/v2 to v3 Generated by renovateBot --- certificate.go | 2 +- constants.go | 2 +- dtlstransport.go | 20 ++++++++++++++------ go.mod | 3 ++- go.sum | 2 ++ internal/mux/endpoint.go | 12 ++++++++++++ settingengine.go | 4 ++-- settingengine_test.go | 2 +- 8 files changed, 35 insertions(+), 12 deletions(-) diff --git a/certificate.go b/certificate.go index a0950eb8527..36d1fb07968 100644 --- a/certificate.go +++ b/certificate.go @@ -20,7 +20,7 @@ import ( "strings" "time" - "github.com/pion/dtls/v2/pkg/crypto/fingerprint" + "github.com/pion/dtls/v3/pkg/crypto/fingerprint" "github.com/pion/webrtc/v4/pkg/rtcerr" ) diff --git a/constants.go b/constants.go index ea484431b77..f248342b394 100644 --- a/constants.go +++ b/constants.go @@ -3,7 +3,7 @@ package webrtc -import "github.com/pion/dtls/v2" +import "github.com/pion/dtls/v3" const ( // Equal to UDP MTU diff --git a/dtlstransport.go b/dtlstransport.go index bfc38d2b724..a49e78ff9a4 100644 --- a/dtlstransport.go +++ b/dtlstransport.go @@ -19,8 +19,8 @@ import ( "sync/atomic" "time" - "github.com/pion/dtls/v2" - "github.com/pion/dtls/v2/pkg/crypto/fingerprint" + "github.com/pion/dtls/v3" + "github.com/pion/dtls/v3/pkg/crypto/fingerprint" "github.com/pion/interceptor" "github.com/pion/logging" "github.com/pion/rtcp" @@ -284,7 +284,7 @@ func (t *DTLSTransport) role() DTLSRole { } // Start DTLS transport negotiation with the parameters of the remote DTLS transport -func (t *DTLSTransport) Start(remoteParameters DTLSParameters) error { +func (t *DTLSTransport) Start(remoteParameters DTLSParameters) error { //nolint: gocognit // Take lock and prepare connection, we must not hold the lock // when connecting prepareTransport := func() (DTLSRole, *dtls.Config, error) { @@ -346,7 +346,6 @@ func (t *DTLSTransport) Start(remoteParameters DTLSParameters) error { dtlsConfig.FlightInterval = t.api.settingEngine.dtls.retransmissionInterval dtlsConfig.InsecureSkipVerifyHello = t.api.settingEngine.dtls.insecureSkipHelloVerify dtlsConfig.EllipticCurves = t.api.settingEngine.dtls.ellipticCurves - dtlsConfig.ConnectContextMaker = t.api.settingEngine.dtls.connectContextMaker dtlsConfig.ExtendedMasterSecret = t.api.settingEngine.dtls.extendedMasterSecret dtlsConfig.ClientCAs = t.api.settingEngine.dtls.clientCAs dtlsConfig.RootCAs = t.api.settingEngine.dtls.rootCAs @@ -355,9 +354,18 @@ func (t *DTLSTransport) Start(remoteParameters DTLSParameters) error { // Connect as DTLS Client/Server, function is blocking and we // must not hold the DTLSTransport lock if role == DTLSRoleClient { - dtlsConn, err = dtls.Client(dtlsEndpoint, dtlsConfig) + dtlsConn, err = dtls.Client(dtlsEndpoint, dtlsEndpoint.RemoteAddr(), dtlsConfig) } else { - dtlsConn, err = dtls.Server(dtlsEndpoint, dtlsConfig) + dtlsConn, err = dtls.Server(dtlsEndpoint, dtlsEndpoint.RemoteAddr(), dtlsConfig) + } + + if err == nil { + if t.api.settingEngine.dtls.connectContextMaker != nil { + handshakeCtx, _ := t.api.settingEngine.dtls.connectContextMaker() + err = dtlsConn.HandshakeContext(handshakeCtx) + } else { + err = dtlsConn.Handshake() + } } // Re-take the lock, nothing beyond here is blocking diff --git a/go.mod b/go.mod index bdb34aea033..fac8b005854 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/pion/datachannel v1.5.8 - github.com/pion/dtls/v2 v2.2.12 + github.com/pion/dtls/v3 v3.0.0 github.com/pion/ice/v3 v3.0.13 github.com/pion/interceptor v0.1.29 github.com/pion/logging v0.2.2 @@ -26,6 +26,7 @@ require ( github.com/google/uuid v1.6.0 // indirect github.com/onsi/ginkgo v1.16.5 // indirect github.com/onsi/gomega v1.17.0 // indirect + github.com/pion/dtls/v2 v2.2.12 // indirect github.com/pion/mdns/v2 v2.0.7 // indirect github.com/pion/transport/v2 v2.2.8 // indirect github.com/pion/turn/v3 v3.0.3 // indirect diff --git a/go.sum b/go.sum index 76916afe459..8f943ca6edb 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,8 @@ github.com/pion/datachannel v1.5.8/go.mod h1:PgmdpoaNBLX9HNzNClmdki4DYW5JtI7Yibu github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s= github.com/pion/dtls/v2 v2.2.12 h1:KP7H5/c1EiVAAKUmXyCzPiQe5+bCJrpOeKg/L05dunk= github.com/pion/dtls/v2 v2.2.12/go.mod h1:d9SYc9fch0CqK90mRk1dC7AkzzpwJj6u2GU3u+9pqFE= +github.com/pion/dtls/v3 v3.0.0 h1:m2hzwPkzqoBjVKXm5ymNuX01OAjht82TdFL6LoTzgi4= +github.com/pion/dtls/v3 v3.0.0/go.mod h1:tiX7NaneB0wNoRaUpaMVP7igAlkMCTQkbpiY+OfeIi0= github.com/pion/ice/v3 v3.0.13 h1:tPi5fh2xbWhS0DBcs7LTEG0SOUTHLVDjTlFwBy3hXfw= github.com/pion/ice/v3 v3.0.13/go.mod h1:q2M/RnfpgGhC4HcluxPpD1wImaqFqU0Z1PE2eeOPrIs= github.com/pion/interceptor v0.1.29 h1:39fsnlP1U8gw2JzOFWdfCU82vHvhW9o0rZnZF56wF+M= diff --git a/internal/mux/endpoint.go b/internal/mux/endpoint.go index 41dd61d5e9d..e087a6e5ce9 100644 --- a/internal/mux/endpoint.go +++ b/internal/mux/endpoint.go @@ -44,6 +44,13 @@ func (e *Endpoint) Read(p []byte) (int, error) { return e.buffer.Read(p) } +// ReadFrom reads a packet of len(p) bytes from the underlying conn +// that are matched by the associated MuxFunc +func (e *Endpoint) ReadFrom(p []byte) (int, net.Addr, error) { + i, err := e.Read(p) + return i, nil, err +} + // Write writes len(p) bytes to the underlying conn func (e *Endpoint) Write(p []byte) (int, error) { n, err := e.mux.nextConn.Write(p) @@ -56,6 +63,11 @@ func (e *Endpoint) Write(p []byte) (int, error) { return n, err } +// WriteTo writes len(p) bytes to the underlying conn +func (e *Endpoint) WriteTo(p []byte, _ net.Addr) (int, error) { + return e.Write(p) +} + // LocalAddr is a stub func (e *Endpoint) LocalAddr() net.Addr { return e.mux.nextConn.LocalAddr() diff --git a/settingengine.go b/settingengine.go index a0d5e3be1ea..cbb2c6e4a6c 100644 --- a/settingengine.go +++ b/settingengine.go @@ -13,8 +13,8 @@ import ( "net" "time" - "github.com/pion/dtls/v2" - dtlsElliptic "github.com/pion/dtls/v2/pkg/crypto/elliptic" + "github.com/pion/dtls/v3" + dtlsElliptic "github.com/pion/dtls/v3/pkg/crypto/elliptic" "github.com/pion/ice/v3" "github.com/pion/logging" "github.com/pion/stun/v2" diff --git a/settingengine_test.go b/settingengine_test.go index 787604b70a5..001305e9035 100644 --- a/settingengine_test.go +++ b/settingengine_test.go @@ -12,7 +12,7 @@ import ( "testing" "time" - "github.com/pion/dtls/v2/pkg/crypto/elliptic" + "github.com/pion/dtls/v3/pkg/crypto/elliptic" "github.com/pion/ice/v3" "github.com/pion/stun/v2" "github.com/pion/transport/v3/test"