safe

package
v0.0.0-...-c70c80c Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserGroup                   GroupName = "usr"
	AdminGroup                  GroupName = "adm"
	ErrGroupChangeSignature               = "errGroupChangeSignature: invalid signature for group change"
	ErrGroupChangeAuthorization           = "errGroupChangeAuthorization: user has no Admin rights"
	CompactThreshold                      = 32
)
View Source
const (
	KeysDir = "keys"
	KeyNode = "keys"
)
View Source
const GroupChainNode = "GroupChain"
View Source
const GroupDir = "groups"
View Source
const GuardNode = "guard"

Variables

View Source
var GroupChangeFileSize int64 = 1024 * 1024 * 128

Functions

func DelConfigs

func DelConfigs(db sql.DB, node string) error

func GetConfig

func GetConfig(db sql.DB, node string, key string) (s string, i int64, v []byte, ok bool)

func GetConfigStruct

func GetConfigStruct(db sql.DB, node string, key string, v interface{}) error

func SetConfig

func SetConfig(db sql.DB, node string, key string, s string, i int64, v []byte) error

func SetConfigStruct

func SetConfigStruct(db sql.DB, node string, key string, v interface{}) error

Types

type CDN

type CDN struct {
	Store storage.Store
	Quota int64
}

type Change

type Change uint64
const (
	ChangeGrant   Change = iota // ChangeGrant grants access to a group
	ChangeRevoke                // ChangeRevoke revokes access to a group
	ChangeCurse                 // ChangeCurse revokes access to all groups and invalidate all changes done by the user
	ChangeEndorse               // ChangeEndorse endorses the validity of the group chain

	ChangeCheckFreq = 8
)

type Endorsers

type Endorsers core.Set[security.UserId]

type FS

type FS struct {
	S        *Safe
	StoreUrl string
	Quota    int64
}

func OpenFS

func OpenFS(c *Safe) (*FS, error)

type GroupChain

type GroupChain struct {
	Changes []GroupChange
	Groups  Groups
	Hash    []byte
}

type GroupChange

type GroupChange struct {
	GroupName GroupName       `msgpack:"g"`
	UserId    security.UserId `msgpack:"u"`
	Change    Change          `msgpack:"c"`
	Timestamp int64           `msgpack:"t"`
	Signer    security.UserId `msgpack:"k"`
	Signature []byte          `msgpack:"s"`
}

type GroupChangeFile

type GroupChangeFile struct {
	Id   uint64
	Size int64
}

type GroupName

type GroupName string

type Groups

type Groups map[GroupName]core.Set[security.UserId]

func (Groups) ToString

func (g Groups) ToString() string

type Key

type Key []byte

type KeyData

type KeyData struct {
	Keys map[uint64]Key
}

type Keystore

type Keystore struct {
	MasterKey map[security.UserId]Key
	DataKeys  []byte
	Signature []byte
	Signer    security.UserId
}

type Safe

type Safe struct {
	Id          int
	Db          sql.DB
	Store       storage.Store
	CreatorId   security.UserId
	CurrentUser security.Identity
	Lock        sync.RWMutex
}

func CopySafe

func CopySafe(c *Safe) *Safe

func NewSafe

func NewSafe(dbUrl, storeUrl string, creatorId security.UserId, currentUser security.Identity) (*Safe, error)

func NewTestSafe

func NewTestSafe(t *testing.T, creatorId security.UserId, currentUser security.Identity, storeId string, persistent bool) *Safe

func (*Safe) GetGroups

func (s *Safe) GetGroups() (Groups, error)

func (*Safe) GetKeys

func (s *Safe) GetKeys(groupName GroupName, expectedMinLength int) ([]Key, error)

GetKeys returns the encryption keys for the given group. If the user is not authorized to access the keys, it returns a AuthErr. The parameter expectedMinLength is used to check if the number of keys is at least the expected value. If it is 0, the check is skipped.

func (*Safe) UpdateGroup

func (s *Safe) UpdateGroup(groupName GroupName, change Change, users ...security.UserId) (Groups, error)

Jump to

Keyboard shortcuts

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