tls

package
v1.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ForceALPN_name = map[int32]string{
		0: "TRANSPORT_PREFERENCE_TAKE_PRIORITY",
		1: "NO_ALPN",
		2: "UTLS_PRESET",
	}
	ForceALPN_value = map[string]int32{
		"TRANSPORT_PREFERENCE_TAKE_PRIORITY": 0,
		"NO_ALPN":                            1,
		"UTLS_PRESET":                        2,
	}
)

Enum value maps for ForceALPN.

View Source
var ErrInvalidLen = errors.New("goech: invalid length")
View Source
var File_protos_tls_certificate_proto protoreflect.FileDescriptor
View Source
var File_protos_tls_tls_proto protoreflect.FileDescriptor
View Source
var ModernFingerprints = map[string]*utls.ClientHelloID{

	"hellofirefox_99":         &utls.HelloFirefox_99,
	"hellofirefox_102":        &utls.HelloFirefox_102,
	"hellofirefox_105":        &utls.HelloFirefox_105,
	"hellofirefox_120":        &utls.HelloFirefox_120,
	"hellochrome_83":          &utls.HelloChrome_83,
	"hellochrome_87":          &utls.HelloChrome_87,
	"hellochrome_96":          &utls.HelloChrome_96,
	"hellochrome_100":         &utls.HelloChrome_100,
	"hellochrome_102":         &utls.HelloChrome_102,
	"hellochrome_106_shuffle": &utls.HelloChrome_106_Shuffle,
	"hellochrome_120":         &utls.HelloChrome_120,
	"hellochrome_131":         &utls.HelloChrome_131,
	"helloios_13":             &utls.HelloIOS_13,
	"helloios_14":             &utls.HelloIOS_14,
	"helloedge_85":            &utls.HelloEdge_85,
	"helloedge_106":           &utls.HelloEdge_106,
	"hellosafari_16_0":        &utls.HelloSafari_16_0,
	"hello360_11_0":           &utls.Hello360_11_0,
	"helloqq_11_1":            &utls.HelloQQ_11_1,
}
View Source
var OtherFingerprints = map[string]*utls.ClientHelloID{

	"hellogolang":            &utls.HelloGolang,
	"hellorandomized":        &utls.HelloRandomized,
	"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,
	"helloandroid_11_okhttp": &utls.HelloAndroid_11_OkHttp,
	"helloedge_auto":         &utls.HelloEdge_Auto,
	"hellosafari_auto":       &utls.HelloSafari_Auto,
	"hello360_auto":          &utls.Hello360_Auto,
	"hello360_7_5":           &utls.Hello360_7_5,
	"helloqq_auto":           &utls.HelloQQ_Auto,

	"hellochrome_100_psk":              &utls.HelloChrome_100_PSK,
	"hellochrome_112_psk_shuf":         &utls.HelloChrome_112_PSK_Shuf,
	"hellochrome_114_padding_psk_shuf": &utls.HelloChrome_114_Padding_PSK_Shuf,
	"hellochrome_115_pq":               &utls.HelloChrome_115_PQ,
	"hellochrome_115_pq_psk":           &utls.HelloChrome_115_PQ_PSK,
	"hellochrome_120_pq":               &utls.HelloChrome_120_PQ,
}
View Source
var PresetFingerprints = map[string]*utls.ClientHelloID{

	"chrome":           &utls.HelloChrome_Auto,
	"firefox":          &utls.HelloFirefox_Auto,
	"safari":           &utls.HelloSafari_Auto,
	"ios":              &utls.HelloIOS_Auto,
	"android":          &utls.HelloAndroid_11_OkHttp,
	"edge":             &utls.HelloEdge_Auto,
	"360":              &utls.Hello360_Auto,
	"qq":               &utls.HelloQQ_Auto,
	"random":           nil,
	"randomized":       nil,
	"randomizednoalpn": nil,
	"unsafe":           nil,
}

Functions

func BuildCertificates

func BuildCertificates(certConfigs []*Certificate) ([]tls.Certificate, error)

func CalculatePEMCertChainSHA256Hash

func CalculatePEMCertChainSHA256Hash(certContent []byte) string

func CertsToCertPool

func CertsToCertPool(certs [][]byte) (*x509.CertPool, error)

func ConvertToGoECHKeys

func ConvertToGoECHKeys(data []byte) ([]tls.EncryptedClientHelloKey, error)

func GenerateCertChainHash

func GenerateCertChainHash(rawCerts [][]byte) []byte

func GetFingerprint

func GetFingerprint(name string) (fingerprint *utls.ClientHelloID, found bool)

Types

type Certificate

