Skip to content

Commit a0e9824

Browse files
SimonVerkadaSean-Der
authored andcommitted
DTLS: Add Client/RootCAs, ClientAuth, Secret Opts
1 parent 2ffab96 commit a0e9824

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

dtlstransport.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func (t *DTLSTransport) Start(remoteParameters DTLSParameters) error {
316316
}(),
317317
ClientAuth: dtls.RequireAnyClientCert,
318318
LoggerFactory: t.api.settingEngine.LoggerFactory,
319-
InsecureSkipVerify: true,
319+
InsecureSkipVerify: !t.api.settingEngine.dtls.disableInsecureSkipVerify,
320320
}, nil
321321
}
322322

@@ -331,10 +331,17 @@ func (t *DTLSTransport) Start(remoteParameters DTLSParameters) error {
331331
dtlsConfig.ReplayProtectionWindow = int(*t.api.settingEngine.replayProtection.DTLS)
332332
}
333333

334+
if t.api.settingEngine.dtls.clientAuth != nil {
335+
dtlsConfig.ClientAuth = *t.api.settingEngine.dtls.clientAuth
336+
}
337+
334338
dtlsConfig.FlightInterval = t.api.settingEngine.dtls.retransmissionInterval
335339
dtlsConfig.InsecureSkipVerifyHello = t.api.settingEngine.dtls.insecureSkipHelloVerify
336340
dtlsConfig.EllipticCurves = t.api.settingEngine.dtls.ellipticCurves
337341
dtlsConfig.ConnectContextMaker = t.api.settingEngine.dtls.connectContextMaker
342+
dtlsConfig.ExtendedMasterSecret = t.api.settingEngine.dtls.extendedMasterSecret
343+
dtlsConfig.ClientCAs = t.api.settingEngine.dtls.clientCAs
344+
dtlsConfig.RootCAs = t.api.settingEngine.dtls.rootCAs
338345

339346
// Connect as DTLS Client/Server, function is blocking and we
340347
// must not hold the DTLSTransport lock

settingengine.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package webrtc
88

99
import (
1010
"context"
11+
"crypto/x509"
1112
"io"
1213
"net"
1314
"time"
@@ -61,10 +62,15 @@ type SettingEngine struct {
6162
SRTCP *uint
6263
}
6364
dtls struct {
64-
insecureSkipHelloVerify bool
65-
retransmissionInterval time.Duration
66-
ellipticCurves []dtlsElliptic.Curve
67-
connectContextMaker func() (context.Context, func())
65+
insecureSkipHelloVerify bool
66+
disableInsecureSkipVerify bool
67+
retransmissionInterval time.Duration
68+
ellipticCurves []dtlsElliptic.Curve
69+
connectContextMaker func() (context.Context, func())
70+
extendedMasterSecret dtls.ExtendedMasterSecretType
71+
clientAuth *dtls.ClientAuthType
72+
clientCAs *x509.CertPool
73+
rootCAs *x509.CertPool
6874
}
6975
sctp struct {
7076
maxReceiveBufferSize uint32
@@ -368,6 +374,12 @@ func (e *SettingEngine) SetDTLSInsecureSkipHelloVerify(skip bool) {
368374
e.dtls.insecureSkipHelloVerify = skip
369375
}
370376

377+
// SetDTLSDisableInsecureSkipVerify sets the disable skip insecure verify flag for DTLS.
378+
// This controls whether a client verifies the server's certificate chain and host name.
379+
func (e *SettingEngine) SetDTLSDisableInsecureSkipVerify(disable bool) {
380+
e.dtls.disableInsecureSkipVerify = disable
381+
}
382+
371383
// SetDTLSEllipticCurves sets the elliptic curves for DTLS.
372384
func (e *SettingEngine) SetDTLSEllipticCurves(ellipticCurves ...dtlsElliptic.Curve) {
373385
e.dtls.ellipticCurves = ellipticCurves
@@ -384,6 +396,26 @@ func (e *SettingEngine) SetDTLSConnectContextMaker(connectContextMaker func() (c
384396
e.dtls.connectContextMaker = connectContextMaker
385397
}
386398

399+
// SetDTLSExtendedMasterSecret sets the extended master secret type for DTLS.
400+
func (e *SettingEngine) SetDTLSExtendedMasterSecret(extendedMasterSecret dtls.ExtendedMasterSecretType) {
401+
e.dtls.extendedMasterSecret = extendedMasterSecret
402+
}
403+
404+
// SetDTLSClientAuth sets the client auth type for DTLS.
405+
func (e *SettingEngine) SetDTLSClientAuth(clientAuth dtls.ClientAuthType) {
406+
e.dtls.clientAuth = &clientAuth
407+
}
408+
409+
// SetDTLSClientCAs sets the client CA certificate pool for DTLS certificate verification.
410+
func (e *SettingEngine) SetDTLSClientCAs(clientCAs *x509.CertPool) {
411+
e.dtls.clientCAs = clientCAs
412+
}
413+
414+
// SetDTLSRootCAs sets the root CA certificate pool for DTLS certificate verification.
415+
func (e *SettingEngine) SetDTLSRootCAs(rootCAs *x509.CertPool) {
416+
e.dtls.rootCAs = rootCAs
417+
}
418+
387419
// SetSCTPMaxReceiveBufferSize sets the maximum receive buffer size.
388420
// Leave this 0 for the default maxReceiveBufferSize.
389421
func (e *SettingEngine) SetSCTPMaxReceiveBufferSize(maxReceiveBufferSize uint32) {

0 commit comments

Comments
 (0)