store

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package store is a local, at-rest-encrypted SQLite persistence layer for an Olvid client: the owned identity, contacts, oblivious-channel state, and the conversation history. Sensitive columns are encrypted with a passphrase- derived key (see crypto.go / STORAGE.md); lookup columns keep a blind index so equality queries still work. It is deliberately isolated so the crypto, server, and client packages stay pure-Go (this is the only package that pulls in a cgo SQLite driver).

Index

Constants

This section is empty.

Variables

View Source
var (
	ProfileInteractive = KDFProfile{Time: 2, Memory: 64 * 1024, Threads: 4}  // 64 MiB
	ProfileParanoid    = KDFProfile{Time: 3, Memory: 512 * 1024, Threads: 4} // 512 MiB
)

Preset profiles. Interactive is the default (snappy for a CLI that unlocks per invocation); Paranoid is opt-in for maximal hardening.

View Source
var ErrWrongPassphrase = fmt.Errorf("store: wrong passphrase")

ErrWrongPassphrase is returned by Open when the DEK cannot be unwrapped — the passphrase is wrong (or the keyring is corrupt).

Functions

This section is empty.

Types

type Contact

type Contact struct {
	Identity    []byte
	DisplayName string
	Trusted     bool
}

Contact is a stored contact.

type KDFProfile

type KDFProfile struct {
	Time    uint32
	Memory  uint32
	Threads uint8
}

KDFProfile holds the Argon2id cost parameters (memory in KiB).

type Message

type Message struct {
	ContactIdentity []byte
	Incoming        bool
	ServerUID       []byte
	Timestamp       int64
	Payload         []byte
	Body            string
}

Message is a stored conversation message.

type Store

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

Store is a handle to the local encrypted SQLite database.

func Open

func Open(path string, passphrase []byte, initProfile KDFProfile) (*Store, error)

Open opens (creating if needed) the encrypted database at path and unlocks it with passphrase. On a fresh database the keyring is initialized using initProfile (e.g. ProfileInteractive); on an existing one the stored profile is used and initProfile is ignored. Returns ErrWrongPassphrase if the passphrase does not unwrap the data key.

func (*Store) ChangePassphrase

func (s *Store) ChangePassphrase(newPassphrase []byte, profile KDFProfile) error

ChangePassphrase re-wraps the data key under a new passphrase (and profile), without re-encrypting any data. The store must already be unlocked.

func (*Store) Close

func (s *Store) Close() error

Close closes the database and best-effort zeroizes the in-memory key material.

func (*Store) DeleteChannel

func (s *Store) DeleteChannel(deviceUID []byte) error

DeleteChannel removes a persisted channel by device UID (so removing a contact frees its channel rows). Implements client.ChannelDeleter.

func (*Store) DeleteContact

func (s *Store) DeleteContact(identity []byte) error

DeleteContact removes a contact by identity. Implements client.ContactStore.

func (*Store) DeleteGroup

func (s *Store) DeleteGroup(groupUID []byte) error

DeleteGroup removes a group by UID. Implements client.GroupStore.

func (*Store) DeleteIntroduction added in v0.3.0

func (s *Store) DeleteIntroduction(instanceUID []byte) error

DeleteIntroduction removes a pending introduction by protocol instance UID. Implements client.IntroductionStore.

func (*Store) DeleteMeta

func (s *Store) DeleteMeta(key string) error

DeleteMeta removes any value stored under key (no error if absent).

func (*Store) GetMeta

func (s *Store) GetMeta(key string) ([]byte, bool, error)

GetMeta returns the value stored under key and whether it was present.

func (*Store) ListContacts

func (s *Store) ListContacts() ([]Contact, error)

ListContacts returns all contacts.

func (*Store) ListMessages

func (s *Store) ListMessages(contactIdentity []byte) ([]Message, error)

ListMessages returns the whole conversation with a contact, oldest first (nil = all contacts). WARNING: this loads the entire matching history into memory; for a long-lived client prefer ListRecentMessages with a limit. Kept for full export.

func (*Store) ListRecentMessages

func (s *Store) ListRecentMessages(contactIdentity []byte, limit int) ([]Message, error)

