1
0
mirror of https://github.com/schollz/croc.git synced 2024-11-24 08:02:33 +03:00

encrypt external ip

This commit is contained in:
Zack Scholl 2020-02-28 12:58:46 -08:00
parent d5846bc88d
commit 5fce2a2e27
3 changed files with 35 additions and 10 deletions

View File

@ -642,9 +642,8 @@ func (c *Client) procesMesssagePake(m message.Message) (err error) {
salt := make([]byte, 8)
rand.Read(salt)
err = message.Send(c.conn[0], c.Key, message.Message{
Type: "salt",
Bytes: salt,
Message: c.ExternalIP,
Type: "salt",
Bytes: salt,
})
if err != nil {
return
@ -684,9 +683,8 @@ func (c *Client) processMessageSalt(m message.Message) (done bool, err error) {
if !c.Options.IsSender {
log.Debug("sending salt back")
err = message.Send(c.conn[0], c.Key, message.Message{
Type: "salt",
Bytes: m.Bytes,
Message: c.ExternalIP,
Type: "salt",
Bytes: m.Bytes,
})
}
log.Debugf("session key is verified, generating encryption with salt: %x", m.Bytes)
@ -699,6 +697,27 @@ func (c *Client) processMessageSalt(m message.Message) (done bool, err error) {
return true, err
}
log.Debugf("key = %+x", c.Key)
if c.Options.IsSender {
log.Debug("sending external IP")
err = message.Send(c.conn[0], c.Key, message.Message{
Type: "externalip",
Bytes: m.Bytes,
})
}
return
}
func (c *Client) processExternalIP(m message.Message) (done bool, err error) {
log.Debug("received external IP")
if !c.Options.IsSender {
err = message.Send(c.conn[0], c.Key, message.Message{
Type: "externalip",
Message: c.ExternalIP,
})
if err != nil {
return true, err
}
}
if c.ExternalIPConnected == "" {
// it can be preset by the local relay
c.ExternalIPConnected = m.Message
@ -711,6 +730,7 @@ func (c *Client) processMessageSalt(m message.Message) (done bool, err error) {
func (c *Client) processMessage(payload []byte) (done bool, err error) {
m, err := message.Decode(c.Key, payload)
if err != nil {
err = fmt.Errorf("problem with decoding: %s", err.Error())
return
}
@ -726,6 +746,8 @@ func (c *Client) processMessage(payload []byte) (done bool, err error) {
err = c.procesMesssagePake(m)
case "salt":
done, err = c.processMessageSalt(m)
case "externalip":
done, err = c.processExternalIP(m)
case "error":
// c.spinner.Stop()
fmt.Print("\r")

View File

@ -12,15 +12,18 @@ import (
"github.com/stretchr/testify/assert"
)
func TestCroc(t *testing.T) {
func init() {
log.SetLevel("trace")
defer os.Remove("README.md")
go tcp.Run("debug", "8081", "pass123", "8082,8083,8084,8085")
go tcp.Run("debug", "8082", "pass123")
go tcp.Run("debug", "8083", "pass123")
go tcp.Run("debug", "8084", "pass123")
go tcp.Run("debug", "8085", "pass123")
time.Sleep(1 * time.Second)
time.Sleep(5 * time.Second)
}
func TestCrocReadme(t *testing.T) {
defer os.Remove("README.md")
log.Debug("setting up sender")
sender, err := New(Options{

View File

@ -24,11 +24,11 @@ func (m Message) String() string {
// Send will send out
func Send(c *comm.Comm, key []byte, m Message) (err error) {
log.Debugf("writing %s message", m.Type)
mSend, err := Encode(key, m)
if err != nil {
return
}
log.Debugf("writing %s message (%d bytes)", m.Type, len(mSend))
_, err = c.Write(mSend)
return
}