From 368c7fa03eed3f331cbd1c53d20684635e35611c Mon Sep 17 00:00:00 2001 From: Anthony Martin Date: Tue, 14 Dec 2010 12:22:28 -0500 Subject: [PATCH] crypto/tls: use rand.Reader in cert generation example R=rsc, agl1 CC=golang-dev https://golang.org/cl/3536043 --- generate_cert.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/generate_cert.go b/generate_cert.go index 2ee8073..3e0c639 100644 --- a/generate_cert.go +++ b/generate_cert.go @@ -9,6 +9,7 @@ package main import ( "crypto/rsa" + "crypto/rand" "crypto/x509" "encoding/pem" "flag" @@ -22,13 +23,7 @@ var hostName *string = flag.String("host", "127.0.0.1", "Hostname to generate a func main() { flag.Parse() - urandom, err := os.Open("/dev/urandom", os.O_RDONLY, 0) - if err != nil { - log.Exitf("failed to open /dev/urandom: %s", err) - return - } - - priv, err := rsa.GenerateKey(urandom, 1024) + priv, err := rsa.GenerateKey(rand.Reader, 1024) if err != nil { log.Exitf("failed to generate private key: %s", err) return @@ -49,7 +44,7 @@ func main() { KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, } - derBytes, err := x509.CreateCertificate(urandom, &template, &template, &priv.PublicKey, priv) + derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv) if err != nil { log.Exitf("Failed to create certificate: %s", err) return