add mtls dialer

This commit is contained in:
ginuerzh
2021-12-17 11:02:39 +08:00
parent 965c6846dd
commit bfe5eae172
21 changed files with 457 additions and 57 deletions

View File

@ -0,0 +1,43 @@
package tls
import (
"crypto/tls"
"net"
"time"
tls_util "github.com/go-gost/gost/pkg/common/util/tls"
md "github.com/go-gost/gost/pkg/metadata"
)
type metadata struct {
tlsConfig *tls.Config
handshakeTimeout time.Duration
}
func (d *tlsDialer) parseMetadata(md md.Metadata) (err error) {
const (
certFile = "certFile"
keyFile = "keyFile"
caFile = "caFile"
secure = "secure"
serverName = "serverName"
handshakeTimeout = "handshakeTimeout"
)
sn, _, _ := net.SplitHostPort(md.GetString(serverName))
if sn == "" {
sn = "localhost"
}
d.md.tlsConfig, err = tls_util.LoadClientConfig(
md.GetString(certFile),
md.GetString(keyFile),
md.GetString(caFile),
md.GetBool(secure),
sn,
)
d.md.handshakeTimeout = md.GetDuration(handshakeTimeout)
return
}