Skip to content

Commit

Permalink
Keep session-encrypt.key in sessions/
Browse files Browse the repository at this point in the history
  • Loading branch information
thomiceli committed Oct 29, 2024
1 parent 7fb30f0 commit f3619a8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 30 deletions.
10 changes: 1 addition & 9 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,10 @@ func InitConfig(configPath string, out io.Writer) error {
}

if c.SecretKey == "" {
var generated bool
path := filepath.Join(GetHomeDir(), "opengist-secret.key")
SecretKey, generated = utils.GenerateSecretKey(path)

if generated {
fmt.Printf("Generated a new secret key at %s\n", path)
} else {
fmt.Printf("Using the secret key from %s\n", path)
}
SecretKey, _ = utils.GenerateSecretKey(path)
} else {
SecretKey = []byte(C.SecretKey)
fmt.Println("Using the secret key from config")
}

if err = os.Setenv("OG_OPENGIST_HOME_INTERNAL", GetHomeDir()); err != nil {
Expand Down
21 changes: 1 addition & 20 deletions internal/config/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,7 @@ func migrateConfig() error {

func v1_8_0() error {
homeDir := GetHomeDir()
sessionsDir := filepath.Join(homeDir, "sessions")

moves := []struct {
oldName string
newName string
}{
{
oldName: filepath.Join(sessionsDir, "session-auth.key"),
newName: filepath.Join(homeDir, "opengist-secret.key"),
},
{
oldName: filepath.Join(sessionsDir, "session-encrypt.key"),
newName: filepath.Join(homeDir, "session-encrypt.key"),
},
}

for _, move := range moves {
moveFile(move.oldName, move.newName)
}

moveFile(filepath.Join(filepath.Join(homeDir, "sessions"), "session-auth.key"), filepath.Join(homeDir, "opengist-secret.key"))
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ type Server struct {
func NewServer(isDev bool, sessionsPath string) *Server {
dev = isDev
flashStore = sessions.NewCookieStore([]byte("opengist"))
encryptKey, _ := utils.GenerateSecretKey(path.Join(config.GetHomeDir(), "session-encrypt.key"))
encryptKey, _ := utils.GenerateSecretKey(filepath.Join(config.GetHomeDir(), "sessions", "session-encrypt.key"))
userStore = sessions.NewFilesystemStore(sessionsPath, config.SecretKey, encryptKey)
userStore.MaxLength(10 * 1024)
gothic.Store = userStore
Expand Down

0 comments on commit f3619a8

Please sign in to comment.