pinentry

package module
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 13 Imported by: 1

README

go-pinentry

PkgGoDev

Package pinentry provides a client to GnuPG's pinentry.

Key Features

  • Support for all pinentry features.
  • Idiomatic Go API.
  • Well tested.

Example

	client, err := pinentry.NewClient(
		pinentry.WithBinaryNameFromGnuPGAgentConf(),
		pinentry.WithDesc("My description"),
		pinentry.WithGPGTTY(),
		pinentry.WithPrompt("My prompt:"),
		pinentry.WithTitle("My title"),
	)
	if err != nil {
		return err
	}
	defer client.Close()

	switch result, err := client.GetPIN(); {
	case pinentry.IsCancelled(err):
		fmt.Println("Cancelled")
	case err != nil:
		return err
	case result.PasswordFromCache:
		fmt.Printf("PIN: %s (from cache)\n", result.PIN)
	default:
		fmt.Printf("PIN: %s\n", result.PIN)
	}

License

MIT

Documentation

Overview

Package pinentry provides a client to GnuPG's pinentry.

See info pinentry. See https://www.gnupg.org/related_software/pinentry/index.html. See https://www.gnupg.org/documentation/manuals/assuan.pdf.

Index

Constants

View Source
const (
	OptionAllowExternalPasswordCache = "allow-external-password-cache"
	OptionDefaultOK                  = "default-ok"
	OptionDefaultCancel              = "default-cancel"
	OptionDefaultPrompt              = "default-prompt"
	OptionTTYName                    = "ttyname"
	OptionTTYType                    = "ttytype"
	OptionLCCType                    = "lc-ctype"
)

Options.

View Source
const (
	AssuanErrorCodeCancelled = 83886179
)

Error codes.

Variables

This section is empty.

Functions

func IsCancelled

func IsCancelled(err error) bool

IsCancelled returns if the error is operation cancelled.

Types

type AssuanError

type AssuanError struct {
	Code        int
	Description string
}

An AssuanError is returned when an error is sent over the Assuan protocol.

func (*AssuanError) Error

func (e *AssuanError) Error() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client is a pinentry client.

func NewClient

func NewClient(options ...ClientOption) (c *Client, err error)

NewClient returns a new Client with the given options.

func (*Client) ClearPassphrase

func (c *Client) ClearPassphrase(cacheID string) error

ClearPassphrase clears the cached passphrase associated with the key identified by cacheID.

func (*Client) Close

func (c *Client) Close() (err error)

Close closes the connection to the pinentry process.

func (*Client) Confirm

func (c *Client) Confirm(option string) (bool, error)

Confirm asks the user for confirmation.

func (*Client) GetPIN

func (c *Client) GetPIN() (GetPINResult, error)

GetPIN gets a PIN from the user. If the user cancels, an error is returned which can be tested with IsCancelled.

func (*Client) Message

func (c *Client) Message() error

Message shows the user a message.

type ClientOption

type ClientOption func(*Client)

A ClientOption sets an option on a Client.

func WithArgs

func WithArgs(args []string) ClientOption

WithArgs appends extra arguments to the pinentry command.

func WithBinaryName

func WithBinaryName(binaryName string) ClientOption

WithBinaryName sets the name of the pinentry binary name. The default is pinentry.

func WithBinaryNameFromGnuPGAgentConf

func WithBinaryNameFromGnuPGAgentConf() (clientOption ClientOption)

WithBinaryNameFromGnuPGAgentConf sets the name of the pinentry binary by reading ~/.gnupg/gpg-agent.conf, if it exists.

func WithCancel

func WithCancel(cancel string) ClientOption

WithCancel sets the cancel button text.

func WithCommand

func WithCommand(command string) ClientOption

WithCommand appends an Assuan command that is sent when the connection is established.

func WithCommandf

func WithCommandf(format string, args ...interface{}) ClientOption

WithCommandf appends an Assuan command that is sent when the connection is established, using fmt.Sprintf to format the command.

func WithDebug

func WithDebug() ClientOption

WithDebug tells the pinentry command to print debug messages.

func WithDesc

func WithDesc(desc string) ClientOption

WithDesc sets the description text.

func WithError

func WithError(err string) ClientOption

WithError sets the error text.

func WithGPGTTY

func WithGPGTTY() ClientOption

WithGPGTTY sets the tty.

func WithGenPIN

func WithGenPIN(genPIN string) ClientOption

WithGenPIN sets the label to be used for a generate action.

func WithGenPINToolTip

func WithGenPINToolTip(genPINTT string) ClientOption

WithGenPINToolTip sets the tooltip to be used for a generate action.

func WithKeyInfo

func WithKeyInfo(keyInfo string) ClientOption

WithKeyInfo sets a stable key identifier for use with password caching.

func WithLogger

func WithLogger(logger *slog.Logger) ClientOption

WithLogger sets the logger.

func WithNoGlobalGrab

func WithNoGlobalGrab() ClientOption

WithNoGlobalGrab instructs pinentry to only grab the password when the window is focused.

func WithNotOK

func WithNotOK(notOK string) ClientOption

WithNotOK sets the text of the non-affirmative response button.

func WithOK

func WithOK(ok string) ClientOption

WithOK sets the text of the OK button.

func WithOption

func WithOption(option string) ClientOption

WithOption sets an option.

func WithOptions

func WithOptions(options []string) ClientOption

WithOptions sets multiple options.

func WithProcess

func WithProcess(process Process) ClientOption

WithProcess sets the process.

func WithPrompt

func WithPrompt(prompt string) ClientOption

WithPrompt sets the prompt.

func WithQualityBar

func WithQualityBar(qualityFunc QualityFunc) ClientOption

WithQualityBar enables the quality bar.

func WithQualityBarToolTip

func WithQualityBarToolTip(qualityBarTT string) ClientOption

WithQualityBarToolTip sets the quality bar tool tip.

func WithRepeat

func WithRepeat(repeat string) ClientOption

WithRepeat sets the repeat passphrase.

func WithRepeatError

func WithRepeatError(repeatError string) ClientOption

WithRepeatError sets the repeat error message.

func WithRepeatOK

func WithRepeatOK(repeatOK string) ClientOption

WithRepeatOK sets the repeat OK message.

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout sets the timeout.

func WithTitle

func WithTitle(title string) ClientOption

WithTitle sets the title.

type GetPINResult

type GetPINResult struct {
	PIN               string
	PasswordFromCache bool
	PINRepeated       bool
}

A GetPINResult is the result of a call to Client.GetPIN.

type Process

type Process interface {
	io.WriteCloser
	ReadLine() ([]byte, bool, error)
	Start(string, []string) error
}

A Process abstracts the interface to a pinentry Process.

type QualityFunc

type QualityFunc func(string) (int, bool)

A QualityFunc evaluates the quality of a password. It should return a value between -100 and 100. The absolute value of the return value is used as the quality. Negative values turn the quality bar red. The boolean return value indicates whether the quality is valid.

type UnexpectedResponseError

type UnexpectedResponseError struct {
	Line string
}

An UnexpectedResponseError is returned when an unexpected response is received.

func (UnexpectedResponseError) Error

func (e UnexpectedResponseError) Error() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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