1
1
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

use shared secret

This commit is contained in:
Zack Scholl 2019-04-13 02:52:58 -07:00
parent 9d84485b97
commit 513fd34298
2 changed files with 8 additions and 8 deletions

View file

@ -138,12 +138,12 @@ func (s *Session) CreateDataHandler() {
})
}
func (s *Session) ReceiveData(pathToFile string, fileSize int64) {
s.receiveData(pathToFile, fileSize)
func (s *Session) ReceiveData(pathToFile string, fileSize int64, sharedSecret []byte) {
s.receiveData(pathToFile, fileSize, sharedSecret)
s.sess.OnCompletion()
}
func (s *Session) receiveData(pathToFile string, fileSize int64) error {
func (s *Session) receiveData(pathToFile string, fileSize int64, sharedSecret []byte) error {
log.Debugln("Starting to receive data...")
log.Debugf("receiving %s", pathToFile)
@ -195,7 +195,7 @@ func (s *Session) receiveData(pathToFile string, fileSize int64) error {
log.Debug("closed gracefully")
return nil
case msg := <-s.msgChannel:
buff, errDecrypt := crypt.DecryptFromBytes(msg.Data, []byte{1, 2, 3, 4})
buff, errDecrypt := crypt.DecryptFromBytes(msg.Data, sharedSecret)
if errDecrypt != nil {
log.Error(errDecrypt)
return errDecrypt

View file

@ -117,8 +117,8 @@ func (s *Session) SetSDP(sdp string) error {
return s.sess.SetSDP(sdp)
}
func (s *Session) TransferFile(pathToFile string) {
s.readFile(pathToFile)
func (s *Session) TransferFile(pathToFile string, sharedSecret []byte) {
s.readFile(pathToFile, sharedSecret)
s.sess.OnCompletion()
}
@ -186,7 +186,7 @@ func (s *Session) CreateDataChannel() error {
return nil
}
func (s *Session) readFile(pathToFile string) error {
func (s *Session) readFile(pathToFile string, sharedSecret []byte) error {
f, err := os.Open(pathToFile)
if err != nil {
log.Error(err)
@ -232,7 +232,7 @@ func (s *Session) readFile(pathToFile string) error {
}
buff = append(buff, s.dataBuff[:n-i]...)
buff = compress.Compress(buff)
buff = crypt.EncryptToBytes(buff, []byte{1, 2, 3, 4})
buff = crypt.EncryptToBytes(buff, sharedSecret)
if len(buff) < maxPacketSize {
if n-i > 0 {
lastBytes = append([]byte(nil), s.dataBuff[n-i:]...)