Turn with external tls termination (#168)
* add TURN TCP port for plain tcp listener * use externalTLS turn config option * remove unused TCPPort config option
This commit is contained in:
@@ -103,12 +103,13 @@ type CodecSpec struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TURNConfig struct {
|
type TURNConfig struct {
|
||||||
Enabled bool `yaml:"enabled"`
|
Enabled bool `yaml:"enabled"`
|
||||||
Domain string `yaml:"domain"`
|
Domain string `yaml:"domain"`
|
||||||
CertFile string `yaml:"cert_file"`
|
CertFile string `yaml:"cert_file"`
|
||||||
KeyFile string `yaml:"key_file"`
|
KeyFile string `yaml:"key_file"`
|
||||||
TLSPort int `yaml:"tls_port"`
|
TLSPort int `yaml:"tls_port"`
|
||||||
UDPPort int `yaml:"udp_port"`
|
UDPPort int `yaml:"udp_port"`
|
||||||
|
ExternalTLS bool `yaml:"external_tls"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebHookConfig struct {
|
type WebHookConfig struct {
|
||||||
|
|||||||
+30
-17
@@ -55,26 +55,39 @@ func NewTurnServer(conf *config.Config, authHandler turn.AuthHandler) (*turn.Ser
|
|||||||
return nil, errors.New("TURN domain is not correct")
|
return nil, errors.New("TURN domain is not correct")
|
||||||
}
|
}
|
||||||
|
|
||||||
cert, err := tls.LoadX509KeyPair(turnConf.CertFile, turnConf.KeyFile)
|
if !turnConf.ExternalTLS {
|
||||||
if err != nil {
|
cert, err := tls.LoadX509KeyPair(turnConf.CertFile, turnConf.KeyFile)
|
||||||
return nil, errors.Wrap(err, "TURN tls cert required")
|
if err != nil {
|
||||||
}
|
return nil, errors.Wrap(err, "TURN tls cert required")
|
||||||
|
}
|
||||||
|
|
||||||
tlsListener, err := tls.Listen("tcp4", "0.0.0.0:"+strconv.Itoa(turnConf.TLSPort),
|
tlsListener, err := tls.Listen("tcp4", "0.0.0.0:"+strconv.Itoa(turnConf.TLSPort),
|
||||||
&tls.Config{
|
&tls.Config{
|
||||||
MinVersion: tls.VersionTLS12,
|
MinVersion: tls.VersionTLS12,
|
||||||
Certificates: []tls.Certificate{cert},
|
Certificates: []tls.Certificate{cert},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not listen on TURN TCP port")
|
return nil, errors.Wrap(err, "could not listen on TURN TCP port")
|
||||||
}
|
}
|
||||||
|
|
||||||
listenerConfig := turn.ListenerConfig{
|
listenerConfig := turn.ListenerConfig{
|
||||||
Listener: tlsListener,
|
Listener: tlsListener,
|
||||||
RelayAddressGenerator: relayAddrGen,
|
RelayAddressGenerator: relayAddrGen,
|
||||||
|
}
|
||||||
|
serverConfig.ListenerConfigs = append(serverConfig.ListenerConfigs, listenerConfig)
|
||||||
|
} else {
|
||||||
|
tcpListener, err := net.Listen("tcp4", "0.0.0.0:"+strconv.Itoa(turnConf.TLSPort))
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "could not listen on TURN TCP port")
|
||||||
|
}
|
||||||
|
|
||||||
|
listenerConfig := turn.ListenerConfig{
|
||||||
|
Listener: tcpListener,
|
||||||
|
RelayAddressGenerator: relayAddrGen,
|
||||||
|
}
|
||||||
|
serverConfig.ListenerConfigs = append(serverConfig.ListenerConfigs, listenerConfig)
|
||||||
}
|
}
|
||||||
serverConfig.ListenerConfigs = append(serverConfig.ListenerConfigs, listenerConfig)
|
logValues = append(logValues, "turn.portTLS", turnConf.TLSPort, "turn.externalTLS", turnConf.ExternalTLS)
|
||||||
logValues = append(logValues, "turn.portTLS", turnConf.TLSPort)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if turnConf.UDPPort > 0 {
|
if turnConf.UDPPort > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user