|
|
@@ -25,7 +25,7 @@ func (c *Config) BuildCertificates() []tls.Certificate {
|
|
|
return certs
|
|
|
}
|
|
|
|
|
|
-func (c *Config) GetTLSConfig() *tls.Config {
|
|
|
+func (c *Config) GetTLSConfig(opts ...Option) *tls.Config {
|
|
|
config := &tls.Config{
|
|
|
ClientSessionCache: globalSessionCache,
|
|
|
NextProtos: []string{"http/1.1"},
|
|
|
@@ -34,6 +34,10 @@ func (c *Config) GetTLSConfig() *tls.Config {
|
|
|
return config
|
|
|
}
|
|
|
|
|
|
+ for _, opt := range opts {
|
|
|
+ opt(config)
|
|
|
+ }
|
|
|
+
|
|
|
config.InsecureSkipVerify = c.AllowInsecure
|
|
|
config.Certificates = c.BuildCertificates()
|
|
|
config.BuildNameToCertificate()
|
|
|
@@ -47,10 +51,10 @@ func (c *Config) GetTLSConfig() *tls.Config {
|
|
|
return config
|
|
|
}
|
|
|
|
|
|
-type Option func(*Config)
|
|
|
+type Option func(*tls.Config)
|
|
|
|
|
|
func WithDestination(dest net.Destination) Option {
|
|
|
- return func(config *Config) {
|
|
|
+ return func(config *tls.Config) {
|
|
|
if dest.Address.Family().IsDomain() && len(config.ServerName) == 0 {
|
|
|
config.ServerName = dest.Address.Domain()
|
|
|
}
|
|
|
@@ -58,23 +62,21 @@ func WithDestination(dest net.Destination) Option {
|
|
|
}
|
|
|
|
|
|
func WithNextProto(protocol ...string) Option {
|
|
|
- return func(config *Config) {
|
|
|
- if len(config.NextProtocol) == 0 {
|
|
|
- config.NextProtocol = protocol
|
|
|
+ return func(config *tls.Config) {
|
|
|
+ if len(config.NextProtos) == 0 {
|
|
|
+ config.NextProtos = protocol
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func ConfigFromContext(ctx context.Context, opts ...Option) *Config {
|
|
|
+func ConfigFromContext(ctx context.Context) *Config {
|
|
|
securitySettings := internet.SecuritySettingsFromContext(ctx)
|
|
|
if securitySettings == nil {
|
|
|
return nil
|
|
|
}
|
|
|
- if config, ok := securitySettings.(*Config); ok {
|
|
|
- for _, opt := range opts {
|
|
|
- opt(config)
|
|
|
- }
|
|
|
- return config
|
|
|
+ config, ok := securitySettings.(*Config)
|
|
|
+ if !ok {
|
|
|
+ return nil
|
|
|
}
|
|
|
- return nil
|
|
|
+ return config
|
|
|
}
|