issue

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigTemplateText = `` /* 1692-byte string literal not displayed */

FIXME[P2]: Factor out subject config as a text/template macro. FIXME[P1]: keyType

Variables

View Source
var Command = &cli.Command{
	Name:  "issue",
	Usage: "Issue a new certificate or renew an existing certificate. Generates private key if needed.",
	Flags: append(structflags.MustPopulateFlagsFromStruct(Config{}),
		&cli.BoolFlag{
			Name:  "dump-template",
			Usage: "dump configuration template yaml without making actual changes",
		},
	),
	Action: func(c *cli.Context) error {
		env := wcli.GlobalEnvironment
		slog := env.Logger.Sugar()

		profile, err := env.Profile()
		if err != nil {
			return err
		}

		issuecfg, err := issue.DefaultConfig(env)

		if err != nil && !c.Bool("dump-template") {
			slog.Debugf("Errors encountered while constructing default config: %v", err)
		}

		cfg := &Config{
			Issue: issuecfg,
		}
		if c.Bool("dump-template") {
			if err := frontend.DumpTemplate(ConfigTemplateText, cfg); err != nil {
				return err
			}
			return nil
		}

		if err := structflags.PopulateStructFromCliContext(cfg, c); err != nil {
			return err
		}

		if err := setup.EnsureCA(env, nil, profile); err != nil {
			return err
		}

		var priv crypto.PrivateKey
		priv, cfg.PrivateKeyPath, err = ReadOrGenerateKey(env, cfg.Issue.KeyType, cfg.PrivateKeyPath)
		if err != nil {
			return fmt.Errorf("Failed to acquire private key: %w", err)
		}

		pub, err := wcrypto.ExtractPublicKey(priv)
		if err != nil {
			return err
		}

		cfg.CertPath, err = PromptCertPath(env, cfg.PrivateKeyPath, cfg.CertPath)
		if err != nil {
			return fmt.Errorf("Failed to acquire certificate file path: %w", err)
		}

		if err := frontend.EditStructWithVerifier(
			env.Frontend, ConfigTemplateText, cfg, frontend.CallVerifyMethod); err != nil {
			return err
		}

		certDer, err := issue.Run(env, pub, cfg.Issue)
		if err != nil {
			return err
		}

		if err := storage.WriteCertificateDerFile(cfg.CertPath, certDer); err != nil {
			return err
		}

		return nil
	},
}
View Source
var ErrCertKeyPathConflict = errors.New("Specified path conflicts with private key output path.")

Functions

func PromptCertPath

func PromptCertPath(env *wcli.Environment, privPath, certPath string) (string, error)

func ReadOrGenerateKey

func ReadOrGenerateKey(env *wcli.Environment, ktype wcrypto.KeyType, privPath string) (crypto.PrivateKey, string, error)

Types

type Config

type Config struct {
	PrivateKeyPath string `yaml:"privateKeyPath" flags:"priv,private key input/output path,,path"`
	CertPath       string `yaml:"certPath" flags:"cert,cert input/output path,,path"`

	Issue *issue.Config `yaml:"issue" flags:""`
}

func (*Config) Verify

func (c *Config) Verify() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL