added insecure flag to allow invalid certificates.
This commit is contained in:
parent
5c0e3401f4
commit
2dae10d093
@ -6,6 +6,7 @@ import (
|
||||
"converge/pkg/iowrappers"
|
||||
"converge/pkg/terminal"
|
||||
"converge/pkg/websocketutil"
|
||||
"crypto/tls"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/gliderlabs/ssh"
|
||||
@ -15,6 +16,7 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -148,6 +150,7 @@ func main() {
|
||||
advanceWarningTime := flag.Duration("warning-time", 5*time.Minute, "advance warning time before sessio ends")
|
||||
agentExpriryTime := flag.Duration("expiry-time", 10*time.Minute, "expiry time of the session")
|
||||
tickerInterval := flag.Duration("check-interval", 60*time.Second, "interval at which expiry is checked")
|
||||
insecure := flag.Bool("insecure", false, "allow invalid certificates")
|
||||
|
||||
flag.Parse()
|
||||
if flag.NArg() != 1 {
|
||||
@ -158,7 +161,14 @@ func main() {
|
||||
|
||||
agent.ConfigureAgent(*advanceWarningTime, *agentExpriryTime, *tickerInterval)
|
||||
|
||||
conn, _, err := websocket.DefaultDialer.Dial(wsURL, nil)
|
||||
dialer := websocket.Dialer{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
HandshakeTimeout: 45 * time.Second,
|
||||
}
|
||||
if *insecure {
|
||||
dialer.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
}
|
||||
conn, _, err := dialer.Dial(wsURL, nil)
|
||||
if err != nil {
|
||||
log.Println("WebSocket connection error:", err)
|
||||
return
|
||||
|
@ -3,10 +3,13 @@ package main
|
||||
import (
|
||||
"converge/pkg/iowrappers"
|
||||
"converge/pkg/websocketutil"
|
||||
"crypto/tls"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/gorilla/websocket"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
@ -18,11 +21,18 @@ func closeConnection(conn net.Conn) {
|
||||
_ = conn.Close()
|
||||
}
|
||||
|
||||
func handleConnection(conn net.Conn, wsURL string) {
|
||||
func handleConnection(conn net.Conn, wsURL string, insecure bool) {
|
||||
defer closeConnection(conn)
|
||||
|
||||
log.Printf("Connecting to '%s'\n", wsURL)
|
||||
_wsConn, _, err := websocket.DefaultDialer.Dial(wsURL, nil)
|
||||
dialer := websocket.Dialer{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
HandshakeTimeout: 45 * time.Second,
|
||||
}
|
||||
if insecure {
|
||||
dialer.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
}
|
||||
_wsConn, _, err := dialer.Dial(wsURL, nil)
|
||||
if err != nil {
|
||||
log.Println("WebSocket connection error:", err)
|
||||
return
|
||||
@ -36,14 +46,23 @@ func handleConnection(conn net.Conn, wsURL string) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 3 {
|
||||
fmt.Fprintln(os.Stderr, "Usage: tcptows <localport> ws[s]://<host>[:port]/client/<ID>")
|
||||
fmt.Fprintln(os.Stderr)
|
||||
fmt.Fprintln(os.Stderr, "Here <ID> is the rendez-vous id of a continuous integratio job")
|
||||
usage := "Usage: tcptows [options] <localport> ws[s]://<host>[:port]/client/<ID>\n" +
|
||||
"\n" +
|
||||
"Here <ID> is the rendez-vous id of a continuous integratio job\n"
|
||||
insecure := flag.Bool("insecure", false, "allow invalid certificates")
|
||||
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintln(os.Stderr, usage)
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
flag.Parse()
|
||||
fmt.Println("Narg ", flag.NArg())
|
||||
if flag.NArg() != 2 {
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
tcpPort := os.Args[1]
|
||||
wsURL := os.Args[2]
|
||||
tcpPort := flag.Arg(0)
|
||||
wsURL := flag.Arg(1)
|
||||
|
||||
listener, err := net.Listen("tcp", ":"+tcpPort)
|
||||
if err != nil {
|
||||
@ -60,6 +79,6 @@ func main() {
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
go handleConnection(conn, wsURL)
|
||||
go handleConnection(conn, wsURL, *insecure)
|
||||
}
|
||||
}
|
||||
|
@ -1,61 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"converge/pkg/iowrappers"
|
||||
"converge/pkg/websocketutil"
|
||||
"fmt"
|
||||
"github.com/gorilla/websocket"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func closeConnection(conn net.Conn) {
|
||||
if tcpConn, ok := conn.(*net.TCPConn); ok {
|
||||
tcpConn.SetLinger(0)
|
||||
}
|
||||
_ = conn.Close()
|
||||
}
|
||||
|
||||
type Stdio struct{}
|
||||
|
||||
func (stdio Stdio) Read(b []byte) (n int, err error) {
|
||||
return os.Stdin.Read(b)
|
||||
}
|
||||
func (stdio Stdio) Write(b []byte) (n int, err error) {
|
||||
return os.Stdout.Write(b)
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 2 {
|
||||
fmt.Fprintln(os.Stderr, "Usage: tcptows ws[s]://<host>[:port]/client/<ID>")
|
||||
fmt.Fprintln(os.Stderr)
|
||||
fmt.Fprintln(os.Stderr, "Here <ID> is the rendez-vous id of a continuous integratio job")
|
||||
fmt.Fprintln(os.Stderr, "Use this in an ssh command like this; ")
|
||||
fmt.Fprintln(os.Stderr)
|
||||
fmt.Fprintln(os.Stderr, " ssh -oProxyCommand='wsproxy ws[s]://<host>[:port]/client/<ID>' abc@localhost")
|
||||
fmt.Fprintln(os.Stderr)
|
||||
fmt.Fprintln(os.Stderr, "This lets ssh connect through wsproxy to the remote websocket on")
|
||||
fmt.Fprintln(os.Stderr, "Converge server.")
|
||||
fmt.Fprintln(os.Stderr)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
wsURL := os.Args[1]
|
||||
|
||||
_wsConn, _, err := websocket.DefaultDialer.Dial(wsURL, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_wsConn.SetReadDeadline(time.Time{})
|
||||
_wsConn.SetWriteDeadline(time.Time{})
|
||||
if err != nil {
|
||||
log.Println("WebSocket connection error:", err)
|
||||
panic(err)
|
||||
}
|
||||
wsConn := websocketutil.NewWebSocketConn(_wsConn)
|
||||
defer wsConn.Close()
|
||||
|
||||
iowrappers.SynchronizeStreams(wsConn, Stdio{})
|
||||
}
|
79
cmd/wsproxy/wsproxy.go
Normal file
79
cmd/wsproxy/wsproxy.go
Normal file
@ -0,0 +1,79 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"converge/pkg/iowrappers"
|
||||
"converge/pkg/websocketutil"
|
||||
"crypto/tls"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/gorilla/websocket"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func closeConnection(conn net.Conn) {
|
||||
if tcpConn, ok := conn.(*net.TCPConn); ok {
|
||||
tcpConn.SetLinger(0)
|
||||
}
|
||||
_ = conn.Close()
|
||||
}
|
||||
|
||||
type Stdio struct{}
|
||||
|
||||
func (stdio Stdio) Read(b []byte) (n int, err error) {
|
||||
return os.Stdin.Read(b)
|
||||
}
|
||||
func (stdio Stdio) Write(b []byte) (n int, err error) {
|
||||
return os.Stdout.Write(b)
|
||||
}
|
||||
|
||||
func main() {
|
||||
usage := "Usage: tcptows ws[s]://<host>[:port]/client/<ID>\n\n" +
|
||||
"\n" +
|
||||
"Here <ID> is the rendez-vous id of a continuous integration job\n" +
|
||||
"\n" +
|
||||
"Use this in an ssh command like this: \n" +
|
||||
"\n" +
|
||||
" ssh -oProxyCommand='wsproxy ws[s]://<host>[:port]/client/<ID>' abc@localhost\n" +
|
||||
"\n" +
|
||||
"This latssh connect through wsproxy tocalhost\n"
|
||||
|
||||
insecure := flag.Bool("insecure", false, "allow invalid certificates")
|
||||
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintln(os.Stderr, usage)
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
flag.Parse()
|
||||
if flag.NArg() != 1 {
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
wsURL := flag.Arg(0)
|
||||
|
||||
dialer := websocket.Dialer{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
HandshakeTimeout: 45 * time.Second,
|
||||
}
|
||||
if *insecure {
|
||||
dialer.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
}
|
||||
_wsConn, _, err := dialer.Dial(wsURL, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_wsConn.SetReadDeadline(time.Time{})
|
||||
_wsConn.SetWriteDeadline(time.Time{})
|
||||
if err != nil {
|
||||
log.Println("WebSocket connection error:", err)
|
||||
panic(err)
|
||||
}
|
||||
wsConn := websocketutil.NewWebSocketConn(_wsConn)
|
||||
defer wsConn.Close()
|
||||
|
||||
iowrappers.SynchronizeStreams(wsConn, Stdio{})
|
||||
}
|
Loading…
Reference in New Issue
Block a user