Skip to content

Commit

Permalink
Add crypto subtle for timing attacks
Browse files Browse the repository at this point in the history
  • Loading branch information
yunimoo authored and arina999999997 committed Aug 6, 2024
1 parent d4a3158 commit 0c92519
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions webui/admin/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"elichika/utils"
"elichika/webui/webui_utils"

"crypto/subtle"
"encoding/base64"
"encoding/json"
"mime/multipart"
Expand All @@ -19,15 +20,14 @@ func login(ctx *gin.Context) {
resp := webui_utils.Response{}
form := ctx.MustGet("form").(*multipart.Form)

// TODO(extra): this is vulnerable to timing attack but it's whatever
adminPassword := form.Value["admin_password"][0]
if *config.Conf.AdminPassword != adminPassword {
resp.Error = &respString
*resp.Error = "Wrong password!"
} else {
if subtle.ConstantTimeCompare([]byte(*config.Conf.AdminPassword), []byte(adminPassword)) == 1 {
newSessionKey()
resp.Response = &respString
*resp.Response = base64.StdEncoding.EncodeToString(adminSessionKey)
} else {
resp.Error = &respString
*resp.Error = "Wrong password!"
}

jsonBytes, err := json.Marshal(resp)
Expand Down

0 comments on commit 0c92519

Please sign in to comment.