12 KiB
cli
import "github.com/effective-security/xpki/cmd/hsm-tool/cli"
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
- type Cli
- func (c *Cli) AfterApply(app *kong.Kong, vars kong.Vars) error
- func (c *Cli) Context() context.Context
- func (c *Cli) CryptoProv() (*cryptoprov.Crypto, cryptoprov.Provider, error)
- func (c *Cli) ErrWriter() io.Writer
- func (c *Cli) ReadFile(filename string) ([]byte, error)
- func (c *Cli) Reader() io.Reader
- func (c *Cli) WithErrWriter(out io.Writer) *Cli
- func (c *Cli) WithReader(reader io.Reader) *Cli
- func (c *Cli) WithWriter(out io.Writer) *Cli
- func (c *Cli) WriteJSON(value any)
- func (c *Cli) Writer() io.Writer
- type CsrCmd
- type CsrCreateCmd
- type CsrSignCmd
- type GenCertCmd
- type HsmCmd
- type HsmGenKeyCmd
- type HsmKeyInfoCmd
- type HsmLsKeyCmd
- type HsmRmKeyCmd
type Cli
Cli provides CLI context to run commands
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
}
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
CsrCmd is the parent for CSR command
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"`
}
type CsrCreateCmd
CsrCreateCmd specifies flags for Create command
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"`
}
func (*CsrCreateCmd) Run
func (a *CsrCreateCmd) Run(ctx *Cli) error
Run the command
type CsrSignCmd
CsrSignCmd signs certificate request
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"`
}
func (*CsrSignCmd) Run
func (a *CsrSignCmd) Run(ctx *Cli) error
Run the command
type GenCertCmd
GenCertCmd specifies flags for GenCert command
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"`
}
func (*GenCertCmd) Run
func (a *GenCertCmd) Run(ctx *Cli) error
Run the command
type HsmCmd
HsmCmd is the parent for HSM command
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"`
}
type HsmGenKeyCmd
HsmGenKeyCmd generates key
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"`
}
func (*HsmGenKeyCmd) Run
func (a *HsmGenKeyCmd) Run(ctx *Cli) error
Run the command
type HsmKeyInfoCmd
HsmKeyInfoCmd prints the key info
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"`
}
func (*HsmKeyInfoCmd) Run
func (a *HsmKeyInfoCmd) Run(ctx *Cli) error
Run the command
type HsmLsKeyCmd
HsmLsKeyCmd prints Keys
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)"`
}
func (*HsmLsKeyCmd) Run
func (a *HsmLsKeyCmd) Run(ctx *Cli) error
Run the command
type HsmRmKeyCmd
HsmRmKeyCmd deletes key
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)"`
}
func (*HsmRmKeyCmd) Run
func (a *HsmRmKeyCmd) Run(ctx *Cli) error
Run the command
Generated by gomarkdoc