Documentation ¶
Index ¶
- Constants
- Variables
- func IsSuperMacaroon(macHex string) bool
- func NewSuperMacaroonRootKeyID(id [4]byte) uint64
- func ParseMacaroon(macHex string) (*macaroon.Macaroon, error)
- func RootKeyIDFromMacaroon(mac *macaroon.Macaroon) (uint64, error)
- func SerializeSession(w io.Writer, session *Session) error
- func UseLogger(logger btclog.Logger)
- type DB
- func (db *DB) CheckSessionGroupPredicate(groupID ID, fn func(s *Session) bool) (bool, error)
- func (db *DB) CreateSession(session *Session) error
- func (db *DB) GetGroupID(sessionID ID) (ID, error)
- func (db *DB) GetSession(key *btcec.PublicKey) (*Session, error)
- func (db *DB) GetSessionByID(id ID) (*Session, error)
- func (db *DB) GetSessionIDs(groupID ID) ([]ID, error)
- func (db *DB) GetUnusedIDAndKeyPair() (ID, *btcec.PrivateKey, error)
- func (db *DB) ListSessions(filterFn func(s *Session) bool) ([]*Session, error)
- func (db *DB) RevokeSession(key *btcec.PublicKey) error
- func (db *DB) UpdateSessionRemotePubKey(localPubKey, remotePubKey *btcec.PublicKey) error
- type FeaturesConfig
- type GRPCServerCreator
- type ID
- type IDToGroupIndex
- type MacaroonBaker
- type MacaroonRecipe
- type PrivacyFlag
- type PrivacyFlags
- type Server
- type Session
- type State
- type Store
- type SuperMacaroonValidator
- type Type
Constants ¶
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 )
const Subsystem = "SESS"
Variables ¶
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") )
var ( // ErrDBReversion is returned when detecting an attempt to revert to a // prior database version. ErrDBReversion = errors.New("cannot revert to prior version") )
var ErrUnknownPrivacyFlag = errors.New("unknown privacy flag")
ErrUnknownPrivacyFlag is an error that is returned when an unknown privacy flag is used.
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 ¶
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 ¶
NewSuperMacaroonRootKeyID returns a new macaroon root key ID that has the prefix to mark it as a super macaroon root key.
func ParseMacaroon ¶
ParseMacaroon parses a hex encoded macaroon into its native struct.
func RootKeyIDFromMacaroon ¶
RootKeyIDFromMacaroon extracts the root key ID of the passed macaroon.
func SerializeSession ¶
SerializeSession binary serializes the given session to the writer using the tlv format.
Types ¶
type DB ¶
DB is a bolt-backed persistent store.
func (*DB) CheckSessionGroupPredicate ¶
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 ¶
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 ¶
GetGroupID will return the group ID for the given session ID.
NOTE: this is part of the IDToGroupIndex interface.
func (*DB) GetSession ¶
GetSession fetches the session with the given key.
NOTE: this is part of the Store interface.
func (*DB) GetSessionByID ¶
GetSessionByID fetches the session with the given ID.
NOTE: this is part of the Store interface.
func (*DB) GetSessionIDs ¶
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 ¶
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 ¶
ListSessions returns all sessions currently known to the store.
NOTE: this is part of the Store interface.
func (*DB) RevokeSession ¶
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 ¶
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 ¶
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 ¶
IDFromBytes is a helper function that creates a session ID from a byte slice.
func IDFromMacRootKeyID ¶
IDFromMacRootKeyID converts a macaroon root key ID to a session ID.
func IDFromMacaroon ¶
IDFromMacaroon is a helper function that creates a session ID from a macaroon ID.
func NewSessionPrivKeyAndID ¶
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 ¶
MacaroonRecipe defines the permissions and caveats that should be used to bake a macaroon.
type PrivacyFlag ¶
type PrivacyFlag uint64
PrivacyFlag is an enum representing privacy flags for obfuscation behavior of feature configuration, feature rules and API calls. Privacy is on by default, by setting a privacy flag one can disable certain obfuscation behavior.
const ( // ClearPubkeys is a privacy flag that indicates that the public node // ids in API should be treated as clear text. ClearPubkeys PrivacyFlag = 0 // ClearAmounts is a privacy flag that indicates that the amounts in the // API should not be obfuscated. ClearAmounts PrivacyFlag = 1 // ClearChanIDs is a privacy flag that indicates that the channel id and // channel points in API should not be obfuscated. ClearChanIDs PrivacyFlag = 2 // ClearTimeStamps is a privacy flag that indicates that the timestamps // in the API should not be obfuscated. ClearTimeStamps PrivacyFlag = 3 // ClearChanInitiator is a privacy flag that indicates that the channel // initiator in the API should not be obfuscated. ClearChanInitiator PrivacyFlag = 4 // ClearHTLCs is a privacy flag that indicates that the HTLCs in the API // should not be obfuscated. ClearHTLCs PrivacyFlag = 5 // ClearClosingTxIds is a privacy flag that indicates that the channel // closing transaction ids in the API should not be obfuscated. ClearClosingTxIds PrivacyFlag = 6 // ClearNetworkAddresses is a privacy flag that indicates that the // network addresses in the API should not be obfuscated. ClearNetworkAddresses PrivacyFlag = 7 )
func (PrivacyFlag) String ¶
func (f PrivacyFlag) String() string
String returns a string representation of the privacy flag.
func (PrivacyFlag) Validate ¶
func (f PrivacyFlag) Validate() error
Validate returns an error if a privacy flag is unknown.
type PrivacyFlags ¶
type PrivacyFlags []PrivacyFlag
PrivacyFlags is a struct representing a set of privacy flags.
func Deserialize ¶
func Deserialize(serialized uint64) (PrivacyFlags, error)
Deserialize returns a PrivacyFlags struct from a serialized representation.
func Parse ¶
func Parse(flags string) (PrivacyFlags, error)
Parse constructs privacy flags from its string representation.
func (PrivacyFlags) Add ¶
func (f PrivacyFlags) Add(other PrivacyFlags) PrivacyFlags
Add adds a set of privacy flags to another set.
func (PrivacyFlags) Contains ¶
func (f PrivacyFlags) Contains(other PrivacyFlag) bool
Contains checks if a privacy flag is contained in the set.
func (PrivacyFlags) Equal ¶
func (f PrivacyFlags) Equal(other PrivacyFlags) bool
Equal checks if two sets of privacy flags are equal.
func (PrivacyFlags) Serialize ¶
func (f PrivacyFlags) Serialize() uint64
Serialize returns a serialized representation of the privacy flags.
func (PrivacyFlags) String ¶
func (f PrivacyFlags) String() string
String returns a string representation of the privacy flags.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(serverCreator GRPCServerCreator) *Server
func (*Server) StartSession ¶
func (*Server) StopSession ¶
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 PrivacyFlags PrivacyFlags // 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 ¶
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, flags PrivacyFlags) (*Session, error)
NewSession creates a new session with the given user-defined parameters.
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.