session

package
v0.12.4-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DBFilename is the default filename of the session database.
	DBFilename = "session.db"

	// DefaultSessionDBTimeout is the default maximum time we wait for the
	// session bbolt database to be opened. If the database is already
	// opened by another process, the unique lock cannot be obtained. With
	// the timeout we error out after the given time instead of just
	// blocking for forever.
	DefaultSessionDBTimeout = 5 * time.Second
)
View Source
const Subsystem = "SESS"

Variables

View Source
var (

	// ErrSessionNotFound is an error returned when we attempt to retrieve
	// information about a session but it is not found.
	ErrSessionNotFound = errors.New("session not found")

	// ErrDBInitErr is returned when a bucket that we expect to have been
	// set up during DB initialisation is not found.
	ErrDBInitErr = errors.New("db did not initialise properly")
)
View Source
var (

	// ErrDBReversion is returned when detecting an attempt to revert to a
	// prior database version.
	ErrDBReversion = errors.New("cannot revert to prior version")
)
View Source
var (
	// SuperMacaroonRootKeyPrefix is the prefix we set on a super macaroon's
	// root key to clearly mark it as such.
	SuperMacaroonRootKeyPrefix = [4]byte{0xFF, 0xEE, 0xDD, 0xCC}
)

Functions

func IsSuperMacaroon

func IsSuperMacaroon(macHex string) bool

IsSuperMacaroon returns true if the given hex encoded macaroon is a super macaroon baked by LiT which can be identified by its root key ID.

func NewSuperMacaroonRootKeyID

func NewSuperMacaroonRootKeyID(id [4]byte) uint64

NewSuperMacaroonRootKeyID returns a new macaroon root key ID that has the prefix to mark it as a super macaroon root key.

func ParseMacaroon

func ParseMacaroon(macHex string) (*macaroon.Macaroon, error)

ParseMacaroon parses a hex encoded macaroon into its native struct.

func RootKeyIDFromMacaroon

func RootKeyIDFromMacaroon(mac *macaroon.Macaroon) (uint64, error)

RootKeyIDFromMacaroon extracts the root key ID of the passed macaroon.

func SerializeSession

func SerializeSession(w io.Writer, session *Session) error

SerializeSession binary serializes the given session to the writer using the tlv format.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

Types

type DB

type DB struct {
	*bbolt.DB
}

DB is a bolt-backed persistent store.

func NewDB

func NewDB(dir, fileName string) (*DB, error)

NewDB creates a new bolt database that can be found at the given directory.

func (*DB) CheckSessionGroupPredicate

func (db *DB) CheckSessionGroupPredicate(groupID ID,
	fn func(s *Session) bool) (bool, error)

CheckSessionGroupPredicate iterates over all the sessions in a group and checks if each one passes the given predicate function. True is returned if each session passes.

NOTE: this is part of the Store interface.

func (*DB) CreateSession

func (db *DB) CreateSession(session *Session) error

CreateSession adds a new session to the store. If a session with the same local public key already exists an error is returned.

NOTE: this is part of the Store interface.

func (*DB) GetGroupID

func (db *DB) GetGroupID(sessionID ID) (ID, error)

GetGroupID will return the group ID for the given session ID.

NOTE: this is part of the IDToGroupIndex interface.

func (*DB) GetSession

func (db *DB) GetSession(key *btcec.PublicKey) (*Session, error)

GetSession fetches the session with the given key.

NOTE: this is part of the Store interface.

func (*DB) GetSessionByID

func (db *DB) GetSessionByID(id ID) (*Session, error)

GetSessionByID fetches the session with the given ID.

NOTE: this is part of the Store interface.

func (*DB) GetSessionIDs

func (db *DB) GetSessionIDs(groupID ID) ([]ID, error)

GetSessionIDs will return the set of session IDs that are in the group with the given ID.

NOTE: this is part of the IDToGroupIndex interface.

func (*DB) GetUnusedIDAndKeyPair

func (db *DB) GetUnusedIDAndKeyPair() (ID, *btcec.PrivateKey, error)

GetUnusedIDAndKeyPair can be used to generate a new, unused, local private key and session ID pair. Care must be taken to ensure that no other thread calls this before the returned ID and key pair from this method are either used or discarded.

NOTE: this is part of the Store interface.

func (*DB) ListSessions

func (db *DB) ListSessions(filterFn func(s *Session) bool) ([]*Session, error)

ListSessions returns all sessions currently known to the store.

NOTE: this is part of the Store interface.

func (*DB) RevokeSession

func (db *DB) RevokeSession(key *btcec.PublicKey) error

RevokeSession updates the state of the session with the given local public key to be revoked.

NOTE: this is part of the Store interface.

func (*DB) UpdateSessionRemotePubKey

func (db *DB) UpdateSessionRemotePubKey(localPubKey,
	remotePubKey *btcec.PublicKey) error

UpdateSessionRemotePubKey can be used to add the given remote pub key to the session with the given local pub key.

NOTE: this is part of the Store interface.

type FeaturesConfig

type FeaturesConfig map[string][]byte

FeaturesConfig is a map from feature name to a raw byte array which stores any config feature config options.

type GRPCServerCreator

type GRPCServerCreator func(opts ...grpc.ServerOption) *grpc.Server

type ID

type ID [4]byte

ID represents the id of a session.

func IDFromBytes

func IDFromBytes(b []byte) (ID, error)

IDFromBytes is a helper function that creates a session ID from a byte slice.

func IDFromMacRootKeyID

func IDFromMacRootKeyID(rootKeyID uint64) ID

