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

Separate SSL Configurations for Device and User #163

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,9 @@ func apiStart(br *broker) {
go func() {
var err error

if cfg.SslCert != "" && cfg.SslKey != "" {
if cfg.WebUISslCert != "" && cfg.WebUISslKey != "" {
log.Info().Msgf("Listen user on: %s SSL on", cfg.AddrUser)
err = r.RunTLS(cfg.AddrUser, cfg.SslCert, cfg.SslKey)
err = r.RunTLS(cfg.AddrUser, cfg.WebUISslCert, cfg.WebUISslKey)
} else {
log.Info().Msgf("Listen user on: %s SSL off", cfg.AddrUser)
err = r.Run(cfg.AddrUser)
Expand Down
17 changes: 16 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ type Config struct {
SslCert string
SslKey string
SslCacert string // mTLS for device
WebUISslCert string
WebUISslKey string
Token string
WhiteList map[string]bool
DB string
LocalAuth bool
SeparateSslConfig bool
}

func getConfigOpt(yamlCfg *yaml.File, name string, opt interface{}) {
Expand All @@ -37,6 +40,8 @@ func getConfigOpt(yamlCfg *yaml.File, name string, opt interface{}) {
*opt = val
case *int:
*opt, _ = strconv.Atoi(val)
case *bool:
*opt, _ = strconv.ParseBool(val)
}
}

Expand All @@ -50,6 +55,9 @@ func Parse(c *cli.Context) *Config {
SslCert: c.String("ssl-cert"),
SslKey: c.String("ssl-key"),
SslCacert: c.String("ssl-cacert"),
SeparateSslConfig: c.Bool("separate-ssl-config"),
WebUISslCert: c.String("webui-ssl-cert"),
WebUISslKey: c.String("webui-ssl-key"),
Token: c.String("token"),
DB: c.String("db"),
LocalAuth: c.Bool("local-auth"),
Expand All @@ -76,10 +84,17 @@ func Parse(c *cli.Context) *Config {
getConfigOpt(yamlCfg, "ssl-cert", &cfg.SslCert)
getConfigOpt(yamlCfg, "ssl-key", &cfg.SslKey)
getConfigOpt(yamlCfg, "ssl-cacert", &cfg.SslCacert)
getConfigOpt(yamlCfg, "separate-ssl-config", &cfg.SeparateSslConfig)
if cfg.SeparateSslConfig {
getConfigOpt(yamlCfg, "webui-ssl-cert", &cfg.WebUISslCert)
getConfigOpt(yamlCfg, "webui-ssl-key", &cfg.WebUISslKey)
} else {
cfg.WebUISslCert = cfg.SslCert
cfg.WebUISslKey = cfg.SslKey
}
getConfigOpt(yamlCfg, "token", &cfg.Token)
getConfigOpt(yamlCfg, "db", &cfg.DB)
getConfigOpt(yamlCfg, "local-auth", &cfg.LocalAuth)

val, err := yamlCfg.Get("white-list")
if err == nil {
if val == "*" || val == "\"*\"" {
Expand Down
5 changes: 5 additions & 0 deletions rttys.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
#ssl-cert: /etc/rttys/rttys.crt
#ssl-key: /etc/rttys/rttys.key

#if you want to use separate SSL config for webui, set this to True.otherwise, it will use the same SSL config for device and webui
#separate-ssl-config: True
#webui-ssl-cert: /etc/rttys/webui-rttys.crt
#webui-ssl-key: /etc/rttys/webui-rttys.key

#token: a1d4cdb1a3cd6a0e94aa3599afcddcf5

# No login required to connect device.
Expand Down