privval

package
v0.31.1 Latest Latest
Warning

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

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

Documentation

Overview

Package privval provides different implementations of the types.PrivValidator.

FilePV

FilePV is the simplest implementation and developer default. It uses one file for the private key and another to store state.

SocketVal

SocketVal establishes a connection to an external process, like a Key Management Server (KMS), using a socket. SocketVal listens for the external KMS process to dial in. SocketVal takes a listener, which determines the type of connection (ie. encrypted over tcp, or unencrypted over unix).

RemoteSigner

RemoteSigner is a simple wrapper around a net.Conn. It's used by both IPCVal and TCPVal.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnTimeout = errors.New("remote signer timed out")
)

Socket errors.

View Source
var (
	ErrDialRetryMax = errors.New("dialed maximum retries")
)

Socket errors.

View Source
var (
	ErrUnexpectedResponse = errors.New("received unexpected response")
)

Socket errors.

Functions

func NewTCPListener added in v0.28.0

func NewTCPListener(ln net.Listener, secretConnKey ed25519.PrivKeyEd25519) *tcpListener

NewTCPListener returns a listener that accepts authenticated encrypted connections using the given secretConnKey and the default timeout values.

func NewUnixListener added in v0.28.0

func NewUnixListener(ln net.Listener) *unixListener

NewUnixListener returns a listener that accepts unencrypted connections using the default timeout values.

func RegisterRemoteSignerMsg added in v0.27.4

func RegisterRemoteSignerMsg(cdc *amino.Codec)

Types

type Dialer added in v0.28.0

type Dialer func() (net.Conn, error)

Dialer dials a remote address and returns a net.Conn or an error.

func DialTCPFn added in v0.28.0

func DialTCPFn(addr string, connTimeout time.Duration, privKey ed25519.PrivKeyEd25519) Dialer

DialTCPFn dials the given tcp addr, using the given connTimeout and privKey for the authenticated encryption handshake.

func DialUnixFn added in v0.28.0

func DialUnixFn(addr string) Dialer

DialUnixFn dials the given unix socket.

type FilePV

type FilePV struct {
	Address       types.Address  `json:"address"`
	PubKey        crypto.PubKey  `json:"pub_key"`
	LastHeight    int64          `json:"last_height"`
	LastRound     int            `json:"last_round"`
	LastStep      int8           `json:"last_step"`
	LastSignature []byte         `json:"last_signature,omitempty"`
	LastSignBytes cmn.HexBytes   `json:"last_signbytes,omitempty"`
	PrivKey       crypto.PrivKey `json:"priv_key"`
	// contains filtered or unexported fields
}

FilePV implements PrivValidator using data persisted to disk to prevent double signing. NOTE: the directory containing the pv.filePath must already exist. It includes the LastSignature and LastSignBytes so we don't lose the signature if the process crashes after signing but before the resulting consensus message is processed.

func GenFilePV

func GenFilePV(filePath string) *FilePV

GenFilePV generates a new validator with randomly generated private key and sets the filePath, but does not call Save().

func LoadFilePV

func LoadFilePV(filePath string) *FilePV

LoadFilePV loads a FilePV from the filePath. The FilePV handles double signing prevention by persisting data to the filePath. If the filePath does not exist, the FilePV must be created manually and saved.

func LoadOrGenFilePV

func LoadOrGenFilePV(filePath string) *FilePV

LoadOrGenFilePV loads a FilePV from the given filePath or else generates a new one and saves it to the filePath.

func (*FilePV) GetAddress

func (pv *FilePV) GetAddress() types.Address

GetAddress returns the address of the validator. Implements PrivValidator.

func (*FilePV) GetPubKey

func (pv *FilePV) GetPubKey() crypto.PubKey

GetPubKey returns the public key of the validator. Implements PrivValidator.

func (*FilePV) Reset

func (pv *FilePV) Reset()

Reset resets all fields in the FilePV. NOTE: Unsafe!

func (*FilePV) Save

func (pv *FilePV) Save()

