Skip to content

Commit

Permalink
Fix check if NegotiatedProtocol is empty
Browse files Browse the repository at this point in the history
If peer doesn't support ALPN, ConnectionState.NegotiatedProtocol will be empty.
NegotiatedProtocol should only be passed when not empty otherwise connection will
fail. We pass what the client supports to the server and look at what was negotiated
with the server. On the local end, we pick the exact protocol so that ALPN works.
  • Loading branch information
buffrr committed May 16, 2022
1 parent 7eea7b1 commit 2258e51
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ func (h *tunneler) Tunnel(ctx context.Context, clientConn *proxy.Conn, network,
// used by the remote server
clientTLSConfig := h.mitm.configForTLSADomain(tlsaDomain)
if alpn {
clientTLSConfig.NextProtos = []string{remote.ConnectionState().NegotiatedProtocol}
if serverProto := remote.ConnectionState().NegotiatedProtocol; serverProto != "" {
clientTLSConfig.NextProtos = []string{serverProto}
}
}

clientTLS := tls.Server(clientConn, clientTLSConfig)
Expand Down

0 comments on commit 2258e51

Please sign in to comment.