-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.go
45 lines (37 loc) · 1.1 KB
/
gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Generate a self-signed X.509 certificate for a TLS server. Outputs to
// 'cert.pem' and 'key.pem' and will overwrite existing files.
package main
import (
"crypto/ecdsa"
"crypto/ed25519"
"crypto/rsa"
"flag"
"fmt"
"github.com/Qingluan/Tunnel/config"
)
var (
host = flag.String("host", "", "Comma-separated hostnames and IPs to generate a certificate for")
isCA = flag.Bool("ca", false, "whether this cert should be its own Certificate Authority")
key = flag.String("key", "", "set some key for generate certificate")
)
func publicKey(priv interface{}) interface{} {
switch k := priv.(type) {
case *rsa.PrivateKey:
return &k.PublicKey
case *ecdsa.PrivateKey:
return &k.PublicKey
case ed25519.PrivateKey:
return k.Public().(ed25519.PublicKey)
default:
return nil
}
}
func main() {
flag.Parse()
// config.SetKey(*key)
key, _ := config.CreateCertificate("127.0.0.1:12345", true)
// e.Write([]byte(pem))
fmt.Println(key)
// fmt.Printf("pem: %x\n", md5.New().Sum([]byte(pem))[:16])
// fmt.Printf("key: %x\n", md5.New().Sum([]byte(key))[:16])
}