Fixed the sub being longer than 255 characters

This commit is contained in:
Tracker-Friendly 2024-05-06 11:22:39 +01:00
parent bef5624ff7
commit 57128304c7
1 changed files with 7 additions and 4 deletions

11
main.go
View File

@ -90,7 +90,10 @@ func hash(password, salt string) string {
derivedKey, _ := scrypt.Key(passwordBytes, saltBytes, 32768, 8, 1, 64) derivedKey, _ := scrypt.Key(passwordBytes, saltBytes, 32768, 8, 1, 64)
hashString := fmt.Sprintf("scrypt:32768:8:1$%s$%s", salt, hex.EncodeToString(derivedKey)) hashString := fmt.Sprintf("scrypt:32768
:8:1$%s$%s", salt, hex.EncodeToString(derivedKey))
return hashString return hashString
} }
@ -409,7 +412,7 @@ func main() {
} }
}(conn) }(conn)
_, err = conn.Exec("INSERT INTO users (username, password, created, uniqueid) VALUES (?, ?, ?, ?)", username, hashedPassword, strconv.FormatInt(time.Now().Unix(), 10), genSalt(512)) _, err = conn.Exec("INSERT INTO users (username, password, created, uniqueid) VALUES (?, ?, ?, ?)", username, hashedPassword, strconv.FormatInt(time.Now().Unix(), 10), genSalt(255))
if err != nil { if err != nil {
log.Println("[ERROR] Unknown in /api/signup user creation at", strconv.FormatInt(time.Now().Unix(), 10)+":", err) log.Println("[ERROR] Unknown in /api/signup user creation at", strconv.FormatInt(time.Now().Unix(), 10)+":", err)
return return
@ -577,7 +580,7 @@ func main() {
return return
} }
c.JSON(200, gin.H{"sub": uniqueid, "name": username}) c.JSON(200, gin.H{"sub": uniqueid[:255], "name": username})
}) })
router.POST("/api/uniqueid", func(c *gin.Context) { router.POST("/api/uniqueid", func(c *gin.Context) {
@ -771,7 +774,7 @@ func main() {
} }
datatemplate := jwt.MapClaims{ datatemplate := jwt.MapClaims{
"sub": uniqueid, "sub": uniqueid[:255],
"iss": "https://auth.hectabit.org", "iss": "https://auth.hectabit.org",
"name": username, "name": username,
"aud": appId, "aud": appId,