Help us shape the future of Go! Take the 2026 Go Developer Survey

cli

package
v1.0.316 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package cli implements the hsm-tool command tree: hsm list/info/generate/ remove and csr create/gen-cert/sign. Providers are registered by blank imports and loaded lazily from the --cfg and --crypto config files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cli

type Cli struct {
	Version  ctl.VersionFlag `name:"version" help:"Print version information and quit" hidden:""`
	Cfg      string          `help:"Location of HSM config file, as default crypto provider" required:""`
	Crypto   []string        `help:"Location of additional HSM config files" type:"path"`
	PlainKey bool            `help:"Generate plain key"`
	Debug    bool            `short:"D" help:"Enable debug mode"`
	LogLevel string          `short:"l" help:"Set the logging level (debug|info|warn|error)" default:"error"`
	// contains filtered or unexported fields
}

Cli provides CLI context to run commands

func (*Cli) AfterApply

func (c *Cli) AfterApply(app *kong.Kong, vars kong.Vars) error

AfterApply hook loads config

func (*Cli) Context

func (c *Cli) Context() context.Context

Context for requests

func (*Cli) CryptoProv

func (c *Cli) CryptoProv() (*cryptoprov.Crypto, cryptoprov.Provider, error)

CryptoProv loads the crypto providers from --cfg and --crypto on the first call, and returns them with the default provider: an in-memory provider with --plain-key, otherwise the provider of --cfg ("inmem" and "plain" name the in-memory provider). It returns an error, for the command to fail with, when --cfg is empty or a provider cannot be initialized (XPKI-084).

func (*Cli) ErrWriter

func (c *Cli) ErrWriter() io.Writer

ErrWriter returns a writer for control output

func (*Cli) ReadFile

func (c *Cli) ReadFile(filename string) ([]byte, error)

ReadFile reads from stdin if the file is "-"

func (*Cli) Reader

func (c *Cli) Reader() io.Reader

Reader is the source to read from, typically set to os.Stdin

func (*Cli) WithErrWriter

func (c *Cli) WithErrWriter(out io.Writer) *Cli

WithErrWriter allows to specify a custom error writer

func (*Cli) WithReader

func (c *Cli) WithReader(reader io.Reader) *Cli

WithReader allows to specify a custom reader

func (*Cli) WithWriter

func (c *Cli) WithWriter(out io.Writer) *Cli

WithWriter allows to specify a custom writer

func (*Cli) WriteJSON

func (c *Cli) WriteJSON(value any)

WriteJSON prints response to out

func (*Cli) Writer

func (c *Cli) Writer() io.Writer

Writer returns a writer for control output

type CsrCmd

type CsrCmd struct {
	Create  CsrCreateCmd `cmd:"" help:"create certificate request"`
	GenCert GenCertCmd   `cmd:"" help:"create CSR and sign certificate"`
	Sign    CsrSignCmd   `cmd:"" help:"sign certificate"`
}

CsrCmd is the parent for CSR command

type CsrCreateCmd

type CsrCreateCmd struct {
	CsrProfile string `required:"" help:"file name with CSR profile"`
	KeyLabel   string `required:"" help:"name for generated key"`
	Output     string `help:"the optional prefix for output files; if not set, the output will be printed to STDOUT only"`
}

CsrCreateCmd specifies flags for Create command

func (*CsrCreateCmd) Run

func (a *CsrCreateCmd) Run(ctx *Cli) error

Run the command

type CsrSignCmd

type CsrSignCmd struct {
	Csr      string   `kong:"arg" required:"" help:"file name with pem-encoded CSR to sign"`
	CACert   string   `required:"" help:"file name of the signing CA cert"`
	CAKey    string   `required:"" help:"file name of the signing CA key"`
	CAConfig string   `required:"" help:"file name with ca-config"`
	Profile  string   `required:"" help:"certificate profile name from CA config"`
	San      []string `help:"Subject Alt Names for generated cert"`

	AiaURL  string `help:"optional AIA to add to the certificate"`
	OcspURL string `help:"optional OCSP URL to add to the certificate"`
	CrlURL  string `help:"optional CRL DP to add to the certificate"`

	PemInfo bool   `help:"Include certificate info in PEM file"`
	Output  string `help:"the optional prefix for output files; if not set, the output will be printed to STDOUT only"`
}

CsrSignCmd signs certificate request

func (*CsrSignCmd) Run

func (a *CsrSignCmd) Run(ctx *Cli) error

Run the command

type GenCertCmd

type GenCertCmd struct {
	SelfSign   bool     `help:"generate self-signed cert"`
	CACert     string   `help:"file name of the signing CA cert"`
	CAKey      string   `help:"file name of the signing CA key"`
	CAConfig   string   `required:"" help:"file name with ca-config"`
	CsrProfile string   `required:"" help:"file name with CSR profile"`
	Profile    string   `required:"" help:"certificate profile name from CA config"`
	KeyLabel   string   `required:"" help:"name for generated key"`
	San        []string `help:"Subject Alt Names for generated cert"`

	PemInfo bool   `help:"Include certificate info in PEM file"`
	Output  string `help:"the optional prefix for output files; if not set, the output will be printed to STDOUT only"`
}

GenCertCmd specifies flags for GenCert command

func (*GenCertCmd) Run

func (a *GenCertCmd) Run(ctx *Cli) error

Run the command

type HsmCmd

type HsmCmd struct {
	List     HsmLsKeyCmd   `cmd:"" help:"list keys"`
	Info     HsmKeyInfoCmd `cmd:"" help:"print key information"`
	Generate HsmGenKeyCmd  `cmd:"" help:"generate key"`
	Remove   HsmRmKeyCmd   `cmd:"" help:"delete key"`
}

HsmCmd is the parent for HSM command

type HsmGenKeyCmd

type HsmGenKeyCmd struct {
	Algo    string `required:"" help:"algorithm: RSA|ECDSA"`
	Size    int    `required:"" help:"key size in bits"`
	Purpose string `required:"" help:"purpose of the key: SIGN|ENCRYPT"`
	Label   string `required:"" help:"name for generated key"`
	Output  string `help:"location to write the key, if not set, the output will be printed to STDOUT only"`
	Force   bool   `help:"force to override key file if exists"`
}

HsmGenKeyCmd generates key

func (*HsmGenKeyCmd) Run

func (a *HsmGenKeyCmd) Run(ctx *Cli) error

Run the command

type HsmKeyInfoCmd

type HsmKeyInfoCmd struct {
	ID     string `kong:"arg" required:"" help:"key ID"`
	Token  string `help:"slot token (optional)"`
	Serial string `help:"slot serial (optional)"`
	Public bool   `help:"print Public Key"`
}

HsmKeyInfoCmd prints the key info

func (*HsmKeyInfoCmd) Run

func (a *HsmKeyInfoCmd) Run(ctx *Cli) error

Run the command

type HsmLsKeyCmd

type HsmLsKeyCmd struct {
	Token  string `help:"specifies slot token (optional)"`
	Serial string `help:"specifies slot serial (optional)"`
	Prefix string `help:"specifies key label prefix (optional)"`
}

HsmLsKeyCmd prints Keys

func (*HsmLsKeyCmd) Run

func (a *HsmLsKeyCmd) Run(ctx *Cli) error

Run the command

type HsmRmKeyCmd

type HsmRmKeyCmd struct {
	ID     string `kong:"arg" required:"" help:"specifies key ID"`
	Token  string `help:"specifies slot token (optional)"`
	Serial string `help:"specifies slot serial (optional)"`
}

HsmRmKeyCmd deletes key

func (*HsmRmKeyCmd) Run

func (a *HsmRmKeyCmd) Run(ctx *Cli) error

Run the command

Jump to

Keyboard shortcuts

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