Skip to content

Commit

Permalink
Add wss transport to interop tester impl (libp2p#2178)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo authored Mar 24, 2023
1 parent 03d4061 commit b23d8b5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
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)
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"
]
}
}

0 comments on commit b23d8b5

Please sign in to comment.