session

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const SessionTimeout = time.Hour

SessionTimeout is how long a session accepts Tocs and generates TOTPs, unless its ttl ends it sooner.

Variables

View Source
var ErrEmptyToc = errors.New("the provided Toc is empty")
View Source
var ErrInvalidKek = errors.New("the provided kek cannot decrypt the session's TEK")
View Source
var ErrInvalidTocSignature = errors.New("the Toc is not signed with its group key")
View Source
var ErrNotEnoughTocs = errors.New("the provided Tocs are less than the threshold")
View Source
var ErrSessionAlreadyExists = errors.New("a session with the requested ID already exists")
View Source
var ErrSessionExpired = errors.New("the session has expired")
View Source
var ErrSessionNotFound = errors.New("session not found")
View Source
var ErrTocAlreadyExists = errors.New("the provided Toc already exists")
View Source
var ErrTocIsNotEncrypted = errors.New("the provided Toc is not a valid age armored string")

Functions

This section is empty.

Types

type DDBGetItemApi

type DDBGetItemApi interface {
	GetItem(ctx context.Context, params *ddb.GetItemInput, optFns ...func(*ddb.Options)) (*ddb.GetItemOutput, error)
}

type DDBQueryApi

type DDBQueryApi interface {
	Query(ctx context.Context, params *ddb.QueryInput, optFns ...func(*ddb.Options)) (*ddb.QueryOutput, error)
}

type DDBTransactWriteItemsApi

type DDBTransactWriteItemsApi interface {
	TransactWriteItems(ctx context.Context, params *ddb.TransactWriteItemsInput, optFns ...func(*ddb.Options)) (*ddb.TransactWriteItemsOutput, error)
}

type DDBUpdateItemApi added in v0.4.0

type DDBUpdateItemApi interface {
	UpdateItem(ctx context.Context, params *ddb.UpdateItemInput, optFns ...func(*ddb.Options)) (*ddb.UpdateItemOutput, error)
}

type DynamoDbStore

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

func (*DynamoDbStore) AddEncryptedToc

func (d *DynamoDbStore) AddEncryptedToc(ctx context.Context, id string, encryptedToc string, expiresAt time.Time) error

AddEncryptedToc writes the Toc and increments the session's TocsProvided in one transaction, which fails if the session does not exist.

func (*DynamoDbStore) CreateSession

func (d *DynamoDbStore) CreateSession(ctx context.Context, session *api.Session, encryptedTEK []byte, encryptedTocZero string) error

func (*DynamoDbStore) GarbageCollect

func (d *DynamoDbStore) GarbageCollect(func(session *api.Session) bool)

GarbageCollect is a no-op: the table's TTL deletes expired items.

func (*DynamoDbStore) GetEncryptedTocs

func (d *DynamoDbStore) GetEncryptedTocs(ctx context.Context, id string) ([]string, error)

func (*DynamoDbStore) GetSession

func (d *DynamoDbStore) GetSession(ctx context.Context, id string) (*api.Session, error)

func (*DynamoDbStore) GetTEK

func (d *DynamoDbStore) GetTEK(ctx context.Context, id string) ([]byte, error)

func (*DynamoDbStore) UpdateExpiresAt added in v0.4.0

func (d *DynamoDbStore) UpdateExpiresAt(ctx context.Context, id string, expiresAt time.Time) error

type InMemoryStore

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

InMemoryStore simply stores session in the process memory. If HA or reliability in the event of failure is needed, this is clearly not a great option...

func (*InMemoryStore) AddEncryptedToc

func (i *InMemoryStore) AddEncryptedToc(_ context.Context, id string, encryptedToc string, _ time.Time) error

func (*InMemoryStore) CreateSession

func (i *InMemoryStore) CreateSession(_ context.Context, session *api.Session, encryptedTEK []byte, encryptedTocZero string) error

func (*InMemoryStore) GarbageCollect

func (i *InMemoryStore) GarbageCollect(shouldDelete func(session *api.Session) bool)

func (*InMemoryStore) GetEncryptedTocs

func (i *InMemoryStore) GetEncryptedTocs(_ context.Context, id string) ([]string, error)

func (*InMemoryStore) GetSession

func (i *InMemoryStore) GetSession(_ context.Context, id string) (*api.Session, error)

func (*InMemoryStore) GetTEK

func (i *InMemoryStore) GetTEK(_ context.Context, id string) ([]byte, error)

func (*InMemoryStore) UpdateExpiresAt added in v0.4.0

func (i *InMemoryStore) UpdateExpiresAt(_ context.Context, id string, expiresAt time.Time) error

type Oracle

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

func NewOracle

func NewOracle(store Store) *Oracle

func (*Oracle) AddToc

func (o *Oracle) AddToc(ctx context.Context, id string, encryptedToc string) error

func (*Oracle) CreateSession

func (o *Oracle) CreateSession(ctx context.Context, req *api.NewSession) (*api.SessionCredentials, error)

func (*Oracle) GenerateTOTP

func (o *Oracle) GenerateTOTP(ctx context.Context, id string, key *api.SessionKeyEncryptionKey) (*api.TOTPCode, error)

func (*Oracle) GetSession

func (o *Oracle) GetSession(ctx context.Context, id string) (*api.Session, error)

type Store

type Store interface {
	// CreateSession is used to persist a new session.
	// It may return ErrSessionAlreadyExists if the ID in session has been already used
	CreateSession(ctx context.Context, session *api.Session, encryptedTEK []byte, encryptedTocZero string) error

	// GetSession retrieves a session by its ID.
	// ErrSessionNotFound may be returned if the provided ID does not exist.
	GetSession(ctx context.Context, id string) (*api.Session, error)

	// UpdateExpiresAt changes when the session expires.
	UpdateExpiresAt(ctx context.Context, id string, expiresAt time.Time) error

	// AddEncryptedToc is used to append a Toc to an existing session.
	// It may return ErrTocAlreadyExists if the provided value has already been seen
	// ErrSessionNotFound may also be returned.
	// expiresAt lets stores with native expiry (e.g. DynamoDB TTL) drop the Toc along with its session.
	AddEncryptedToc(ctx context.Context, id string, encryptedToc string, expiresAt time.Time) error

	// GetEncryptedTocs returns a slice of strings with the encrypted Tocs
	GetEncryptedTocs(ctx context.Context, id string) ([]string, error)

	// GetTEK is used to retrieve the Toc encryption key
	GetTEK(ctx context.Context, id string) ([]byte, error)

	// GarbageCollect should process all sessions by sending them to the shouldDelete func;
	// if it returns true, remove the given session from storage
	GarbageCollect(shouldDelete func(session *api.Session) bool)
}

Store is used to keep track of Sessions, and their Tocs ErrSessionNotFound may be returned by any method where a session is referenced by ID. ctx carries the request's deadline to stores that do I/O.

func NewDynamoDbStore

func NewDynamoDbStore(client DDBClient, table string) Store

func NewInMemoryStore

func NewInMemoryStore() Store

Jump to

Keyboard shortcuts

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