diff --git a/README.md b/README.md index 19fec8e..f9c2cd6 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ $ brew install https://raw.githubusercontent.com/moul/ssh2docker/master/contrib/ * Add an error if the go version is lower than 1.5 * Flexible parsing of the input URL * Add tests +* Support of `--skip-tls-verify` [full commits list](https://github.com/moul/gotty-client/compare/v1.3.0...master) diff --git a/cmd/gotty-client/main.go b/cmd/gotty-client/main.go index 543fd7a..980f794 100644 --- a/cmd/gotty-client/main.go +++ b/cmd/gotty-client/main.go @@ -28,6 +28,11 @@ func main() { Usage: "Enable debug mode", EnvVar: "GOTTY_CLIENT_DEBUG", }, + cli.BoolFlag{ + Name: "skip-tls-verify", + Usage: "Skip TLS verify", + EnvVar: "SKIP_TLS_VERIFY", + }, } app.Action = Action @@ -55,6 +60,10 @@ func Action(c *cli.Context) { logrus.Fatalf("Cannot create client: %v", err) } + if c.Bool("skip-tls-verify") { + client.SkipTLSVerify = true + } + // loop if err = client.Loop(); err != nil { logrus.Fatalf("Communication error: %v", err) diff --git a/gotty-client.go b/gotty-client.go index 87586fc..562896e 100644 --- a/gotty-client.go +++ b/gotty-client.go @@ -1,6 +1,7 @@ package gottyclient import ( + "crypto/tls" "encoding/base64" "encoding/json" "fmt" @@ -80,6 +81,7 @@ type Client struct { Output io.Writer QuitChan chan struct{} QuitChanClosed bool + SkipTLSVerify bool } type querySingleType struct { @@ -104,6 +106,11 @@ func (c *Client) GetAuthToken() (string, error) { req, err := http.NewRequest("GET", target.String(), nil) req.Header = *header client := http.Client{} + if c.SkipTLSVerify { + client.Transport = &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + } + } resp, err := client.Do(req) if err != nil { return "", err @@ -146,6 +153,9 @@ func (c *Client) Connect() error { return err } logrus.Debugf("Connecting to websocket: %q", target.String()) + if c.SkipTLSVerify { + c.Dialer.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + } conn, _, err := c.Dialer.Dial(target.String(), *header) if err != nil { return err