A Device Bound Session Credentials (DBSC) library and example server
- DBSC session creation / registration / refresh protocol
- ES256, RS256 JWT proof signature verification (OpenSSL)
- Session stores: memory, SQLite, Redis, ODBC (MySQL, PostgreSQL, MSSQL, etc.)
- mongoose-based HTTPS server wrapper
- Doxygen documentation support
The following packages must be installed before building.
# Debian/Ubuntu
sudo apt update
sudo apt install build-essential cmake pkg-config libssl-dev libsqlite3-dev
# RHEL/CentOS/Fedora
sudo dnf install gcc cmake pkgconfig openssl-devel sqlite-develCloned directly into libs/.
mkdir -p libs
git clone https://github.com/redis/hiredis.git libs/hiredis
git clone https://github.com/cesanta/mongoose.git libs/mongooseFetched automatically at build time.
cd opendbsc
cmake -B build
cmake --build build -j4Build outputs:
build/libopendbsc.a: static librarybuild/server: example HTTPS server
The example server requires a TLS certificate and private key at cert/cert.pem and cert/key.pem relative to the working directory. Do not commit certificates to git. Generate them locally:
mkdir -p cert
openssl req -x509 -newkey rsa:2048 -keyout cert/key.pem -out cert/cert.pem -sha256 -days 7 -nodes -subj "/CN=localhost"# Install mkcert first, then:
mkdir -p cert
mkcert -cert-file cert/cert.pem -key-file cert/key.pem localhost 127.0.0.1 ::1# Memory backend
./build/server memory
# SQLite backend
./build/server sqlite
# Redis backend (requires redis-server)
./build/server redis
# ODBC backend (requires an ODBC driver manager such as unixODBC or iODBC,
# plus a driver for your RDBMS). The connection string comes from the second
# argument or the DBSC_ODBC_CONN environment variable.
./build/server odbc 'DRIVER={MySQL ODBC 8.0 Driver};SERVER=localhost;PORT=3306;DATABASE=dbsc;USER=dbsc;PASSWORD=secret'
DBSC_ODBC_CONN='DRIVER={PostgreSQL Unicode};SERVER=localhost;PORT=5432;DATABASE=dbsc;UID=dbsc;PWD=secret' ./build/server odbcThe default address is https://0.0.0.0:8447.
The ODBC backend is enabled by default when CMake finds an ODBC driver
manager (-DOPENDBSC_WITH_ODBC=OFF disables it). On Debian/Ubuntu install
unixodbc-dev plus the driver for your database (e.g. odbc-postgresql or
the MySQL ODBC driver).
The schema is created automatically on a best-effort basis
(auto_create_table). To create it manually:
CREATE TABLE sessions (
id VARCHAR(64) PRIMARY KEY,
user_id VARCHAR(255) NOT NULL,
state VARCHAR(16) NOT NULL DEFAULT 'active',
public_key TEXT,
algorithm VARCHAR(64),
challenge TEXT,
expires_at VARCHAR(32),
created_at VARCHAR(32) NOT NULL
);
CREATE INDEX idx_sessions_user_id ON sessions(user_id);
CREATE INDEX idx_sessions_expires_at ON sessions(expires_at);| Method | Path | Description |
|---|---|---|
GET |
/ |
Static page (examples/static/index.html) |
POST |
/login |
Form-based login (username, password) |
POST |
/dbsc/register |
DBSC registration (Secure-Session-Response) |
POST |
/dbsc/refresh |
DBSC refresh (Sec-Secure-Session-Id, Secure-Session-Response) |
GET |
/api/status |
Server status |
GET |
/api/me |
Current session info |
GET |
/api/events |
Event log |
opendbsc/
├── include/ # Public headers
├── src/
│ ├── algo/ # UUID/challenge utilities
│ ├── protocol/ # header, instruction, jwt
│ ├── session/ # Session model
│ ├── store/ # memory/sqlite/redis/odbc store
│ ├── manager/ # DBSC manager
│ └── wrapper/ # mongoose HTTP wrapper
├── examples/ # Example server and static files
├── libs/ # Vendored dependencies (hiredis, mongoose)
├── cert/ # TLS certificates (generated locally, gitignore)
├── build/ # Build output (gitignore)
└── CMakeLists.txt
If Doxygen is installed:
doxygen DoxyfileGenerated documentation can be viewed at docs/html/index.html.
This project is distributed under the MIT License. See LICENSE for details. Vendored third-party libraries retain their own licenses.