From 6d8140337ef0f68f5177988f3c87bba5e4946399 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Mon, 18 Jun 2018 12:39:22 -0400 Subject: MM-8701 Limit the number of client config fields sent before user logs in (#8954) * MM-8701 Limit the number of client config fields sent before user logs in * Fixed missing client config field * Reduced duplication between limited and regular client config --- app/app.go | 7 ++++--- app/config.go | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/app.go b/app/app.go index d97c6c385..3f70974cf 100644 --- a/app/app.go +++ b/app/app.go @@ -90,9 +90,10 @@ type App struct { pluginCommands []*PluginCommand pluginCommandsLock sync.RWMutex - clientConfig map[string]string - clientConfigHash string - diagnosticId string + clientConfig map[string]string + clientConfigHash string + limitedClientConfig map[string]string + diagnosticId string phase2PermissionsMigrationComplete bool } diff --git a/app/config.go b/app/config.go index b4fbfe725..21571f291 100644 --- a/app/config.go +++ b/app/config.go @@ -91,6 +91,10 @@ func (a *App) ClientConfigHash() string { return a.clientConfigHash } +func (a *App) LimitedClientConfig() map[string]string { + return a.limitedClientConfig +} + func (a *App) EnableConfigWatch() { if a.configWatcher == nil && !a.disableConfigWatch { configWatcher, err := utils.NewConfigWatcher(a.ConfigFileName(), func() { @@ -211,10 +215,14 @@ func (a *App) AsymmetricSigningKey() *ecdsa.PrivateKey { func (a *App) regenerateClientConfig() { a.clientConfig = utils.GenerateClientConfig(a.Config(), a.DiagnosticId(), a.License()) + a.limitedClientConfig = utils.GenerateLimitedClientConfig(a.Config(), a.DiagnosticId(), a.License()) + if key := a.AsymmetricSigningKey(); key != nil { der, _ := x509.MarshalPKIXPublicKey(&key.PublicKey) a.clientConfig["AsymmetricSigningPublicKey"] = base64.StdEncoding.EncodeToString(der) + a.limitedClientConfig["AsymmetricSigningPublicKey"] = base64.StdEncoding.EncodeToString(der) } + clientConfigJSON, _ := json.Marshal(a.clientConfig) a.clientConfigHash = fmt.Sprintf("%x", md5.Sum(clientConfigJSON)) } @@ -291,3 +299,17 @@ func (a *App) ClientConfigWithComputed() map[string]string { return respCfg } + +// LimitedClientConfigWithComputed gets the configuration in a format suitable for sending to the client. +func (a *App) LimitedClientConfigWithComputed() map[string]string { + respCfg := map[string]string{} + for k, v := range a.LimitedClientConfig() { + respCfg[k] = v + } + + // These properties are not configurable, but nevertheless represent configuration expected + // by the client. + respCfg["NoAccounts"] = strconv.FormatBool(a.IsFirstUserAccount()) + + return respCfg +} -- cgit v1.2.3-1-g7c22