Skip to content

Commit

Permalink
feat: add factory for TLS proxying with uTLS
Browse files Browse the repository at this point in the history
This commit adds an experimental factory for create proxying
TLS connections using uTLS rather than crypto/tls.

A user has requested this functionality.

For now, I'd like to avoid advertising it until I get confirmation
that this interface is okay for the user who requested it.

When it's confirmed it's okay, I'll change the README.
  • Loading branch information
bassosimone committed Dec 6, 2021
1 parent bde36fd commit d6f7e24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tlsconn.go
Expand Up @@ -22,3 +22,9 @@ type TLSConn interface {
// in time by the given context.
HandshakeContext(ctx context.Context) error
}

// TLSClientFactory is the factory used when creating connections
// using a proxy inside of the HTTP library. By default, this is
// the tls.Client function. You'll need to override this factory if
// you want to use refraction-networking/utls for proxied conns.
var TLSClientFactory = tls.Client
2 changes: 1 addition & 1 deletion transport.go
Expand Up @@ -1519,7 +1519,7 @@ func (pconn *persistConn) addTLS(ctx context.Context, name string, trace *httptr
cfg.NextProtos = nil
}
plainConn := pconn.conn
tlsConn := tls.Client(plainConn, cfg)
tlsConn := TLSClientFactory(plainConn, cfg)
errc := make(chan error, 2)
var timer *time.Timer // for canceling TLS handshake
if d := pconn.t.TLSHandshakeTimeout; d != 0 {
Expand Down

1 comment on commit d6f7e24

@frankwalter1301
Copy link

@frankwalter1301 frankwalter1301 commented on d6f7e24 Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since TLSClientFactory variable type is crypto/tls.Conn. It cannot be overridden with functions from other libraries.

Please sign in to comment.