props.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package http
  2. import (
  3. "encoding/base64"
  4. "encoding/json"
  5. "github.com/diamondburned/arikawa/v3/discord"
  6. "github.com/diamondburned/arikawa/v3/gateway"
  7. "github.com/google/uuid"
  8. )
  9. const (
  10. Browser = "Chrome"
  11. BrowserVersion = "143.0.0.0"
  12. BrowserUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " + Browser + "/" + BrowserVersion + " Safari/537.36"
  13. )
  14. var (
  15. Locale = discord.EnglishUS
  16. )
  17. func IdentifyProperties() gateway.IdentifyProperties {
  18. return gateway.IdentifyProperties{
  19. gateway.IdentifyDevice: "",
  20. gateway.IdentifyOS: "Windows",
  21. "os_version": "10",
  22. gateway.IdentifyBrowser: Browser,
  23. "browser_version": BrowserVersion,
  24. "browser_user_agent": BrowserUserAgent,
  25. "client_build_number": 482285,
  26. "client_event_source": nil,
  27. "client_app_state": "focused",
  28. "client_launch_id": uuid.NewString(),
  29. "client_heartbeat_session_id": uuid.NewString(),
  30. "launch_signature": generateLaunchSignature(),
  31. "system_locale": Locale,
  32. "release_channel": "stable",
  33. "has_client_mods": false,
  34. "referrer": "",
  35. "referrer_current": "",
  36. "referring_domain": "",
  37. "referring_domain_current": "",
  38. // These properties are only sent when identifying with the gateway and are not included in the X-Super-Properties header.
  39. "is_fast_connect": false,
  40. "gateway_connect_reasons": "AppSkeleton",
  41. }
  42. }
  43. func getSuperProps() (string, error) {
  44. props := IdentifyProperties()
  45. delete(props, "is_fast_connect")
  46. delete(props, "gateway_connect_reasons")
  47. raw, err := json.Marshal(props)
  48. if err != nil {
  49. return "", err
  50. }
  51. return base64.StdEncoding.EncodeToString(raw), nil
  52. }
  53. func generateLaunchSignature() string {
  54. // Discord uses specific UUID bits to detect client modifications.
  55. // This mask clears detection bits to avoid identification.
  56. // Reference: https://docs.discord.food/reference#launch-signature
  57. //
  58. // Required version and variant bits for UUIDv4 validity are set by google/uuid.
  59. // Reference: https://github.com/google/uuid/blob/master/version4.go#L54
  60. mask := [16]byte{
  61. 0b11111111, 0b01111111, 0b11101111, 0b11101111,
  62. 0b11110111, 0b11101111, 0b11110111, 0b11111111,
  63. 0b11011111, 0b01111110, 0b11111111, 0b10111111,
  64. 0b11111110, 0b11111111, 0b11110111, 0b11111111,
  65. }
  66. id := uuid.New()
  67. for i := range mask {
  68. id[i] &= mask[i]
  69. }
  70. return id.String()
  71. }