Skip to content

Commit ecfe977

Browse files
Duncan Joneselazarl
Duncan Jones
authored andcommitted
Use random numbers for certificate serials
1 parent aaf7bbe commit ecfe977

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

signer.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"crypto/x509/pkix"
1212
"fmt"
1313
"math/big"
14+
"math/rand"
1415
"net"
1516
"runtime"
1617
"sort"
@@ -48,9 +49,8 @@ func signHost(ca tls.Certificate, hosts []string) (cert *tls.Certificate, err er
4849
if err != nil {
4950
panic(err)
5051
}
51-
hash := hashSorted(append(hosts, goproxySignerVersion, ":"+runtime.Version()))
52-
serial := new(big.Int)
53-
serial.SetBytes(hash)
52+
53+
serial := big.NewInt(rand.Int63())
5454
template := x509.Certificate{
5555
// TODO(elazar): instead of this ugly hack, just encode the certificate and hash the binary form.
5656
SerialNumber: serial,
@@ -74,6 +74,7 @@ func signHost(ca tls.Certificate, hosts []string) (cert *tls.Certificate, err er
7474
}
7575
}
7676

77+
hash := hashSorted(append(hosts, goproxySignerVersion, ":"+runtime.Version()))
7778
var csprng CounterEncryptorRand
7879
if csprng, err = NewCounterEncryptorRandFromKey(ca.PrivateKey, hash); err != nil {
7980
return
@@ -102,3 +103,8 @@ func signHost(ca tls.Certificate, hosts []string) (cert *tls.Certificate, err er
102103
PrivateKey: certpriv,
103104
}, nil
104105
}
106+
107+
func init() {
108+
// Avoid deterministic random numbers
109+
rand.Seed(time.Now().UnixNano())
110+
}

0 commit comments

Comments
 (0)