add Certificate Pinning support
This commit is contained in:
parent
a28b03d9ee
commit
7220d7478a
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
@ -84,9 +85,14 @@ func initChain() (*gost.Chain, error) {
|
||||
serverName = "localhost" // default server name
|
||||
}
|
||||
|
||||
rootCAs, err := loadCA(node.Values.Get("ca"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tlsCfg := &tls.Config{
|
||||
ServerName: serverName,
|
||||
InsecureSkipVerify: !toBool(node.Values.Get("scure")),
|
||||
RootCAs: rootCAs,
|
||||
}
|
||||
var tr gost.Transporter
|
||||
switch node.Transport {
|
||||
@ -379,6 +385,21 @@ func tlsConfig(certFile, keyFile string) (*tls.Config, error) {
|
||||
return &tls.Config{Certificates: []tls.Certificate{cert}}, nil
|
||||
}
|
||||
|
||||
func loadCA(caFile string) (cp *x509.CertPool, err error) {
|
||||
if caFile == "" {
|
||||
return
|
||||
}
|
||||
cp = x509.NewCertPool()
|
||||
data, err := ioutil.ReadFile(caFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !cp.AppendCertsFromPEM(data) {
|
||||
return nil, errors.New("AppendCertsFromPEM failed")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func loadConfigureFile(configureFile string) error {
|
||||
if configureFile == "" {
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user