refactor(http): use standard uuid package
This commit is contained in:
parent
e70162b2c3
commit
36a4c05dd4
4 changed files with 27 additions and 9 deletions
1
go.mod
1
go.mod
|
|
@ -20,7 +20,6 @@ require (
|
|||
github.com/bogdanfinn/tls-client v1.15.1
|
||||
github.com/gdamore/tcell/v3 v3.4.2
|
||||
github.com/google/go-cmp v0.6.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
github.com/klauspost/compress v1.19.2
|
||||
github.com/ncruces/zenity v0.10.15
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -52,8 +52,6 @@ github.com/godbus/dbus/v5 v5.2.2 h1:TUR3TgtSVDmjiXOgAAyaZbYmIeP3DPkld3jgKGV8mXQ=
|
|||
github.com/godbus/dbus/v5 v5.2.2/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E=
|
||||
github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM=
|
||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
package http
|
||||
|
||||
import (
|
||||
"uuid"
|
||||
|
||||
"github.com/ayn2op/arikawa/v3/discord"
|
||||
"github.com/ayn2op/arikawa/v3/gateway"
|
||||
"github.com/ayn2op/discordo/internal/tls"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
//go:generate go run generator.go
|
||||
|
|
@ -37,7 +38,7 @@ func CommonProperties() gateway.IdentifyProperties {
|
|||
|
||||
"client_build_number": ClientBuildNumber,
|
||||
"client_event_source": nil,
|
||||
"client_launch_id": uuid.NewString(),
|
||||
"client_launch_id": uuid.NewV4().String(),
|
||||
|
||||
"system_locale": Locale,
|
||||
"release_channel": "stable",
|
||||
|
|
@ -59,7 +60,7 @@ func IdentifyProperties() gateway.IdentifyProperties {
|
|||
func XSuperProperties() gateway.IdentifyProperties {
|
||||
props := CommonProperties()
|
||||
props["client_app_state"] = "focused"
|
||||
props["client_heartbeat_session_id"] = uuid.NewString()
|
||||
props["client_heartbeat_session_id"] = uuid.NewV4().String()
|
||||
props["launch_signature"] = generateLaunchSignature()
|
||||
return props
|
||||
}
|
||||
|
|
@ -69,15 +70,15 @@ func generateLaunchSignature() string {
|
|||
// This mask clears detection bits to avoid identification.
|
||||
// Reference: https://docs.discord.food/reference#launch-signature
|
||||
//
|
||||
// Required version and variant bits for UUIDv4 validity are set by google/uuid.
|
||||
// Reference: https://github.com/google/uuid/blob/master/version4.go#L54
|
||||
// Required version and variant bits for UUIDv4 validity are set by uuid.NewV4.
|
||||
// Reference: https://pkg.go.dev/uuid#NewV4
|
||||
mask := [16]byte{
|
||||
0b11111111, 0b01111111, 0b11101111, 0b11101111,
|
||||
0b11110111, 0b11101111, 0b11110111, 0b11111111,
|
||||
0b11011111, 0b01111110, 0b11111111, 0b10111111,
|
||||
0b11111110, 0b11111111, 0b11110111, 0b11111111,
|
||||
}
|
||||
id := uuid.New()
|
||||
id := uuid.NewV4()
|
||||
for i := range mask {
|
||||
id[i] &= mask[i]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package http
|
|||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"uuid"
|
||||
|
||||
"github.com/ayn2op/arikawa/v3/gateway"
|
||||
"github.com/ayn2op/discordo/internal/tls"
|
||||
|
|
@ -53,3 +54,22 @@ func TestBrowserClientHints(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPropertyUUIDs(t *testing.T) {
|
||||
properties := XSuperProperties()
|
||||
for _, key := range []gateway.IdentifyPropertyKey{"client_launch_id", "client_heartbeat_session_id", "launch_signature"} {
|
||||
t.Run(string(key), func(t *testing.T) {
|
||||
value, ok := properties[key].(string)
|
||||
if !ok {
|
||||
t.Fatalf("got %T, want string", properties[key])
|
||||
}
|
||||
id, err := uuid.Parse(value)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if id[6]>>4 != 4 || id[8]>>6 != 2 {
|
||||
t.Errorf("got non-v4 UUID %q", id)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue