|
|
|
@ -3,6 +3,7 @@ package main |
|
|
|
|
import ( |
|
|
|
|
"context" |
|
|
|
|
"crypto/tls" |
|
|
|
|
"fmt" |
|
|
|
|
"io/ioutil" |
|
|
|
|
"log" |
|
|
|
|
"net" |
|
|
|
@ -23,8 +24,8 @@ var patientIf = "0.0.0.0:8085" |
|
|
|
|
|
|
|
|
|
var binFolder = "./bin/arm64" |
|
|
|
|
|
|
|
|
|
func loadCert() *tls.Certificate { |
|
|
|
|
_, err := os.Stat("certs/client.crt") |
|
|
|
|
func loadCert(name string) *tls.Certificate { |
|
|
|
|
_, err := os.Stat(fmt.Sprintf("certs/%s.crt", name)) |
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
_, _, certPem, keyPem, err := cryptoutil.GenCert("whitebox", "whitebox") |
|
|
|
@ -37,15 +38,15 @@ func loadCert() *tls.Certificate { |
|
|
|
|
panic(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err := ioutil.WriteFile("certs/client.crt", []byte(certPem), 0600); err != nil { |
|
|
|
|
if err := ioutil.WriteFile(fmt.Sprintf("certs/%s.crt", name), []byte(certPem), 0600); err != nil { |
|
|
|
|
panic(err) |
|
|
|
|
} |
|
|
|
|
if err := ioutil.WriteFile("certs/client.key", []byte(keyPem), 0600); err != nil { |
|
|
|
|
if err := ioutil.WriteFile(fmt.Sprintf("certs/%s.key", name), []byte(keyPem), 0600); err != nil { |
|
|
|
|
panic(err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
certificate, err := tls.LoadX509KeyPair("certs/client.crt", "certs/client.key") |
|
|
|
|
certificate, err := tls.LoadX509KeyPair(fmt.Sprintf("certs/%s.crt", name), fmt.Sprintf("certs/%s.key", name)) |
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
panic("Load client certification failed: " + err.Error()) |
|
|
|
@ -55,7 +56,7 @@ func loadCert() *tls.Certificate { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func loadKeyPair() credentials.TransportCredentials { |
|
|
|
|
certificate := loadCert() |
|
|
|
|
certificate := loadCert("client") |
|
|
|
|
|
|
|
|
|
tlsConfig := &tls.Config{ |
|
|
|
|
ClientAuth: tls.RequestClientCert, |
|
|
|
|