feat: customizable ALPN

This commit is contained in:
Toby 2021-11-24 23:35:37 -08:00
parent db01b7000e
commit 4140927003
3 changed files with 13 additions and 4 deletions

View File

@ -30,9 +30,13 @@ func client(config *clientConfig) {
tlsConfig := &tls.Config{
ServerName: config.ServerName,
InsecureSkipVerify: config.Insecure,
NextProtos: []string{tlsProtocolName},
MinVersion: tls.VersionTLS13,
}
if config.ALPN != "" {
tlsConfig.NextProtos = []string{config.ALPN}
} else {
tlsConfig.NextProtos = []string{DefaultALPN}
}
// Load CA
if len(config.CustomCA) > 0 {
bs, err := ioutil.ReadFile(config.CustomCA)

View File

@ -13,7 +13,7 @@ const (
DefaultConnectionReceiveWindow = 67108864 // 64 MB/s
DefaultMaxIncomingStreams = 1024
tlsProtocolName = "hysteria"
DefaultALPN = "hysteria"
)
type serverConfig struct {
@ -38,6 +38,7 @@ type serverConfig struct {
Mode string `json:"mode"`
Config json5.RawMessage `json:"config"`
} `json:"auth"`
ALPN string `json:"alpn"`
PrometheusListen string `json:"prometheus_listen"`
ReceiveWindowConn uint64 `json:"recv_window_conn"`
ReceiveWindowClient uint64 `json:"recv_window_client"`
@ -120,6 +121,7 @@ type clientConfig struct {
Obfs string `json:"obfs"`
Auth []byte `json:"auth"`
AuthString string `json:"auth_str"`
ALPN string `json:"alpn"`
ServerName string `json:"server_name"`
Insecure bool `json:"insecure"`
CustomCA string `json:"ca"`

View File

@ -34,7 +34,6 @@ func server(config *serverConfig) {
"error": err,
}).Fatal("Failed to get a certificate with ACME")
}
tc.NextProtos = []string{tlsProtocolName}
tc.MinVersion = tls.VersionTLS13
tlsConfig = tc
} else {
@ -49,10 +48,14 @@ func server(config *serverConfig) {
}
tlsConfig = &tls.Config{
Certificates: []tls.Certificate{cert},
NextProtos: []string{tlsProtocolName},
MinVersion: tls.VersionTLS13,
}
}
if config.ALPN != "" {
tlsConfig.NextProtos = []string{config.ALPN}
} else {
tlsConfig.NextProtos = []string{DefaultALPN}
}
// QUIC config
quicConfig := &quic.Config{
InitialStreamReceiveWindow: config.ReceiveWindowConn,