Skip to content

Commit 6d84c25

Browse files
committed
Undo previous commit, authenticate via Steam API
1 parent 267e373 commit 6d84c25

4 files changed

Lines changed: 54 additions & 28 deletions

File tree

go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ require (
88
github.com/aws/aws-sdk-go-v2/service/s3 v1.78.2
99
github.com/blezek/tga v0.0.0-20150626111426-80720cbc1017
1010
github.com/go-sql-driver/mysql v1.9.0
11-
github.com/tmcarey/steam-appticket-go v0.0.0-20250415182558-823c1784f126
1211
)
1312

14-
require google.golang.org/protobuf v1.30.0 // indirect
15-
1613
require (
1714
filippo.io/edwards25519 v1.1.0 // indirect
1815
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.10 // indirect
@@ -29,6 +26,6 @@ require (
2926
github.com/aws/aws-sdk-go-v2/service/sso v1.25.1 // indirect
3027
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.29.1 // indirect
3128
github.com/aws/aws-sdk-go-v2/service/sts v1.33.17 // indirect
32-
github.com/aws/smithy-go v1.22.3 // indirect
29+
github.com/aws/smithy-go v1.22.2 // indirect
3330
github.com/ftrvxmtrx/tga v0.0.0-20150524081124-bd8e8d5be13a // indirect
3431
)

go.sum

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,11 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.29.1 h1:KwuLovgQPcdjNMfFt9OhUd9a
3434
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.29.1/go.mod h1:MlYRNmYu/fGPoxBQVvBYr9nyr948aY/WLUvwBMBJubs=
3535
github.com/aws/aws-sdk-go-v2/service/sts v1.33.17 h1:PZV5W8yk4OtH1JAuhV2PXwwO9v5G5Aoj+eMCn4T+1Kc=
3636
github.com/aws/aws-sdk-go-v2/service/sts v1.33.17/go.mod h1:cQnB8CUnxbMU82JvlqjKR2HBOm3fe9pWorWBza6MBJ4=
37-
github.com/aws/smithy-go v1.22.3 h1:Z//5NuZCSW6R4PhQ93hShNbyBbn8BWCmCVCt+Q8Io5k=
38-
github.com/aws/smithy-go v1.22.3/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI=
37+
github.com/aws/smithy-go v1.22.2 h1:6D9hW43xKFrRx/tXXfAlIZc4JI+yQe6snnWcQyxSyLQ=
38+
github.com/aws/smithy-go v1.22.2/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
3939
github.com/blezek/tga v0.0.0-20150626111426-80720cbc1017 h1:TWk6m6k3qegbUZsdsHk/ix22ANqPgLau40bPwiNQN40=
4040
github.com/blezek/tga v0.0.0-20150626111426-80720cbc1017/go.mod h1:WnX8JiQN+UtyUPq/1EIUaB2WVX3wdAmOBH5K52NyOO0=
4141
github.com/ftrvxmtrx/tga v0.0.0-20150524081124-bd8e8d5be13a h1:eSqaRmdlZ9JsJ7JuWfDr3ym3monToXRczohBOL+heVQ=
4242
github.com/ftrvxmtrx/tga v0.0.0-20150524081124-bd8e8d5be13a/go.mod h1:US5WvgEHtG+BvWNNs6gk937h0QL2g2x+r7RH8m3g80Y=
4343
github.com/go-sql-driver/mysql v1.9.0 h1:Y0zIbQXhQKmQgTp44Y1dp3wTXcn804QoTptLZT1vtvo=
4444
github.com/go-sql-driver/mysql v1.9.0/go.mod h1:pDetrLJeA3oMujJuvXc8RJoasr589B6A9fwzD3QMrqw=
45-
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
46-
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
47-
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
48-
github.com/tmcarey/steam-appticket-go v0.0.0-20250415182558-823c1784f126 h1:9Fo5DAXX55SJTdcNiIWP0xCgCWWEoy/mApnQ8H8Vs9w=
49-
github.com/tmcarey/steam-appticket-go v0.0.0-20250415182558-823c1784f126/go.mod h1:TJFVH9O45IxZNWgnBtvWMl/5RlOCQ+eikbdNYACo1K4=
50-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
51-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
52-
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
53-
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
54-
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=

ingame/toyboxapi/auth.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ import (
2323
"encoding/base64"
2424
"fmt"
2525
"net/http"
26-
"slices"
27-
"strconv"
26+
"strings"
2827

2928
"github.com/flatgrassdotnet/cloudbox/db"
3029
"github.com/flatgrassdotnet/cloudbox/utils"
31-
32-
appticket "github.com/tmcarey/steam-appticket-go"
3330
)
3431

3532
// auth logs someone into the toybox api
@@ -49,18 +46,22 @@ func Auth(w http.ResponseWriter, r *http.Request) {
4946
return
5047
}
5148

52-
token := utils.UnBinHex(utils.UnBinHexString(r.FormValue("token")))
53-
49+
token := utils.UnBinHexString(r.FormValue("token"))
5450
steamid := utils.UnBinHexString(r.FormValue("u"))
55-
5651
vac := utils.UnBinHexString(r.FormValue("vac"))
57-
if !slices.Contains([]string{"good", "banned"}, vac) {
58-
utils.WriteError(w, r, "invalid vac value")
52+
53+
user, err := utils.AuthenticateUserTicket(token)
54+
if err != nil {
55+
utils.WriteError(w, r, fmt.Sprintf("failed to validate steam ticket: %s", err))
56+
57+
// net/http errors shouldn't cause the game to exit
58+
if !strings.Contains(err.Error(), "net/http:") {
59+
fmt.Fprint(w, "chrome") // terminate game with anti-piracy error
60+
}
61+
5962
return
6063
}
61-
62-
appticket, err := appticket.ParseAppTicket(token, false)
63-
if err != nil || !appticket.IsValid || appticket.AppID != 4000 || strconv.Itoa(int(appticket.SteamID)) != steamid {
64+
if user.SteamID != steamid {
6465
fmt.Fprint(w, "chrome") // terminate game with anti-piracy error
6566
return
6667
}

utils/steam.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,44 @@ import (
3535

3636
var SteamAPIKey string
3737

38+
type AuthenticateUserTicketResponse struct {
39+
Response struct {
40+
Params common.UserTicketInfo `json:"params"`
41+
Error struct {
42+
ErrorCode int `json:"errorcode"`
43+
ErrorDesc string `json:"errordesc"`
44+
} `json:"error"`
45+
} `json:"response"`
46+
}
47+
48+
func AuthenticateUserTicket(ticket string) (common.UserTicketInfo, error) {
49+
v := make(url.Values)
50+
51+
v.Set("key", SteamAPIKey)
52+
v.Set("appid", "4000") // garry's mod
53+
v.Set("ticket", ticket)
54+
55+
r, err := http.Get(fmt.Sprintf("https://api.steampowered.com/ISteamUserAuth/AuthenticateUserTicket/v0001/?%s", v.Encode()))
56+
if err != nil {
57+
return common.UserTicketInfo{}, err
58+
}
59+
60+
defer r.Body.Close()
61+
62+
var rd AuthenticateUserTicketResponse
63+
err = json.NewDecoder(r.Body).Decode(&rd)
64+
if err != nil {
65+
return common.UserTicketInfo{}, err
66+
}
67+
68+
// no steamid, something is wrong
69+
if rd.Response.Params.SteamID == "" {
70+
return common.UserTicketInfo{}, errors.New(rd.Response.Error.ErrorDesc)
71+
}
72+
73+
return rd.Response.Params, nil
74+
}
75+
3876
type GetPlayerSummariesResponse struct {
3977
Response struct {
4078
Players []common.PlayerSummaryInfo `json:"players"`

0 commit comments

Comments
 (0)