|
@@ -37,6 +37,17 @@ func setupSocket() (listen net.Listener, addr string) {
|
|
|
return listener, address
|
|
|
}
|
|
|
|
|
|
+var KeyPair tls.Certificate
|
|
|
+var HasKeyPair bool
|
|
|
+
|
|
|
+func GenerateKeyPair() (keypair tls.Certificate) {
|
|
|
+ if !HasKeyPair {
|
|
|
+ KeyPair = generateKeyPair()
|
|
|
+ HasKeyPair = true
|
|
|
+ }
|
|
|
+ return KeyPair
|
|
|
+}
|
|
|
+
|
|
|
func generateKeyPair() (keypair tls.Certificate) {
|
|
|
// generate test certificate
|
|
|
priv, _ := ecdsa.GenerateKey(elliptic.P521(), rand.Reader)
|
|
@@ -78,7 +89,7 @@ func setupTLSSocket() (listen net.Listener, addr string) {
|
|
|
var listener net.Listener
|
|
|
var address string
|
|
|
var tlsconfig tls.Config
|
|
|
- var keypair tls.Certificate = generateKeyPair()
|
|
|
+ var keypair tls.Certificate = GenerateKeyPair()
|
|
|
|
|
|
tlsconfig.Certificates = make([]tls.Certificate, 0)
|
|
|
tlsconfig.Certificates = append(tlsconfig.Certificates, keypair)
|