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:
parent
adb3f59a51
commit
86b12a3770
2 changed files with 27 additions and 19 deletions
39
crypto.go
39
crypto.go
|
@ -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) {
|
||||||
|
if dontEncrypt {
|
||||||
return plaintext, "salt", "iv"
|
return plaintext, "salt", "iv"
|
||||||
// key, salt := deriveKey(passphrase, nil)
|
}
|
||||||
// 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) {
|
||||||
|
if dontEncrypt {
|
||||||
return data, nil
|
return data, nil
|
||||||
// saltBytes, _ := hex.DecodeString(salt)
|
}
|
||||||
// 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
|
@ -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 != "" {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue