set the LocalAddr that is used in the tls.ClientHelloInfo.Conn

This commit is contained in:
Marten Seemann
2020-02-16 14:10:30 +07:00
parent abf55af7e9
commit f034e8ba19
5 changed files with 31 additions and 6 deletions

View File

@@ -122,6 +122,7 @@ func NewCryptoSetupClient(
initialStream io.Writer,
handshakeStream io.Writer,
connID protocol.ConnectionID,
localAddr net.Addr,
remoteAddr net.Addr,
tp *TransportParameters,
runner handshakeRunner,
@@ -142,7 +143,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
}
@@ -151,6 +152,7 @@ func NewCryptoSetupServer(
initialStream io.Writer,
handshakeStream io.Writer,
connID protocol.ConnectionID,
localAddr net.Addr,
remoteAddr net.Addr,
tp *TransportParameters,
runner handshakeRunner,
@@ -171,7 +173,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
}

View File

@@ -89,6 +89,7 @@ var _ = Describe("Crypto Setup TLS", func() {
&bytes.Buffer{},
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
NewMockHandshakeRunner(mockCtrl),
tlsConf,
@@ -120,6 +121,7 @@ var _ = Describe("Crypto Setup TLS", func() {
sHandshakeStream,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
runner,
testdata.GetTLSConfig(),
@@ -157,6 +159,7 @@ var _ = Describe("Crypto Setup TLS", func() {
sHandshakeStream,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
runner,
testdata.GetTLSConfig(),
@@ -197,6 +200,7 @@ var _ = Describe("Crypto Setup TLS", func() {
sHandshakeStream,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
runner,
serverConf,
@@ -230,6 +234,7 @@ var _ = Describe("Crypto Setup TLS", func() {
sHandshakeStream,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
NewMockHandshakeRunner(mockCtrl),
serverConf,
@@ -323,6 +328,7 @@ var _ = Describe("Crypto Setup TLS", func() {
cHandshakeStream,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
cRunner,
clientConf,
@@ -344,6 +350,7 @@ var _ = Describe("Crypto Setup TLS", func() {
sHandshakeStream,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{StatelessResetToken: &token},
sRunner,
serverConf,
@@ -396,6 +403,7 @@ var _ = Describe("Crypto Setup TLS", func() {
cHandshakeStream,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
runner,
&tls.Config{InsecureSkipVerify: true},
@@ -436,6 +444,7 @@ var _ = Describe("Crypto Setup TLS", func() {
cHandshakeStream,
protocol.ConnectionID{},
nil,
nil,
cTransportParameters,
cRunner,
clientConf,
@@ -458,6 +467,7 @@ var _ = Describe("Crypto Setup TLS", func() {
sHandshakeStream,
protocol.ConnectionID{},
nil,
nil,
sTransportParameters,
sRunner,
serverConf,
@@ -489,6 +499,7 @@ var _ = Describe("Crypto Setup TLS", func() {
cHandshakeStream,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
cRunner,
clientConf,
@@ -506,6 +517,7 @@ var _ = Describe("Crypto Setup TLS", func() {
sHandshakeStream,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
sRunner,
serverConf,
@@ -544,6 +556,7 @@ var _ = Describe("Crypto Setup TLS", func() {
cHandshakeStream,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
cRunner,
clientConf,
@@ -561,6 +574,7 @@ var _ = Describe("Crypto Setup TLS", func() {
sHandshakeStream,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
sRunner,
serverConf,
@@ -671,6 +685,7 @@ var _ = Describe("Crypto Setup TLS", func() {
cHandshakeStream,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
cRunner,
clientConf,
@@ -688,6 +703,7 @@ var _ = Describe("Crypto Setup TLS", func() {
sHandshakeStream,
protocol.ConnectionID{},
nil,
nil,
&TransportParameters{},
sRunner,
serverConf,

View File

@@ -11,11 +11,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{}
@@ -24,7 +27,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 }