Save persists the FilePV to disk.

func (*FilePV) SignProposal

func (pv *FilePV) SignProposal(chainID string, proposal *types.Proposal) error

SignProposal signs a canonical representation of the proposal, along with the chainID. Implements PrivValidator.

func (*FilePV) SignVote

func (pv *FilePV) SignVote(chainID string, vote *types.Vote) error

SignVote signs a canonical representation of the vote, along with the chainID. Implements PrivValidator.

func (*FilePV) String

func (pv *FilePV) String() string

String returns a string representation of the FilePV.

type PingRequest added in v0.27.4

type PingRequest struct {
}

PingRequest is a PrivValidatorSocket message to keep the connection alive.

type PingResponse added in v0.27.4

type PingResponse struct {
}

type PubKeyRequest added in v0.27.4

type PubKeyRequest struct{}

PubKeyRequest requests the consensus public key from the remote signer.

type PubKeyResponse added in v0.27.4

type PubKeyResponse struct {
	PubKey crypto.PubKey
	Error  *RemoteSignerError
}

PubKeyResponse is a PrivValidatorSocket message containing the public key.

type RemoteSigner

type RemoteSigner struct {
	cmn.BaseService
	// contains filtered or unexported fields
}

RemoteSigner dials using its dialer and responds to any signature requests using its privVal.

func NewRemoteSigner

func NewRemoteSigner(
	logger log.Logger,
	chainID string,
	privVal types.PrivValidator,
	dialer Dialer,
) *RemoteSigner

NewRemoteSigner return a RemoteSigner that will dial using the given dialer and respond to any signature requests over the connection using the given privVal.

func (*RemoteSigner) OnStart

func (rs *RemoteSigner) OnStart() error

OnStart implements cmn.Service.

func (*RemoteSigner) OnStop

func (rs *RemoteSigner) OnStop()

OnStop implements cmn.Service.

type RemoteSignerClient added in v0.27.4

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

RemoteSignerClient implements PrivValidator. It uses a net.Conn to request signatures from an external process.

func NewRemoteSignerClient added in v0.27.4

func NewRemoteSignerClient(conn net.Conn) (*RemoteSignerClient, error)

NewRemoteSignerClient returns an instance of RemoteSignerClient.

func (*RemoteSignerClient) Close added in v0.28.0

func (sc *RemoteSignerClient) Close() error

Close calls Close on the underlying net.Conn.

func (*RemoteSignerClient) GetPubKey added in v0.27.4

func (sc *RemoteSignerClient) GetPubKey() crypto.PubKey

GetPubKey implements PrivValidator.

func (*RemoteSignerClient) Ping added in v0.27.4

func (sc *RemoteSignerClient) Ping() error

Ping is used to check connection health.

func (*RemoteSignerClient) SignProposal added in v0.27.4

func (sc *RemoteSignerClient) SignProposal(
	chainID string,
	proposal *types.Proposal,
) error

SignProposal implements PrivValidator.

func (*RemoteSignerClient) SignVote added in v0.27.4

func (sc *RemoteSignerClient) SignVote(chainID string, vote *types.Vote) error

SignVote implements PrivValidator.

type RemoteSignerError added in v0.27.4

type RemoteSignerError struct {
	// TODO(ismail): create an enum of known errors
	Code        int
	Description string
}

RemoteSignerError allows (remote) validators to include meaningful error descriptions in their reply.

func (*RemoteSignerError) Error added in v0.27.4

func (e *RemoteSignerError) Error() string

type RemoteSignerMsg added in v0.27.4

type RemoteSignerMsg interface{}

RemoteSignerMsg is sent between RemoteSigner and the RemoteSigner client.

type RemoteSignerOption

type RemoteSignerOption func(*RemoteSigner)

RemoteSignerOption sets an optional parameter on the RemoteSigner.

func RemoteSignerConnDeadline

func RemoteSignerConnDeadline(deadline time.Duration) RemoteSignerOption

RemoteSignerConnDeadline sets the read and write deadline for connections from external signing processes.

