check turn domain and port range (#90)
* check negative turn port * check turn domain * domain check test code
This commit is contained in:
+6
-2
@@ -26,7 +26,7 @@ func NewTurnServer(conf *config.Config, roomStore RoomStore, node routing.LocalN
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if turnConf.TLSPort == 0 && turnConf.UDPPort == 0 {
|
if turnConf.TLSPort <= 0 && turnConf.UDPPort <= 0 {
|
||||||
return nil, errors.New("invalid TURN ports")
|
return nil, errors.New("invalid TURN ports")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +49,10 @@ func NewTurnServer(conf *config.Config, roomStore RoomStore, node routing.LocalN
|
|||||||
return nil, errors.New("TURN domain required")
|
return nil, errors.New("TURN domain required")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if IsValidDomain(turnConf.Domain) == false {
|
||||||
|
return nil, errors.New("TURN domain is not correct")
|
||||||
|
}
|
||||||
|
|
||||||
cert, err := tls.LoadX509KeyPair(turnConf.CertFile, turnConf.KeyFile)
|
cert, err := tls.LoadX509KeyPair(turnConf.CertFile, turnConf.KeyFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "TURN tls cert required")
|
return nil, errors.Wrap(err, "TURN tls cert required")
|
||||||
@@ -99,4 +103,4 @@ func newTurnAuthHandler(roomStore RoomStore) turn.AuthHandler {
|
|||||||
|
|
||||||
return turn.GenerateAuthKey(username, livekitRealm, rm.TurnPassword), true
|
return turn.GenerateAuthKey(username, livekitRealm, rm.TurnPassword), true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
"github.com/google/wire"
|
"github.com/google/wire"
|
||||||
@@ -93,6 +94,11 @@ func boolValue(s string) bool {
|
|||||||
return s == "1" || s == "true"
|
return s == "1" || s == "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsValidDomain(domain string) bool {
|
||||||
|
domainRegexp := regexp.MustCompile(`^(?i)[a-z0-9-]+(\.[a-z0-9-]+)+\.?$`)
|
||||||
|
return domainRegexp.MatchString(domain)
|
||||||
|
}
|
||||||
|
|
||||||
func permissionFromGrant(claim *auth.VideoGrant) *livekit.ParticipantPermission {
|
func permissionFromGrant(claim *auth.VideoGrant) *livekit.ParticipantPermission {
|
||||||
p := &livekit.ParticipantPermission{
|
p := &livekit.ParticipantPermission{
|
||||||
CanSubscribe: true,
|
CanSubscribe: true,
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ package service_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
|
"github.com/livekit/livekit-server/pkg/service"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func redisClient() *redis.Client {
|
func redisClient() *redis.Client {
|
||||||
@@ -9,3 +12,16 @@ func redisClient() *redis.Client {
|
|||||||
Addr: "localhost:6379",
|
Addr: "localhost:6379",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsValidDomain(t *testing.T) {
|
||||||
|
list := map[string]bool{
|
||||||
|
"turn.myhost.com": true,
|
||||||
|
"turn.google.com": true,
|
||||||
|
"https://host.com": false,
|
||||||
|
"turn://host.com": false,
|
||||||
|
}
|
||||||
|
for key, result := range list {
|
||||||
|
service.IsValidDomain(key)
|
||||||
|
require.Equal(t, service.IsValidDomain(key), result)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user