Skip to content

Commit

Permalink
Merge pull request hashrocket#5 from 8tomat8/master
Browse files Browse the repository at this point in the history
Added flag to skip ssl certificate validation
  • Loading branch information
mattpolito authored Nov 15, 2018
2 parents 2ecd9f3 + a852fc0 commit bc51635
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions connection.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/tls"
"encoding/hex"
"fmt"
"net/http"
Expand All @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Version = "0.2.1"
var options struct {
origin string
printVersion bool
insecure bool
}

func main() {
Expand All @@ -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()
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bc51635

Please sign in to comment.