TUN-1648: ConnectionID is now a UUID

This commit is contained in:
Adam Chalmers 2019-03-28 12:58:23 -05:00
parent b5dab1f5da
commit 6804a5ff9d
1 changed files with 15 additions and 12 deletions

View File

@ -4,10 +4,8 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"encoding/hex"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math/rand"
"net" "net"
"net/http" "net/http"
"os" "os"
@ -21,13 +19,13 @@ import (
"github.com/cloudflare/cloudflared/tlsconfig" "github.com/cloudflare/cloudflared/tlsconfig"
tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs" tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
"github.com/cloudflare/cloudflared/validation" "github.com/cloudflare/cloudflared/validation"
"golang.org/x/crypto/ssh/terminal"
"github.com/sirupsen/logrus"
"gopkg.in/urfave/cli.v2"
"github.com/google/uuid"
"github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh/terminal"
"gopkg.in/urfave/cli.v2"
) )
var ( var (
@ -49,11 +47,13 @@ func findDefaultOriginCertPath() string {
return "" return ""
} }
func generateRandomClientID() string { func generateRandomClientID(logger *logrus.Logger) (string, error) {
r := rand.New(rand.NewSource(time.Now().UnixNano())) u, err := uuid.NewRandom()
id := make([]byte, 32) if err != nil {
r.Read(id) logger.WithError(err).Error("couldn't create UUID for client ID")
return hex.EncodeToString(id) return "", err
}
return u.String(), nil
} }
func handleDeprecatedOptions(c *cli.Context) error { func handleDeprecatedOptions(c *cli.Context) error {
@ -159,7 +159,10 @@ func prepareTunnelConfig(
isFreeTunnel := hostname == "" isFreeTunnel := hostname == ""
clientID := c.String("id") clientID := c.String("id")
if !c.IsSet("id") { if !c.IsSet("id") {
clientID = generateRandomClientID() clientID, err = generateRandomClientID(logger)
if err != nil {
return nil, err
}
} }
tags, err := NewTagSliceFromCLI(c.StringSlice("tag")) tags, err := NewTagSliceFromCLI(c.StringSlice("tag"))