mirror of
https://github.com/schollz/croc.git
synced 2024-11-23 23:54:17 +03:00
add flag for skipping encryption
This commit is contained in:
parent
adb3f59a51
commit
86b12a3770
43
crypto.go
43
crypto.go
@ -1,9 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
mathrand "math/rand"
|
||||
"strings"
|
||||
@ -26,27 +29,31 @@ func GetRandomName() string {
|
||||
}
|
||||
|
||||
func Encrypt(plaintext []byte, passphrase string) ([]byte, string, string) {
|
||||
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)
|
||||
if dontEncrypt {
|
||||
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) {
|
||||
return data, 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
|
||||
if dontEncrypt {
|
||||
return data, 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) {
|
||||
|
3
main.go
3
main.go
@ -19,7 +19,7 @@ var server, file string
|
||||
|
||||
// Global varaibles
|
||||
var serverAddress, fileName, codePhraseFlag, connectionTypeFlag string
|
||||
var runAsRelay, debugFlag bool
|
||||
var runAsRelay, debugFlag, dontEncrypt bool
|
||||
var fileSalt, fileIV, fileHash string
|
||||
var fileBytes []byte
|
||||
|
||||
@ -29,6 +29,7 @@ func main() {
|
||||
flag.StringVar(&serverAddress, "server", "cowyo.com", "address of relay server")
|
||||
flag.StringVar(&fileName, "send", "", "file to send")
|
||||
flag.StringVar(&codePhraseFlag, "code", "", "use your own code phrase")
|
||||
flag.BoolVar(&dontEncrypt, "no-encrypt", false, "turn off encryption")
|
||||
flag.Parse()
|
||||
// Check build flags too, which take precedent
|
||||
if server != "" {
|
||||
|
Loading…
Reference in New Issue
Block a user