You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was experimenting with magic-wormhole protocol using golang and was experimenting send functionality. Then I encountered error on my side and noticed on mailbox server side there is this stack trace dumped on screen.
package main
import (
"encoding/hex""encoding/json""fmt""github.com/gorilla/websocket""log""net/url""salsa.debian.org/vasudev/magicwormhole/internal/core"
peer "salsa.debian.org/vasudev/magicwormhole/internal/peermessages"
server "salsa.debian.org/vasudev/magicwormhole/internal/servermessages""time"
)
funcstartSend(incomingchan server.IncommingMessage, c*websocket.Conn) {
k:=core.NewKey("lothar,com/wormhole/text-or-file-xfer", "side0", make(map[string]string))
varsharedKey []bytevarnameplate, mailbox, code, phase, textstringnameplateRelease:=falsefor {
select {
casemsg:=<-incoming:
switchmsg.(type) {
case*server.Welcome:
w:=msg.(*server.Welcome)
ifmotd, ok:=w.Welcome["motd"]; ok {
fmt.Printf("Message from server: %s\n", motd)
}
iferr:=c.WriteJSON(server.Bind{"lothar.com/wormhole/text-or-file-xfer", "side0"}); err!=nil {
log.Fatal("Failed to bind with server, ", err)
}
iferr:=c.WriteJSON(server.Allocate{}); err!=nil {
log.Fatal("Failed to request allocate nameplate: ", err)
}
case*server.Allocated:
a:=msg.(*server.Allocated)
nameplate=*a.Nameplateiferr:=c.WriteJSON(server.Claim{nameplate}); err!=nil {
log.Fatal("Failed to claim the nameplate: ", err)
}
fmt.Printf("Please enter a code (without nameplate): ")
varxstringfmt.Scanf("%s", &x)
code=fmt.Sprintf("%s-%s", nameplate, x)
fmt.Printf("Please run `wormhole rx %s` on other end\n", code)
case*server.Claimed:
claimed:=msg.(*server.Claimed)
mailbox=*claimed.Mailboxiferr:=c.WriteJSON(server.Open{mailbox}); err!=nil {
log.Fatal("Failed to open mailbox: ", err)
}
fmt.Print("Please enter message: ")
fmt.Scanf("%s", &text)
pake, err:=k.BuildPake(code)
iferr!=nil {
log.Fatal("Failed to build pake: ", err)
}
time.Sleep(time.Duration(10*time.Second))
iferr=c.WriteJSON(server.Add{"pake", hex.EncodeToString(pake)}); err!=nil {
log.Fatal("Failed to send pake message: ", err)
}
myVersion, err:=k.PrepareVersionMessage(sharedKey)
iferr!=nil {
log.Fatal("Failed to create version image: ", err)
}
iferr=c.WriteJSON(myVersion); err!=nil {
log.Fatal("Failed to send my version: ", err)
}
case*server.Message:
m:=msg.(*server.Message)
if*m.Side!="side0" {
if!nameplateRelease {
iferr:=c.WriteJSON(server.Release{nameplate}); err!=nil {
log.Fatal("Failed to release nameplate: ", err)
}
}
switch*m.Phase {
case"pake":
varerrerrorsharedKey, err=k.ComputeKey(*m.Body)
iferr!=nil {
log.Fatal("Failed to compute key: ", err)
}
fmt.Printf("shared key: %x\n", sharedKey)
default:
fmt.Printf("phase: %s side: %s\n", *m.Phase, *m.Side)
phaseKey:=core.DerivePhaseKey(sharedKey, *m.Side, *m.Phase)
body, err:=hex.DecodeString(*m.Body)
iferr!=nil {
log.Fatal("failed to decode body bytes: ", err)
}
data, err:=core.DecryptData(phaseKey, body)
iferr!=nil {
log.Fatal("failed to decrypt payload: ", err)
}
switch*m.Phase {
case"version":
varversion peer.Versioniferr:=json.Unmarshal(data, &version); err!=nil {
log.Fatal("payload unmarshaling for version failed: ", err)
}
iflen(version.AppVersion) !=0 {
fmt.Printf("%s\n", version.AppVersion)
}
fmt.Printf("key verified. Sending data... \n")
phase="0"phaseKey:=core.DerivePhaseKey(sharedKey, *m.Side, phase)
encrypted, err:=core.EncryptData(phaseKey, []byte(text))
iferr!=nil {
log.Fatal("Failed to encrypt data: ", err)
}
iferr=c.WriteJSON(server.Add{phase, hex.EncodeToString(encrypted)}); err!=nil {
log.Fatal("Failed to send message to other side: ", err)
}
default:
varanswer peer.Answeriferr:=json.Unmarshal(data, &answer); err!=nil {
log.Fatalf("Failed to unmarshal the answer: %s, unrecognized message: %s", err, string(data))
}
switchanswer.Answer.(type) {
case peer.MessageAck:
m:=answer.Answer.(peer.MessageAck)
ifm.Ack=="ok" {
fmt.Println("text message sent succesfully")
close:= server.Close{mailbox, "happy"}
iferr:=c.WriteJSON(close); err!=nil {
log.Fatal("Failed to close mailbox: ", err)
}
return
}
}
}
}
}
case*server.Released:
nameplateRelease=true
}
}
}
}
funcmain() {
u:= url.URL{Scheme: "ws", Host: "localhost:4000", Path: "v1"}
log.Printf("connecting to %s", u.String())
c, _, err:=websocket.DefaultDialer.Dial(u.String(), nil)
iferr!=nil {
log.Fatal("dial: ", err)
}
deferc.Close()
input:=make(chan server.IncommingMessage)
inputDone:=make(chanbool)
inputTimer:=time.NewTicker(time.Second)
deferinputTimer.Stop()
gofunc() {
deferclose(input)
varin server.IncommingMessagefor {
select {
case<-inputDone:
returncase<-inputTimer.C:
_, message, err:=c.ReadMessage()
iferr!=nil {
log.Println("Read: ", err)
}
in, err=server.Decode(json.RawMessage(message))
iferr!=nil {
log.Fatal("Decode: ", err, string(message))
}
input<-in
}
}
}()
startSend(input, c)
}
You would need to use salsa.debian.org/vasudev/magicwormhole for building this binary. Once built just execute and enter the code without nameplate (nameplate got from server). And you will see abrupt connection closure error and above trace back on mailbox server.
I was expecting an error message instead suggesting what might have gone wrong. Ofcourse its my code at fault but the above error is not handled in server side.
The text was updated successfully, but these errors were encountered:
Hi,
I was experimenting with magic-wormhole protocol using
golang
and was experimenting send functionality. Then I encountered error on my side and noticed on mailbox server side there is this stack trace dumped on screen.Here is the go code which causes this.
You would need to use
salsa.debian.org/vasudev/magicwormhole
for building this binary. Once built just execute and enter the code without nameplate (nameplate got from server). And you will see abrupt connection closure error and above trace back on mailbox server.I was expecting an error message instead suggesting what might have gone wrong. Ofcourse its my code at fault but the above error is not handled in server side.
The text was updated successfully, but these errors were encountered: