|
4 | 4 | "flag" |
5 | 5 | "fmt" |
6 | 6 | "log" |
| 7 | + "net" |
7 | 8 | "net/http" |
| 9 | + "net/url" |
8 | 10 | "os" |
9 | 11 | "runtime" |
10 | 12 | "strconv" |
@@ -118,8 +120,9 @@ var serverHelp = ` |
118 | 120 | --keyfile, An optional path to a PEM-encoded SSH private key. When |
119 | 121 | this flag is set, the --key option is ignored, and the provided private key |
120 | 122 | is used to secure all communications. (defaults to the CHISEL_KEY_FILE |
121 | | - environment variable). Since ECDSA keys are short, you may also set keyfile |
122 | | - to an inline base64 private key (e.g. chisel server --keygen - | base64). |
| 123 | + environment variable). Since ECDSA keys are short, you may also supply |
| 124 | + the chiselkey (output of "chisel server --keygen -") as the argument |
| 125 | + to --keyfile and forgo requiring a file on disk. |
123 | 126 |
|
124 | 127 | --authfile, An optional path to a users.json file. This file should |
125 | 128 | be an object with users defined like: |
@@ -454,10 +457,26 @@ func client(args []string) { |
454 | 457 | if config.Auth == "" { |
455 | 458 | config.Auth = os.Getenv("AUTH") |
456 | 459 | } |
457 | | - //move hostname onto headers |
| 460 | + |
| 461 | + Hostname := "" |
| 462 | + //set via --hostname |
458 | 463 | if *hostname != "" { |
459 | | - config.Headers.Set("Host", *hostname) |
460 | | - config.TLS.ServerName = *hostname |
| 464 | + Hostname = *hostname |
| 465 | + } else { |
| 466 | + //not set via --hostname but ':' in Server, we need to set Header without Port or connection will fail |
| 467 | + u, err := url.Parse(config.Server) |
| 468 | + if err == nil { |
| 469 | + host, port, _ := net.SplitHostPort(u.Host) |
| 470 | + if port != "" { |
| 471 | + Hostname = host |
| 472 | + } |
| 473 | + } |
| 474 | + } |
| 475 | + |
| 476 | + //move hostname onto headers |
| 477 | + if Hostname != "" { |
| 478 | + config.Headers.Set("Host", Hostname) |
| 479 | + config.TLS.ServerName = Hostname |
461 | 480 | } |
462 | 481 |
|
463 | 482 | if *sni != "" { |
|
0 commit comments