Allow to define secret key & move the secret key file to parent directory (#358)

This commit is contained in:
Thomas Miceli
2024-10-31 14:50:13 +01:00
committed by GitHub
parent 20372f44e4
commit 4fd0832df9
11 changed files with 98 additions and 43 deletions

View File

@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
ogtotp "github.com/thomiceli/opengist/internal/auth/totp"
"github.com/thomiceli/opengist/internal/config"
"github.com/thomiceli/opengist/internal/utils"
"slices"
)
@ -29,7 +30,7 @@ func GetTOTPByUserID(userID uint) (*TOTP, error) {
func (totp *TOTP) StoreSecret(secret string) error {
secretBytes := []byte(secret)
encrypted, err := utils.AESEncrypt([]byte("tmp"), secretBytes)
encrypted, err := utils.AESEncrypt(config.SecretKey, secretBytes)
if err != nil {
return err
}
@ -44,7 +45,7 @@ func (totp *TOTP) ValidateCode(code string) (bool, error) {
return false, err
}
secretBytes, err := utils.AESDecrypt([]byte("tmp"), ciphertext)
secretBytes, err := utils.AESDecrypt(config.SecretKey, ciphertext)
if err != nil {
return false, err
}