use random salt

This commit is contained in:
Zack Scholl 2019-04-30 16:10:07 -06:00
parent e72795985b
commit 9952da9f6d
1 changed files with 25 additions and 9 deletions

View File

@ -3,6 +3,7 @@ package croc
import ( import (
"bytes" "bytes"
"crypto/elliptic" "crypto/elliptic"
"crypto/rand"
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
"fmt" "fmt"
@ -396,14 +397,13 @@ func (c *Client) processMessage(payload []byte) (done bool, err error) {
}) })
} }
if c.Pake.IsVerified() { if c.Pake.IsVerified() {
log.Debug("session key is verified, generating encryption") if c.Options.IsSender {
key, err := c.Pake.SessionKey() salt := make([]byte, 8)
if err != nil { rand.Read(salt)
return true, err err = message.Send(c.conn[0], c.Key, message.Message{
} Type: "salt",
c.Key, err = crypt.New(key, []byte(c.Options.SharedSecret)) Bytes: salt,
if err != nil { })
return true, err
} }
// connects to the other ports of the server for transfer // connects to the other ports of the server for transfer
@ -425,8 +425,24 @@ func (c *Client) processMessage(payload []byte) (done bool, err error) {
}(i) }(i)
} }
wg.Wait() wg.Wait()
c.Step1ChannelSecured = true
} }
case "salt":
if !c.Options.IsSender {
err = message.Send(c.conn[0], c.Key, message.Message{
Type: "salt",
Bytes: m.Bytes,
})
}
log.Debugf("session key is verified, generating encryption with salt: %x", m.Bytes)
key, err := c.Pake.SessionKey()
if err != nil {
return true, err
}
c.Key, err = crypt.New(key, m.Bytes)
if err != nil {
return true, err
}
c.Step1ChannelSecured = true
case "error": case "error":
// c.spinner.Stop() // c.spinner.Stop()
fmt.Print("\r") fmt.Print("\r")