Loading...
Searching...
No Matches
lime_lime.hpp
Go to the documentation of this file.
/*
lime_lime.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_lime_hpp
#define lime_lime_hpp
#include <memory> // unique_ptr
#include <unordered_map>
#include <vector>
#include <mutex>
namespace lime {
class LimeGeneric {
public:
// Encrypt/Decrypt
virtual void encrypt(std::shared_ptr<const std::vector<uint8_t>> recipientUserId, std::shared_ptr<std::vector<RecipientData>> recipients, std::shared_ptr<const std::vector<uint8_t>> plainMessage, const lime::EncryptionPolicy encryptionPolicy, std::shared_ptr<std::vector<uint8_t>> cipherMessage, const limeCallback &callback) = 0;
virtual lime::PeerDeviceStatus decrypt(const std::vector<uint8_t> &recipientUserId, const std::string &senderDeviceId, const std::vector<uint8_t> &DRmessage, const std::vector<uint8_t> &cipherMessage, std::vector<uint8_t> &plainMessage) = 0;
// User management
virtual void publish_user(const limeCallback &callback, const uint16_t OPkInitialBatchSize) = 0;
virtual void delete_user(const limeCallback &callback) = 0;
virtual void delete_peerDevice(const std::string &peerDeviceId) = 0;
// User keys management
virtual void update_SPk(const limeCallback &callback) = 0;
virtual void update_OPk(const limeCallback &callback, uint16_t OPkServerLowLimit, uint16_t OPkBatchSize) = 0;
virtual void get_Ik(std::vector<uint8_t> &Ik) = 0;
virtual void set_x3dhServerUrl(const std::string &x3dhServerUrl) = 0;
virtual std::string get_x3dhServerUrl() = 0;
virtual void stale_sessions(const std::string &peerDeviceId) = 0;
virtual ~LimeGeneric() {};
};
/* Lime Factory functions : return a pointer to the implementation using the specified elliptic curve. Two functions: one for creation, one for loading from local storage */
std::shared_ptr<LimeGeneric> insert_LimeUser(std::shared_ptr<lime::Db> localStorage, const std::string &deviceId, const std::string &url, const lime::CurveId curve, const uint16_t OPkInitialBatchSize,
const limeX3DHServerPostData &X3DH_post_data, const limeCallback &callback);
std::shared_ptr<LimeGeneric> load_LimeUser(std::shared_ptr<lime::Db> localStorage, const std::string &deviceId, const limeX3DHServerPostData &X3DH_post_data, const bool allStatus=false);
}
#endif // lime_lime_hpp
lime::LimeGeneric
A pure abstract class defining the API to encrypt/decrypt/manage user and its keys.
Definition lime_lime.hpp:35
lime::LimeGeneric::decrypt
virtual lime::PeerDeviceStatus decrypt(const std::vector< uint8_t > &recipientUserId, const std::string &senderDeviceId, const std::vector< uint8_t > &DRmessage, const std::vector< uint8_t > &cipherMessage, std::vector< uint8_t > &plainMessage)=0
Decrypt the given message.
lime::LimeGeneric::delete_user
virtual void delete_user(const limeCallback &callback)=0
Delete user from local Storage and from X3DH server.
lime::LimeGeneric::stale_sessions
virtual void stale_sessions(const std::string &peerDeviceId)=0
Stale all sessions between localDeviceId and peerDevice. If peerDevice keep using this session to enc...
lime::LimeGeneric::get_x3dhServerUrl
virtual std::string get_x3dhServerUrl()=0
Get the X3DH key server URL for this identified user.
lime::LimeGeneric::set_x3dhServerUrl
virtual void set_x3dhServerUrl(const std::string &x3dhServerUrl)=0
Set the X3DH key server URL for this identified user.
lime::LimeGeneric::~LimeGeneric
virtual ~LimeGeneric()
Definition lime_lime.hpp:170
lime::LimeGeneric::update_OPk
virtual void update_OPk(const limeCallback &callback, uint16_t OPkServerLowLimit, uint16_t OPkBatchSize)=0
check if we shall upload more OPks on X3DH server
lime::LimeGeneric::delete_peerDevice
virtual void delete_peerDevice(const std::string &peerDeviceId)=0
Purge cached sessions for a given peer Device (used when a peer device is being deleted).
lime::LimeGeneric::publish_user
virtual void publish_user(const limeCallback &callback, const uint16_t OPkInitialBatchSize)=0
Publish on X3DH server the user, it is performed just after creation in local storage this will,...
lime::LimeGeneric::encrypt
virtual void encrypt(std::shared_ptr< const std::vector< uint8_t > > recipientUserId, std::shared_ptr< std::vector< RecipientData > > recipients, std::shared_ptr< const std::vector< uint8_t > > plainMessage, const lime::EncryptionPolicy encryptionPolicy, std::shared_ptr< std::vector< uint8_t > > cipherMessage, const limeCallback &callback)=0
Encrypt a buffer(text or file) for a given list of recipient devices if specified localDeviceId is no...
lime::LimeGeneric::get_Ik
virtual void get_Ik(std::vector< uint8_t > &Ik)=0
Retrieve self public Identity key.
lime::LimeGeneric::update_SPk
virtual void update_SPk(const limeCallback &callback)=0
Check if the current SPk needs to be updated, if yes, generate a new one and publish it on server.
lime
Definition lime.cpp:30
lime::EncryptionPolicy
EncryptionPolicy
Definition lime.hpp:42
lime::EncryptionPolicy::cipherMessage
@ cipherMessage
Definition lime.hpp:44
lime::load_LimeUser
std::shared_ptr< LimeGeneric > load_LimeUser(std::shared_ptr< lime::Db > localStorage, const std::string &deviceId, const limeX3DHServerPostData &X3DH_post_data, const bool allStatus)
: Load user from database and return a pointer to the control class instanciating the appropriate Lim...
Definition lime.cpp:448
lime::CurveId
CurveId
Definition lime.hpp:35
lime::PeerDeviceStatus
PeerDeviceStatus
Definition lime.hpp:54
lime::insert_LimeUser
std::shared_ptr< LimeGeneric > insert_LimeUser(std::shared_ptr< lime::Db > localStorage, const std::string &deviceId, const std::string &url, const lime::CurveId curve, const uint16_t OPkInitialBatchSize, const limeX3DHServerPostData &X3DH_post_data, const limeCallback &callback)
: Insert user in database and return a pointer to the control class instanciating the appropriate Lim...
Definition lime.cpp:389
lime::limeCallback
std::function< void(const lime::CallbackReturn status, const std::string message)> limeCallback
Callback use to give a status on asynchronous operation.
Definition lime.hpp:96
lime::limeX3DHServerPostData
std::function< void(const std::string &url, const std::string &from, const std::vector< uint8_t > &message, const limeX3DHServerResponseProcess &reponseProcess)> limeX3DHServerPostData
Post a message to the X3DH server.
Definition lime.hpp:116