Documentation
¶
Index ¶
- Constants
- Variables
- type DDBClient
- type DDBGetItemApi
- type DDBQueryApi
- type DDBTransactWriteItemsApi
- type DDBUpdateItemApi
- type DynamoDbStore
- func (d *DynamoDbStore) AddEncryptedToc(ctx context.Context, id string, encryptedToc string, expiresAt time.Time) error
- func (d *DynamoDbStore) CreateSession(ctx context.Context, session *api.Session, encryptedTEK []byte, ...) error
- func (d *DynamoDbStore) GarbageCollect(func(session *api.Session) bool)
- func (d *DynamoDbStore) GetEncryptedTocs(ctx context.Context, id string) ([]string, error)
- func (d *DynamoDbStore) GetSession(ctx context.Context, id string) (*api.Session, error)
- func (d *DynamoDbStore) GetTEK(ctx context.Context, id string) ([]byte, error)
- func (d *DynamoDbStore) UpdateExpiresAt(ctx context.Context, id string, expiresAt time.Time) error
- type InMemoryStore
- func (i *InMemoryStore) AddEncryptedToc(_ context.Context, id string, encryptedToc string, _ time.Time) error
- func (i *InMemoryStore) CreateSession(_ context.Context, session *api.Session, encryptedTEK []byte, ...) error
- func (i *InMemoryStore) GarbageCollect(shouldDelete func(session *api.Session) bool)
- func (i *InMemoryStore) GetEncryptedTocs(_ context.Context, id string) ([]string, error)
- func (i *InMemoryStore) GetSession(_ context.Context, id string) (*api.Session, error)
- func (i *InMemoryStore) GetTEK(_ context.Context, id string) ([]byte, error)
- func (i *InMemoryStore) UpdateExpiresAt(_ context.Context, id string, expiresAt time.Time) error
- type Oracle
- func (o *Oracle) AddToc(ctx context.Context, id string, encryptedToc string) error
- func (o *Oracle) CreateSession(ctx context.Context, req *api.NewSession) (*api.SessionCredentials, error)
- func (o *Oracle) GenerateTOTP(ctx context.Context, id string, key *api.SessionKeyEncryptionKey) (*api.TOTPCode, error)
- func (o *Oracle) GetSession(ctx context.Context, id string) (*api.Session, error)
- type Store
Constants ¶
const SessionTimeout = time.Hour
SessionTimeout is how long a session accepts Tocs and generates TOTPs, unless its ttl ends it sooner.
Variables ¶
var ErrEmptyToc = errors.New("the provided Toc is empty")
var ErrInvalidKek = errors.New("the provided kek cannot decrypt the session's TEK")
var ErrInvalidTocSignature = errors.New("the Toc is not signed with its group key")
var ErrNotEnoughTocs = errors.New("the provided Tocs are less than the threshold")
var ErrSessionAlreadyExists = errors.New("a session with the requested ID already exists")
var ErrSessionExpired = errors.New("the session has expired")
var ErrSessionNotFound = errors.New("session not found")
var ErrTocAlreadyExists = errors.New("the provided Toc already exists")
var ErrTocIsNotEncrypted = errors.New("the provided Toc is not a valid age armored string")
Functions ¶
This section is empty.
Types ¶
type DDBClient ¶
type DDBClient interface {
DDBGetItemApi
DDBQueryApi
DDBUpdateItemApi
DDBTransactWriteItemsApi
}
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 (*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 (*DynamoDbStore) GetSession ¶
func (*DynamoDbStore) UpdateExpiresAt ¶ added in v0.4.0
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 (*InMemoryStore) CreateSession ¶
func (*InMemoryStore) GarbageCollect ¶
func (i *InMemoryStore) GarbageCollect(shouldDelete func(session *api.Session) bool)
func (*InMemoryStore) GetEncryptedTocs ¶
func (*InMemoryStore) GetSession ¶
func (*InMemoryStore) UpdateExpiresAt ¶ added in v0.4.0
type Oracle ¶
type Oracle struct {
// contains filtered or unexported fields
}
func (*Oracle) CreateSession ¶
func (o *Oracle) CreateSession(ctx context.Context, req *api.NewSession) (*api.SessionCredentials, error)
func (*Oracle) GenerateTOTP ¶
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 NewInMemoryStore ¶
func NewInMemoryStore() Store