rsa/cmd/ca/intermediate.go

38 lines
776 B
Go
Raw Normal View History

package ca
import (
"crypto/rand"
"crypto/rsa"
"fmt"
"os"
"github.com/spf13/cobra"
"src.lwithers.me.uk/go/rsa/pkg/ca"
)
// Intermediate uses an existing CA to create a new intermediate CA in a new
// directory.
func Intermediate(cmd *cobra.Command, args []string) {
newCADir := args[0]
desc := args[1]
ca, err := ca.Open(dir)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
template := createCATemplate(desc)
key, err := rsa.GenerateKey(rand.Reader, bits)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to generate new key (%d bits): %v\n", bits, err)
os.Exit(1)
}
_, err = ca.CreateIntermediate(newCADir, template, key)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to initialise new intermediate CA: %v\n", err)
os.Exit(1)
}
}