type Certificate struct {
	Certificate         []byte `protobuf:"bytes,1,opt,name=certificate,proto3" json:"certificate,omitempty"`
	Key                 []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"`
	CertificateFilepath string `protobuf:"bytes,4,opt,name=certificate_filepath,json=certificateFilepath,proto3" json:"certificate_filepath,omitempty"`
	KeyFilepath         string `protobuf:"bytes,5,opt,name=key_filepath,json=keyFilepath,proto3" json:"key_filepath,omitempty"`
	// contains filtered or unexported fields
}

func ParseCertificate

func ParseCertificate(c *cert.Certificate) *Certificate

ParseCertificate converts a cert.Certificate to Certificate.

func (*Certificate) Descriptor deprecated

func (*Certificate) Descriptor() ([]byte, []int)

Deprecated: Use Certificate.ProtoReflect.Descriptor instead.

func (*Certificate) GetCertificate

func (x *Certificate) GetCertificate() []byte

func (*Certificate) GetCertificateFilepath

func (x *Certificate) GetCertificateFilepath() string

func (*Certificate) GetKey

func (x *Certificate) GetKey() []byte

func (*Certificate) GetKeyFilepath

func (x *Certificate) GetKeyFilepath() string

func (*Certificate) ProtoMessage

func (*Certificate) ProtoMessage()

func (*Certificate) ProtoReflect

func (x *Certificate) ProtoReflect() protoreflect.Message

func (*Certificate) Reset

func (x *Certificate) Reset()

func (*Certificate) String

func (x *Certificate) String() string

type Conn

type Conn struct {
	*tls.Conn
}

a wrapper of tls.Conn

func (*Conn) GetConnectionApplicationProtocol

func (c *Conn) GetConnectionApplicationProtocol() (string, error)

func (*Conn) HandshakeAddress

func (c *Conn) HandshakeAddress() net.Address

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(config EngineConfig) (*Engine, error)

TODO: prebuild tls.Config

func (*Engine) ApplyECH

func (e *Engine) ApplyECH(config *tls.Config)

func (*Engine) GetClientConn

func (c *Engine) GetClientConn(conn net.Conn, opts ...security.Option) (net.Conn, error)

func (*Engine) GetTLSConfig

func (c *Engine) GetTLSConfig(opts ...security.Option) *tls.Config

type EngineConfig

type EngineConfig struct {
	Config    *TlsConfig
	DnsServer i.ECHResolver
}

type ForceALPN

type ForceALPN int32
const (
	// 优先使用用户在 TLS 设置中手动制定了 APLN 的值,否则使用传输协议的默认 ALPN 设置。
	ForceALPN_TRANSPORT_PREFERENCE_TAKE_PRIORITY ForceALPN = 0
	// 不发送 ALPN TLS 扩展
	ForceALPN_NO_ALPN ForceALPN = 1
	// 以 uTLS 的特征模板中的 ALPN 设置为准
	ForceALPN_UTLS_PRESET ForceALPN = 2
)

func (ForceALPN) Descriptor

func (ForceALPN) Descriptor() protoreflect.EnumDescriptor

func (ForceALPN) Enum

func (x ForceALPN) Enum() *ForceALPN

func (ForceALPN) EnumDescriptor deprecated

func (ForceALPN) EnumDescriptor() ([]byte, []int)

Deprecated: Use ForceALPN.Descriptor instead.

func (ForceALPN) Number

func (x ForceALPN) Number() protoreflect.EnumNumber

func (ForceALPN) String

func (x ForceALPN) String() string

func (ForceALPN) Type

type Option

type Option func(*tls.Config)

func WithDestination

func WithDestination(dest net.Destination) Option

if c.ServerName has been specified, dont apply dest as ServerName

func WithNextProtocol

func WithNextProtocol(protos []string) Option

type TlsConfig

