session

package
v0.6.4-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: MIT Imports: 27 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 (

	// 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 (

	// 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")
)
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 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) ListSessions

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

ListSessions returns all sessions currently known to the store.

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.

func (*DB) StoreSession

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

StoreSession stores a session in the store. If a session with the same local public key already exists, the existing record is updated/ overwritten instead.

type GRPCServerCreator

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

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) (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 {
	Label           string
	State           State
	Type            Type
	Expiry          time.Time
	ServerAddr      string
	DevServer       bool
	MacaroonRootKey uint64
	MacaroonRecipe  *MacaroonRecipe
	PairingSecret   [mailbox.NumPasswordBytes]byte
	LocalPrivateKey *btcec.PrivateKey
	LocalPublicKey  *btcec.PublicKey
	RemotePublicKey *btcec.PublicKey
}

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(label string, typ Type, expiry time.Time, serverAddr string,
	devServer bool, perms []bakery.Op, caveats []macaroon.Caveat) (*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 {
	// StoreSession stores a session in the store. If a session with the
	// same local public key already exists, the existing record is updated/
	// overwritten instead.
	StoreSession(*Session) error

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

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

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
)

Jump to

Keyboard shortcuts

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