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>
24 #include <unordered_map>
25 #include <vector>
26 #include <mutex>
27 
28 #include "lime_defines.hpp"
29 
30 namespace lime {
31 
32 
33  // forward declarations
34  class DR;
35  class X3DH;
36 
42  class LimeGeneric {
43 
44  public:
45  // Encrypt/Decrypt
87  virtual void encrypt(std::shared_ptr<lime::EncryptionContext> encryptionContext, const std::shared_ptr<limeCallback> callback, const std::shared_ptr<limeRandomSeedCallback> randomSeedCallback = nullptr) = 0;
88 
101  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;
102 
107  virtual std::unique_lock<std::mutex> lock(void) = 0;
108 
113  virtual void processEncryptionQueue(void) = 0;
114 
120  virtual void DRcache_delete(const std::string &deviceId) = 0;
121 
129  virtual void DRcache_insert(const std::string &deviceId, std::shared_ptr<DR> DRsession) = 0;
130 
136  virtual std::shared_ptr<X3DH> get_X3DH(void) = 0;
137 
138  // User management
146  virtual void publish_user(const std::shared_ptr<limeCallback> callback, const uint16_t OPkInitialBatchSize) = 0;
147 
153  virtual void delete_user(const std::shared_ptr<limeCallback> callback) = 0;
154 
160  virtual void delete_peerDevice(const std::string &peerDeviceId) = 0;
161 
162 
163 
164  // User keys management
170  virtual void update_SPk(const std::shared_ptr<limeCallback> callback) = 0;
171 
181  virtual void update_OPk(const std::shared_ptr<limeCallback> callback, uint16_t OPkServerLowLimit, uint16_t OPkBatchSize) = 0;
182 
188  virtual void get_Ik(std::vector<uint8_t> &Ik) = 0;
189 
195  virtual void set_x3dhServerUrl(const std::string &x3dhServerUrl) = 0;
196 
202  virtual std::string get_x3dhServerUrl() = 0;
203 
212  virtual void stale_sessions(const std::string &peerDeviceId) = 0;
213 
214  virtual ~LimeGeneric() {};
215  };
216 
217  /* 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 */
218 
219  std::shared_ptr<LimeGeneric> insert_LimeUser(std::shared_ptr<lime::Db> localStorage, const DeviceId &deviceId, const std::string &url, const uint16_t OPkInitialBatchSize,
220  const limeX3DHServerPostData &X3DH_post_data, const std::shared_ptr<limeCallback> callback);
221 
222  std::shared_ptr<LimeGeneric> load_LimeUser(std::shared_ptr<lime::Db> localStorage, const DeviceId &deviceId, const limeX3DHServerPostData &X3DH_post_data, const bool allStatus=false);
223 
224 }
225 #endif // lime_lime_hpp
virtual ~LimeGeneric()
Definition: lime_lime.hpp:214
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.
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 processEncryptionQueue(void)=0
Check if we have queued encryption to process, if yes, do it.
virtual void update_OPk(const std::shared_ptr< limeCallback > callback, uint16_t OPkServerLowLimit, uint16_t OPkBatchSize)=0
check if we shall upload more OPks on X3DH server
virtual void set_x3dhServerUrl(const std::string &x3dhServerUrl)=0
Set the X3DH key server URL for this identified user.
virtual std::unique_lock< std::mutex > lock(void)=0
virtual void publish_user(const std::shared_ptr< 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 std::shared_ptr< X3DH > get_X3DH(void)=0
accessor to the internal X3DH engine
virtual void encrypt(std::shared_ptr< lime::EncryptionContext > encryptionContext, const std::shared_ptr< limeCallback > callback, const std::shared_ptr< limeRandomSeedCallback > randomSeedCallback=nullptr)=0
Encrypt a buffer (text or file) for a given list of recipient devices.
std::shared_ptr< LimeGeneric > load_LimeUser(std::shared_ptr< lime::Db > localStorage, const DeviceId &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:556
std::function< void(const std::string &url, const std::string &from, std::vector< uint8_t > &&message, const limeX3DHServerResponseProcess &reponseProcess)> limeX3DHServerPostData
Post a message to the X3DH server.
Definition: lime.hpp:123
virtual void get_Ik(std::vector< uint8_t > &Ik)=0
Retrieve self public Identity key.
PeerDeviceStatus
Definition: lime.hpp:59
virtual std::string get_x3dhServerUrl()=0
Get the X3DH key server URL for this identified user.
Definition: lime.cpp:33
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 update_SPk(const std::shared_ptr< limeCallback > callback)=0
Check if the current SPk needs to be updated, if yes, generate a new one and publish it on server...
virtual void delete_user(const std::shared_ptr< limeCallback > callback)=0
Delete user from local Storage and from X3DH server.
virtual void DRcache_delete(const std::string &deviceId)=0
delete an entry (if found) from the DR session cache
virtual void DRcache_insert(const std::string &deviceId, std::shared_ptr< DR > DRsession)=0
insert an entry in the DR session cache if an entry with the same key already exists, do nothing
A pure abstract class defining the API to encrypt/decrypt/manage user and its keys.
Definition: lime_lime.hpp:42
std::shared_ptr< LimeGeneric > insert_LimeUser(std::shared_ptr< lime::Db > localStorage, const DeviceId &deviceId, const std::string &url, const uint16_t OPkInitialBatchSize, const limeX3DHServerPostData &X3DH_post_data, const std::shared_ptr< limeCallback > callback)
: Insert user in database and return a pointer to the control class instanciating the appropriate Lim...
Definition: lime.cpp:453