Skip to content

Commit 6256b4d

Browse files
committed
Fix improper removals of randomness
1 parent ad79483 commit 6256b4d

2 files changed

Lines changed: 8 additions & 24 deletions

File tree

ra/ra_test.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"encoding/pem"
1616
"errors"
1717
"fmt"
18-
"math"
1918
"math/big"
2019
mrand "math/rand/v2"
2120
"net/netip"
@@ -2907,27 +2906,6 @@ func TestFinalizeWithMustStaple(t *testing.T) {
29072906
}, testKey)
29082907
test.AssertNotError(t, err, "creating must-staple CSR")
29092908

2910-
serial, err := rand.Int(nil, big.NewInt(math.MaxInt64))
2911-
test.AssertNotError(t, err, "generating random serial number")
2912-
template := &x509.Certificate{
2913-
SerialNumber: serial,
2914-
Subject: pkix.Name{CommonName: domain},
2915-
DNSNames: []string{domain},
2916-
NotBefore: fc.Now(),
2917-
NotAfter: fc.Now().Add(365 * 24 * time.Hour),
2918-
BasicConstraintsValid: true,
2919-
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
2920-
ExtraExtensions: []pkix.Extension{ocspMustStapleExt},
2921-
}
2922-
cert, err := x509.CreateCertificate(nil, template, template, testKey.Public(), testKey)
2923-
test.AssertNotError(t, err, "creating certificate")
2924-
ra.CA = &mocks.MockCA{
2925-
PEM: pem.EncodeToMemory(&pem.Block{
2926-
Bytes: cert,
2927-
Type: "CERTIFICATE",
2928-
}),
2929-
}
2930-
29312909
_, err = ra.FinalizeOrder(context.Background(), &rapb.FinalizeOrderRequest{
29322910
Order: order,
29332911
Csr: csr,

wfe2/wfe_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,11 @@ func (fr fakeRand) Read(p []byte) (int, error) {
803803
func TestDirectory(t *testing.T) {
804804
wfe, _, signer := setupWFE(t)
805805
mux := wfe.Handler(metrics.NoopRegisterer)
806+
807+
// We need deterministic randomness for the random directory entry.
808+
origRand := core.RandReader
806809
core.RandReader = fakeRand{}
807-
defer func() { core.RandReader = nil }()
810+
defer func() { core.RandReader = origRand }()
808811

809812
dirURL, _ := url.Parse("/directory")
810813

@@ -920,8 +923,11 @@ func TestDirectory(t *testing.T) {
920923
func TestRelativeDirectory(t *testing.T) {
921924
wfe, _, _ := setupWFE(t)
922925
mux := wfe.Handler(metrics.NoopRegisterer)
926+
927+
// We need deterministic randomness for the random directory entry.
928+
origRand := core.RandReader
923929
core.RandReader = fakeRand{}
924-
defer func() { core.RandReader = nil }()
930+
defer func() { core.RandReader = origRand }()
925931

926932
expectedDirectory := func(hostname string) string {
927933
expected := new(bytes.Buffer)

0 commit comments

Comments
 (0)