Skip to content

Commit

Permalink
set the LocalAddr that is used in the tls.ClientHelloInfo.Conn
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Feb 17, 2020
1 parent 2e1387c commit 038cd1d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
6 changes: 4 additions & 2 deletions internal/handshake/crypto_setup.go
Expand Up @@ -120,6 +120,7 @@ func NewCryptoSetupClient(
handshakeStream io.Writer,
oneRTTStream io.Writer,
connID protocol.ConnectionID,
localAddr net.Addr,
remoteAddr net.Addr,
tp *TransportParameters,
runner handshakeRunner,
Expand All @@ -139,7 +140,7 @@ func NewCryptoSetupClient(
logger,
protocol.PerspectiveClient,
)
cs.conn = qtls.Client(newConn(remoteAddr), cs.tlsConf)
cs.conn = qtls.Client(newConn(localAddr, remoteAddr), cs.tlsConf)
return cs, clientHelloWritten
}

Expand All @@ -149,6 +150,7 @@ func NewCryptoSetupServer(
handshakeStream io.Writer,
oneRTTStream io.Writer,
connID protocol.ConnectionID,
localAddr net.Addr,
remoteAddr net.Addr,
tp *TransportParameters,
runner handshakeRunner,
Expand All @@ -168,7 +170,7 @@ func NewCryptoSetupServer(
logger,
protocol.PerspectiveServer,
)
cs.conn = qtls.Server(newConn(remoteAddr), cs.tlsConf)
cs.conn = qtls.Server(newConn(localAddr, remoteAddr), cs.tlsConf)
return cs
}

Expand Down
14 changes: 14 additions & 0 deletions internal/handshake/crypto_setup_test.go
Expand Up @@ -92,6 +92,7 @@ var _ = Describe("Crypto Setup TLS", func() {
ioutil.Discard,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
NewMockHandshakeRunner(mockCtrl),
tlsConf,
Expand Down Expand Up @@ -123,6 +124,7 @@ var _ = Describe("Crypto Setup TLS", func() {
ioutil.Discard,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
runner,
testdata.GetTLSConfig(),
Expand Down Expand Up @@ -160,6 +162,7 @@ var _ = Describe("Crypto Setup TLS", func() {
ioutil.Discard,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
runner,
testdata.GetTLSConfig(),
Expand Down Expand Up @@ -200,6 +203,7 @@ var _ = Describe("Crypto Setup TLS", func() {
ioutil.Discard,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
runner,
serverConf,
Expand Down Expand Up @@ -233,6 +237,7 @@ var _ = Describe("Crypto Setup TLS", func() {
ioutil.Discard,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
NewMockHandshakeRunner(mockCtrl),
serverConf,
Expand Down Expand Up @@ -321,6 +326,7 @@ var _ = Describe("Crypto Setup TLS", func() {
cOneRTTStream,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
cRunner,
clientConf,
Expand All @@ -342,6 +348,7 @@ var _ = Describe("Crypto Setup TLS", func() {
sOneRTTStream,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{StatelessResetToken: &token},
sRunner,
serverConf,
Expand Down Expand Up @@ -394,6 +401,7 @@ var _ = Describe("Crypto Setup TLS", func() {
ioutil.Discard,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
runner,
&tls.Config{InsecureSkipVerify: true},
Expand Down Expand Up @@ -434,6 +442,7 @@ var _ = Describe("Crypto Setup TLS", func() {
ioutil.Discard,
protocol.ConnectionID{},
nil,
nil,
cTransportParameters,
cRunner,
clientConf,
Expand All @@ -456,6 +465,7 @@ var _ = Describe("Crypto Setup TLS", func() {
ioutil.Discard,
protocol.ConnectionID{},
nil,
nil,
sTransportParameters,
sRunner,
serverConf,
Expand Down Expand Up @@ -492,6 +502,7 @@ var _ = Describe("Crypto Setup TLS", func() {
ioutil.Discard,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
cRunner,
clientConf,
Expand All @@ -509,6 +520,7 @@ var _ = Describe("Crypto Setup TLS", func() {
ioutil.Discard,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
sRunner,
serverConf,
Expand Down Expand Up @@ -547,6 +559,7 @@ var _ = Describe("Crypto Setup TLS", func() {
ioutil.Discard,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
cRunner,
clientConf,
Expand All @@ -564,6 +577,7 @@ var _ = Describe("Crypto Setup TLS", func() {
ioutil.Discard,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
sRunner,
serverConf,
Expand Down
11 changes: 7 additions & 4 deletions internal/handshake/qtls.go
Expand Up @@ -10,11 +10,14 @@ import (
)

type conn struct {
remoteAddr net.Addr
localAddr, remoteAddr net.Addr
}

func newConn(remote net.Addr) net.Conn {
return &conn{remoteAddr: remote}
func newConn(local, remote net.Addr) net.Conn {
return &conn{
localAddr: local,
remoteAddr: remote,
}
}

var _ net.Conn = &conn{}
Expand All @@ -23,7 +26,7 @@ func (c *conn) Read([]byte) (int, error) { return 0, nil }
func (c *conn) Write([]byte) (int, error) { return 0, nil }
func (c *conn) Close() error { return nil }
func (c *conn) RemoteAddr() net.Addr { return c.remoteAddr }
func (c *conn) LocalAddr() net.Addr { return nil }
func (c *conn) LocalAddr() net.Addr { return c.localAddr }
func (c *conn) SetReadDeadline(time.Time) error { return nil }
func (c *conn) SetWriteDeadline(time.Time) error { return nil }
func (c *conn) SetDeadline(time.Time) error { return nil }
Expand Down
2 changes: 2 additions & 0 deletions session.go
Expand Up @@ -260,6 +260,7 @@ var newSession = func(
handshakeStream,
oneRTTStream,
clientDestConnID,
conn.LocalAddr(),
conn.RemoteAddr(),
params,
&handshakeRunner{
Expand Down Expand Up @@ -359,6 +360,7 @@ var newClientSession = func(
handshakeStream,
oneRTTStream,
destConnID,
conn.LocalAddr(),
conn.RemoteAddr(),
params,
&handshakeRunner{
Expand Down

0 comments on commit 038cd1d

Please sign in to comment.