Loading...
Searching...
No Matches
lime_localStorage.hpp
Go to the documentation of this file.
/*
lime_localStorage.hpp
@author Johan Pascal
@copyright Copyright (C) 2017 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef lime_localStorage_hpp
#define lime_localStorage_hpp
#include "soci/soci.h"
#include "lime_crypto_primitives.hpp"
#include <mutex>
namespace lime {
class Db {
public:
soci::session sql;
std::shared_ptr<std::recursive_mutex> m_db_mutex;
Db()=delete; // we can't create a new DB holder without DB filename
Db(const std::string &filename, std::shared_ptr<std::recursive_mutex> db_mutex);
~Db(){sql.close();};
void load_LimeUser(const std::string &deviceId, long int &Uid, lime::CurveId &curveId, std::string &url, const bool allStatus=false);
void delete_LimeUser(const std::string &deviceId);
void clean_DRSessions();
void clean_SPk();
bool is_updateRequested(const std::string &deviceId);
void set_updateTs(const std::string &deviceId);
void set_peerDeviceStatus(const std::string &peerDeviceId, const std::vector<uint8_t> &Ik, lime::PeerDeviceStatus status);
void set_peerDeviceStatus(const std::string &peerDeviceId, lime::PeerDeviceStatus status);
lime::PeerDeviceStatus get_peerDeviceStatus(const std::string &peerDeviceId);
lime::PeerDeviceStatus get_peerDeviceStatus(const std::list<std::string> &peerDeviceIds);
bool is_localUser(const std::string &deviceId);
void delete_peerDevice(const std::string &peerDeviceId);
template <typename Curve>
long int check_peerDevice(const std::string &peerDeviceId, const DSA<Curve, lime::DSAtype::publicKey> &peerIk, const bool updateInvalid=false);
template <typename Curve>
long int store_peerDevice(const std::string &peerDeviceId, const DSA<Curve, lime::DSAtype::publicKey> &peerIk);
void start_transaction();
void commit_transaction();
void rollback_transaction();
};
/* this templates are instanciated once in the lime_localStorage.cpp file, explicitly tell anyone including this header that there is no need to re-instanciate them */
#ifdef EC25519_ENABLED
extern template long int Db::check_peerDevice<C255>(const std::string &peerDeviceId, const DSA<C255, lime::DSAtype::publicKey> &Ik, const bool updateInvalid);
extern template long int Db::store_peerDevice<C255>(const std::string &peerDeviceId, const DSA<C255, lime::DSAtype::publicKey> &Ik);
#endif
#ifdef EC448_ENABLED
extern template long int Db::check_peerDevice<C448>(const std::string &peerDeviceId, const DSA<C448, lime::DSAtype::publicKey> &Ik, const bool updateInvalid);
extern template long int Db::store_peerDevice<C448>(const std::string &peerDeviceId, const DSA<C448, lime::DSAtype::publicKey> &Ik);
#endif
}
#endif /* lime_localStorage_hpp */
lime::DSA
Base buffer definition for DSA data structure.
Definition lime_crypto_primitives.hpp:97
lime::Db::store_peerDevice
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 storag...
Definition lime_localStorage.cpp:669
lime::Db::clean_SPk
void clean_SPk()
Delete old stale SPk. Apply to all users in localStorage.
Definition lime_localStorage.cpp:299
lime::Db::clean_DRSessions
void clean_DRSessions()
Delete old stale sessions and old stored message key. Apply to all users in localStorage.
Definition lime_localStorage.cpp:284
lime::Db::set_peerDeviceStatus
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.
Definition lime_localStorage.cpp:339
lime::Db::Db
Db()=delete
lime::Db::is_localUser
bool is_localUser(const std::string &deviceId)
checks if a device Id exists in the local users table
Definition lime_localStorage.cpp:553
lime::Db::sql
soci::session sql
soci connexion to DB
Definition lime_localStorage.hpp:37
lime::Db::delete_peerDevice
void delete_peerDevice(const std::string &peerDeviceId)
delete a peerDevice from local storage
Definition lime_localStorage.cpp:594
lime::Db::commit_transaction
void commit_transaction()
commit a transaction on this Db
Definition lime_localStorage.cpp:717
lime::Db::is_updateRequested
bool is_updateRequested(const std::string &deviceId)
checks if a device needs to be updated return true if the device exists and updateTs is older than OP...
Definition lime_localStorage.cpp:568
lime::Db::m_db_mutex
std::shared_ptr< std::recursive_mutex > m_db_mutex
mutex on database access
Definition lime_localStorage.hpp:39
lime::Db::delete_LimeUser
void delete_LimeUser(const std::string &deviceId)
if exists, delete user
Definition lime_localStorage.cpp:698
lime::Db::start_transaction
void start_transaction()
start a transaction on this Db
Definition lime_localStorage.cpp:708
lime::Db::load_LimeUser
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...
Definition lime_localStorage.cpp:238
lime::Db::check_peerDevice
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 storag...
Definition lime_localStorage.cpp:611
lime::Db::rollback_transaction
void rollback_transaction()
rollback a transaction on this Db
Definition lime_localStorage.cpp:726
lime::Db::get_peerDeviceStatus
lime::PeerDeviceStatus get_peerDeviceStatus(const std::string &peerDeviceId)
get the status of a peer device: unknown, untrusted, trusted, unsafe device's Id matching a local acc...
Definition lime_localStorage.cpp:445
lime::Db::~Db
~Db()
Definition lime_localStorage.hpp:50
lime::Db::set_updateTs
void set_updateTs(const std::string &deviceId)
update the update timestamp to now()
Definition lime_localStorage.cpp:581
lime_crypto_primitives.hpp
lime
Definition lime.cpp:30
lime::CurveId
CurveId
Definition lime.hpp:35
lime::PeerDeviceStatus
PeerDeviceStatus
Definition lime.hpp:54