Documentation
¶
Index ¶
- Variables
- func Close(ctx context.Context, logger LogI, yk *piv.YubiKey)
- func CloseYubikey(logger LogI, yk *piv.YubiKey)
- func Decrypt(yubikey *piv.GPGYubiKey, cipherTextBytes []byte) ([]byte, error)
- func DecryptBase64(yubikey *piv.GPGYubiKey, base64Data string) ([]byte, error)
- func FilePathExists(ctx context.Context, logger LogI, filePath string) (bool, string, error)
- func HasValidKeyType(logger LogI, yubikey *piv.GPGYubiKey, keyType piv.KeyType) (bool, error)
- func IsValidFileArg(logger LogI, name string, args []string) error
- func LoadFile(ctx context.Context, logger LogI, filePath string) ([]byte, error)
- func MakeJSONString(data interface{}) string
- func OpenFile(ctx context.Context, logger LogI, filePath string) (*os.File, string, error)
- func ToFileNotFound(err error) error
- func ValidateFileFlag(ctx context.Context, logger LogI, commandName, fileName string) error
- func ValidatePath(ctx context.Context, logger LogI, path string) (string, error)
- type CardAccess
- type CardSelection
- type Config
- func (c *Config) DecryptSetup(ctx context.Context, logger LogI) (*GPGYubiKeyImpl, error)
- func (c *Config) DevEncryptDecryptSetup(ctx context.Context, logger LogI, commandName, fileName string) (*GPGYubiKeyImpl, []byte, error)
- func (c *Config) DisplayKey(ctx context.Context, logger LogI, index int, yubikey *piv.GPGYubiKey, ...) error
- func (c *Config) DisplayKeys(ctx context.Context, logger LogI, yubikeys []*piv.GPGYubiKey, closeKey bool, ...) error
- func (c *Config) PGPCardSelection() *CardSelection
- func (c *Config) SelectCards(ctx context.Context, logger LogI) ([]*piv.GPGYubiKey, error)
- func (c *Config) String() string
- func (c *Config) WithBase64Encoded(value bool) *Config
- func (c *Config) WithCardSelection(value *CardSelection) *Config
- func (c *Config) WithDebug(value bool) *Config
- func (c *Config) WithQuiet(value bool) *Config
- func (c *Config) WithShowPublic(value bool) *Config
- func (c *Config) WithTrace(value bool) *Config
- func (c *Config) WithVerbose(value bool) *Config
- func (c *Config) WithYubikeyData(value *YubikeyData) *Config
- type GPGWrapper
- type GPGYubiKeyImpl
- func (g *GPGYubiKeyImpl) AuthPIN(ctx context.Context, logger LogI, pin []byte) error
- func (g *GPGYubiKeyImpl) Close(ctx context.Context, logger LogI)
- func (g *GPGYubiKeyImpl) Decrypt(ctx context.Context, logger LogI, data []byte) ([]byte, error)
- func (g *GPGYubiKeyImpl) Encrypt(ctx context.Context, logger LogI, data []byte) ([]byte, error)
- func (g *GPGYubiKeyImpl) Fingerprint(ctx context.Context, logger LogI) (string, error)
- func (g *GPGYubiKeyImpl) GetAttestationCert(ctx context.Context, logger LogI, keyType piv.KeyType) ([]byte, error)
- func (g *GPGYubiKeyImpl) ReadPasswordAndSendToYubikey(ctx context.Context, logger LogI) error
- func (g *GPGYubiKeyImpl) ReadPublicKey(ctx context.Context, logger LogI, keyType piv.AsymmetricKeyType) (*rsa.PublicKey, error)
- func (g *GPGYubiKeyImpl) SerialString(ctx context.Context, logger LogI) (string, error)
- type LogI
- type NopLogger
- func (n *NopLogger) DebugMsg(string)
- func (n *NopLogger) DebugMsgf(string, ...interface{})
- func (n *NopLogger) ErrorMsg(error, string)
- func (n *NopLogger) ErrorMsgf(err error, format string, args ...interface{})
- func (n *NopLogger) InfoMsg(string)
- func (n *NopLogger) InfoMsgf(string, ...interface{})
- func (n *NopLogger) IsDebugEnabled() bool
- func (n *NopLogger) VerboseMsg(string)
- func (n *NopLogger) VerboseMsgf(string, ...interface{})
- type PGPCardAccess
- type YubikeyData
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func CloseYubikey ¶
CloseYubikey closes a key and logs any errors. Deprecated: Use Close nolint:varnamelen
func DecryptBase64 ¶
func DecryptBase64(yubikey *piv.GPGYubiKey, base64Data string) ([]byte, error)
func FilePathExists ¶
func HasValidKeyType ¶
HasValidKeyType will check if the yubikey has the expected key. This is used in the filtering to make sure we pick the first yubikey with a gpg key. FIXME: move to piv.
func MakeJSONString ¶
func MakeJSONString(data interface{}) string
MakeJSONString dumps a struct to json as a helper.
func ToFileNotFound ¶
ToFileNotFound converts ENOENT to constants.ErrFileNotFound to make life simpler.
func ValidateFileFlag ¶
Types ¶
type CardAccess ¶
type CardSelection ¶
type CardSelection struct { *YubikeyData CardAccessor CardAccess }
CardSelection is created to filter cards. Currently, it can only filter on serial.
func NewCardSelection ¶
func NewCardSelection() *CardSelection
func (*CardSelection) GetCards ¶
func (c *CardSelection) GetCards(ctx context.Context, logger LogI, cfg *Config) ([]*piv.GPGYubiKey, error)
GetCards returns an array of pointers to piv.GPGPYubikey that have been filtered based on serial. TODO: add fingerprint and other styles. nolint:funlen,cyclop
func (*CardSelection) WithYubikeyData ¶
func (c *CardSelection) WithYubikeyData(value *YubikeyData) *CardSelection
type Config ¶
type Config struct { *CardSelection // Debug toggles verbose logging in downstream commands. Debug bool // Verbose toggles verbose logging in downstream commands. Verbose bool // Debug toggles verbose logging in downstream commands. Trace bool // Quiet disables all output other than expected value outputs. Quiet bool ShowPublic bool Base64Encoded bool }
func (*Config) DecryptSetup ¶
DecryptSetup will look for the specified yubikey and return it open. The caller *MUST* close the yubikey if err is nil. nolint:ireturn
func (*Config) DevEncryptDecryptSetup ¶
func (c *Config) DevEncryptDecryptSetup(ctx context.Context, logger LogI, commandName, fileName string) (*GPGYubiKeyImpl, []byte, error)
DevEncryptDecryptSetup will look for the specified yubikey and return it open. It will also load and base64 decode the file argument. The caller *MUST* close the yubikey if err is nil.
func (*Config) DisplayKey ¶
func (c *Config) DisplayKey(ctx context.Context, logger LogI, index int, yubikey *piv.GPGYubiKey, closeKey bool, showPublicKey bool) error
DisplayKey will display information about a yubikey. if closeKey is true, it will close the key. nolint:funlen,cyclop
func (*Config) DisplayKeys ¶
func (*Config) PGPCardSelection ¶
func (c *Config) PGPCardSelection() *CardSelection
func (*Config) SelectCards ¶
func (*Config) WithBase64Encoded ¶
func (*Config) WithCardSelection ¶
func (c *Config) WithCardSelection(value *CardSelection) *Config
func (*Config) WithShowPublic ¶
func (*Config) WithVerbose ¶
func (*Config) WithYubikeyData ¶
func (c *Config) WithYubikeyData(value *YubikeyData) *Config
type GPGWrapper ¶
type GPGWrapper interface { // SerialString returns the YubiKey's serial number. SerialString(ctx context.Context, logger LogI) (string, error) // Close closes the yubikey. Close(ctx context.Context, logger LogI) // ReadPasswordAndSendToYubikey reads the password from the terminal and sends it to the yubikey for verification. // This must be called before the Decrypt call will work. ReadPasswordAndSendToYubikey(ctx context.Context, logger LogI) error Decrypt(ctx context.Context, logger LogI, data []byte) ([]byte, error) Encrypt(ctx context.Context, logger LogI, data []byte) ([]byte, error) ReadPublicKey(ctx context.Context, logger LogI, keyType piv.AsymmetricKeyType) (*rsa.PublicKey, error) AuthPIN(ctx context.Context, logger LogI, pin []byte) error Fingerprint(ctx context.Context, logger LogI) (string, error) GetAttestationCert(ctx context.Context, logger LogI, keyType piv.KeyType) ([]byte, error) }
type GPGYubiKeyImpl ¶
type GPGYubiKeyImpl struct {
// contains filtered or unexported fields
}
func NewGPGYubiKeyImpl ¶
func NewGPGYubiKeyImpl(yubikey *piv.GPGYubiKey) *GPGYubiKeyImpl
func (*GPGYubiKeyImpl) Fingerprint ¶
func (*GPGYubiKeyImpl) GetAttestationCert ¶
func (*GPGYubiKeyImpl) ReadPasswordAndSendToYubikey ¶
func (g *GPGYubiKeyImpl) ReadPasswordAndSendToYubikey(ctx context.Context, logger LogI) error
ReadPasswordAndSendToYubikey reads the password from the terminal and sends it to the yubikey for verification. This must be called before the Decrypt call will work. nolint:forbidigo
func (*GPGYubiKeyImpl) ReadPublicKey ¶
func (g *GPGYubiKeyImpl) ReadPublicKey(ctx context.Context, logger LogI, keyType piv.AsymmetricKeyType) (*rsa.PublicKey, error)
func (*GPGYubiKeyImpl) SerialString ¶
type LogI ¶
type LogI interface { VerboseMsg(message string) VerboseMsgf(format string, args ...interface{}) // InfoMsgf will only log if quiet flag is NOT set. InfoMsg(message string) InfoMsgf(format string, args ...interface{}) DebugMsgf(format string, args ...interface{}) DebugMsg(message string) IsDebugEnabled() bool ErrorMsg(err error, message string) ErrorMsgf(err error, format string, args ...interface{}) }
LogI hides ZeroLogger from bits that don't need to care about it.
type NopLogger ¶
type NopLogger struct{}
func (*NopLogger) IsDebugEnabled ¶
func (*NopLogger) VerboseMsg ¶
func (*NopLogger) VerboseMsgf ¶
type PGPCardAccess ¶
type PGPCardAccess struct{}
func (*PGPCardAccess) Cards ¶
func (p *PGPCardAccess) Cards() ([]string, error)
func (*PGPCardAccess) OpenGPG ¶
func (p *PGPCardAccess) OpenGPG(card string) (*piv.GPGYubiKey, error)
type YubikeyData ¶
type YubikeyData struct { // Yubikey fingerprint. Fingerprint string // Yubikey key ID. KeyID string // Yubikey Serial. Serial string // Yubikey Name. Name string }
func NewYubikeyData ¶
func NewYubikeyData() *YubikeyData