fix: do not use part of secret as room name

This commit is contained in:
Zack Scholl 2021-04-16 08:13:43 -07:00
parent 828de41d6c
commit 628043b228
3 changed files with 21 additions and 5 deletions

View File

@ -157,7 +157,7 @@ func New(ops Options) (c *Client, err error) {
Debug(c.Options.Debug)
log.Debugf("options: %+v", c.Options)
if len(c.Options.SharedSecret) < 4 {
if len(c.Options.SharedSecret) < 6 {
err = fmt.Errorf("code is too short")
return
}
@ -166,9 +166,9 @@ func New(ops Options) (c *Client, err error) {
// initialize pake
if c.Options.IsSender {
c.Pake, err = pake.Init([]byte(c.Options.SharedSecret), 1, siec.SIEC255(), 1*time.Microsecond)
c.Pake, err = pake.Init([]byte(c.Options.SharedSecret[5:]), 1, siec.SIEC255(), 1*time.Microsecond)
} else {
c.Pake, err = pake.Init([]byte(c.Options.SharedSecret), 0, siec.SIEC255(), 1*time.Microsecond)
c.Pake, err = pake.Init([]byte(c.Options.SharedSecret[5:]), 0, siec.SIEC255(), 1*time.Microsecond)
}
if err != nil {
return
@ -872,7 +872,7 @@ func (c *Client) procesMessagePake(m message.Message) (err error) {
c.conn[j+1], _, _, err = tcp.ConnectToTCPServer(
server,
c.Options.RelayPassword,
fmt.Sprintf("%s-%d", utils.SHA256(c.Options.SharedSecret)[:7], j),
fmt.Sprintf("%s-%d", utils.SHA256(c.Options.SharedSecret[:5])[:6], j),
)
if err != nil {
panic(err)

View File

@ -12,6 +12,7 @@ import (
"io/ioutil"
"log"
"math"
"math/big"
"net"
"net/http"
"os"
@ -140,13 +141,27 @@ func LocalIP() string {
return localAddr.IP.String()
}
func GenerateRandomPin() string {
s := ""
max := new(big.Int)
max.SetInt64(9)
for i := 0; i < 4; i++ {
v, err := rand.Int(rand.Reader, max)
if err != nil {
panic(err)
}
s += fmt.Sprintf("%d", v)
}
return s
}
// GetRandomName returns mnemoicoded random name
func GetRandomName() string {
var result []string
bs := make([]byte, 4)
rand.Read(bs)
result = mnemonicode.EncodeWordList(result, bs)
return strings.Join(result, "-")
return GenerateRandomPin() + "-" + strings.Join(result, "-")
}
// ByteCountDecimal converts bytes to human readable byte string

View File

@ -184,6 +184,7 @@ func TestLocalIP(t *testing.T) {
func TestGetRandomName(t *testing.T) {
name := GetRandomName()
fmt.Println(name)
assert.NotEmpty(t, name)
}