mirror of https://github.com/schollz/croc.git
recipient sends errors through websockets
This commit is contained in:
parent
d05e196139
commit
6e10ed25af
|
@ -4,7 +4,6 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -16,6 +15,7 @@ import (
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
humanize "github.com/dustin/go-humanize"
|
humanize "github.com/dustin/go-humanize"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/schollz/croc/src/comm"
|
"github.com/schollz/croc/src/comm"
|
||||||
"github.com/schollz/croc/src/compress"
|
"github.com/schollz/croc/src/compress"
|
||||||
"github.com/schollz/croc/src/crypt"
|
"github.com/schollz/croc/src/crypt"
|
||||||
|
@ -26,7 +26,6 @@ import (
|
||||||
"github.com/schollz/pake"
|
"github.com/schollz/pake"
|
||||||
"github.com/schollz/progressbar/v2"
|
"github.com/schollz/progressbar/v2"
|
||||||
"github.com/schollz/spinner"
|
"github.com/schollz/spinner"
|
||||||
"github.com/tscholl2/siec"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var DebugLevel string
|
var DebugLevel string
|
||||||
|
@ -38,6 +37,10 @@ func (cr *Croc) startRecipient(forceSend int, serverAddress string, tcpPorts []s
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !strings.HasPrefix(err.Error(), "websocket: close 100") {
|
if !strings.HasPrefix(err.Error(), "websocket: close 100") {
|
||||||
fmt.Fprintf(os.Stderr, "\n"+err.Error())
|
fmt.Fprintf(os.Stderr, "\n"+err.Error())
|
||||||
|
cr.StateString = err.Error()
|
||||||
|
err = errors.Wrap(err, "error in recipient:")
|
||||||
|
c.WriteMessage(websocket.TextMessage, []byte(err.Error()))
|
||||||
|
time.Sleep(50 * time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done <- struct{}{}
|
done <- struct{}{}
|
||||||
|
@ -74,16 +77,11 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
|
||||||
spin.Start()
|
spin.Start()
|
||||||
defer spin.Stop()
|
defer spin.Stop()
|
||||||
|
|
||||||
// pick an elliptic curve
|
|
||||||
curve := siec.SIEC255()
|
|
||||||
// both parties should have a weak key
|
// both parties should have a weak key
|
||||||
pw := []byte(codephrase)
|
pw := []byte(codephrase)
|
||||||
|
|
||||||
// initialize recipient Q ("1" indicates recipient)
|
// initialize recipient Q ("1" indicates recipient)
|
||||||
Q, err := pake.Init(pw, 1, curve, 1*time.Millisecond)
|
var Q *pake.Pake
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
step := 0
|
step := 0
|
||||||
for {
|
for {
|
||||||
|
@ -101,10 +99,22 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
|
||||||
log.Debugf("got %d: %s", messageType, message)
|
log.Debugf("got %d: %s", messageType, message)
|
||||||
switch step {
|
switch step {
|
||||||
case 0:
|
case 0:
|
||||||
// sender has initiated, sends their ip address
|
// sender has initiated, sends their initial data
|
||||||
cr.OtherIP = string(message)
|
var initialData models.Initial
|
||||||
|
err = json.Unmarshal(message, &initialData)
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrap(err, "incompatible versions of croc")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cr.OtherIP = initialData.IPAddress
|
||||||
log.Debugf("sender IP: %s", cr.OtherIP)
|
log.Debugf("sender IP: %s", cr.OtherIP)
|
||||||
|
|
||||||
|
Q, err = pake.InitCurve(pw, 1, initialData.CurveType, 1*time.Millisecond)
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrap(err, "incompatible curve type")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// recipient begins by sending address
|
// recipient begins by sending address
|
||||||
ip := ""
|
ip := ""
|
||||||
if isLocal {
|
if isLocal {
|
||||||
|
|
Loading…
Reference in New Issue