func Config()

in server/config/tlsutil/tlsutil.go [34:57]


func Config(c *config.TLS) (*tls.Config, error) {
	var password string
	if c.CertPwdFile != "" {
		pwdBytes, err := os.ReadFile(c.CertPwdFile)
		if err != nil {
			openlog.Error("read cert password file failed: " + err.Error())
			return nil, err
		}
		password = cipherutil.TryDecrypt(stringutil.Bytes2str(pwdBytes))
	}
	if c.RootCA == "" {
		openlog.Error(ErrRootCAMissing.Error())
		return nil, ErrRootCAMissing
	}
	opts := append(tlsutil.DefaultClientTLSOptions(),
		tlsutil.WithVerifyPeer(c.VerifyPeer),
		tlsutil.WithVerifyHostName(false),
		tlsutil.WithKeyPass(password),
		tlsutil.WithCA(c.RootCA),
		tlsutil.WithCert(c.CertFile),
		tlsutil.WithKey(c.KeyFile),
	)
	return tlsutil.GetClientTLSConfig(opts...)
}