Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions core/packet.go

This file was deleted.

23 changes: 0 additions & 23 deletions core/stream.go

This file was deleted.

26 changes: 22 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/url"
"os"
Expand All @@ -30,6 +31,7 @@ func main() {
Client string
Server string
Cipher string
KeyFile string
Key string
Password string
Keygen int
Expand All @@ -47,7 +49,8 @@ func main() {

flag.BoolVar(&config.Verbose, "verbose", false, "verbose mode")
flag.StringVar(&flags.Cipher, "cipher", "AEAD_CHACHA20_POLY1305", "available ciphers: "+strings.Join(core.ListCipher(), " "))
flag.StringVar(&flags.Key, "key", "", "base64url-encoded key (derive from password if empty)")
flag.StringVar(&flags.KeyFile, "key-file", "", "path of base64url-encoded key file")
flag.StringVar(&flags.Key, "key", "", "base64url-encoded key (derive from password if both key-file and key are empty)")
flag.IntVar(&flags.Keygen, "keygen", 0, "generate a base64url-encoded random key of given length in byte")
flag.StringVar(&flags.Password, "password", "", "password")
flag.StringVar(&flags.Server, "s", "", "server listen address or url")
Expand All @@ -68,7 +71,10 @@ func main() {

if flags.Keygen > 0 {
key := make([]byte, flags.Keygen)
io.ReadFull(rand.Reader, key)
_, err := io.ReadFull(rand.Reader, key)
if err != nil {
log.Fatal(err)
}
fmt.Println(base64.URLEncoding.EncodeToString(key))
return
}
Expand All @@ -78,9 +84,21 @@ func main() {
return
}

var key []byte
var encodedKey string
if flags.KeyFile != "" {
e, err := ioutil.ReadFile(flags.KeyFile)
if err != nil {
log.Fatal(err)
}
encodedKey = string(e)
}
if flags.Key != "" {
k, err := base64.URLEncoding.DecodeString(flags.Key)
encodedKey = flags.Key
}

var key []byte
if encodedKey != "" {
k, err := base64.URLEncoding.DecodeString(encodedKey)
if err != nil {
log.Fatal(err)
}
Expand Down