From 1889eb3801d43536003e6160f3d80a1af154bdad Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 8 Mar 2023 16:46:15 -0800 Subject: [PATCH] Add wss transport to interop tester impl --- test-plans/cmd/ping/main.go | 34 ++++++++++++++++++++++++++++++++++ test-plans/ping-version.json | 3 ++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/test-plans/cmd/ping/main.go b/test-plans/cmd/ping/main.go index f73c6ec124..66cf248420 100644 --- a/test-plans/cmd/ping/main.go +++ b/test-plans/cmd/ping/main.go @@ -2,9 +2,15 @@ package main import ( "context" + "crypto/rand" + "crypto/rsa" + "crypto/tls" + "crypto/x509" + "crypto/x509/pkix" "encoding/json" "fmt" "log" + "math/big" "os" "strconv" "time" @@ -85,6 +91,9 @@ func main() { case "ws": options = append(options, libp2p.Transport(websocket.New)) listenAddr = fmt.Sprintf("/ip4/%s/tcp/0/ws", ip) + case "wss": + options = append(options, libp2p.Transport(websocket.New, websocket.WithTLSConfig(generateTLSConfig()), websocket.WithTLSClientConfig(&tls.Config{InsecureSkipVerify: true}))) + listenAddr = fmt.Sprintf("/ip4/%s/tcp/0/wss", ip) case "tcp": options = append(options, libp2p.Transport(tcp.NewTCPTransport)) listenAddr = fmt.Sprintf("/ip4/%s/tcp/0", ip) @@ -200,3 +209,28 @@ func main() { os.Exit(1) } } + +func generateTLSConfig() *tls.Config { + priv, err := rsa.GenerateKey(rand.Reader, 2048) + if err != nil { + log.Fatal(err) + } + tmpl := &x509.Certificate{ + SerialNumber: big.NewInt(1), + Subject: pkix.Name{}, + SignatureAlgorithm: x509.SHA256WithRSA, + NotBefore: time.Now(), + NotAfter: time.Now().Add(time.Hour), // valid for an hour + BasicConstraintsValid: true, + } + certDER, err := x509.CreateCertificate(rand.Reader, tmpl, tmpl, priv.Public(), priv) + if err != nil { + log.Fatal(err) + } + return &tls.Config{ + Certificates: []tls.Certificate{{ + PrivateKey: priv, + Certificate: [][]byte{certDER}, + }}, + } +} diff --git a/test-plans/ping-version.json b/test-plans/ping-version.json index 354a9248b9..b7ad53044b 100644 --- a/test-plans/ping-version.json +++ b/test-plans/ping-version.json @@ -4,6 +4,7 @@ "transports": [ "tcp", "ws", + "wss", "quic", "quic-v1", "webtransport" @@ -16,4 +17,4 @@ "mplex", "yamux" ] -} +} \ No newline at end of file