diff --git a/connect.go b/connect.go index 8a5e382..1706b4d 100644 --- a/connect.go +++ b/connect.go @@ -220,9 +220,6 @@ func sendFile(id int, connection net.Conn, codePhrase string) { if id+1 == numberConnections { bytesPerConnection = int64(len(fileBytes)) - (numberConnections-1)*bytesPerConnection } - fileSize := fillString(strconv.FormatInt(int64(bytesPerConnection), 10), 10) - - fileNameToSend := fillString(path.Base(fileName), 64) if id == 0 || id == numberConnections-1 { logger.Debugf("numChunks: %v", numChunks) @@ -232,12 +229,12 @@ func sendFile(id int, connection net.Conn, codePhrase string) { } // send file size - logger.Debugf("sending fileSize: %s", fileSize) - connection.Write([]byte(fileSize)) + logger.Debugf("sending fileSize: %d", bytesPerConnection) + connection.Write([]byte(fillString(strconv.FormatInt(int64(bytesPerConnection), 10), 10))) // send fileName - logger.Debugf("sending fileNameToSend: %s", fileNameToSend) - connection.Write([]byte(fileNameToSend)) + logger.Debugf("sending fileName: %s", path.Base(fileName)) + connection.Write([]byte(fillString(path.Base(fileName), 64))) // send iv logger.Debugf("sending iv: %s", fileIV) diff --git a/crypto.go b/crypto.go index 7f278ac..2e5f2cb 100644 --- a/crypto.go +++ b/crypto.go @@ -1,12 +1,9 @@ package main import ( - "crypto/aes" - "crypto/cipher" "crypto/rand" "crypto/sha256" "encoding/binary" - "encoding/hex" "fmt" mathrand "math/rand" "strings" @@ -29,25 +26,27 @@ func GetRandomName() string { } func Encrypt(plaintext []byte, passphrase string) ([]byte, string, string) { - key, salt := deriveKey(passphrase, nil) - iv := make([]byte, 12) - // http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf - // Section 8.2 - rand.Read(iv) - b, _ := aes.NewCipher(key) - aesgcm, _ := cipher.NewGCM(b) - data := aesgcm.Seal(nil, iv, plaintext, nil) - return data, hex.EncodeToString(salt), hex.EncodeToString(iv) + return plaintext, "salt", "iv" + // key, salt := deriveKey(passphrase, nil) + // iv := make([]byte, 12) + // // http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf + // // Section 8.2 + // rand.Read(iv) + // b, _ := aes.NewCipher(key) + // aesgcm, _ := cipher.NewGCM(b) + // data := aesgcm.Seal(nil, iv, plaintext, nil) + // return data, hex.EncodeToString(salt), hex.EncodeToString(iv) } func Decrypt(data []byte, passphrase string, salt string, iv string) (plaintext []byte, err error) { - saltBytes, _ := hex.DecodeString(salt) - ivBytes, _ := hex.DecodeString(iv) - key, _ := deriveKey(passphrase, saltBytes) - b, _ := aes.NewCipher(key) - aesgcm, _ := cipher.NewGCM(b) - plaintext, err = aesgcm.Open(nil, ivBytes, data, nil) - return + return plaintext, nil + // saltBytes, _ := hex.DecodeString(salt) + // ivBytes, _ := hex.DecodeString(iv) + // key, _ := deriveKey(passphrase, saltBytes) + // b, _ := aes.NewCipher(key) + // aesgcm, _ := cipher.NewGCM(b) + // plaintext, err = aesgcm.Open(nil, ivBytes, data, nil) + // return } func deriveKey(passphrase string, salt []byte) ([]byte, []byte) { diff --git a/main.go b/main.go index 0d552ac..46d9e0c 100644 --- a/main.go +++ b/main.go @@ -66,6 +66,9 @@ func main() { } fileBytes, fileSalt, fileIV = Encrypt(fdata, codePhraseFlag) fileHash = HashBytes(fdata) + if debugFlag { + ioutil.WriteFile(fileName+".encrypted", fileBytes, 0644) + } } log.SetFormatter(&log.TextFormatter{})