type TlsConfig struct {

	// certs to be provided to peer
	Certificates []*Certificate `protobuf:"bytes,1,rep,name=certificates,proto3" json:"certificates,omitempty"`
	// certs to be used as root CA
	RootCas [][]byte `protobuf:"bytes,2,rep,name=root_cas,json=rootCas,proto3" json:"root_cas,omitempty"`
	// certs to issue certificates which will be provided to peer
	IssueCas []*Certificate `protobuf:"bytes,3,rep,name=issue_cas,json=issueCas,proto3" json:"issue_cas,omitempty"`
	// if not specified, the server name will be destination domain of the connection if
	// it is a domain
	ServerName              string   `protobuf:"bytes,4,opt,name=server_name,json=serverName,proto3" json:"server_name,omitempty"`
	DisableSystemRoot       bool     `protobuf:"varint,5,opt,name=disable_system_root,json=disableSystemRoot,proto3" json:"disable_system_root,omitempty"`
	AllowInsecure           bool     `protobuf:"varint,6,opt,name=allow_insecure,json=allowInsecure,proto3" json:"allow_insecure,omitempty"`
	NextProtocol            []string `protobuf:"bytes,7,rep,name=next_protocol,json=nextProtocol,proto3" json:"next_protocol,omitempty"`
	EnableSessionResumption bool     `` /* 133-byte string literal not displayed */
	// A list of byte slice, each of which is a hash of a cert chain.
	PinnedPeerCertificateChainSha256 [][]byte `` /* 163-byte string literal not displayed */
	VerifyClientCertificate          bool     `` /* 134-byte string literal not displayed */
	// utls-related
	Imitate string `protobuf:"bytes,11,opt,name=imitate,proto3" json:"imitate,omitempty"`
	// utls-related
	NoSNI bool `protobuf:"varint,12,opt,name=noSNI,proto3" json:"noSNI,omitempty"`
	// utls-related
	ForceAlpn    ForceALPN `protobuf:"varint,13,opt,name=force_alpn,json=forceAlpn,proto3,enum=x.tls.ForceALPN" json:"force_alpn,omitempty"`
	MasterKeyLog string    `protobuf:"bytes,14,opt,name=master_key_log,json=masterKeyLog,proto3" json:"master_key_log,omitempty"`
	// server ech key
	EchKey []byte `protobuf:"bytes,15,opt,name=ech_key,json=echKey,proto3" json:"ech_key,omitempty"`
	// client ech config
	EchConfig []byte `protobuf:"bytes,16,opt,name=ech_config,json=echConfig,proto3" json:"ech_config,omitempty"`
	// client only
	// enable ech
	EnableEch bool `protobuf:"varint,17,opt,name=enable_ech,json=enableEch,proto3" json:"enable_ech,omitempty"`
	// contains filtered or unexported fields
}

func (*TlsConfig) Descriptor deprecated

func (*TlsConfig) Descriptor() ([]byte, []int)

Deprecated: Use TlsConfig.ProtoReflect.Descriptor instead.

func (*TlsConfig) GetAllowInsecure

func (x *TlsConfig) GetAllowInsecure() bool

func (*TlsConfig) GetCertificates

func (x *TlsConfig) GetCertificates() []*Certificate

func (*TlsConfig) GetDisableSystemRoot

func (x *TlsConfig) GetDisableSystemRoot() bool

func (*TlsConfig) GetEchConfig

func (x *TlsConfig) GetEchConfig() []byte

func (*TlsConfig) GetEchKey

func (x *TlsConfig) GetEchKey() []byte

func (*TlsConfig) GetEnableEch

func (x *TlsConfig) GetEnableEch() bool

func (*TlsConfig) GetEnableSessionResumption

func (x *TlsConfig) GetEnableSessionResumption() bool

func (*TlsConfig) GetForceAlpn

func (x *TlsConfig) GetForceAlpn() ForceALPN

func (*TlsConfig) GetImitate

func (x *TlsConfig) GetImitate() string

func (*TlsConfig) GetIssueCas

func (x *TlsConfig) GetIssueCas() []*Certificate

func (*TlsConfig) GetMasterKeyLog

func (x *TlsConfig) GetMasterKeyLog() string

func (*TlsConfig) GetNextProtocol

func (x *TlsConfig) GetNextProtocol() []string

func (*TlsConfig) GetNoSNI

func (x *TlsConfig) GetNoSNI() bool

func (*TlsConfig) GetPinnedPeerCertificateChainSha256

func (x *TlsConfig) GetPinnedPeerCertificateChainSha256() [][]byte

func (*TlsConfig) GetRootCas

func (x *TlsConfig) GetRootCas() [][]byte

func (*TlsConfig) GetServerName

func (x *TlsConfig) GetServerName() string

func (*TlsConfig) GetTLSConfig

func (c *TlsConfig) GetTLSConfig(opts ...Option) (*tls.Config, error)

GetTLSConfig converts this Config into tls.Config.

func (*TlsConfig) GetUClient

func (c *TlsConfig) GetUClient(conn net.Conn, tlsConfig *tls.Config) (net.Conn, error)

func (*TlsConfig) GetVerifyClientCertificate

func (x *TlsConfig) GetVerifyClientCertificate() bool

func (*TlsConfig) IsExperiment8357

func (c *TlsConfig) IsExperiment8357() bool

func (*TlsConfig) ProtoMessage

func (*TlsConfig) ProtoMessage()

func (*TlsConfig) ProtoReflect

func (x *TlsConfig) ProtoReflect() protoreflect.Message

func (*TlsConfig) Reset

func (x *TlsConfig) Reset()

func (*TlsConfig) String

func (x *TlsConfig) String() string

func (*TlsConfig) VerifyPeerCert

func (c *TlsConfig) VerifyPeerCert(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error

type UConn

type UConn struct {
	*utls.UConn
}

func (UConn) GetConnectionApplicationProtocol

func (u UConn) GetConnectionApplicationProtocol() (string, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL