clienthelloID.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package utlsutil
  2. import (
  3. "fmt"
  4. utls "github.com/refraction-networking/utls"
  5. "strings"
  6. )
  7. var (
  8. // This should be kept in sync with what is available in utls.
  9. clientHelloIDMap = map[string]*utls.ClientHelloID{
  10. "hellogolang": nil, // Don't bother with utls.
  11. "hellorandomized": &utls.HelloRandomized,
  12. "hellorandomizedalpn": &utls.HelloRandomizedALPN,
  13. "hellorandomizednoalpn": &utls.HelloRandomizedNoALPN,
  14. "hellofirefox_auto": &utls.HelloFirefox_Auto,
  15. "hellofirefox_55": &utls.HelloFirefox_55,
  16. "hellofirefox_56": &utls.HelloFirefox_56,
  17. "hellofirefox_63": &utls.HelloFirefox_63,
  18. "hellofirefox_65": &utls.HelloFirefox_65,
  19. "hellofirefox_99": &utls.HelloFirefox_99,
  20. "hellofirefox_102": &utls.HelloFirefox_102,
  21. "hellofirefox_105": &utls.HelloFirefox_105,
  22. "hellochrome_auto": &utls.HelloChrome_Auto,
  23. "hellochrome_58": &utls.HelloChrome_58,
  24. "hellochrome_62": &utls.HelloChrome_62,
  25. "hellochrome_70": &utls.HelloChrome_70,
  26. "hellochrome_72": &utls.HelloChrome_72,
  27. "hellochrome_83": &utls.HelloChrome_83,
  28. "hellochrome_87": &utls.HelloChrome_87,
  29. "hellochrome_96": &utls.HelloChrome_96,
  30. "hellochrome_100": &utls.HelloChrome_100,
  31. "hellochrome_102": &utls.HelloChrome_102,
  32. "helloios_auto": &utls.HelloIOS_Auto,
  33. "helloios_11_1": &utls.HelloIOS_11_1,
  34. "helloios_12_1": &utls.HelloIOS_12_1,
  35. "helloios_13": &utls.HelloIOS_13,
  36. "helloios_14": &utls.HelloIOS_14,
  37. "helloandroid_11": &utls.HelloAndroid_11_OkHttp,
  38. "helloedge_auto": &utls.HelloEdge_Auto,
  39. "helloedge_85": &utls.HelloEdge_85,
  40. "helloedge_106": &utls.HelloEdge_106,
  41. "hellosafari_auto": &utls.HelloSafari_Auto,
  42. "hellosafari_16_0": &utls.HelloSafari_16_0,
  43. "hello360_auto": &utls.Hello360_Auto,
  44. "hello360_7_5": &utls.Hello360_7_5,
  45. "hello360_11_0": &utls.Hello360_11_0,
  46. "helloqq_auto": &utls.HelloQQ_Auto,
  47. "helloqq_11_1": &utls.HelloQQ_11_1,
  48. }
  49. defaultClientHello = &utls.HelloChrome_Auto
  50. )
  51. func ParseClientHelloID(s string) (*utls.ClientHelloID, error) {
  52. s = strings.ToLower(s)
  53. switch s {
  54. case "none":
  55. return nil, nil
  56. case "":
  57. return defaultClientHello, nil
  58. default:
  59. if ret := clientHelloIDMap[s]; ret != nil {
  60. return ret, nil
  61. }
  62. }
  63. return nil, fmt.Errorf("invalid ClientHelloID: '%v'", s)
  64. }