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

Fixed hash

This commit is contained in:
Zack Scholl 2017-10-17 20:33:27 -06:00
parent cd92fd6c8f
commit 302db87079
3 changed files with 12 additions and 10 deletions

View file

@ -152,14 +152,14 @@ func sendFile(id int, connection net.Conn, codePhrase string) {
// Open the file that needs to be send to the client // Open the file that needs to be send to the client
file, err := os.Open(fileName + ".encrypted") file, err := os.Open(fileName + ".encrypted")
if err != nil { if err != nil {
fmt.Println(err) logger.Error(err)
return return
} }
defer file.Close() defer file.Close()
// Get the filename and filesize // Get the filename and filesize
fileInfo, err := file.Stat() fileInfo, err := file.Stat()
if err != nil { if err != nil {
fmt.Println(err) logger.Error(err)
return return
} }
@ -181,8 +181,9 @@ func sendFile(id int, connection net.Conn, codePhrase string) {
logger.Debugf("fileNameToSend: %v", path.Base(fileName)) logger.Debugf("fileNameToSend: %v", path.Base(fileName))
} }
logger.Debugf("sending %s", fileSize) logger.Debugf("sending fileSize: %s", fileSize)
connection.Write([]byte(fileSize)) connection.Write([]byte(fileSize))
logger.Debugf("sending fileNameToSend: %s", fileNameToSend)
connection.Write([]byte(fileNameToSend)) connection.Write([]byte(fileNameToSend))
sendBuffer := make([]byte, BUFFERSIZE) sendBuffer := make([]byte, BUFFERSIZE)

View file

@ -4,7 +4,9 @@ import (
"crypto/aes" "crypto/aes"
"crypto/cipher" "crypto/cipher"
"crypto/rand" "crypto/rand"
"crypto/sha256"
"encoding/binary" "encoding/binary"
"fmt"
"io" "io"
mathrand "math/rand" mathrand "math/rand"
"strings" "strings"
@ -12,7 +14,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/schollz/mnemonicode" "github.com/schollz/mnemonicode"
"golang.org/x/crypto/bcrypt"
) )
func init() { func init() {
@ -86,6 +87,6 @@ func Decrypt(ciphertext []byte, key string) (plaintext []byte, err error) {
} }
func Hash(data string) string { func Hash(data string) string {
hashed, _ := bcrypt.GenerateFromPassword([]byte(data), 14) sum := sha256.Sum256([]byte(data))
return string(hashed) return fmt.Sprintf("%x", sum)
} }

View file

@ -41,7 +41,7 @@ func runServer() {
func listenerThread(id int, wg *sync.WaitGroup) { func listenerThread(id int, wg *sync.WaitGroup) {
logger := log.WithFields(log.Fields{ logger := log.WithFields(log.Fields{
"function": "listenerThread@" + serverAddress + ":" + strconv.Itoa(27000+id), "function": "listenerThread:" + strconv.Itoa(27000+id),
}) })
defer wg.Done() defer wg.Done()
@ -54,11 +54,11 @@ func listenerThread(id int, wg *sync.WaitGroup) {
func listener(id int) (err error) { func listener(id int) (err error) {
port := strconv.Itoa(27001 + id) port := strconv.Itoa(27001 + id)
logger := log.WithFields(log.Fields{ 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 { if err != nil {
return errors.Wrap(err, "Error listening on "+serverAddress+":"+port) return errors.Wrap(err, "Error listening on "+":"+port)
} }
defer server.Close() defer server.Close()
logger.Debug("waiting for connections") logger.Debug("waiting for connections")