mirror of
https://github.com/schollz/croc.git
synced 2024-11-28 01:16:10 +03:00
fix: do not use part of secret as room name
This commit is contained in:
parent
828de41d6c
commit
628043b228
@ -157,7 +157,7 @@ func New(ops Options) (c *Client, err error) {
|
|||||||
Debug(c.Options.Debug)
|
Debug(c.Options.Debug)
|
||||||
log.Debugf("options: %+v", c.Options)
|
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")
|
err = fmt.Errorf("code is too short")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -166,9 +166,9 @@ func New(ops Options) (c *Client, err error) {
|
|||||||
|
|
||||||
// initialize pake
|
// initialize pake
|
||||||
if c.Options.IsSender {
|
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 {
|
} 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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -872,7 +872,7 @@ func (c *Client) procesMessagePake(m message.Message) (err error) {
|
|||||||
c.conn[j+1], _, _, err = tcp.ConnectToTCPServer(
|
c.conn[j+1], _, _, err = tcp.ConnectToTCPServer(
|
||||||
server,
|
server,
|
||||||
c.Options.RelayPassword,
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -140,13 +141,27 @@ func LocalIP() string {
|
|||||||
return localAddr.IP.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
|
// GetRandomName returns mnemoicoded random name
|
||||||
func GetRandomName() string {
|
func GetRandomName() string {
|
||||||
var result []string
|
var result []string
|
||||||
bs := make([]byte, 4)
|
bs := make([]byte, 4)
|
||||||
rand.Read(bs)
|
rand.Read(bs)
|
||||||
result = mnemonicode.EncodeWordList(result, bs)
|
result = mnemonicode.EncodeWordList(result, bs)
|
||||||
return strings.Join(result, "-")
|
return GenerateRandomPin() + "-" + strings.Join(result, "-")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ByteCountDecimal converts bytes to human readable byte string
|
// ByteCountDecimal converts bytes to human readable byte string
|
||||||
|
@ -184,6 +184,7 @@ func TestLocalIP(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetRandomName(t *testing.T) {
|
func TestGetRandomName(t *testing.T) {
|
||||||
name := GetRandomName()
|
name := GetRandomName()
|
||||||
|
fmt.Println(name)
|
||||||
assert.NotEmpty(t, name)
|
assert.NotEmpty(t, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user