2023-03-27

Signed-off-by: Yuan Si <do4suki@gmail.com>
This commit is contained in:
2023-03-26 22:21:33 +08:00
parent c4da6c74f8
commit 966606afc2
19 changed files with 804 additions and 77 deletions
+43 -3
View File
@@ -1,9 +1,15 @@
package handler
import (
"encoding/base64"
"fmt"
"honoka-chan/config"
"honoka-chan/database"
"honoka-chan/encrypt"
"honoka-chan/resp"
"honoka-chan/utils"
"net/http"
"time"
"github.com/gin-gonic/gin"
)
@@ -13,9 +19,43 @@ func AnnounceIndexHandler(ctx *gin.Context) {
}
func AnnounceCheckStateHandler(ctx *gin.Context) {
reqTime := time.Now().Unix()
authorizeStr := ctx.Request.Header["Authorize"]
authToken, err := utils.GetAuthorizeToken(authorizeStr)
if err != nil {
ctx.String(http.StatusForbidden, "Fuck you!")
return
}
userId := ctx.Request.Header[http.CanonicalHeaderKey("User-ID")]
if len(userId) == 0 {
ctx.String(http.StatusForbidden, "Fuck you!")
return
}
if !database.MatchTokenUid(authToken, userId[0]) {
ctx.String(http.StatusForbidden, "Fuck you!")
return
}
nonce, err := utils.GetAuthorizeNonce(authorizeStr)
if err != nil {
fmt.Println(err)
ctx.String(http.StatusForbidden, "Fuck you!")
return
}
nonce++
respTime := time.Now().Unix()
newAuthorizeStr := fmt.Sprintf("consumerKey=lovelive_test&timeStamp=%d&version=1.1&token=%s&nonce=%d&user_id=%s&requestTimeStamp=%d", respTime, authToken, nonce, userId[0], reqTime)
// fmt.Println(newAuthorizeStr)
xms := encrypt.RSA_Sign_SHA1([]byte(resp.AnnounceState), "privatekey.pem")
xms64 := base64.RawStdEncoding.EncodeToString(xms)
ctx.Header("Server-Version", config.Conf.Server.VersionNumber)
ctx.Header("user_id", "3241988")
ctx.Header("authorize", "consumerKey=lovelive_test&timeStamp=1679360075&version=1.1&token=4JM3w3i6FDXr4lHN4K2Q5ys7Fn56QMT5ytIzPLCZ0ItuouoraRlfCYPlnzqsFsE1v9Phd66Cw4bmjcKoxE52gd&nonce=12&requestTimeStamp=1679360075")
ctx.Header("X-Message-Sign", "CGfQ1rVjIRXxdq1zPyfp8aHDyekfCJ6PwzZ+a6JZkXJdyzGZXnFK6ZZ9lup5KLYLXKzSOmbzeOUbTV6lYdE5G+hoP+oVSpnKDGt1NKdoy5IeJihfXVbNjM5AC8NF7d8oMGk/zTVsVqHHENCX4bbMMIQuFP+K+iw2SiRRD1dbZPw=")
ctx.Header("user_id", userId[0])
ctx.Header("authorize", newAuthorizeStr)
ctx.Header("X-Message-Sign", xms64)
ctx.String(http.StatusOK, resp.AnnounceState)
}