encrypt master key

This commit is contained in:
Lunny Xiao 2022-10-20 23:56:42 +08:00 committed by Jason Song
parent b8c7ea782c
commit 34a1bb2c20

View File

@ -6,6 +6,7 @@
package setting
import (
"crypto/sha1"
"encoding/base64"
"fmt"
"math"
@ -28,6 +29,7 @@ import (
"code.gitea.io/gitea/modules/user"
"code.gitea.io/gitea/modules/util"
"golang.org/x/crypto/pbkdf2"
gossh "golang.org/x/crypto/ssh"
ini "gopkg.in/ini.v1"
)
@ -970,10 +972,9 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
MasterKeyProvider = sec.Key("MASTER_KEY_PROVIDER").MustString("plain")
switch MasterKeyProvider {
case "plain":
tempSalt := []byte{'g', 'i', 't', 'e', 'a'}
MasterKey = []byte(sec.Key("MASTER_KEY").MustString(SecretKey))
if len(MasterKey) > 32 {
MasterKey = MasterKey[:32]
}
MasterKey = pbkdf2.Key(MasterKey, tempSalt, 4096, 32, sha1.New)
case "none":
default:
log.Fatal("invalid master key provider type: %v", MasterKeyProvider)