Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test-plans: Add wss transport to interop tester impl #2178

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions test-plans/cmd/ping/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -200,3 +209,28 @@ func main() {
os.Exit(1)
}
}

func generateTLSConfig() *tls.Config {
priv, err := rsa.GenerateKey(rand.Reader, 2048)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not use ed25519 here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this from our existing generateTLSConfig func in tests

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},
}},
}
}
3 changes: 2 additions & 1 deletion test-plans/ping-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"transports": [
"tcp",
"ws",
"wss",
"quic",
"quic-v1",
"webtransport"
Expand All @@ -16,4 +17,4 @@
"mplex",
"yamux"
]
}
}