1
0
mirror of https://github.com/golang/go synced 2024-11-22 02:34:40 -07:00

crypto/tls: use rand.Reader in cert generation example

R=rsc, agl1
CC=golang-dev
https://golang.org/cl/3536043
This commit is contained in:
Anthony Martin 2010-12-14 12:22:28 -05:00 committed by Russ Cox
parent 11b49ff124
commit 6a4b0191c0

View File

@ -9,6 +9,7 @@ package main
import ( import (
"crypto/rsa" "crypto/rsa"
"crypto/rand"
"crypto/x509" "crypto/x509"
"encoding/pem" "encoding/pem"
"flag" "flag"
@ -22,13 +23,7 @@ var hostName *string = flag.String("host", "127.0.0.1", "Hostname to generate a
func main() { func main() {
flag.Parse() flag.Parse()
urandom, err := os.Open("/dev/urandom", os.O_RDONLY, 0) priv, err := rsa.GenerateKey(rand.Reader, 1024)
if err != nil {
log.Exitf("failed to open /dev/urandom: %s", err)
return
}
priv, err := rsa.GenerateKey(urandom, 1024)
if err != nil { if err != nil {
log.Exitf("failed to generate private key: %s", err) log.Exitf("failed to generate private key: %s", err)
return return
@ -49,7 +44,7 @@ func main() {
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, 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 { if err != nil {
log.Exitf("Failed to create certificate: %s", err) log.Exitf("Failed to create certificate: %s", err)
return return