@@ -11,6 +11,7 @@ import (
1111 "time"
1212
1313 "github.com/pion/dtls/v3/pkg/crypto/elliptic"
14+ "github.com/pion/dtls/v3/pkg/protocol"
1415 "github.com/pion/dtls/v3/pkg/protocol/handshake"
1516 "github.com/pion/logging"
1617)
@@ -80,6 +81,8 @@ type dtlsConfig struct { //nolint:dupl
8081 certificateRequestMessageHook func (handshake.MessageCertificateRequest ) handshake.Message
8182 onConnectionAttempt func (net.Addr ) error
8283 listenConfig net.ListenConfig
84+ minVersion protocol.Version
85+ maxVersion protocol.Version
8386}
8487
8588// applyDefaults applies default values to the config.
@@ -124,6 +127,8 @@ func (c *dtlsConfig) toConfig() *Config {
124127 CertificateRequestMessageHook : c .certificateRequestMessageHook ,
125128 OnConnectionAttempt : c .onConnectionAttempt ,
126129 listenConfig : c .listenConfig ,
130+ minVersion : c .minVersion ,
131+ maxVersion : c .maxVersion ,
127132 }
128133
129134 if len (c .certificates ) > 0 {
@@ -561,6 +566,34 @@ func WithClientHelloMessageHook(fn func(handshake.MessageClientHello) handshake.
561566 })
562567}
563568
569+ // MinVersion sets the minimum TLS version that is acceptable.
570+ // By default, DTLS 1.2 is currently used as the minimum as it's the only supported version.
571+ func withMinVersion (version protocol.Version ) Option { // nolint:unused
572+ return sharedOption (func (c * dtlsConfig ) error {
573+ if protocol .IsSupportedVersion (version ) {
574+ c .minVersion = version
575+
576+ return nil
577+ }
578+
579+ return errUnsupportedProtocolVersion
580+ })
581+ }
582+
583+ // MaxVersion sets the maxiumum TLS version that is acceptable.
584+ // By default, DTLS 1.2 is currently used as the minimum as it's the only supported version.
585+ func withMaxVersion (version protocol.Version ) Option { // nolint:unused
586+ return sharedOption (func (c * dtlsConfig ) error {
587+ if protocol .IsSupportedVersion (version ) {
588+ c .maxVersion = version
589+
590+ return nil
591+ }
592+
593+ return errUnsupportedProtocolVersion
594+ })
595+ }
596+
564597// serverOnlyOption wraps an apply function for server-only options.
565598type serverOnlyOption func (* dtlsConfig ) error
566599
0 commit comments