Skip to content

Commit

Permalink
set a net.Conn with the correct addresses on the tls.ClientHelloInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Jul 29, 2023
1 parent 469a615 commit 36ff0f4
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ var newConnection = func(
}
cs := handshake.NewCryptoSetupServer(
clientDestConnID,
conn.LocalAddr(),
conn.RemoteAddr(),
params,
tlsConf,
conf.Allow0RTT,
Expand Down
3 changes: 3 additions & 0 deletions fuzzing/handshake/cmd/corpus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"crypto/tls"
"log"
"net"

fuzzhandshake "github.com/quic-go/quic-go/fuzzing/handshake"
"github.com/quic-go/quic-go/fuzzing/internal/helper"
Expand Down Expand Up @@ -37,6 +38,8 @@ func main() {
config.NextProtos = []string{alpn}
server := handshake.NewCryptoSetupServer(
protocol.ConnectionID{},
&net.UDPAddr{IP: net.IPv6loopback, Port: 1234},
&net.UDPAddr{IP: net.IPv6loopback, Port: 4321},
&wire.TransportParameters{ActiveConnectionIDLimit: 2},
config,
false,
Expand Down
3 changes: 3 additions & 0 deletions fuzzing/handshake/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"log"
"math"
mrand "math/rand"
"net"
"time"

"github.com/quic-go/quic-go/fuzzing/internal/helper"
Expand Down Expand Up @@ -304,6 +305,8 @@ func runHandshake(runConfig [confLen]byte, messageConfig uint8, clientConf *tls.

server := handshake.NewCryptoSetupServer(
protocol.ConnectionID{},
&net.UDPAddr{IP: net.IPv6loopback, Port: 1234},
&net.UDPAddr{IP: net.IPv6loopback, Port: 4321},
serverTP,
serverConf,
enable0RTTServer,
Expand Down
21 changes: 21 additions & 0 deletions integrationtests/self/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,27 @@ var _ = Describe("Handshake tests", func() {
Expect(err).ToNot(HaveOccurred())
})

It("has the right local and remote address on the ClientHelloInfo.Conn", func() {
var local, remote net.Addr
tlsConf := &tls.Config{
GetConfigForClient: func(info *tls.ClientHelloInfo) (*tls.Config, error) {
local = info.Conn.LocalAddr()
remote = info.Conn.RemoteAddr()
return getTLSConfig(), nil
},
}
runServer(tlsConf)
conn, err := quic.DialAddr(
context.Background(),
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(nil),
)
Expect(err).ToNot(HaveOccurred())
Expect(server.Addr()).To(Equal(local))
Expect(conn.LocalAddr().(*net.UDPAddr).Port).To(Equal(remote.(*net.UDPAddr).Port))
})

It("works with a long certificate chain", func() {
runServer(getTLSConfigWithLongCertChain())
_, err := quic.DialAddr(
Expand Down
9 changes: 9 additions & 0 deletions internal/handshake/crypto_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/tls"
"errors"
"fmt"
"net"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -104,6 +105,7 @@ func NewCryptoSetupClient(
// NewCryptoSetupServer creates a new crypto setup for the server
func NewCryptoSetupServer(
connID protocol.ConnectionID,
localAddr, remoteAddr net.Addr,
tp *wire.TransportParameters,
tlsConf *tls.Config,
allow0RTT bool,
Expand All @@ -125,6 +127,13 @@ func NewCryptoSetupServer(

quicConf := &qtls.QUICConfig{TLSConfig: tlsConf}
qtls.SetupConfigForServer(quicConf, cs.allow0RTT, cs.getDataForSessionTicket, cs.accept0RTT)
if quicConf.TLSConfig.GetConfigForClient != nil {
gcfc := quicConf.TLSConfig.GetConfigForClient
quicConf.TLSConfig.GetConfigForClient = func(info *tls.ClientHelloInfo) (*tls.Config, error) {
info.Conn = &conn{localAddr: localAddr, remoteAddr: remoteAddr}

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / gogenerate

undefined: conn

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / gogenerate

undefined: conn

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / Cross Compilation (Go 1.20.x)

undefined: conn

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / Unit tests (macos, Go 1.20.x)

undefined: conn

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / Cross Compilation (Go 1.21.0-rc.2)

undefined: conn

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / Cross Compilation (Go 1.20.x)

undefined: conn

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / Unit tests (macos, Go 1.21.0-rc.2)

undefined: conn

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / Unit tests (macos, Go 1.20.x)

undefined: conn

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu, Go 1.20.x)

undefined: conn

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / Unit tests (windows, Go 1.21.0-rc.2)

undefined: conn

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / Cross Compilation (Go 1.21.0-rc.2)

undefined: conn

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu, Go 1.21.0-rc.2)

undefined: conn

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu, Go 1.20.x)

undefined: conn

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / Unit tests (windows, Go 1.21.0-rc.2)

undefined: conn

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: conn) (typecheck)

Check failure on line 133 in internal/handshake/crypto_setup.go

View workflow job for this annotation

GitHub Actions / Unit tests (windows, Go 1.20.x)

undefined: conn
return gcfc(info)
}
}

cs.tlsConf = quicConf.TLSConfig
cs.conn = qtls.QUICServer(quicConf)
Expand Down
7 changes: 7 additions & 0 deletions internal/handshake/crypto_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"math/big"
"net"
"time"

mocktls "github.com/quic-go/quic-go/internal/mocks/tls"
Expand Down Expand Up @@ -65,6 +66,8 @@ var _ = Describe("Crypto Setup TLS", func() {
var token protocol.StatelessResetToken
server := NewCryptoSetupServer(
protocol.ConnectionID{},
&net.UDPAddr{IP: net.IPv6loopback, Port: 1234},
&net.UDPAddr{IP: net.IPv6loopback, Port: 4321},
&wire.TransportParameters{StatelessResetToken: &token},
testdata.GetTLSConfig(),
false,
Expand Down Expand Up @@ -204,6 +207,8 @@ var _ = Describe("Crypto Setup TLS", func() {
}
server := NewCryptoSetupServer(
protocol.ConnectionID{},
&net.UDPAddr{IP: net.IPv6loopback, Port: 1234},
&net.UDPAddr{IP: net.IPv6loopback, Port: 4321},
serverTransportParameters,
serverConf,
enable0RTT,
Expand Down Expand Up @@ -273,6 +278,8 @@ var _ = Describe("Crypto Setup TLS", func() {
}
server := NewCryptoSetupServer(
protocol.ConnectionID{},
&net.UDPAddr{IP: net.IPv6loopback, Port: 1234},
&net.UDPAddr{IP: net.IPv6loopback, Port: 4321},
sTransportParameters,
serverConf,
false,
Expand Down

0 comments on commit 36ff0f4

Please sign in to comment.