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

dtlstransport: Add ExtendedMasterSecret, ClientCAs, RootCAs, ClientAuth #2495

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion dtlstransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
}(),
ClientAuth: dtls.RequireAnyClientCert,
LoggerFactory: t.api.settingEngine.LoggerFactory,
InsecureSkipVerify: true,
InsecureSkipVerify: !t.api.settingEngine.dtls.disableInsecureSkipVerify,
}, nil
}

Expand All @@ -331,10 +331,17 @@
dtlsConfig.ReplayProtectionWindow = int(*t.api.settingEngine.replayProtection.DTLS)
}

if t.api.settingEngine.dtls.clientAuth != nil {
dtlsConfig.ClientAuth = *t.api.settingEngine.dtls.clientAuth
}

Check warning on line 336 in dtlstransport.go

View check run for this annotation

Codecov / codecov/patch

dtlstransport.go#L335-L336

Added lines #L335 - L336 were not covered by tests

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

// Connect as DTLS Client/Server, function is blocking and we
// must not hold the DTLSTransport lock
Expand Down
40 changes: 36 additions & 4 deletions settingengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import (
"context"
"crypto/x509"
"io"
"net"
"time"
Expand Down Expand Up @@ -61,10 +62,15 @@
SRTCP *uint
}
dtls struct {
insecureSkipHelloVerify bool
retransmissionInterval time.Duration
ellipticCurves []dtlsElliptic.Curve
connectContextMaker func() (context.Context, func())
insecureSkipHelloVerify bool
disableInsecureSkipVerify bool
retransmissionInterval time.Duration
ellipticCurves []dtlsElliptic.Curve
connectContextMaker func() (context.Context, func())
extendedMasterSecret dtls.ExtendedMasterSecretType
clientAuth *dtls.ClientAuthType
clientCAs *x509.CertPool
rootCAs *x509.CertPool
}
sctp struct {
maxReceiveBufferSize uint32
Expand Down Expand Up @@ -368,6 +374,12 @@
e.dtls.insecureSkipHelloVerify = skip
}

// SetDTLSDisableInsecureSkipVerify sets the disable skip insecure verify flag for DTLS.
// This controls whether a client verifies the server's certificate chain and host name.
func (e *SettingEngine) SetDTLSDisableInsecureSkipVerify(disable bool) {
e.dtls.disableInsecureSkipVerify = disable

Check warning on line 380 in settingengine.go

View check run for this annotation

Codecov / codecov/patch

settingengine.go#L379-L380

Added lines #L379 - L380 were not covered by tests
}

// SetDTLSEllipticCurves sets the elliptic curves for DTLS.
func (e *SettingEngine) SetDTLSEllipticCurves(ellipticCurves ...dtlsElliptic.Curve) {
e.dtls.ellipticCurves = ellipticCurves
Expand All @@ -384,6 +396,26 @@
e.dtls.connectContextMaker = connectContextMaker
}

// SetDTLSExtendedMasterSecret sets the extended master secret type for DTLS.
func (e *SettingEngine) SetDTLSExtendedMasterSecret(extendedMasterSecret dtls.ExtendedMasterSecretType) {
e.dtls.extendedMasterSecret = extendedMasterSecret

Check warning on line 401 in settingengine.go

View check run for this annotation

Codecov / codecov/patch

settingengine.go#L400-L401

Added lines #L400 - L401 were not covered by tests
}

// SetDTLSClientAuth sets the client auth type for DTLS.
func (e *SettingEngine) SetDTLSClientAuth(clientAuth dtls.ClientAuthType) {
e.dtls.clientAuth = &clientAuth

Check warning on line 406 in settingengine.go

View check run for this annotation

Codecov / codecov/patch

settingengine.go#L405-L406

Added lines #L405 - L406 were not covered by tests
}

// SetDTLSClientCAs sets the client CA certificate pool for DTLS certificate verification.
func (e *SettingEngine) SetDTLSClientCAs(clientCAs *x509.CertPool) {
e.dtls.clientCAs = clientCAs

Check warning on line 411 in settingengine.go

View check run for this annotation

Codecov / codecov/patch

settingengine.go#L410-L411

Added lines #L410 - L411 were not covered by tests
}

// SetDTLSRootCAs sets the root CA certificate pool for DTLS certificate verification.
func (e *SettingEngine) SetDTLSRootCAs(rootCAs *x509.CertPool) {
e.dtls.rootCAs = rootCAs

Check warning on line 416 in settingengine.go

View check run for this annotation

Codecov / codecov/patch

settingengine.go#L415-L416

Added lines #L415 - L416 were not covered by tests
}

// SetSCTPMaxReceiveBufferSize sets the maximum receive buffer size.
// Leave this 0 for the default maxReceiveBufferSize.
func (e *SettingEngine) SetSCTPMaxReceiveBufferSize(maxReceiveBufferSize uint32) {
Expand Down
Loading