mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 05:11:06 +02:00
Turn off decryption
This commit is contained in:
parent
5e1068961e
commit
109fef84d0
3 changed files with 25 additions and 26 deletions
11
connect.go
11
connect.go
|
@ -220,9 +220,6 @@ func sendFile(id int, connection net.Conn, codePhrase string) {
|
||||||
if id+1 == numberConnections {
|
if id+1 == numberConnections {
|
||||||
bytesPerConnection = int64(len(fileBytes)) - (numberConnections-1)*bytesPerConnection
|
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 {
|
if id == 0 || id == numberConnections-1 {
|
||||||
logger.Debugf("numChunks: %v", numChunks)
|
logger.Debugf("numChunks: %v", numChunks)
|
||||||
|
@ -232,12 +229,12 @@ func sendFile(id int, connection net.Conn, codePhrase string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// send file size
|
// send file size
|
||||||
logger.Debugf("sending fileSize: %s", fileSize)
|
logger.Debugf("sending fileSize: %d", bytesPerConnection)
|
||||||
connection.Write([]byte(fileSize))
|
connection.Write([]byte(fillString(strconv.FormatInt(int64(bytesPerConnection), 10), 10)))
|
||||||
|
|
||||||
// send fileName
|
// send fileName
|
||||||
logger.Debugf("sending fileNameToSend: %s", fileNameToSend)
|
logger.Debugf("sending fileName: %s", path.Base(fileName))
|
||||||
connection.Write([]byte(fileNameToSend))
|
connection.Write([]byte(fillString(path.Base(fileName), 64)))
|
||||||
|
|
||||||
// send iv
|
// send iv
|
||||||
logger.Debugf("sending iv: %s", fileIV)
|
logger.Debugf("sending iv: %s", fileIV)
|
||||||
|
|
37
crypto.go
37
crypto.go
|
@ -1,12 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/aes"
|
|
||||||
"crypto/cipher"
|
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
mathrand "math/rand"
|
mathrand "math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -29,25 +26,27 @@ func GetRandomName() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Encrypt(plaintext []byte, passphrase string) ([]byte, string, string) {
|
func Encrypt(plaintext []byte, passphrase string) ([]byte, string, string) {
|
||||||
key, salt := deriveKey(passphrase, nil)
|
return plaintext, "salt", "iv"
|
||||||
iv := make([]byte, 12)
|
// key, salt := deriveKey(passphrase, nil)
|
||||||
// http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
|
// iv := make([]byte, 12)
|
||||||
// Section 8.2
|
// // http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
|
||||||
rand.Read(iv)
|
// // Section 8.2
|
||||||
b, _ := aes.NewCipher(key)
|
// rand.Read(iv)
|
||||||
aesgcm, _ := cipher.NewGCM(b)
|
// b, _ := aes.NewCipher(key)
|
||||||
data := aesgcm.Seal(nil, iv, plaintext, nil)
|
// aesgcm, _ := cipher.NewGCM(b)
|
||||||
return data, hex.EncodeToString(salt), hex.EncodeToString(iv)
|
// 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) {
|
func Decrypt(data []byte, passphrase string, salt string, iv string) (plaintext []byte, err error) {
|
||||||
saltBytes, _ := hex.DecodeString(salt)
|
return plaintext, nil
|
||||||
ivBytes, _ := hex.DecodeString(iv)
|
// saltBytes, _ := hex.DecodeString(salt)
|
||||||
key, _ := deriveKey(passphrase, saltBytes)
|
// ivBytes, _ := hex.DecodeString(iv)
|
||||||
b, _ := aes.NewCipher(key)
|
// key, _ := deriveKey(passphrase, saltBytes)
|
||||||
aesgcm, _ := cipher.NewGCM(b)
|
// b, _ := aes.NewCipher(key)
|
||||||
plaintext, err = aesgcm.Open(nil, ivBytes, data, nil)
|
// aesgcm, _ := cipher.NewGCM(b)
|
||||||
return
|
// plaintext, err = aesgcm.Open(nil, ivBytes, data, nil)
|
||||||
|
// return
|
||||||
}
|
}
|
||||||
|
|
||||||
func deriveKey(passphrase string, salt []byte) ([]byte, []byte) {
|
func deriveKey(passphrase string, salt []byte) ([]byte, []byte) {
|
||||||
|
|
3
main.go
3
main.go
|
@ -66,6 +66,9 @@ func main() {
|
||||||
}
|
}
|
||||||
fileBytes, fileSalt, fileIV = Encrypt(fdata, codePhraseFlag)
|
fileBytes, fileSalt, fileIV = Encrypt(fdata, codePhraseFlag)
|
||||||
fileHash = HashBytes(fdata)
|
fileHash = HashBytes(fdata)
|
||||||
|
if debugFlag {
|
||||||
|
ioutil.WriteFile(fileName+".encrypted", fileBytes, 0644)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.SetFormatter(&log.TextFormatter{})
|
log.SetFormatter(&log.TextFormatter{})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue