github.com/MerlinKodo/quic-go@v0.39.2/internal/qtls/cipher_suite_test.go (about) 1 //go:build go1.21 2 3 package qtls 4 5 import ( 6 "crypto/tls" 7 "fmt" 8 "net" 9 10 "github.com/MerlinKodo/quic-go/internal/testdata" 11 12 . "github.com/onsi/ginkgo/v2" 13 . "github.com/onsi/gomega" 14 ) 15 16 var _ = Describe("Setting the Cipher Suite", func() { 17 for _, cs := range []uint16{tls.TLS_AES_128_GCM_SHA256, tls.TLS_CHACHA20_POLY1305_SHA256, tls.TLS_AES_256_GCM_SHA384} { 18 cs := cs 19 20 It(fmt.Sprintf("selects %s", tls.CipherSuiteName(cs)), func() { 21 reset := SetCipherSuite(cs) 22 defer reset() 23 24 ln, err := tls.Listen("tcp4", "localhost:0", testdata.GetTLSConfig()) 25 Expect(err).ToNot(HaveOccurred()) 26 defer ln.Close() 27 28 done := make(chan struct{}) 29 go func() { 30 defer GinkgoRecover() 31 defer close(done) 32 conn, err := ln.Accept() 33 Expect(err).ToNot(HaveOccurred()) 34 _, err = conn.Read(make([]byte, 10)) 35 Expect(err).ToNot(HaveOccurred()) 36 Expect(conn.(*tls.Conn).ConnectionState().CipherSuite).To(Equal(cs)) 37 }() 38 39 conn, err := tls.Dial( 40 "tcp4", 41 fmt.Sprintf("localhost:%d", ln.Addr().(*net.TCPAddr).Port), 42 &tls.Config{RootCAs: testdata.GetRootCA()}, 43 ) 44 Expect(err).ToNot(HaveOccurred()) 45 _, err = conn.Write([]byte("foobar")) 46 Expect(err).ToNot(HaveOccurred()) 47 Expect(conn.ConnectionState().CipherSuite).To(Equal(cs)) 48 Expect(conn.Close()).To(Succeed()) 49 Eventually(done).Should(BeClosed()) 50 }) 51 } 52 })