Skip to content

Conversation

@Doy-lee
Copy link
Contributor

@Doy-lee Doy-lee commented Jan 8, 2026

This introduces SQLCipher, building on from https://github.com/mpretty-cyro/libsession-util/tree/feature/initial-database# The database is exposed under the session::database::Connection interface and we also in addition to that introduce a overarching managing class dubbed session::core::Core that manages requests going into the database, caching queries before insertion and returning results from caches instead of the DB if it hasn't been invalidated yet.

The intended usage pattern of the new code looks something like this:

  #include <sodium/randombytes.h>
  #include <session/core.hpp>

  int main() {
    session::core::Core core = {};

    // Optionally create/open the DB to persist state to. If this step is skipped the core will only
    // maintain libsession state (like the user's long term seed or the pro revocation list) in
    // runtime memory and will be lost on shutdown. Persisting user state is then left to the
    // integrating application's discretion.
    try {
      // Generate the encryption key for the DB (if you had a pre-existing DB this is where you
      // would load the key to pass in).
      session::cleared_array<48> db_enc_key = {};
      randombytes_buf(db_enc_key.data(), db_enc_key.size());

      core.open_db(":memory:", db_enc_key);
    } catch (const std::exception& e) {
      // ... error handling
    }

    // Update the revocation list stored in Core (if the DB was opened successfully, this will also
    // persist the revocation list to the DB for example).
    //
    // In a production application you would sleep on an event loop responsible for dispatching and
    // receiving the revocation list queries and call this function to update the revocation list
    // that is cached and the DB
    if (core.pro_update_revocations(...)) { ... }

    // Interfacing code calls this API to check if the specific proof in question is revoked or not
    if (core.pro_proof_is_revoked(...)) { ... }
  }

Doy-lee and others added 29 commits January 5, 2026 11:14
Pre-empting the idea that libsession should start managing state on
behalf of the caller by first having a runtime cache of the Session Pro
revocation list that backs up to the DB on update.
Alongside upgrading from 4.6.1 to 4.12 there are a few new changes to
some of the conventions followed by SQLCipher which are summarised as follows:

- SQLCipher now generates a libsqlite3.a instead of libsqlcipher.a
- The include directory mirrors sqlite3 layout so #include
  <sqlcipher/sqlite3.h> turns into #include <sqlite3.h>
- tcl is no longer required as a dependency which was previously used to
  create the amalgamated SQLite source file (they now have an internal
  tool jimsh0 to create this if tcl's missing).
- Some SQLCipher ./configure options are updated
  - --with-pic does not exist anymore
  - --enable-fts5 was updated to --fts5
  - --with-tempstore=3 (or =always) was added
- -DSQLITE_EXTRA_INIT=sqlcipher_extra_init and
  -DSQLITE_EXTRA_SHUTDOWN=sqlcipher_extra_shutdown are new defines that must be
  set
…vided by libsession

Initially these changes were stored as a separate database library and
it was tempting to put everything into the crypto library but from the
architecture aspect this didn't seem right. The crypto library contains all the
low-level primitives to talk on the Session Protocol.

These new changes include a database and a manager for libsession state
which exclusively uses the primitives and tooling provided by libsession
that merging it into the low-level cryptography didn't seem right. In
essence this is more the service layer that provides, _additional_ services for
applications to use to book-keep the libsession state such as

- persistent storage, i.e. the database
- caching of the runtime state of libsession i.e. the core
@Doy-lee Doy-lee force-pushed the doyle-pro-with-sqlite branch from 628d31e to 7efbb76 Compare January 9, 2026 05:36
@Doy-lee Doy-lee force-pushed the doyle-pro-with-sqlite branch 2 times, most recently from efe9c66 to a3064d3 Compare January 13, 2026 06:59
@Doy-lee Doy-lee force-pushed the doyle-pro-with-sqlite branch from a3064d3 to 64a9894 Compare January 13, 2026 07:07
@Doy-lee Doy-lee force-pushed the doyle-pro-with-sqlite branch from a35144e to ea1ddb7 Compare January 13, 2026 08:54
@Doy-lee Doy-lee force-pushed the doyle-pro-with-sqlite branch from ea1ddb7 to 15e824d Compare January 13, 2026 09:16
…oid builds

Whilst we can use the new android targets for the ./Configure tool that
openssl has, this has issues in that it doesn't support the clang NDK
toolchain, it still defaults to gcc and there doesn't seem to be a way to
override this without setting CC/AR/CXX/RANLIB e.t.c.

Oxen-core can statically build openssl already without issues so we're
going to revert back to what it's doing and KISS.
@Doy-lee Doy-lee force-pushed the doyle-pro-with-sqlite branch from 9b41cad to 5871b2c Compare January 14, 2026 04:11
@Doy-lee Doy-lee force-pushed the doyle-pro-with-sqlite branch 2 times, most recently from b3b4484 to 3be2126 Compare January 14, 2026 06:28
@Doy-lee Doy-lee force-pushed the doyle-pro-with-sqlite branch from 3be2126 to 8673e75 Compare January 14, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants