mirror of https://github.com/schollz/croc.git
Fixed hash
This commit is contained in:
parent
cd92fd6c8f
commit
302db87079
|
@ -152,14 +152,14 @@ func sendFile(id int, connection net.Conn, codePhrase string) {
|
|||
// Open the file that needs to be send to the client
|
||||
file, err := os.Open(fileName + ".encrypted")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
// Get the filename and filesize
|
||||
fileInfo, err := file.Stat()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -181,8 +181,9 @@ func sendFile(id int, connection net.Conn, codePhrase string) {
|
|||
logger.Debugf("fileNameToSend: %v", path.Base(fileName))
|
||||
}
|
||||
|
||||
logger.Debugf("sending %s", fileSize)
|
||||
logger.Debugf("sending fileSize: %s", fileSize)
|
||||
connection.Write([]byte(fileSize))
|
||||
logger.Debugf("sending fileNameToSend: %s", fileNameToSend)
|
||||
connection.Write([]byte(fileNameToSend))
|
||||
sendBuffer := make([]byte, BUFFERSIZE)
|
||||
|
||||
|
|
|
@ -4,7 +4,9 @@ import (
|
|||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
mathrand "math/rand"
|
||||
"strings"
|
||||
|
@ -12,7 +14,6 @@ import (
|
|||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/schollz/mnemonicode"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -86,6 +87,6 @@ func Decrypt(ciphertext []byte, key string) (plaintext []byte, err error) {
|
|||
}
|
||||
|
||||
func Hash(data string) string {
|
||||
hashed, _ := bcrypt.GenerateFromPassword([]byte(data), 14)
|
||||
return string(hashed)
|
||||
sum := sha256.Sum256([]byte(data))
|
||||
return fmt.Sprintf("%x", sum)
|
||||
}
|
||||
|
|
8
relay.go
8
relay.go
|
@ -41,7 +41,7 @@ func runServer() {
|
|||
|
||||
func listenerThread(id int, wg *sync.WaitGroup) {
|
||||
logger := log.WithFields(log.Fields{
|
||||
"function": "listenerThread@" + serverAddress + ":" + strconv.Itoa(27000+id),
|
||||
"function": "listenerThread:" + strconv.Itoa(27000+id),
|
||||
})
|
||||
|
||||
defer wg.Done()
|
||||
|
@ -54,11 +54,11 @@ func listenerThread(id int, wg *sync.WaitGroup) {
|
|||
func listener(id int) (err error) {
|
||||
port := strconv.Itoa(27001 + id)
|
||||
logger := log.WithFields(log.Fields{
|
||||
"function": "listener@" + serverAddress + ":" + port,
|
||||
"function": "listener" + ":" + port,
|
||||
})
|
||||
server, err := net.Listen("tcp", serverAddress+":"+port)
|
||||
server, err := net.Listen("tcp", "0.0.0.0:"+port)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error listening on "+serverAddress+":"+port)
|
||||
return errors.Wrap(err, "Error listening on "+":"+port)
|
||||
}
|
||||
defer server.Close()
|
||||
logger.Debug("waiting for connections")
|
||||
|
|
Loading…
Reference in New Issue