ListRecentMessages returns the most recent `limit` messages with a contact (nil = all contacts), oldest-first, bounding memory over a long history. limit <= 0 means no limit.

func (*Store) LoadChannels

func (s *Store) LoadChannels() (map[string]*engine.ObliviousChannel, error)

LoadChannels returns all persisted channels keyed by contact device UID (hex).

func (*Store) LoadChannelsInto

func (s *Store) LoadChannelsInto(add func(deviceUID, encoded []byte, ownDevice bool)) error

LoadChannelsInto invokes add for every persisted channel with its decrypted device UID, encoded state, and own-device flag. Implements client's channel-restore contract without coupling the two packages to a shared record type.

func (*Store) LoadContactBlobs

func (s *Store) LoadContactBlobs() ([][]byte, error)

LoadContactBlobs returns all persisted contact records. Implements client.ContactStore.

func (*Store) LoadGroupBlobs

func (s *Store) LoadGroupBlobs() ([][]byte, error)

LoadGroupBlobs returns all persisted group records. Implements client.GroupStore.

func (*Store) LoadIntroductions added in v0.3.0

func (s *Store) LoadIntroductions() ([][]byte, error)

LoadIntroductions returns all persisted pending introductions. Implements client.IntroductionStore.

func (*Store) LoadOwnedIdentity

func (s *Store) LoadOwnedIdentity() (*engine.OwnedCryptoIdentity, []byte, error)

LoadOwnedIdentity returns the stored owned identity + device UID, or (nil, nil, nil) if none has been saved yet.

func (*Store) MarkOwnDeviceChannel

func (s *Store) MarkOwnDeviceChannel(deviceUID []byte) error

MarkOwnDeviceChannel flags a persisted channel as one of the owned identity's own devices, so multi-device sync survives a restart. Implements client.OwnDeviceMarker.

func (*Store) SaveChannel

func (s *Store) SaveChannel(contactDeviceUID, encoded []byte) error

SaveChannel persists an oblivious channel's ratchet state (already encoded). Implements the client.ChannelStore interface. The state is encrypted at rest.

func (*Store) SaveChannelState

func (s *Store) SaveChannelState(contactDeviceUID []byte, ch *engine.ObliviousChannel) error

SaveChannelState is a convenience wrapper that encodes and saves a channel.

func (*Store) SaveContact

func (s *Store) SaveContact(identity []byte, displayName string, trusted bool) error

SaveContact inserts or updates a contact.

func (*Store) SaveContactBlob

func (s *Store) SaveContactBlob(identity, encoded []byte) error

SaveContactBlob upserts a contact's encoded record (client.Contact.Encode()), keyed by identity. Implements client.ContactStore.

func (*Store) SaveGroupBlob

func (s *Store) SaveGroupBlob(groupUID, encoded []byte) error

SaveGroupBlob upserts a group's encoded record, keyed by group UID. Implements client.GroupStore.

func (*Store) SaveIntroduction added in v0.3.0

func (s *Store) SaveIntroduction(instanceUID, encoded []byte) error

SaveIntroduction upserts a pending introduction, keyed by protocol instance UID. Implements client.IntroductionStore.

func (*Store) SaveMessage

func (s *Store) SaveMessage(contactIdentity []byte, incoming bool, serverUID []byte, timestamp int64, payload []byte, body string) error

SaveMessage appends a message to the conversation history (content encrypted at rest).

func (*Store) SaveOwnedIdentity

func (s *Store) SaveOwnedIdentity(owned *engine.OwnedCryptoIdentity, deviceUID []byte) error

SaveOwnedIdentity stores the single owned identity + device (the private keys are encrypted at rest).

func (*Store) SetMeta

func (s *Store) SetMeta(key string, value []byte) error

SetMeta stores an opaque value under key, private at rest: the key is kept only as a blind index (never in plaintext) and the value is encrypted. It overwrites any existing value. This is generic client-agnostic storage (e.g. the IRC gateway's nick registry).

func (*Store) SetTrusted

func (s *Store) SetTrusted(identity []byte, trusted bool) error

SetTrusted marks a contact identity as trusted (or not).

Jump to

Keyboard shortcuts

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