From a852fc06404b9694e05276d678f6833946c0cf52 Mon Sep 17 00:00:00 2001 From: Borys Hulii <8tomat8@gmail.com> Date: Fri, 14 Sep 2018 15:10:17 +0200 Subject: [PATCH] Added flag to skip ssl certificate validation --- connection.go | 11 +++++++++-- main.go | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/connection.go b/connection.go index 529d17e..9a6265e 100644 --- a/connection.go +++ b/connection.go @@ -1,6 +1,7 @@ package main import ( + "crypto/tls" "encoding/hex" "fmt" "net/http" @@ -17,11 +18,17 @@ type session struct { errChan chan error } -func connect(url, origin string, rlConf *readline.Config) error { +func connect(url, origin string, rlConf *readline.Config, allowInsecure bool) error { headers := make(http.Header) headers.Add("Origin", origin) - ws, _, err := websocket.DefaultDialer.Dial(url, headers) + dialer := websocket.Dialer{ + Proxy: http.ProxyFromEnvironment, + TLSClientConfig:&tls.Config{ + InsecureSkipVerify: allowInsecure, + }, + } + ws, _, err := dialer.Dial(url, headers) if err != nil { return err } diff --git a/main.go b/main.go index a12c446..7fdc26b 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ const Version = "0.2.1" var options struct { origin string printVersion bool + insecure bool } func main() { @@ -27,6 +28,7 @@ func main() { } rootCmd.Flags().StringVarP(&options.origin, "origin", "o", "", "websocket origin") rootCmd.Flags().BoolVarP(&options.printVersion, "version", "v", false, "print version") + rootCmd.Flags().BoolVarP(&options.insecure, "insecure", "k", false, "skip ssl certificate check") rootCmd.Execute() } @@ -70,7 +72,7 @@ func root(cmd *cobra.Command, args []string) { err = connect(dest.String(), origin, &readline.Config{ Prompt: "> ", HistoryFile: historyFile, - }) + }, options.insecure) if err != nil { fmt.Fprintln(os.Stderr, err) if err != io.EOF && err != readline.ErrInterrupt {