lime
Lime is a C++ library implementing Open Whisper System Signal protocol
lime_lime.hpp
Go to the documentation of this file.
1 /*
2  lime_lime.hpp
3  @author Johan Pascal
4  @copyright Copyright (C) 2017 Belledonne Communications SARL
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef lime_lime_hpp
21 #define lime_lime_hpp
22 
23 #include <memory> // unique_ptr
24 #include <unordered_map>
25 #include <vector>
26 #include <mutex>
27 
28 namespace lime {
29 
35  class LimeGeneric {
36 
37  public:
38  // Encrypt/Decrypt
76  virtual void encrypt(std::shared_ptr<const std::string> 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;
77 
90  virtual lime::PeerDeviceStatus decrypt(const std::string &recipientUserId, const std::string &senderDeviceId, const std::vector<uint8_t> &DRmessage, const std::vector<uint8_t> &cipherMessage, std::vector<uint8_t> &plainMessage) = 0;
91 
92 
93 
94  // User management
102  virtual void publish_user(const limeCallback &callback, const uint16_t OPkInitialBatchSize) = 0;
103 
109  virtual void delete_user(const limeCallback &callback) = 0;
110 
116  virtual void delete_peerDevice(const std::string &peerDeviceId) = 0;
117 
118 
119 
120  // User keys management
126  virtual void update_SPk(const limeCallback &callback) = 0;
127 
137  virtual void update_OPk(const limeCallback &callback, uint16_t OPkServerLowLimit, uint16_t OPkBatchSize) = 0;
138 
144  virtual void get_Ik(std::vector<uint8_t> &Ik) = 0;
145 
151  virtual void set_x3dhServerUrl(const std::string &x3dhServerUrl) = 0;
152 
158  virtual std::string get_x3dhServerUrl() = 0;
159 
168  virtual void stale_sessions(const std::string &peerDeviceId) = 0;
169 
170  virtual ~LimeGeneric() {};
171  };
172 
173  /* 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 */
174 
175  std::shared_ptr<LimeGeneric> insert_LimeUser(const std::string &dbFilename, const std::string &deviceId, const std::string &url, const lime::CurveId curve, const uint16_t OPkInitialBatchSize,
176  const limeX3DHServerPostData &X3DH_post_data, const limeCallback &callback, std::shared_ptr<std::recursive_mutex> mutex);
177 
178  std::shared_ptr<LimeGeneric> load_LimeUser(const std::string &dbFilename, const std::string &deviceId, const limeX3DHServerPostData &X3DH_post_data, std::shared_ptr<std::recursive_mutex> mutex, const bool allStatus=false);
179 
180 }
181 #endif // lime_lime_hpp
virtual ~LimeGeneric()
Definition: lime_lime.hpp:170
virtual void stale_sessions(const std::string &peerDeviceId)=0
Stale all sessions between localDeviceId and peerDevice. If peerDevice keep using this session to enc...
virtual void set_x3dhServerUrl(const std::string &x3dhServerUrl)=0
Set the X3DH key server URL for this identified user.
std::shared_ptr< LimeGeneric > insert_LimeUser(const std::string &dbFilename, 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< std::recursive_mutex > db_mutex)
: Insert user in database and return a pointer to the control class instanciating the appropriate Lim...
Definition: lime.cpp:390
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:115
std::function< void(const lime::CallbackReturn status, const std::string message)> limeCallback
Callback use to give a status on asynchronous operation.
Definition: lime.hpp:95
virtual void get_Ik(std::vector< uint8_t > &Ik)=0
Retrieve self public Identity key.
std::shared_ptr< LimeGeneric > load_LimeUser(const std::string &dbFilename, const std::string &deviceId, const limeX3DHServerPostData &X3DH_post_data, std::shared_ptr< std::recursive_mutex > db_mutex, const bool allStatus)
: Load user from database and return a pointer to the control class instanciating the appropriate Lim...
Definition: lime.cpp:457
PeerDeviceStatus
Definition: lime.hpp:53
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...
virtual std::string get_x3dhServerUrl()=0
Get the X3DH key server URL for this identified user.
Definition: lime.cpp:30
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) ...
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...
virtual void update_OPk(const limeCallback &callback, uint16_t OPkServerLowLimit, uint16_t OPkBatchSize)=0
check if we shall upload more OPks on X3DH server
EncryptionPolicy
Definition: lime.hpp:41
CurveId
Definition: lime.hpp:34
virtual lime::PeerDeviceStatus decrypt(const std::string &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.
virtual void encrypt(std::shared_ptr< const std::string > 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...
A pure abstract class defining the API to encrypt/decrypt/manage user and its keys.
Definition: lime_lime.hpp:35
virtual void delete_user(const limeCallback &callback)=0
Delete user from local Storage and from X3DH server.