From 87c935dc1e95b35291d4474d44469ae106edf4e0 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Fri, 29 Jun 2018 06:30:02 -0700 Subject: [PATCH] update the curve in client --- src/client.go | 2 ++ src/models.go | 3 ++- src/server.go | 17 +---------------- src/utils.go | 21 +++++++++++++++++++++ 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/client.go b/src/client.go index 3ceada1..02a6e18 100644 --- a/src/client.go +++ b/src/client.go @@ -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 diff --git a/src/models.go b/src/models.go index 691d543..e10aa5d 100644 --- a/src/models.go +++ b/src/models.go @@ -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 diff --git a/src/server.go b/src/server.go index 56853b3..d256815 100644 --- a/src/server.go +++ b/src/server.go @@ -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) } diff --git a/src/utils.go b/src/utils.go index 0554d77..7641b7b 100644 --- a/src/utils.go +++ b/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.