Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to configure client mtls redis cert and key #381

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions irma/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func configureIRMAServer() (*server.Configuration, error) {

conf.RedisSettings.TLSCertificate = viper.GetString("redis_tls_cert")
conf.RedisSettings.TLSCertificateFile = viper.GetString("redis_tls_cert_file")
conf.RedisSettings.TLSClientKeyFile = viper.GetString("redis_tls_client_key_file")
conf.RedisSettings.TLSClientCertificateFile = viper.GetString("redis_tls_client_cert_file")

conf.RedisSettings.DisableTLS = viper.GetBool("redis_no_tls")
}
return conf, nil
Expand Down
26 changes: 21 additions & 5 deletions server/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ type RedisSettings struct {

DB int `json:"db,omitempty" mapstructure:"db"`

TLSCertificate string `json:"tls_cert,omitempty" mapstructure:"tls_cert"`
TLSCertificateFile string `json:"tls_cert_file,omitempty" mapstructure:"tls_cert_file"`
DisableTLS bool `json:"no_tls,omitempty" mapstructure:"no_tls"`
TLSCertificate string `json:"tls_cert,omitempty" mapstructure:"tls_cert"`
TLSCertificateFile string `json:"tls_cert_file,omitempty" mapstructure:"tls_cert_file"`
TLSClientCertificateFile string `json:"tls_client_cert_file,omitempty" mapstructure:"tls_client_cert_file"`
TLSClientKeyFile string `json:"tls_client_key_file,omitempty" mapstructure:"tls_client_key_file"`
DisableTLS bool `json:"no_tls,omitempty" mapstructure:"no_tls"`
}

// Check ensures that the Configuration is loaded, usable and free of errors.
Expand Down Expand Up @@ -513,14 +515,28 @@ func (conf *Configuration) redisTLSConfig() (*tls.Config, error) {
}

if conf.RedisSettings.TLSCertificate != "" || conf.RedisSettings.TLSCertificateFile != "" {
cert, err := common.ReadKey(conf.RedisSettings.TLSCertificate, conf.RedisSettings.TLSCertificateFile)
caCert, err := common.ReadKey(conf.RedisSettings.TLSCertificate, conf.RedisSettings.TLSCertificateFile)
if err != nil {
return nil, errors.WrapPrefix(err, "Redis TLS config failed", 0)
}

tlsConfig := &tls.Config{
RootCAs: x509.NewCertPool(),
}
tlsConfig.RootCAs.AppendCertsFromPEM(cert)
tlsConfig.RootCAs.AppendCertsFromPEM(caCert)

if conf.RedisSettings.TLSClientKeyFile != "" || conf.RedisSettings.TLSClientCertificateFile != "" {
if conf.RedisSettings.TLSClientKeyFile == "" || conf.RedisSettings.TLSClientCertificateFile == "" {
return nil, errors.New("provide either certificate and key or neither of them")
}

cert, err := tls.LoadX509KeyPair(conf.RedisSettings.TLSClientCertificateFile, conf.RedisSettings.TLSClientKeyFile)
if err != nil {
return nil, errors.WrapPrefix(err, "Redis TLS config failed", 0)
}

tlsConfig.Certificates = []tls.Certificate{cert}
}
return tlsConfig, nil
}

Expand Down