func RemoteSignerConnRetries

func RemoteSignerConnRetries(retries int) RemoteSignerOption

RemoteSignerConnRetries sets the amount of attempted retries to connect.

type SignProposalRequest added in v0.27.4

type SignProposalRequest struct {
	Proposal *types.Proposal
}

SignProposalRequest is a PrivValidatorSocket message containing a Proposal.

type SignVoteRequest added in v0.27.4

type SignVoteRequest struct {
	Vote *types.Vote
}

SignVoteRequest is a PrivValidatorSocket message containing a vote.

type SignedProposalResponse added in v0.27.4

type SignedProposalResponse struct {
	Proposal *types.Proposal
	Error    *RemoteSignerError
}

type SignedVoteResponse added in v0.27.4

type SignedVoteResponse struct {
	Vote  *types.Vote
	Error *RemoteSignerError
}

SignedVoteResponse is a PrivValidatorSocket message containing a signed vote along with a potenial error message.

type SocketVal added in v0.28.0

type SocketVal struct {
	cmn.BaseService
	// contains filtered or unexported fields
}

SocketVal implements PrivValidator. It listens for an external process to dial in and uses the socket to request signatures.

func NewSocketVal added in v0.28.0

func NewSocketVal(
	logger log.Logger,
	listener net.Listener,
) *SocketVal

NewSocketVal returns an instance of SocketVal.

func (*SocketVal) Close added in v0.28.0

func (sc *SocketVal) Close()

Close closes the underlying net.Conn.

func (*SocketVal) GetPubKey added in v0.28.0

func (sc *SocketVal) GetPubKey() crypto.PubKey

GetPubKey implements PrivValidator.

func (*SocketVal) OnStart added in v0.28.0

func (sc *SocketVal) OnStart() error

OnStart implements cmn.Service.

func (*SocketVal) OnStop added in v0.28.0

func (sc *SocketVal) OnStop()

OnStop implements cmn.Service.

func (*SocketVal) Ping added in v0.28.0

func (sc *SocketVal) Ping() error

Ping is used to check connection health.

func (*SocketVal) SignProposal added in v0.28.0

func (sc *SocketVal) SignProposal(chainID string, proposal *types.Proposal) error

SignProposal implements PrivValidator.

func (*SocketVal) SignVote added in v0.28.0

func (sc *SocketVal) SignVote(chainID string, vote *types.Vote) error

SignVote implements PrivValidator.

type SocketValOption added in v0.28.0

type SocketValOption func(*SocketVal)

SocketValOption sets an optional parameter on the SocketVal.

func SocketValHeartbeat added in v0.28.0

func SocketValHeartbeat(period time.Duration) SocketValOption

SocketValHeartbeat sets the period on which to check the liveness of the connected Signer connections.

type TCPListenerOption added in v0.28.0

type TCPListenerOption func(*tcpListener)

TCPListenerOption sets an optional parameter on the tcpListener.

func TCPListenerAcceptDeadline added in v0.28.0

func TCPListenerAcceptDeadline(deadline time.Duration) TCPListenerOption

TCPListenerAcceptDeadline sets the deadline for the listener. A zero time value disables the deadline.

func TCPListenerConnDeadline added in v0.28.0

func TCPListenerConnDeadline(deadline time.Duration) TCPListenerOption

TCPListenerConnDeadline sets the read and write deadline for connections from external signing processes.

type UnixListenerOption added in v0.28.0

type UnixListenerOption func(*unixListener)

func UnixListenerAcceptDeadline added in v0.28.0

func UnixListenerAcceptDeadline(deadline time.Duration) UnixListenerOption

UnixListenerAcceptDeadline sets the deadline for the listener. A zero time value disables the deadline.

func UnixListenerConnDeadline added in v0.28.0

func UnixListenerConnDeadline(deadline time.Duration) UnixListenerOption

UnixListenerConnDeadline sets the read and write deadline for connections from external signing processes.

Jump to

Keyboard shortcuts

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