From ad4dc87ed0d7a8e09bb30886f39c483b3088d554 Mon Sep 17 00:00:00 2001 From: Abhishek Kondur Date: Thu, 20 Apr 2023 16:28:24 +0400 Subject: [PATCH] base64encode and decode turn creds --- turnserver/internal/auth/auth.go | 3 ++- turnserver/src/turn/server.go | 17 +++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/turnserver/internal/auth/auth.go b/turnserver/internal/auth/auth.go index 8e30e80d..f5ba1e97 100644 --- a/turnserver/internal/auth/auth.go +++ b/turnserver/internal/auth/auth.go @@ -1,6 +1,7 @@ package auth import ( + "encoding/base64" "encoding/json" "os" "path/filepath" @@ -25,7 +26,7 @@ func init() { func RegisterNewHostWithTurn(hostID, hostPass string) { authMapLock.Lock() - HostMap[hostID] = string(turn.GenerateAuthKey(hostID, config.GetTurnHost(), hostPass)) + HostMap[hostID] = base64.StdEncoding.EncodeToString(turn.GenerateAuthKey(hostID, config.GetTurnHost(), hostPass)) dumpCredsToFile() authMapLock.Unlock() } diff --git a/turnserver/src/turn/server.go b/turnserver/src/turn/server.go index f7cc8b22..d946660c 100644 --- a/turnserver/src/turn/server.go +++ b/turnserver/src/turn/server.go @@ -2,12 +2,12 @@ package turn import ( "context" + "encoding/base64" "log" "net" "strconv" "sync" "syscall" - "time" "github.com/gravitl/netmaker/logger" "github.com/gravitl/netmaker/turnserver/config" @@ -74,24 +74,21 @@ func Start(ctx context.Context, wg *sync.WaitGroup) { // Return the key for that user, or false when no user is found AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { if key, ok := auth.HostMap[username]; ok { - return []byte(key), true + keyBytes, err := base64.StdEncoding.DecodeString(key) + if err != nil { + return nil, false + } + return keyBytes, true } return nil, false }, - ChannelBindTimeout: time.Duration(time.Hour * 36), + //ChannelBindTimeout: time.Duration(time.Minute), // PacketConnConfigs is a list of UDP Listeners and the configuration around them PacketConnConfigs: packetConnConfigs, }) if err != nil { log.Panic(err) } - go func() { - for { - time.Sleep(time.Second * 10) - log.Print(s.AllocationCount()) - } - }() - // Block until user sends SIGINT or SIGTERM <-ctx.Done() logger.Log(0, "## Stopping Turn Server...")