IDFromMacRootKeyID converts a macaroon root key ID to a session ID.

func IDFromMacaroon

func IDFromMacaroon(mac *macaroon.Macaroon) (ID, error)

IDFromMacaroon is a helper function that creates a session ID from a macaroon ID.

func NewSessionPrivKeyAndID

func NewSessionPrivKeyAndID() (*btcec.PrivateKey, ID, error)

NewSessionPrivKeyAndID randomly derives a new private key and session ID pair.

type IDToGroupIndex

type IDToGroupIndex interface {
	// GetGroupID will return the group ID for the given session ID.
	GetGroupID(sessionID ID) (ID, error)

	// GetSessionIDs will return the set of session IDs that are in the
	// group with the given ID.
	GetSessionIDs(groupID ID) ([]ID, error)
}

IDToGroupIndex defines an interface for the session ID to group ID index.

type MacaroonBaker

type MacaroonBaker func(ctx context.Context, rootKeyID uint64,
	recipe *MacaroonRecipe) (string, error)

MacaroonBaker is a function type for baking a super macaroon.

type MacaroonRecipe

type MacaroonRecipe struct {
	Permissions []bakery.Op
	Caveats     []macaroon.Caveat
}

MacaroonRecipe defines the permissions and caveats that should be used to bake a macaroon.

type Server

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

func NewServer

func NewServer(serverCreator GRPCServerCreator) *Server

func (*Server) StartSession

func (s *Server) StartSession(session *Session, authData []byte,
	onUpdate func(local, remote *btcec.PublicKey) error,
	onNewStatus func(s mailbox.ServerStatus)) (chan struct{}, error)

func (*Server) Stop

func (s *Server) Stop()

func (*Server) StopSession

func (s *Server) StopSession(localPublicKey *btcec.PublicKey) error

type Session

type Session struct {
	ID                ID
	Label             string
	State             State
	Type              Type
	Expiry            time.Time
	CreatedAt         time.Time
	RevokedAt         time.Time
	ServerAddr        string
	DevServer         bool
	MacaroonRootKey   uint64
	MacaroonRecipe    *MacaroonRecipe
	PairingSecret     [mailbox.NumPassphraseEntropyBytes]byte
	LocalPrivateKey   *btcec.PrivateKey
	LocalPublicKey    *btcec.PublicKey
	RemotePublicKey   *btcec.PublicKey
	FeatureConfig     *FeaturesConfig
	WithPrivacyMapper bool

	// GroupID is the Session ID of the very first Session in the linked
	// group of sessions. If this is the very first session in the group
	// then this will be the same as ID.
	GroupID ID
}

Session is a struct representing a long-term Terminal Connect session.

func DeserializeSession

func DeserializeSession(r io.Reader) (*Session, error)

DeserializeSession deserializes a session from the given reader, expecting the data to be encoded in the tlv format.

func NewSession

func NewSession(id ID, localPrivKey *btcec.PrivateKey, label string, typ Type,
	expiry time.Time, serverAddr string, devServer bool, perms []bakery.Op,
	caveats []macaroon.Caveat, featureConfig FeaturesConfig,
	privacy bool, linkedGroupID *ID) (*Session, error)

NewSession creates a new session with the given user-defined parameters.

type State

type State uint8

State represents the state of a session.

const (
	StateCreated State = 0
	StateInUse   State = 1
	StateRevoked State = 2
	StateExpired State = 3
)

type Store

type Store interface {
	// CreateSession adds a new session to the store. If a session with the
	// same local public key already exists an error is returned. This
	// can only be called with a Session with an ID that the Store has
	// reserved.
	CreateSession(*Session) error

	// GetSession fetches the session with the given key.
	GetSession(key *btcec.PublicKey) (*Session, error)

	// ListSessions returns all sessions currently known to the store.
	ListSessions(filterFn func(s *Session) bool) ([]*Session, error)

	// RevokeSession updates the state of the session with the given local
	// public key to be revoked.
	RevokeSession(*btcec.PublicKey) error

	// UpdateSessionRemotePubKey can be used to add the given remote pub key
	// to the session with the given local pub key.
	UpdateSessionRemotePubKey(localPubKey,
		remotePubKey *btcec.PublicKey) error

	// GetUnusedIDAndKeyPair can be used to generate a new, unused, local
	// private key and session ID pair. Care must be taken to ensure that no
	// other thread calls this before the returned ID and key pair from this
	// method are either used or discarded.
	GetUnusedIDAndKeyPair() (ID, *btcec.PrivateKey, error)

	// GetSessionByID fetches the session with the given ID.
	GetSessionByID(id ID) (*Session, error)

	// CheckSessionGroupPredicate iterates over all the sessions in a group
	// and checks if each one passes the given predicate function. True is
	// returned if each session passes.
	CheckSessionGroupPredicate(groupID ID,
		fn func(s *Session) bool) (bool, error)

	IDToGroupIndex
}

Store is the interface a persistent storage must implement for storing and retrieving Terminal Connect sessions.

type SuperMacaroonValidator

type SuperMacaroonValidator func(ctx context.Context,
	superMacaroon []byte, requiredPermissions []bakery.Op,
	fullMethod string) error

SuperMacaroonValidator is a function type for validating a super macaroon.

type Type

type Type uint8

Type represents the type of session.

const (
	TypeMacaroonReadonly Type = 0
	TypeMacaroonAdmin    Type = 1
	TypeMacaroonCustom   Type = 2
	TypeUIPassword       Type = 3
	TypeAutopilot        Type = 4
	TypeMacaroonAccount  Type = 5
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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