mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 05:11:06 +02:00
fix: make sure that only pake messages are unencrypted
This commit is contained in:
parent
babfd5f35f
commit
c02b4f1256
1 changed files with 20 additions and 11 deletions
|
@ -104,11 +104,11 @@ type Client struct {
|
||||||
longestFilename int
|
longestFilename int
|
||||||
firstSend bool
|
firstSend bool
|
||||||
|
|
||||||
mutex *sync.Mutex
|
mutex *sync.Mutex
|
||||||
fread *os.File
|
fread *os.File
|
||||||
numfinished int
|
numfinished int
|
||||||
quit chan bool
|
quit chan bool
|
||||||
finishedNum int
|
finishedNum int
|
||||||
numberOfTransferedFiles int
|
numberOfTransferedFiles int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,7 +678,7 @@ func (c *Client) Receive() (err error) {
|
||||||
err = c.transfer(TransferOptions{})
|
err = c.transfer(TransferOptions{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if c.numberOfTransferedFiles == 0 {
|
if c.numberOfTransferedFiles == 0 {
|
||||||
fmt.Fprintf(os.Stderr,"\rNo files need transfering.")
|
fmt.Fprintf(os.Stderr, "\rNo files need transfering.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -931,6 +931,15 @@ func (c *Client) processMessage(payload []byte) (done bool, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only "pake" messages should be unencrypted
|
||||||
|
// if a non-"pake" message is received unencrypted something
|
||||||
|
// is weird
|
||||||
|
if m.Type != "pake" && c.Key == nil {
|
||||||
|
err = fmt.Errorf("unencrypted communication rejected")
|
||||||
|
done = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
switch m.Type {
|
switch m.Type {
|
||||||
case "finished":
|
case "finished":
|
||||||
err = message.Send(c.conn[0], c.Key, message.Message{
|
err = message.Send(c.conn[0], c.Key, message.Message{
|
||||||
|
@ -1209,7 +1218,7 @@ func (c *Client) updateIfRecipientHasFileInfo() (err error) {
|
||||||
err = c.createEmptyFileAndFinish(fileInfo, i)
|
err = c.createEmptyFileAndFinish(fileInfo, i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
} else{
|
} else {
|
||||||
c.numberOfTransferedFiles++
|
c.numberOfTransferedFiles++
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
|
@ -1217,12 +1226,12 @@ func (c *Client) updateIfRecipientHasFileInfo() (err error) {
|
||||||
log.Debugf("%s %+x %+x %+v", fileInfo.Name, fileHash, fileInfo.Hash, errHash)
|
log.Debugf("%s %+x %+x %+v", fileInfo.Name, fileHash, fileInfo.Hash, errHash)
|
||||||
if !bytes.Equal(fileHash, fileInfo.Hash) {
|
if !bytes.Equal(fileHash, fileInfo.Hash) {
|
||||||
log.Debugf("hashes are not equal %x != %x", fileHash, fileInfo.Hash)
|
log.Debugf("hashes are not equal %x != %x", fileHash, fileInfo.Hash)
|
||||||
if errHash== nil && !c.Options.Overwrite {
|
if errHash == nil && !c.Options.Overwrite {
|
||||||
ans := utils.GetInput(fmt.Sprintf("\rOverwrite '%s'? (y/n) ",path.Join(fileInfo.FolderRemote, fileInfo.Name)))
|
ans := utils.GetInput(fmt.Sprintf("\rOverwrite '%s'? (y/n) ", path.Join(fileInfo.FolderRemote, fileInfo.Name)))
|
||||||
if strings.TrimSpace(strings.ToLower(ans)) != "y" {
|
if strings.TrimSpace(strings.ToLower(ans)) != "y" {
|
||||||
fmt.Fprintf(os.Stderr,"skipping '%s'",path.Join(fileInfo.FolderRemote, fileInfo.Name))
|
fmt.Fprintf(os.Stderr, "skipping '%s'", path.Join(fileInfo.FolderRemote, fileInfo.Name))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Debugf("hashes are equal %x == %x", fileHash, fileInfo.Hash)
|
log.Debugf("hashes are equal %x == %x", fileHash, fileInfo.Hash)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue