pinentry

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: MIT Imports: 13 Imported by: 6

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 pin, fromCache, err := client.GetPIN(); {
	case pinentry.IsCancelled(err):
		fmt.Println("Cancelled")
	case err != nil:
		return err
	case fromCache:
		fmt.Printf("PIN: %s (from cache)\n", pin)
	default:
		fmt.Printf("PIN: %s\n", 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 added in v0.0.2

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) 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() (pin string, fromCache bool, err error)

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

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 added in v0.0.2

func WithBinaryName(binaryName string) ClientOption

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

func WithBinaryNameFromGnuPGAgentConf added in v0.0.2

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 added in v0.0.2

func WithGPGTTY() ClientOption

WithGPGTTY sets the tty.

func WithKeyInfo

func WithKeyInfo(keyInfo string) ClientOption

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

func WithLogger

func WithLogger(logger *zerolog.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 added in v0.1.0

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 added in v0.0.2

func WithQualityBarToolTip(qualityBarTT string) ClientOption

WithQualityBarToolTip sets the quality bar tool tip.

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout sets the timeout.

func WithTitle

func WithTitle(title string) ClientOption

WithTitle sets the title.

type Process added in v0.1.0

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