mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 21:30:16 +02:00
update the curve in client
This commit is contained in:
parent
b32d7060bf
commit
87c935dc1e
4 changed files with 26 additions and 17 deletions
|
@ -129,6 +129,8 @@ func (c *Croc) processState(cd channelData) (err error) {
|
||||||
for key := range cd.State {
|
for key := range cd.State {
|
||||||
c.cs.channel.State[key] = cd.State[key]
|
c.cs.channel.State[key] = cd.State[key]
|
||||||
}
|
}
|
||||||
|
// update the curve
|
||||||
|
_, c.cs.channel.curve = getCurve(string(c.cs.channel.State["curve"]))
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// process the client state
|
// process the client state
|
||||||
|
|
|
@ -51,6 +51,7 @@ type channelData struct {
|
||||||
// Channel is the name of the channel
|
// Channel is the name of the channel
|
||||||
Channel string `json:"channel,omitempty"`
|
Channel string `json:"channel,omitempty"`
|
||||||
// State contains state variables that are public to both parties
|
// State contains state variables that are public to both parties
|
||||||
|
// contains "curve", "h_k", "hh_k", "x", "y"
|
||||||
State map[string][]byte `json:"state"`
|
State map[string][]byte `json:"state"`
|
||||||
// TransferReady is set by the relaying when both parties have connected
|
// TransferReady is set by the relaying when both parties have connected
|
||||||
// with their credentials
|
// with their credentials
|
||||||
|
@ -61,7 +62,7 @@ type channelData struct {
|
||||||
// Error is sent if there is an error
|
// Error is sent if there is an error
|
||||||
Error string `json:"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 is sent out only to one person at a time
|
||||||
UUID string `json:"uuid"`
|
UUID string `json:"uuid"`
|
||||||
// Role is the role the person will play
|
// Role is the role the person will play
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package croc
|
package croc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/elliptic"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"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].isopen = true
|
||||||
c.rs.channel[p.Channel].Ports = c.TcpPorts
|
c.rs.channel[p.Channel].Ports = c.TcpPorts
|
||||||
c.rs.channel[p.Channel].startTime = time.Now()
|
c.rs.channel[p.Channel].startTime = time.Now()
|
||||||
switch curve := p.Curve; curve {
|
p.Curve, c.rs.channel[p.Channel].curve = getCurve(p.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()
|
|
||||||
}
|
|
||||||
log.Debugf("(%s) using curve '%s'", p.Channel, p.Curve)
|
log.Debugf("(%s) using curve '%s'", p.Channel, p.Curve)
|
||||||
c.rs.channel[p.Channel].State["curve"] = []byte(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
|
package croc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/elliptic"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -69,6 +70,26 @@ func splitFile(fileName string, numPieces int) (err error) {
|
||||||
return nil
|
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
|
// 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
|
// 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.
|
// between the two files. If that fail, copy the file contents from src to dst.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue