File: client_hello_id.go

package info (click to toggle)
snowflake 2.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports, forky, sid, trixie
  • size: 968 kB
  • sloc: makefile: 5
file content (46 lines) | stat: -rw-r--r-- 1,519 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package utls

import (
	"errors"
	utls "github.com/refraction-networking/utls"
	"strings"
)

// ported from https://github.com/max-b/snowflake/commit/9dded063cb74c6941a16ad90b9dd0e06e618e55e
var clientHelloIDMap = map[string]utls.ClientHelloID{
	// No HelloCustom: not useful for external configuration.
	// No HelloRandomized: doesn't negotiate consistent ALPN.
	"hellorandomizedalpn":   utls.HelloRandomizedALPN,
	"hellorandomizednoalpn": utls.HelloRandomizedNoALPN,
	"hellofirefox_auto":     utls.HelloFirefox_Auto,
	"hellofirefox_55":       utls.HelloFirefox_55,
	"hellofirefox_56":       utls.HelloFirefox_56,
	"hellofirefox_63":       utls.HelloFirefox_63,
	"hellofirefox_65":       utls.HelloFirefox_65,
	"hellochrome_auto":      utls.HelloChrome_Auto,
	"hellochrome_58":        utls.HelloChrome_58,
	"hellochrome_62":        utls.HelloChrome_62,
	"hellochrome_70":        utls.HelloChrome_70,
	"hellochrome_72":        utls.HelloChrome_72,
	"helloios_auto":         utls.HelloIOS_Auto,
	"helloios_11_1":         utls.HelloIOS_11_1,
	"helloios_12_1":         utls.HelloIOS_12_1,
}

var errNameNotFound = errors.New("client hello name is unrecognized")

func NameToUTLSID(name string) (utls.ClientHelloID, error) {
	normalizedName := strings.ToLower(name)
	if id, ok := clientHelloIDMap[normalizedName]; ok {
		return id, nil
	}
	return utls.ClientHelloID{}, errNameNotFound
}

func ListAllNames() []string {
	var names []string
	for k, _ := range clientHelloIDMap {
		names = append(names, k)
	}
	return names
}