-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webtransport: use deterministic TLS certificates (#1833)
* Use deterministic TLS certificates for webtransport * Update test to work with buckets * Make sure to overlap and use a random offset * Fixup mistaken change in other test * Add QuickCheck tests for cert behavior * Lint fix * Add more tests * Add webtransport integration test * Use same key * Actually offset by at least clockSkew * Use seeded key for certs after reboot test * PR comments * Remove debug code * Fix calculation for cert having been valid Fixes the logic that a cert has been valid for a clockSkew by subtracting the clockSkew from the start time rather than incorporating it into the offset. The offset should be used to shift the buckets. * Update comment * Lint fix * Update TestGetCurrentBucketStartTimeIsWithinBounds to include clockSkew calculation * Rebase fixes
- Loading branch information
Showing
7 changed files
with
493 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package webtransport_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/benbjohnson/clock" | ||
"github.com/libp2p/go-libp2p" | ||
ic "github.com/libp2p/go-libp2p/core/crypto" | ||
"github.com/libp2p/go-libp2p/core/test" | ||
libp2pwebtransport "github.com/libp2p/go-libp2p/p2p/transport/webtransport" | ||
ma "github.com/multiformats/go-multiaddr" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func extractCertHashes(addr ma.Multiaddr) []string { | ||
var certHashesStr []string | ||
ma.ForEach(addr, func(c ma.Component) bool { | ||
if c.Protocol().Code == ma.P_CERTHASH { | ||
certHashesStr = append(certHashesStr, c.Value()) | ||
} | ||
return true | ||
}) | ||
return certHashesStr | ||
} | ||
|
||
func TestDeterministicCertsAfterReboot(t *testing.T) { | ||
priv, _, err := test.RandTestKeyPair(ic.Ed25519, 256) | ||
require.NoError(t, err) | ||
|
||
cl := clock.NewMock() | ||
// Move one year ahead to avoid edge cases around epoch | ||
cl.Add(time.Hour * 24 * 365) | ||
h, err := libp2p.New(libp2p.NoTransports, libp2p.Transport(libp2pwebtransport.New, libp2pwebtransport.WithClock(cl)), libp2p.Identity(priv)) | ||
require.NoError(t, err) | ||
err = h.Network().Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic/webtransport")) | ||
require.NoError(t, err) | ||
|
||
prevCerthashes := extractCertHashes(h.Addrs()[0]) | ||
h.Close() | ||
|
||
h, err = libp2p.New(libp2p.NoTransports, libp2p.Transport(libp2pwebtransport.New, libp2pwebtransport.WithClock(cl)), libp2p.Identity(priv)) | ||
require.NoError(t, err) | ||
defer h.Close() | ||
err = h.Network().Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic/webtransport")) | ||
require.NoError(t, err) | ||
|
||
nextCertHashes := extractCertHashes(h.Addrs()[0]) | ||
|
||
for i := range prevCerthashes { | ||
require.Equal(t, prevCerthashes[i], nextCertHashes[i]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.