GPCM: Check reported payload version

This commit is contained in:
mkwcat
2023-11-23 20:05:31 -05:00
parent 7dcb4109ad
commit 9b5de86063
2 changed files with 25 additions and 16 deletions

View File

@@ -7,16 +7,16 @@ import (
)
type GPError struct {
errorCode int
errorString string
fatal bool
ErrorCode int
ErrorString string
Fatal bool
}
func MakeGPError(errorCode int, errorString string, fatal bool) GPError {
return GPError{
errorCode: errorCode,
errorString: errorString,
fatal: fatal,
ErrorCode: errorCode,
ErrorString: errorString,
Fatal: fatal,
}
}
@@ -144,12 +144,12 @@ func (err GPError) GetMessage() string {
Command: "error",
CommandValue: "",
OtherValues: map[string]string{
"err": strconv.Itoa(err.errorCode),
"errmsg": err.errorString,
"err": strconv.Itoa(err.ErrorCode),
"errmsg": err.ErrorString,
},
}
if err.fatal {
if err.Fatal {
command.OtherValues["fatal"] = ""
}
@@ -157,6 +157,6 @@ func (err GPError) GetMessage() string {
}
func (g *GameSpySession) replyError(err GPError) {
logging.Error(g.ModuleName, "Reply error:", err.errorString)
logging.Error(g.ModuleName, "Reply error:", err.ErrorString)
g.Conn.Write([]byte(err.GetMessage()))
}

View File

@@ -4,11 +4,11 @@ import (
"crypto/md5"
"encoding/base64"
"encoding/hex"
"log"
"strconv"
"strings"
"wwfc/common"
"wwfc/database"
"wwfc/logging"
)
func generateResponse(gpcmChallenge, nasChallenge, authToken, clientChallenge string) string {
@@ -32,21 +32,30 @@ func generateProof(gpcmChallenge, nasChallenge, authToken, clientChallenge strin
func (g *GameSpySession) login(command common.GameSpyCommand) {
if g.LoggedIn {
log.Fatalf("Attempt to login twice")
logging.Error(g.ModuleName, "Attempt to login twice")
g.replyError(ErrLogin)
return
}
if command.OtherValues["payload_ver"] != "1" {
g.replyError(GPError{
ErrorCode: ErrLogin.ErrorCode,
ErrorString: "The payload version is invalid.",
Fatal: true,
})
return
}
authToken := command.OtherValues["authtoken"]
challenge := database.GetChallenge(pool, ctx, authToken)
if challenge == "" {
// There was an error validating the pre-authentication.
g.replyError(ErrLoginBadPreAuth)
g.replyError(ErrLogin)
return
}
response := generateResponse(g.Challenge, challenge, authToken, command.OtherValues["challenge"])
if response != command.OtherValues["response"] {
// There was an error validating the pre-authentication.
g.replyError(ErrLoginBadPreAuth)
g.replyError(ErrLogin)
return
}