Skip to content

Commit e814c44

Browse files
authored
Merge pull request jpillora#376 from ip-rw/master
Set ServerName (SNI) to *hostname.
2 parents d79bebe + 2b90de6 commit e814c44

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

client/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type TLSConfig struct {
5050
CA string
5151
Cert string
5252
Key string
53+
ServerName string
5354
}
5455

5556
//Client represents a client instance
@@ -107,6 +108,9 @@ func NewClient(c *Config) (*Client, error) {
107108
//configure tls
108109
if u.Scheme == "wss" {
109110
tc := &tls.Config{}
111+
if c.TLS.ServerName != "" {
112+
tc.ServerName = c.TLS.ServerName
113+
}
110114
//certificate verification config
111115
if c.TLS.SkipVerify {
112116
client.Infof("TLS verification disabled")

client/client_connect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (c *Client) connectionLoop(ctx context.Context) error {
3939
if attempt > 0 {
4040
maxAttemptVal := fmt.Sprint(maxAttempt)
4141
if maxAttempt < 0 {
42-
maxAttemptVal = "unlimited";
42+
maxAttemptVal = "unlimited"
4343
}
4444
msg += fmt.Sprintf(" (Attempt: %d/%s)", attempt, maxAttemptVal)
4545
}

main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ var clientHelp = `
366366
--hostname, Optionally set the 'Host' header (defaults to the host
367367
found in the server url).
368368
369+
--sni, Override the ServerName when using TLS (defaults to the
370+
hostname).
371+
369372
--tls-ca, An optional root certificate bundle used to verify the
370373
chisel server. Only valid when connecting to the server with
371374
"https" or "wss". By default, the operating system CAs will be used.
@@ -401,6 +404,7 @@ func client(args []string) {
401404
flags.StringVar(&config.TLS.Key, "tls-key", "", "")
402405
flags.Var(&headerFlags{config.Headers}, "header", "")
403406
hostname := flags.String("hostname", "", "")
407+
sni := flags.String("sni", "", "")
404408
pid := flags.Bool("pid", false, "")
405409
verbose := flags.Bool("v", false, "")
406410
flags.Usage = func() {
@@ -422,7 +426,13 @@ func client(args []string) {
422426
//move hostname onto headers
423427
if *hostname != "" {
424428
config.Headers.Set("Host", *hostname)
429+
config.TLS.ServerName = *hostname
430+
}
431+
432+
if *sni != "" {
433+
config.TLS.ServerName = *sni
425434
}
435+
426436
//ready
427437
c, err := chclient.NewClient(&config)
428438
if err != nil {

0 commit comments

Comments
 (0)