]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/tls: add support for -reject-alpn and -decline-alpn flags to bogo_shim_test
authorClide Stefani <cstefani.sites@gmail.com>
Tue, 11 Jun 2024 18:42:13 +0000 (14:42 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 9 Jul 2024 16:14:04 +0000 (16:14 +0000)
The existing implementation of bogo_shim_test does not support tests
which use the reject-alpn or the decline-alpn flag.
This change adds support for these flags in bogo_shim_test.

Updates #51434
Updates #46310

Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest
Change-Id: I3ff23ff4edd8f4c6c37ee6c9f2ee4689066c4e00
Reviewed-on: https://go-review.googlesource.com/c/go/+/592198
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Roland Shoemaker <roland@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/crypto/tls/bogo_shim_test.go

index 2d8100d1bbf36afc99415f49b1ca9e506c7d6976..38087d2b1cb3bdc42d253e54c532073dae0f8a99 100644 (file)
@@ -75,6 +75,8 @@ var (
 
        advertiseALPN = flag.String("advertise-alpn", "", "")
        expectALPN    = flag.String("expect-alpn", "", "")
+       rejectALPN    = flag.Bool("reject-alpn", false, "")
+       declineALPN   = flag.Bool("decline-alpn", false, "")
 
        hostName = flag.String("host-name", "", "")
 
@@ -126,6 +128,14 @@ func bogoShim() {
                }
        }
 
+       if *rejectALPN {
+               cfg.NextProtos = []string{"unnegotiableprotocol"}
+       }
+
+       if *declineALPN {
+               cfg.NextProtos = []string{}
+       }
+
        if *hostName != "" {
                cfg.ServerName = *hostName
        }
@@ -256,6 +266,9 @@ func bogoShim() {
                        if *expectVersion != 0 && cs.Version != uint16(*expectVersion) {
                                log.Fatalf("expected ssl version %q, got %q", uint16(*expectVersion), cs.Version)
                        }
+                       if *declineALPN && cs.NegotiatedProtocol != "" {
+                               log.Fatal("unexpected ALPN protocol")
+                       }
                        if *expectECHAccepted && !cs.ECHAccepted {
                                log.Fatal("expected ECH to be accepted, but connection state shows it was not")
                        } else if i == 0 && *onInitialExpectECHAccepted && !cs.ECHAccepted {