Skip to content

Commit

Permalink
compatibility with old clients
Browse files Browse the repository at this point in the history
  • Loading branch information
dviejokfs committed Apr 3, 2022
1 parent eb52d36 commit c912c3e
Show file tree
Hide file tree
Showing 4 changed files with 494 additions and 20 deletions.
16 changes: 14 additions & 2 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ func (c *serverCmd) run() error {
log.Warn().Msgf("Failed to unmarshal tunnel request: %v", err)
continue
}
sni := tunnelReq.Sni
tlsProps := tunnelReq.GetTls()
if tlsProps == nil {
log.Warn().Msgf("TLS properties not found in tunnel request")
continue
}
sni := tlsProps.GetSni()
for _, session := range sessions {
if session.SNI == sni {
log.Warn().Msgf("trying to add another connection to SNI %s", sni)
Expand Down Expand Up @@ -116,11 +121,18 @@ func (c *serverCmd) run() error {

clientHello, originalConn, err := peekClientHello(conn)
if err != nil {
err = conn.Close()
if err != nil {
log.Warn().Msgf("Failed to close connection: %v", err)
}
log.Error().Msgf("Error extracting client hello %v", err)
continue
}
if clientHello == nil {
log.Error().Msgf("client hello is nil %v", err)
}
_ = originalConn
sni := clientHello.ServerName
//sni := "localhost"
log.Info().Msgf("SNI=%s", sni)
if len(sessions) == 0 {
conn.Close()
Expand Down
27 changes: 26 additions & 1 deletion messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,33 @@ syntax = "proto3";
package tutorial;

option go_package = "pkg/messages";

enum Protocol {
TCP = 0;
HTTP = 1;
}
message TunnelRequest {
oneof req {
TlsTunnelRequest tls = 1;
HttpTunnelRequest http = 2;
}
}

message TlsTunnelRequest {
string sni = 1;
}
message HttpTunnelRequest {
string host = 1;
}
message TlsTunnel {
string sni = 1;
}

message HttpTunnel {
string host = 1;
}

message Auth {
string user = 1;
string password = 2;
map<string, string> metadata = 3;
}
6 changes: 5 additions & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ func (c *tunnelClient) StartTlsTunnel(sni string, remoteAddress string) error {
return err
}
tunnelReq := &messages.TunnelRequest{
Sni: sni,
Req: &messages.TunnelRequest_Tls{
Tls: &messages.TlsTunnelRequest{
Sni: sni,
},
},
}
initialConn, err := session.Open()
if err != nil {
Expand Down
Loading

0 comments on commit c912c3e

Please sign in to comment.