mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 18:35:51 +02:00
fix: user curd panic after install
This commit is contained in:
parent
c5bd8cc580
commit
d83272d5b8
6 changed files with 16 additions and 24 deletions
|
@ -4,13 +4,13 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/0xJacky/Nginx-UI/api"
|
"github.com/0xJacky/Nginx-UI/api"
|
||||||
"github.com/0xJacky/Nginx-UI/internal/sign"
|
"github.com/0xJacky/Nginx-UI/internal/crypto"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetPublicKey generates a new ED25519 key pair and registers it in the cache
|
// GetPublicKey generates a new ED25519 key pair and registers it in the cache
|
||||||
func GetPublicKey(c *gin.Context) {
|
func GetPublicKey(c *gin.Context) {
|
||||||
sign, err := sign.GetCryptoParams()
|
sign, err := crypto.GetCryptoParams()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.ErrHandler(c, err)
|
api.ErrHandler(c, err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package sign
|
package crypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
@ -44,7 +44,7 @@ func GenerateRSAKeyPair() (privateKeyPEM, publicKeyPEM []byte, err error) {
|
||||||
// GetCryptoParams registers a new key pair in the cache if it doesn't exist
|
// GetCryptoParams registers a new key pair in the cache if it doesn't exist
|
||||||
// otherwise, it returns the existing nonce and public key
|
// otherwise, it returns the existing nonce and public key
|
||||||
func GetCryptoParams() (sign *Sign, err error) {
|
func GetCryptoParams() (sign *Sign, err error) {
|
||||||
// Check if key pair exists in cache
|
// Check if the key pair exists in then cache
|
||||||
if sign, ok := cache.Get(CacheKey); ok {
|
if sign, ok := cache.Get(CacheKey); ok {
|
||||||
return sign.(*Sign), nil
|
return sign.(*Sign), nil
|
||||||
}
|
}
|
|
@ -6,4 +6,5 @@ var (
|
||||||
e = cosy.NewErrorScope("crypto")
|
e = cosy.NewErrorScope("crypto")
|
||||||
ErrPlainTextEmpty = e.New(50001, "plain text is empty")
|
ErrPlainTextEmpty = e.New(50001, "plain text is empty")
|
||||||
ErrCipherTextTooShort = e.New(50002, "cipher text is too short")
|
ErrCipherTextTooShort = e.New(50002, "cipher text is too short")
|
||||||
|
ErrTimeout = e.New(40401, "request timeout")
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,6 +3,10 @@ package kernel
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"mime"
|
||||||
|
"path"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/0xJacky/Nginx-UI/internal/analytic"
|
"github.com/0xJacky/Nginx-UI/internal/analytic"
|
||||||
"github.com/0xJacky/Nginx-UI/internal/cache"
|
"github.com/0xJacky/Nginx-UI/internal/cache"
|
||||||
"github.com/0xJacky/Nginx-UI/internal/cert"
|
"github.com/0xJacky/Nginx-UI/internal/cert"
|
||||||
|
@ -17,10 +21,8 @@ import (
|
||||||
"github.com/uozi-tech/cosy"
|
"github.com/uozi-tech/cosy"
|
||||||
sqlite "github.com/uozi-tech/cosy-driver-sqlite"
|
sqlite "github.com/uozi-tech/cosy-driver-sqlite"
|
||||||
"github.com/uozi-tech/cosy/logger"
|
"github.com/uozi-tech/cosy/logger"
|
||||||
|
cModel "github.com/uozi-tech/cosy/model"
|
||||||
cSettings "github.com/uozi-tech/cosy/settings"
|
cSettings "github.com/uozi-tech/cosy/settings"
|
||||||
"mime"
|
|
||||||
"path"
|
|
||||||
"runtime"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Boot() {
|
func Boot() {
|
||||||
|
@ -73,12 +75,13 @@ func recovery() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitDatabase() {
|
func InitDatabase() {
|
||||||
|
cModel.ResolvedModels()
|
||||||
// Skip install
|
// Skip install
|
||||||
if settings.NodeSettings.SkipInstallation {
|
if settings.NodeSettings.SkipInstallation {
|
||||||
skipInstall()
|
skipInstall()
|
||||||
}
|
}
|
||||||
|
|
||||||
if "" != cSettings.AppSettings.JwtSecret {
|
if cSettings.AppSettings.JwtSecret != "" {
|
||||||
db := cosy.InitDB(sqlite.Open(path.Dir(cSettings.ConfPath), settings.DatabaseSettings))
|
db := cosy.InitDB(sqlite.Open(path.Dir(cSettings.ConfPath), settings.DatabaseSettings))
|
||||||
model.Use(db)
|
model.Use(db)
|
||||||
query.Init(db)
|
query.Init(db)
|
||||||
|
@ -88,7 +91,7 @@ func InitDatabase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitNodeSecret() {
|
func InitNodeSecret() {
|
||||||
if "" == settings.NodeSettings.Secret {
|
if settings.NodeSettings.Secret == "" {
|
||||||
logger.Info("Secret is empty, generating...")
|
logger.Info("Secret is empty, generating...")
|
||||||
uuidStr := uuid.New().String()
|
uuidStr := uuid.New().String()
|
||||||
settings.NodeSettings.Secret = uuidStr
|
settings.NodeSettings.Secret = uuidStr
|
||||||
|
@ -102,7 +105,7 @@ func InitNodeSecret() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitCryptoSecret() {
|
func InitCryptoSecret() {
|
||||||
if "" == settings.CryptoSettings.Secret {
|
if settings.CryptoSettings.Secret == "" {
|
||||||
logger.Info("Secret is empty, generating...")
|
logger.Info("Secret is empty, generating...")
|
||||||
|
|
||||||
key := make([]byte, 32)
|
key := make([]byte, 32)
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/0xJacky/Nginx-UI/internal/sign"
|
"github.com/0xJacky/Nginx-UI/internal/crypto"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/uozi-tech/cosy"
|
"github.com/uozi-tech/cosy"
|
||||||
)
|
)
|
||||||
|
@ -30,7 +30,7 @@ func EncryptedParams() gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Decrypt the parameters (implement your decryption logic)
|
// 2. Decrypt the parameters (implement your decryption logic)
|
||||||
decryptedData, err := sign.Decrypt(encryptedReq.EncryptedParams)
|
decryptedData, err := crypto.Decrypt(encryptedReq.EncryptedParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithStatusJSON(http.StatusBadRequest, ErrDecryptionFailed)
|
c.AbortWithStatusJSON(http.StatusBadRequest, ErrDecryptionFailed)
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
package sign
|
|
||||||
|
|
||||||
import "github.com/uozi-tech/cosy"
|
|
||||||
|
|
||||||
var (
|
|
||||||
e = cosy.NewErrorScope("sign")
|
|
||||||
ErrTimeout = e.New(40401, "request timeout")
|
|
||||||
ErrInvalidNonce = e.New(50000, "invalid nonce")
|
|
||||||
ErrDecodePrivateKey = e.New(50001, "failed to decode private key")
|
|
||||||
ErrInvalidSign = e.New(50002, "invalid signature")
|
|
||||||
ErrEncryptedDataTooShort = e.New(50003, "encrypted data too short")
|
|
||||||
)
|
|
Loading…
Add table
Add a link
Reference in a new issue