base64encode and decode turn creds

This commit is contained in:
Abhishek Kondur 2023-04-20 16:28:24 +04:00
parent 23e3c1ce29
commit ad4dc87ed0
2 changed files with 9 additions and 11 deletions

View file

@ -1,6 +1,7 @@
package auth package auth
import ( import (
"encoding/base64"
"encoding/json" "encoding/json"
"os" "os"
"path/filepath" "path/filepath"
@ -25,7 +26,7 @@ func init() {
func RegisterNewHostWithTurn(hostID, hostPass string) { func RegisterNewHostWithTurn(hostID, hostPass string) {
authMapLock.Lock() authMapLock.Lock()
HostMap[hostID] = string(turn.GenerateAuthKey(hostID, config.GetTurnHost(), hostPass)) HostMap[hostID] = base64.StdEncoding.EncodeToString(turn.GenerateAuthKey(hostID, config.GetTurnHost(), hostPass))
dumpCredsToFile() dumpCredsToFile()
authMapLock.Unlock() authMapLock.Unlock()
} }

View file

@ -2,12 +2,12 @@ package turn
import ( import (
"context" "context"
"encoding/base64"
"log" "log"
"net" "net"
"strconv" "strconv"
"sync" "sync"
"syscall" "syscall"
"time"
"github.com/gravitl/netmaker/logger" "github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/turnserver/config" "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 // Return the key for that user, or false when no user is found
AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) {
if key, ok := auth.HostMap[username]; ok { 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 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 is a list of UDP Listeners and the configuration around them
PacketConnConfigs: packetConnConfigs, PacketConnConfigs: packetConnConfigs,
}) })
if err != nil { if err != nil {
log.Panic(err) log.Panic(err)
} }
go func() {
for {
time.Sleep(time.Second * 10)
log.Print(s.AllocationCount())
}
}()
// Block until user sends SIGINT or SIGTERM // Block until user sends SIGINT or SIGTERM
<-ctx.Done() <-ctx.Done()
logger.Log(0, "## Stopping Turn Server...") logger.Log(0, "## Stopping Turn Server...")