1
0
mirror of https://github.com/schollz/croc.git synced 2024-11-23 23:54:17 +03:00

Turn off decryption

This commit is contained in:
Zack Scholl 2017-10-17 22:03:48 -06:00
parent 5e1068961e
commit 109fef84d0
3 changed files with 25 additions and 26 deletions

View File

@ -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)

View File

@ -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) {

View File

@ -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{})