Browse Source

base64encode and decode turn creds

Abhishek Kondur 2 years ago
parent
commit
ad4dc87ed0
2 changed files with 9 additions and 11 deletions
  1. 2 1
      turnserver/internal/auth/auth.go
  2. 7 10
      turnserver/src/turn/server.go

+ 2 - 1
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()
 }

+ 7 - 10
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...")