lime
Lime is a C++ library implementing Open Whisper System Signal protocol
|
Database access class. More...
Public Member Functions | |
Db ()=delete | |
Db (const std::string &filename, std::shared_ptr< std::recursive_mutex > db_mutex) | |
Open and check DB validity, create or update db schema is needed. More... | |
~Db () | |
void | load_LimeUser (const std::string &deviceId, long int &Uid, lime::CurveId &curveId, std::string &url, const bool allStatus=false) |
Check for existence, retrieve Uid for local user based on its userId (GRUU) and curve from table lime_LocalUsers. More... | |
void | delete_LimeUser (const std::string &deviceId) |
if exists, delete user More... | |
void | clean_DRSessions () |
Delete old stale sessions and old stored message key. Apply to all users in localStorage. More... | |
void | clean_SPk () |
Delete old stale SPk. Apply to all users in localStorage. More... | |
void | get_allLocalDevices (std::vector< std::string > &deviceIds) |
Get a list of deviceIds of all local users present in localStorage. More... | |
void | set_peerDeviceStatus (const std::string &peerDeviceId, const std::vector< uint8_t > &Ik, lime::PeerDeviceStatus status) |
set the peer device status flag in local storage: unsafe, trusted or untrusted. More... | |
void | set_peerDeviceStatus (const std::string &peerDeviceId, lime::PeerDeviceStatus status) |
lime::PeerDeviceStatus | get_peerDeviceStatus (const std::string &peerDeviceId) |
get the status of a peer device: unknown, untrusted, trusted, unsafe More... | |
bool | is_localUser (const std::string &deviceId) |
checks if a device Id exists in the local users table More... | |
void | delete_peerDevice (const std::string &peerDeviceId) |
delete a peerDevice from local storage More... | |
template<typename Curve > | |
long int | check_peerDevice (const std::string &peerDeviceId, const DSA< Curve, lime::DSAtype::publicKey > &peerIk, const bool updateInvalid=false) |
Check peer device information(DeviceId - GRUU -, public Ik, Uid to link it to a user) in local storage. More... | |
template<typename Curve > | |
long int | store_peerDevice (const std::string &peerDeviceId, const DSA< Curve, lime::DSAtype::publicKey > &peerIk) |
Store peer device information(DeviceId - GRUU -, public Ik, Uid to link it to a user) in local storage. More... | |
Public Attributes | |
soci::session | sql |
soci connexion to DB More... | |
std::shared_ptr< std::recursive_mutex > | m_db_mutex |
mutex on database access More... | |
Database access class.
relies on SOCI
|
delete |
lime::Db::Db | ( | const std::string & | filename, |
std::shared_ptr< std::recursive_mutex > | db_mutex | ||
) |
Open and check DB validity, create or update db schema is needed.
[in] | filename | The path to DB file |
[in] | db_mutex | database access mutex |
|
inline |
long int lime::Db::check_peerDevice | ( | const std::string & | peerDeviceId, |
const DSA< Curve, lime::DSAtype::publicKey > & | peerIk, | ||
const bool | updateInvalid = false |
||
) |
Check peer device information(DeviceId - GRUU -, public Ik, Uid to link it to a user) in local storage.
[in] | peerDeviceId | The device id to check |
[in] | peerIk | The public EDDSA identity key of this device |
[in] | updateInvalid | When true, will update the Ik with the given one if the stored one is lime:settings::DBInvalidIk and returns its id. |
BCTBX_EXCEPTION | if the device is found in local storage but with a different Ik (if Ik is lime::settings::DBInvalidIk, just pretend we never found the device) |
void lime::Db::clean_DRSessions | ( | ) |
Delete old stale sessions and old stored message key. Apply to all users in localStorage.
void lime::Db::clean_SPk | ( | ) |
Delete old stale SPk. Apply to all users in localStorage.
SPk in stale status for more than SPK_limboTime_days are deleted
void lime::Db::delete_LimeUser | ( | const std::string & | deviceId | ) |
if exists, delete user
[in] | deviceId | a string holding the user to look for in DB, shall be its GRUU |
void lime::Db::delete_peerDevice | ( | const std::string & | peerDeviceId | ) |
delete a peerDevice from local storage
[in] | peerDeviceId | The device Id to be removed from local storage, shall be its GRUU |
Call is silently ignored if the device is not found in local storage
void lime::Db::get_allLocalDevices | ( | std::vector< std::string > & | deviceIds | ) |
Get a list of deviceIds of all local users present in localStorage.
[out] | deviceIds | the list of all local users (their device Id) |
lime::PeerDeviceStatus lime::Db::get_peerDeviceStatus | ( | const std::string & | peerDeviceId | ) |
get the status of a peer device: unknown, untrusted, trusted, unsafe
[in] | peerDeviceId | The device Id of peer, shall be its GRUU |
bool lime::Db::is_localUser | ( | const std::string & | deviceId | ) |
checks if a device Id exists in the local users table
[in] | deviceId | The device Id |
void lime::Db::load_LimeUser | ( | const std::string & | deviceId, |
long int & | Uid, | ||
lime::CurveId & | curveId, | ||
std::string & | url, | ||
const bool | allStatus = false |
||
) |
Check for existence, retrieve Uid for local user based on its userId (GRUU) and curve from table lime_LocalUsers.
[in] | deviceId | a string holding the user to look for in DB, shall be its GRUU |
[out] | Uid | the DB internal Id matching given userId (if find in DB, 0 if not find, -1 if found but not active) |
[out] | curveId | the curve selected at user creation |
[out] | url | the url of the X3DH server this user is registered on |
[in] | allStatus | allow loading of inactive user if set to true(default is false) |
void lime::Db::set_peerDeviceStatus | ( | const std::string & | peerDeviceId, |
const std::vector< uint8_t > & | Ik, | ||
lime::PeerDeviceStatus | status | ||
) |
set the peer device status flag in local storage: unsafe, trusted or untrusted.
[in] | peerDeviceId | The device Id of peer, shall be its GRUU |
[in] | Ik | the EdDSA peer public identity key, formatted as in RFC8032 |
[in] | status | value of flag to set: accepted values are trusted, untrusted, unsafe |
BCTBX_EXCEPTION | if given key doesn't match the one present in local storage |
if the status flag value is unexpected (not one of trusted, untrusted, unsafe), ignore the call
if the status flag is unsafe or untrusted, ignore the value of Ik and call the version of this function without it
if peer Device is not present in local storage and status is trusted or unsafe, it is added, if status is untrusted, it is just ignored
General algorithm followed by the set_peerDeviceStatus functions
-status is unsafe
void lime::Db::set_peerDeviceStatus | ( | const std::string & | peerDeviceId, |
lime::PeerDeviceStatus | status | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Calls with status unsafe or untrusted are executed by this function as they do not need Ik.
long int lime::Db::store_peerDevice | ( | const std::string & | peerDeviceId, |
const DSA< Curve, lime::DSAtype::publicKey > & | peerIk | ||
) |
Store peer device information(DeviceId - GRUU -, public Ik, Uid to link it to a user) in local storage.
[in] | peerDeviceId | The device id to insert |
[in] | peerIk | The public EDDSA identity key of this device |
std::shared_ptr<std::recursive_mutex> lime::Db::m_db_mutex |
mutex on database access
soci::session lime::Db::sql |
soci connexion to DB