fix: Use helpser in CA command.

This commit is contained in:
jmug committed 2026-10-23 00:11:43 -07:00
1 parent b4b628210f
commit abecfc3708
1 file changed
+2 -11
+2 -11
View File
@@ -5,9 +5,6 @@ import (
"crypto/x509" "crypto/x509"
"crypto/x509/pkix" "crypto/x509/pkix"
"encoding/pem" "encoding/pem"
"errors"
"math"
"math/big"
"path" "path"
"time" "time"
@@ -32,17 +29,11 @@ var generateCACmd = &cobra.Command{
Short: "Generate a Certificate Authority", Short: "Generate a Certificate Authority",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
// Private key for the ca. // Private key for the ca.
key := pki.GenerateKey() key := pki.NewKey()
// Cryptographically random 64bit number as the serial.
sn, err := rand.Int(rand.Reader, big.NewInt(math.MaxInt64))
if err != nil {
return errors.New("Could not generate a ca serial number")
}
caTmpl := &x509.Certificate{ caTmpl := &x509.Certificate{
SerialNumber: sn, SerialNumber: pki.NewCertSerialNumber(),
Subject: pkix.Name{ Subject: pkix.Name{
// TODO: Accept common name as a flag.
CommonName: CommonName, CommonName: CommonName,
}, },
// Valid starting now and for 10 years. // Valid starting now and for 10 years.