Skip to content

Commit

Permalink
feat/encrypt-request (#854)
Browse files Browse the repository at this point in the history
* feat: encrypt login and install request #852

* fix: user curd panic after install

* chore: update error definations
  • Loading branch information
0xJacky authored Feb 7, 2025
2 parents fb532b6 + 7bb8cb5 commit 9cbbd42
Show file tree
Hide file tree
Showing 33 changed files with 1,108 additions and 768 deletions.
22 changes: 22 additions & 0 deletions api/crypto/crypto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package crypto

import (
"net/http"

"github.com/0xJacky/Nginx-UI/api"
"github.com/0xJacky/Nginx-UI/internal/crypto"
"github.com/gin-gonic/gin"
)

// GetPublicKey generates a new ED25519 key pair and registers it in the cache
func GetPublicKey(c *gin.Context) {
sign, err := crypto.GetCryptoParams()
if err != nil {
api.ErrHandler(c, err)
return
}

c.JSON(http.StatusOK, gin.H{
"public_key": sign.PublicKey,
})
}
10 changes: 10 additions & 0 deletions api/crypto/router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package crypto

import "github.com/gin-gonic/gin"

func InitPublicRouter(r *gin.RouterGroup) {
g := r.Group("/crypto")
{
g.GET("public_key", GetPublicKey)
}
}
3 changes: 2 additions & 1 deletion api/system/router.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package system

import (
"github.com/0xJacky/Nginx-UI/internal/middleware"
"github.com/gin-gonic/gin"
)

func InitPublicRouter(r *gin.RouterGroup) {
r.GET("install", InstallLockCheck)
r.POST("install", InstallNginxUI)
r.POST("install", middleware.EncryptedParams(), InstallNginxUI)
r.GET("translation/:code", GetTranslation)
}

Expand Down
3 changes: 2 additions & 1 deletion api/user/router.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package user

import (
"github.com/0xJacky/Nginx-UI/internal/middleware"
"github.com/gin-gonic/gin"
)

func InitAuthRouter(r *gin.RouterGroup) {
r.POST("/login", Login)
r.POST("/login", middleware.EncryptedParams(), Login)
r.DELETE("/logout", Logout)

r.GET("/begin_passkey_login", BeginPasskeyLogin)
Expand Down
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"axios": "^1.7.9",
"dayjs": "^1.11.13",
"highlight.js": "^11.11.1",
"jsencrypt": "^3.3.2",
"lodash": "^4.17.21",
"marked": "^15.0.6",
"marked-highlight": "^2.2.1",
Expand Down
8 changes: 8 additions & 0 deletions app/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/src/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const auth = {
password,
otp,
recovery_code: recoveryCode,
})
}, { crypto: true })
},
async casdoor_login(code?: string, state?: string) {
await http.post('/casdoor_callback', {
Expand Down
2 changes: 1 addition & 1 deletion app/src/api/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const install = {
return http.get('/install')
},
install_nginx_ui(data: InstallRequest) {
return http.post('/install', data)
return http.post('/install', data, { crypto: true })
},
}

Expand Down
1 change: 1 addition & 0 deletions app/src/constants/errors/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default {
50001: () => $gettext('Plain text is empty'),
50002: () => $gettext('Cipher text is too short'),
40401: () => $gettext('Request timeout'),
}
4 changes: 4 additions & 0 deletions app/src/constants/errors/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
40000: () => $gettext('Invalid request format'),
40001: () => $gettext('Decryption failed'),
}
Loading

0 comments on commit 9cbbd42

Please sign in to comment.