Generate salts when empty
Этот коммит содержится в:
@@ -164,6 +164,23 @@ func ConfigFromJson(data io.Reader) *Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *Config) SetDefaults() {
|
func (o *Config) SetDefaults() {
|
||||||
|
|
||||||
|
if len(o.SqlSettings.AtRestEncryptKey) == 0 {
|
||||||
|
o.SqlSettings.AtRestEncryptKey = NewRandomString(32)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(o.FileSettings.PublicLinkSalt) == 0 {
|
||||||
|
o.FileSettings.PublicLinkSalt = NewRandomString(32)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(o.EmailSettings.InviteSalt) == 0 {
|
||||||
|
o.EmailSettings.InviteSalt = NewRandomString(32)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(o.EmailSettings.PasswordResetSalt) == 0 {
|
||||||
|
o.EmailSettings.PasswordResetSalt = NewRandomString(32)
|
||||||
|
}
|
||||||
|
|
||||||
if o.ServiceSettings.EnableSecurityFixAlert == nil {
|
if o.ServiceSettings.EnableSecurityFixAlert == nil {
|
||||||
o.ServiceSettings.EnableSecurityFixAlert = new(bool)
|
o.ServiceSettings.EnableSecurityFixAlert = new(bool)
|
||||||
*o.ServiceSettings.EnableSecurityFixAlert = true
|
*o.ServiceSettings.EnableSecurityFixAlert = true
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/rand"
|
||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -81,6 +82,17 @@ func NewId() string {
|
|||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewRandomString(length int) string {
|
||||||
|
var b bytes.Buffer
|
||||||
|
str := make([]byte, length+8)
|
||||||
|
rand.Read(str)
|
||||||
|
encoder := base32.NewEncoder(encoding, &b)
|
||||||
|
encoder.Write(str)
|
||||||
|
encoder.Close()
|
||||||
|
b.Truncate(length) // removes the '==' padding
|
||||||
|
return b.String()
|
||||||
|
}
|
||||||
|
|
||||||
// GetMillis is a convience method to get milliseconds since epoch.
|
// GetMillis is a convience method to get milliseconds since epoch.
|
||||||
func GetMillis() int64 {
|
func GetMillis() int64 {
|
||||||
return time.Now().UnixNano() / int64(time.Millisecond)
|
return time.Now().UnixNano() / int64(time.Millisecond)
|
||||||
|
|||||||
@@ -17,6 +17,18 @@ func TestNewId(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRandomString(t *testing.T) {
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
r := NewRandomString(32)
|
||||||
|
t.Log(r)
|
||||||
|
if len(r) != 32 {
|
||||||
|
t.Fatal("should be 32 chars")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Fatal("test")
|
||||||
|
}
|
||||||
|
|
||||||
func TestAppError(t *testing.T) {
|
func TestAppError(t *testing.T) {
|
||||||
err := NewAppError("TestAppError", "message", "")
|
err := NewAppError("TestAppError", "message", "")
|
||||||
json := err.ToJson()
|
json := err.ToJson()
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user