From d4757395b644d4a12cf45a4317ab0fd6f8019685 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 5 May 2020 17:03:40 +0700 Subject: [PATCH] make it possible to run the handshake unit tests with race detector --- go.mod | 1 - go.sum | 2 -- internal/handshake/handshake_suite_test.go | 24 +++++++++++++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 37e40b1e..7da8f769 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/lucas-clemente/quic-go go 1.13 require ( - github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75 github.com/cheekybits/genny v1.0.0 github.com/francoispqt/gojay v1.2.13 github.com/golang/mock v1.4.0 diff --git a/go.sum b/go.sum index 7da464e7..eb0f498e 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,6 @@ dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1 dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU= git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75 h1:3ILjVyslFbc4jl1w5TWuvvslFD/nDfR2H8tVaMVLrEY= -github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75/go.mod h1:uAXEEpARkRhCZfEvy/y0Jcc888f9tHCc1W7/UeEtreE= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= diff --git a/internal/handshake/handshake_suite_test.go b/internal/handshake/handshake_suite_test.go index e43bccc7..6e96343e 100644 --- a/internal/handshake/handshake_suite_test.go +++ b/internal/handshake/handshake_suite_test.go @@ -5,8 +5,8 @@ import ( "crypto/cipher" "encoding/hex" "strings" + "unsafe" - "github.com/alangpierce/go-forceexport" "github.com/golang/mock/gomock" "github.com/marten-seemann/qtls" @@ -31,8 +31,6 @@ var _ = AfterEach(func() { mockCtrl.Finish() }) -var aeadChaCha20Poly1305 func(key, nonceMask []byte) cipher.AEAD - var cipherSuites = []*qtls.CipherSuiteTLS13{ &qtls.CipherSuiteTLS13{ ID: qtls.TLS_AES_128_GCM_SHA256, @@ -66,13 +64,25 @@ func splitHexString(s string) (slice []byte) { return } +type cipherSuiteTLS13 struct { + ID uint16 + KeyLen int + AEAD func(key, fixedNonce []byte) cipher.AEAD + Hash crypto.Hash +} + +//go:linkname cipherSuiteTLS13ByID github.com/marten-seemann/qtls.cipherSuiteTLS13ByID +func cipherSuiteTLS13ByID(id uint16) *cipherSuiteTLS13 + func init() { - if err := forceexport.GetFunc(&aeadChaCha20Poly1305, "github.com/marten-seemann/qtls.aeadChaCha20Poly1305"); err != nil { - panic(err) - } + val := cipherSuiteTLS13ByID(qtls.TLS_CHACHA20_POLY1305_SHA256) + chacha := (*cipherSuiteTLS13)(unsafe.Pointer(val)) for _, s := range cipherSuites { if s.ID == qtls.TLS_CHACHA20_POLY1305_SHA256 { - s.AEAD = aeadChaCha20Poly1305 + if s.KeyLen != chacha.KeyLen || s.Hash != chacha.Hash { + panic("invalid parameters for ChaCha20") + } + s.AEAD = chacha.AEAD } } }