mirror of https://github.com/schollz/croc.git
update the curve in client
This commit is contained in:
parent
b32d7060bf
commit
87c935dc1e
|
@ -129,6 +129,8 @@ func (c *Croc) processState(cd channelData) (err error) {
|
|||
for key := range cd.State {
|
||||
c.cs.channel.State[key] = cd.State[key]
|
||||
}
|
||||
// update the curve
|
||||
_, c.cs.channel.curve = getCurve(string(c.cs.channel.State["curve"]))
|
||||
|
||||
// TODO:
|
||||
// process the client state
|
||||
|
|
|
@ -51,6 +51,7 @@ type channelData struct {
|
|||
// Channel is the name of the channel
|
||||
Channel string `json:"channel,omitempty"`
|
||||
// State contains state variables that are public to both parties
|
||||
// contains "curve", "h_k", "hh_k", "x", "y"
|
||||
State map[string][]byte `json:"state"`
|
||||
// TransferReady is set by the relaying when both parties have connected
|
||||
// with their credentials
|
||||
|
@ -61,7 +62,7 @@ type channelData struct {
|
|||
// Error is sent if there is an error
|
||||
Error string `json:"error"`
|
||||
|
||||
// Sent on initialization
|
||||
// Sent on initialization, specific to a single user
|
||||
// UUID is sent out only to one person at a time
|
||||
UUID string `json:"uuid"`
|
||||
// Role is the role the person will play
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package croc
|
||||
|
||||
import (
|
||||
"crypto/elliptic"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
|
@ -141,21 +140,7 @@ func (c *Croc) joinChannel(ws *websocket.Conn, p payload) (channel string, err e
|
|||
c.rs.channel[p.Channel].isopen = true
|
||||
c.rs.channel[p.Channel].Ports = c.TcpPorts
|
||||
c.rs.channel[p.Channel].startTime = time.Now()
|
||||
switch curve := p.Curve; curve {
|
||||
case "p224":
|
||||
c.rs.channel[p.Channel].curve = elliptic.P224()
|
||||
case "p256":
|
||||
c.rs.channel[p.Channel].curve = elliptic.P256()
|
||||
case "p384":
|
||||
c.rs.channel[p.Channel].curve = elliptic.P384()
|
||||
case "p521":
|
||||
c.rs.channel[p.Channel].curve = elliptic.P521()
|
||||
default:
|
||||
// TODO:
|
||||
// add SIEC
|
||||
p.Curve = "p256"
|
||||
c.rs.channel[p.Channel].curve = elliptic.P256()
|
||||
}
|
||||
p.Curve, c.rs.channel[p.Channel].curve = getCurve(p.Curve)
|
||||
log.Debugf("(%s) using curve '%s'", p.Channel, p.Curve)
|
||||
c.rs.channel[p.Channel].State["curve"] = []byte(p.Curve)
|
||||
}
|
||||
|
|
21
src/utils.go
21
src/utils.go
|
@ -1,6 +1,7 @@
|
|||
package croc
|
||||
|
||||
import (
|
||||
"crypto/elliptic"
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -69,6 +70,26 @@ func splitFile(fileName string, numPieces int) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
func getCurve(s string) (curveString string, curve elliptic.Curve) {
|
||||
curveString = s
|
||||
switch s {
|
||||
case "p224":
|
||||
curve = elliptic.P224()
|
||||
case "p256":
|
||||
curve = elliptic.P256()
|
||||
case "p384":
|
||||
curve = elliptic.P384()
|
||||
case "p521":
|
||||
curve = elliptic.P521()
|
||||
default:
|
||||
// TODO:
|
||||
// add SIEC
|
||||
curveString = "p256"
|
||||
curve = elliptic.P256()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// copyFile copies a file from src to dst. If src and dst files exist, and are
|
||||
// the same, then return success. Otherise, attempt to create a hard link
|
||||
// between the two files. If that fail, copy the file contents from src to dst.
|
||||
|
|
Loading…
Reference in New Issue