Add TLS connection support for tty-proxy connections

pull/25/head
Vasile Popescu 4 years ago committed by Elis Popescu
parent 2d481a5a98
commit 2100e4ab90

@ -67,6 +67,7 @@ Flags:
proxyServerAddress := flag.String("tty-proxy", "localhost:9000", "Address of the proxy for public facing connections") proxyServerAddress := flag.String("tty-proxy", "localhost:9000", "Address of the proxy for public facing connections")
readOnly := flag.Bool("readonly", false, "Start a read only session") readOnly := flag.Bool("readonly", false, "Start a read only session")
publicSession := flag.Bool("public", false, "Create a public session") publicSession := flag.Bool("public", false, "Create a public session")
noTLS := flag.Bool("no-tls", false, "Don't use TLS to connect to the tty-proxy server. Useful for local debugging")
flag.Usage = func() { flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "%s", usageString) fmt.Fprintf(flag.CommandLine.Output(), "%s", usageString)
flag.PrintDefaults() flag.PrintDefaults()
@ -114,7 +115,7 @@ Flags:
sessionID := "local" sessionID := "local"
if *publicSession { if *publicSession {
proxy, err := proxy.NewProxyConnection(*listenAddress, *proxyServerAddress) proxy, err := proxy.NewProxyConnection(*listenAddress, *proxyServerAddress, *noTLS)
if err != nil { if err != nil {
fmt.Printf("Can't connect to the proxy: %s\n", err.Error()) fmt.Printf("Can't connect to the proxy: %s\n", err.Error())
return return

@ -1,6 +1,8 @@
package proxy package proxy
import ( import (
"crypto/tls"
"crypto/x509"
"encoding/json" "encoding/json"
"io" "io"
"net" "net"
@ -28,10 +30,24 @@ type proxyConnection struct {
PublicURL string PublicURL string
} }
func NewProxyConnection(backConnAddrr, proxyAddr string) (*proxyConnection, error) { func NewProxyConnection(backConnAddrr, proxyAddr string, noTLS bool) (*proxyConnection, error) {
conn, err := net.Dial("tcp", proxyAddr) var conn net.Conn
if err != nil { var err error
return nil, err
if noTLS {
conn, err = net.Dial("tcp", proxyAddr)
if err != nil {
return nil, err
}
} else {
roots, err := x509.SystemCertPool()
if err != nil {
return nil, err
}
conn, err = tls.Dial("tcp", proxyAddr, &tls.Config{RootCAs: roots})
if err != nil {
return nil, err
}
} }
// C -> S: HelloCLient // C -> S: HelloCLient

Loading…
Cancel
Save