client_hello_id.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package utls
  2. import (
  3. "errors"
  4. utls "github.com/refraction-networking/utls"
  5. "strings"
  6. )
  7. // ported from https://github.com/max-b/snowflake/commit/9dded063cb74c6941a16ad90b9dd0e06e618e55e
  8. var clientHelloIDMap = map[string]utls.ClientHelloID{
  9. // No HelloCustom: not useful for external configuration.
  10. // No HelloRandomized: doesn't negotiate consistent ALPN.
  11. "hellorandomizedalpn": utls.HelloRandomizedALPN,
  12. "hellorandomizednoalpn": utls.HelloRandomizedNoALPN,
  13. "hellofirefox_auto": utls.HelloFirefox_Auto,
  14. "hellofirefox_55": utls.HelloFirefox_55,
  15. "hellofirefox_56": utls.HelloFirefox_56,
  16. "hellofirefox_63": utls.HelloFirefox_63,
  17. "hellofirefox_65": utls.HelloFirefox_65,
  18. "hellochrome_auto": utls.HelloChrome_Auto,
  19. "hellochrome_58": utls.HelloChrome_58,
  20. "hellochrome_62": utls.HelloChrome_62,
  21. "hellochrome_70": utls.HelloChrome_70,
  22. "hellochrome_72": utls.HelloChrome_72,
  23. "helloios_auto": utls.HelloIOS_Auto,
  24. "helloios_11_1": utls.HelloIOS_11_1,
  25. "helloios_12_1": utls.HelloIOS_12_1,
  26. }
  27. var errNameNotFound = errors.New("client hello name is unrecognized")
  28. func NameToUTLSID(name string) (utls.ClientHelloID, error) {
  29. normalizedName := strings.ToLower(name)
  30. if id, ok := clientHelloIDMap[normalizedName]; ok {
  31. return id, nil
  32. }
  33. return utls.ClientHelloID{}, errNameNotFound
  34. }
  35. func ListAllNames() []string {
  36. var names []string
  37. for k, _ := range clientHelloIDMap {
  38. names = append(names, k)
  39. }
  40. return names
  41. }