mirror of https://github.com/cbeuw/Cloak
Change keygen behaviour for scripting
This commit is contained in:
parent
55780fc85d
commit
c4abb48788
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
ecdh "github.com/cbeuw/go-ecdh"
|
ecdh "github.com/cbeuw/go-ecdh"
|
||||||
)
|
)
|
||||||
|
|
@ -10,38 +11,23 @@ import (
|
||||||
var b64 = base64.StdEncoding.EncodeToString
|
var b64 = base64.StdEncoding.EncodeToString
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
for {
|
var isUID *bool
|
||||||
fmt.Println("1 to generate UID, 2 to generate a key pair")
|
var isKeypair *bool
|
||||||
|
isUID = flag.Bool("u", false, "Generate UID")
|
||||||
|
isKeypair = flag.Bool("k", false, "Generate a key pair")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
var sel int
|
if *isUID {
|
||||||
_, err := fmt.Scanln(&sel)
|
UID := make([]byte, 32)
|
||||||
if err != nil {
|
rand.Read(UID)
|
||||||
fmt.Println("Please enter a number")
|
fmt.Printf(b64(UID))
|
||||||
continue
|
} else if *isKeypair {
|
||||||
}
|
ec := ecdh.NewCurve25519ECDH()
|
||||||
if sel != 1 && sel != 2 {
|
staticPv, staticPub, _ := ec.GenerateKey(rand.Reader)
|
||||||
fmt.Println("Please enter 1 or 2")
|
marshPub := ec.Marshal(staticPub)
|
||||||
continue
|
marshPv := staticPv.(*[32]byte)[:]
|
||||||
}
|
|
||||||
|
|
||||||
if sel == 1 {
|
fmt.Printf("%v,%v", b64(marshPub), b64(marshPv))
|
||||||
UID := make([]byte, 32)
|
|
||||||
rand.Read(UID)
|
|
||||||
fmt.Printf("\"UID\":\"%v\"\n", b64(UID))
|
|
||||||
} else if sel == 2 {
|
|
||||||
|
|
||||||
ec := ecdh.NewCurve25519ECDH()
|
|
||||||
staticPv, staticPub, _ := ec.GenerateKey(rand.Reader)
|
|
||||||
marshPub := ec.Marshal(staticPub)
|
|
||||||
marshPv := staticPv.(*[32]byte)[:]
|
|
||||||
|
|
||||||
fmt.Printf("USER: \n")
|
|
||||||
fmt.Printf("\"PublicKey\":\"%v\"\n", b64(marshPub))
|
|
||||||
|
|
||||||
fmt.Println("=========================================")
|
|
||||||
|
|
||||||
fmt.Printf("SERVER: \n")
|
|
||||||
fmt.Printf("\"PrivateKey\":\"%v\"\n", b64(marshPv))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue