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

add flag for skipping encryption

This commit is contained in:
Zack Scholl 2017-10-17 22:23:31 -06:00
parent adb3f59a51
commit 86b12a3770
2 changed files with 27 additions and 19 deletions

View file

@ -1,9 +1,12 @@
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"
@ -26,27 +29,31 @@ func GetRandomName() string {
} }
func Encrypt(plaintext []byte, passphrase string) ([]byte, string, string) { func Encrypt(plaintext []byte, passphrase string) ([]byte, string, string) {
return plaintext, "salt", "iv" if dontEncrypt {
// key, salt := deriveKey(passphrase, nil) return plaintext, "salt", "iv"
// iv := make([]byte, 12) }
// // http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf key, salt := deriveKey(passphrase, nil)
// // Section 8.2 iv := make([]byte, 12)
// rand.Read(iv) // http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
// b, _ := aes.NewCipher(key) // Section 8.2
// aesgcm, _ := cipher.NewGCM(b) rand.Read(iv)
// data := aesgcm.Seal(nil, iv, plaintext, nil) b, _ := aes.NewCipher(key)
// return data, hex.EncodeToString(salt), hex.EncodeToString(iv) 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) { func Decrypt(data []byte, passphrase string, salt string, iv string) (plaintext []byte, err error) {
return data, nil if dontEncrypt {
// saltBytes, _ := hex.DecodeString(salt) return data, nil
// ivBytes, _ := hex.DecodeString(iv) }
// key, _ := deriveKey(passphrase, saltBytes) saltBytes, _ := hex.DecodeString(salt)
// b, _ := aes.NewCipher(key) ivBytes, _ := hex.DecodeString(iv)
// aesgcm, _ := cipher.NewGCM(b) key, _ := deriveKey(passphrase, saltBytes)
// plaintext, err = aesgcm.Open(nil, ivBytes, data, nil) b, _ := aes.NewCipher(key)
// return aesgcm, _ := cipher.NewGCM(b)
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) {

View file

@ -19,7 +19,7 @@ var server, file string
// Global varaibles // Global varaibles
var serverAddress, fileName, codePhraseFlag, connectionTypeFlag string var serverAddress, fileName, codePhraseFlag, connectionTypeFlag string
var runAsRelay, debugFlag bool var runAsRelay, debugFlag, dontEncrypt bool
var fileSalt, fileIV, fileHash string var fileSalt, fileIV, fileHash string
var fileBytes []byte var fileBytes []byte
@ -29,6 +29,7 @@ func main() {
flag.StringVar(&serverAddress, "server", "cowyo.com", "address of relay server") flag.StringVar(&serverAddress, "server", "cowyo.com", "address of relay server")
flag.StringVar(&fileName, "send", "", "file to send") flag.StringVar(&fileName, "send", "", "file to send")
flag.StringVar(&codePhraseFlag, "code", "", "use your own code phrase") flag.StringVar(&codePhraseFlag, "code", "", "use your own code phrase")
flag.BoolVar(&dontEncrypt, "no-encrypt", false, "turn off encryption")
flag.Parse() flag.Parse()
// Check build flags too, which take precedent // Check build flags too, which take precedent
if server != "" { if server != "" {