Commit aca1ed5c authored by Matthieu Tanon's avatar Matthieu Tanon

Refactor lime v2

parent c2fe8584
......@@ -114,7 +114,7 @@ struct _LinphoneProxyConfig
bool_t publish;
bool_t dial_escape_plus;
bool_t lime_v2;
bool_t lime_x3dh;
bool_t send_publish;
bool_t quality_reporting_enabled;
......
......@@ -144,7 +144,7 @@ static void linphone_proxy_config_init(LinphoneCore* lc, LinphoneProxyConfig *cf
cfg->avpf_rr_interval = lc ? !!lp_config_get_default_int(lc->config, "proxy", "avpf_rr_interval", 5) : 5;
cfg->publish_expires= lc ? lp_config_get_default_int(lc->config, "proxy", "publish_expires", -1) : -1;
cfg->publish = lc ? !!lp_config_get_default_int(lc->config, "proxy", "publish", FALSE) : FALSE;
cfg->lime_v2 = lc ? !!lp_config_get_int(lc->config, "lime", "lime_v2", FALSE) : FALSE;
cfg->lime_x3dh = lc ? !!lp_config_get_int(lc->config, "lime", "lime_v2", FALSE) : FALSE;
cfg->push_notification_allowed = lc ? !!lp_config_get_default_int(lc->config, "proxy", "push_notification_allowed", TRUE) : TRUE;
cfg->refkey = refkey ? ms_strdup(refkey) : NULL;
if (nat_policy_ref) {
......@@ -1042,12 +1042,12 @@ const char *linphone_proxy_config_get_contact_uri_parameters(const LinphoneProxy
return cfg->contact_uri_params;
}
bool_t linphone_proxy_config_lime_v2_enabled(const LinphoneProxyConfig *cfg){
return cfg->lime_v2;
bool_t linphone_proxy_config_lime_x3dh_enabled(const LinphoneProxyConfig *cfg){
return cfg->lime_x3dh;
}
void linphone_proxy_config_enable_lime_v2(LinphoneProxyConfig *cfg, const bool_t val){
cfg->lime_v2=val;
void linphone_proxy_config_enable_lime_x3dh(LinphoneProxyConfig *cfg, const bool_t val){
cfg->lime_x3dh=val;
}
struct _LinphoneCore * linphone_proxy_config_get_core(const LinphoneProxyConfig *cfg){
......@@ -1202,7 +1202,7 @@ void linphone_proxy_config_write_to_config_file(LpConfig *config, LinphoneProxyC
lp_config_set_int(config,key,"push_notification_allowed",(int)cfg->push_notification_allowed);
if (cfg->refkey) lp_config_set_string(config,key,"refkey",cfg->refkey);
lp_config_set_int(config,key,"publish_expires",cfg->publish_expires);
lp_config_set_int(config,key,"lime_v2",cfg->lime_v2);
lp_config_set_int(config,key,"lime_x3dh",cfg->lime_x3dh);
if (cfg->nat_policy != NULL) {
lp_config_set_string(config,key,"nat_policy_ref",cfg->nat_policy->ref);
......@@ -1274,7 +1274,7 @@ LinphoneProxyConfig *linphone_proxy_config_new_from_config_file(LinphoneCore* lc
CONFIGURE_STRING_VALUE(cfg,config,key,ref_key,"refkey")
CONFIGURE_INT_VALUE(cfg,config,key,publish_expires,"publish_expires",int)
CONFIGURE_BOOL_VALUE(cfg,config,key,lime_v2,"lime_v2")
CONFIGURE_BOOL_VALUE(cfg,config,key,lime_x3dh,"lime_v2")
nat_policy_ref = lp_config_get_string(config, key, "nat_policy_ref", NULL);
if (nat_policy_ref != NULL) {
......@@ -1336,7 +1336,7 @@ void linphone_proxy_config_update(LinphoneProxyConfig *cfg){
linphone_proxy_config_activate_sip_setup(cfg);
}
if (can_register(cfg)){
linphone_core_enable_lime_v2(lc, cfg->lime_v2);
linphone_core_enable_lime_x3dh(lc, cfg->lime_x3dh);
linphone_proxy_config_register(cfg);
cfg->commit=FALSE;
}
......
......@@ -1536,41 +1536,41 @@ LINPHONE_PUBLIC LinphoneLimeState linphone_core_lime_enabled(const LinphoneCore
LINPHONE_PUBLIC bool_t linphone_core_lime_available(const LinphoneCore *lc);
/**
* Tells to LinphoneCore to use LIMEv2
* Tells to LinphoneCore to use LIME X3DH
* @param[in] lc LinphoneCore object
* @param[in] val The new lime state
* @ingroup network_parameters
*/
LINPHONE_PUBLIC void linphone_core_enable_lime_v2(LinphoneCore *lc, bool_t enable);
LINPHONE_PUBLIC void linphone_core_enable_lime_x3dh(LinphoneCore *lc, bool_t enable);
/**
* Tells to LinphoneCore to update LIMEv2
* Tells to LinphoneCore to update LIME X3DH
* @param[in] lc LinphoneCore object
* @ingroup network_parameters
*/
LINPHONE_PUBLIC void linphone_core_update_lime_v2(const LinphoneCore *lc);
LINPHONE_PUBLIC void linphone_core_update_lime_x3dh(const LinphoneCore *lc);
/**
* Returns the LIMEv2 state
* Returns the LIME X3DH state
* @param[in] lc LinphoneCore object
* @return The current lime state
* @ingroup network_parameters
**/
LINPHONE_PUBLIC bool_t linphone_core_lime_v2_enabled(const LinphoneCore *lc);
LINPHONE_PUBLIC bool_t linphone_core_lime_x3dh_enabled(const LinphoneCore *lc);
/**
* Tells if LIMEv2 is available
* Tells if LIME X3DH is available
* @param[in] lc LinphoneCore object
* @ingroup network_parameters
**/
LINPHONE_PUBLIC bool_t linphone_core_lime_v2_available(const LinphoneCore *lc);
LINPHONE_PUBLIC bool_t linphone_core_lime_x3dh_available(const LinphoneCore *lc);
/**
* Deletes local LIMEv2 database
* Deletes local LIME X3DH database
* @param[in] lc LinphoneCore object
* @ingroup network_parameters
**/
LINPHONE_PUBLIC void linphone_core_delete_local_lime_v2_db(const LinphoneCore *lc);
LINPHONE_PUBLIC void linphone_core_delete_local_lime_x3dh_db(const LinphoneCore *lc);
/**
* Tells whether IPv6 is enabled or not.
......
......@@ -25,8 +25,8 @@
#define L_ENUM_VALUES_SECURITY_EVENT_TYPE(F) \
F(Null /**< Event is not a security event */) \
F(SecurityLevelDowngraded /**< Chatroom security level downgraded event */) \
F(MultideviceParticipantDetected /**< Encrypting message to multidevice participant event */) \
F(LimeIdentityKeyChanged /**< Lime identity key change changed event */) \
F(ParticipantMaxDeviceCountExceeded /**< Participant has exceeded the maximum number of device event */) \
F(LimeIdentityKeyChanged /**< Peer device lime identity key has changed event */) \
F(ManInTheMiddleDetected /**< Man in the middle detected event */) \
#endif // ifndef _L_SECURITY_EVENT_ENUMS_H_
......@@ -366,15 +366,15 @@ LINPHONE_PUBLIC void linphone_proxy_config_set_contact_uri_parameters(LinphonePr
LINPHONE_PUBLIC const char* linphone_proxy_config_get_contact_uri_parameters(const LinphoneProxyConfig *cfg);
/**
* @return TRUE if LIMEv2 is enabled.
* @return TRUE if LIME X3DH is enabled.
**/
LINPHONE_PUBLIC bool_t linphone_proxy_config_lime_v2_enabled(const LinphoneProxyConfig *cfg);
LINPHONE_PUBLIC bool_t linphone_proxy_config_lime_x3dh_enabled(const LinphoneProxyConfig *cfg);
/**
* @param[in] cfg #LinphoneProxyConfig object.
* @param val if TRUE LIMEv2 will be enabled for this user
* @param val if TRUE LIME X3DH will be enabled for this user
**/
LINPHONE_PUBLIC void linphone_proxy_config_enable_lime_v2(LinphoneProxyConfig *cfg, const bool_t val);
LINPHONE_PUBLIC void linphone_proxy_config_enable_lime_x3dh(LinphoneProxyConfig *cfg, const bool_t val);
/**
* Get the #LinphoneCore object to which is associated the #LinphoneProxyConfig.
......
......@@ -116,9 +116,9 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
chat/cpim/header/cpim-header.h
chat/cpim/message/cpim-message.h
chat/cpim/parser/cpim-parser.h
chat/encryption/encryption-engine-listener.h
chat/encryption/lime-backwards-compatible.h
chat/encryption/lime-v2.h
chat/encryption/encryption-engine.h
chat/encryption/lime-legacy-encryption-engine.h
chat/encryption/lime-x3dh-encryption-engine.h
chat/modifier/chat-message-modifier.h
chat/modifier/cpim-chat-message-modifier.h
chat/modifier/encryption-chat-message-modifier.h
......@@ -275,8 +275,8 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
chat/cpim/header/cpim-header.cpp
chat/cpim/message/cpim-message.cpp
chat/cpim/parser/cpim-parser.cpp
chat/encryption/lime-backwards-compatible.cpp
chat/encryption/lime-v2.cpp
chat/encryption/lime-legacy-encryption-engine.cpp
chat/encryption/lime-x3dh-encryption-engine.cpp
chat/modifier/cpim-chat-message-modifier.cpp
chat/modifier/encryption-chat-message-modifier.cpp
chat/modifier/file-transfer-chat-message-modifier.cpp
......
......@@ -24,7 +24,7 @@
#include "private_structs.h"
#include "chat/encryption/lime-backwards-compatible.h"
#include "chat/encryption/lime-legacy-encryption-engine.h"
// =============================================================================
......@@ -51,7 +51,8 @@ static void _linphone_core_destructor (LinphoneCore *lc) {
}
void linphone_core_set_im_encryption_engine (LinphoneCore *lc, LinphoneImEncryptionEngine *imee) {
L_GET_CPP_PTR_FROM_C_OBJECT(lc)->setEncryptionEngine(new LimeBackwardsCompatible);
auto core = L_GET_CPP_PTR_FROM_C_OBJECT(lc);
core->setEncryptionEngine(new LimeLegacyEncryptionEngine(core));
if (lc->im_encryption_engine) {
linphone_im_encryption_engine_unref(lc->im_encryption_engine);
......@@ -63,30 +64,30 @@ void linphone_core_set_im_encryption_engine (LinphoneCore *lc, LinphoneImEncrypt
}
}
void linphone_core_enable_lime_v2 (LinphoneCore *lc, bool_t enable) {
// if (L_GET_CPP_PTR_FROM_C_OBJECT(lc)->limeV2Available()) {
void linphone_core_enable_lime_x3dh (LinphoneCore *lc, bool_t enable) {
// if (L_GET_CPP_PTR_FROM_C_OBJECT(lc)->limeX3dhAvailable()) {
// cout << "LIMEv2 is available, enabling" << endl;
// } else {
// cout << "LIMEv2 is unavailable, not enabling" << endl;
// }
L_GET_CPP_PTR_FROM_C_OBJECT(lc)->enableLimeV2(enable);
L_GET_CPP_PTR_FROM_C_OBJECT(lc)->enableLimeX3dh(enable);
}
void linphone_core_update_lime_v2 (const LinphoneCore *lc) {
L_GET_CPP_PTR_FROM_C_OBJECT(lc)->updateLimeV2();
void linphone_core_update_lime_x3dh (const LinphoneCore *lc) {
L_GET_CPP_PTR_FROM_C_OBJECT(lc)->updateLimeX3dh();
}
bool_t linphone_core_lime_v2_enabled (const LinphoneCore *lc) {
bool isEnabled = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->limeV2Enabled();
bool_t linphone_core_lime_x3dh_enabled (const LinphoneCore *lc) {
bool isEnabled = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->limeX3dhEnabled();
return isEnabled?TRUE:FALSE;
}
bool_t linphone_core_lime_v2_available (const LinphoneCore *lc) {
return L_GET_CPP_PTR_FROM_C_OBJECT(lc)->limeV2Available();
bool_t linphone_core_lime_x3dh_available (const LinphoneCore *lc) {
return L_GET_CPP_PTR_FROM_C_OBJECT(lc)->limeX3dhAvailable();
}
void linphone_core_delete_local_lime_v2_db (const LinphoneCore *lc) {
if (L_GET_CPP_PTR_FROM_C_OBJECT(lc)->limeV2Enabled()) {
void linphone_core_delete_local_lime_x3dh_db (const LinphoneCore *lc) {
if (L_GET_CPP_PTR_FROM_C_OBJECT(lc)->limeX3dhEnabled()) {
L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getEncryptionEngine()->cleanDb();
} else {
lWarning() << "Trying to clean local LIMEv2 databases but LIMEv2 is disabled";
......
......@@ -538,7 +538,7 @@ LinphoneReason ChatMessagePrivate::receive () {
// If LIMEv2 disabled, the authenticatedFromAddress must be set here as the SIP From Address
// If LIMEv2 disabled in group chat room the sender authentication is disabled
// TODO replace me with future "chatRoom->isEncrypted()" API because LIMEv2 will always be enabled
if (!core->limeV2Enabled()) {
if (!core->limeX3dhEnabled()) {
if (q->getSharedFromThis()->getChatRoom()->getCapabilities() & ChatRoom::Capabilities::Basic) {
IdentityAddress sipFromAddress = q->getSharedFromThis()->getFromAddress();
setAuthenticatedFromAddress(sipFromAddress);
......
......@@ -56,7 +56,7 @@ class LINPHONE_PUBLIC ChatMessage : public Object, public CoreAccessor {
friend class MainDbPrivate;
friend class RealTimeTextChatRoomPrivate;
friend class ServerGroupChatRoomPrivate;
friend class LimeV2;
friend class LimeX3DHEncryptionEngine;
public:
L_OVERRIDE_SHARED_FROM_THIS(ChatMessage);
......
......@@ -21,7 +21,7 @@
#define _L_CLIENT_GROUP_CHAT_ROOM_P_H_
#include "chat/chat-room/chat-room-p.h"
#include "chat/encryption/encryption-engine-listener.h"
#include "chat/encryption/encryption-engine.h"
#include "client-group-chat-room.h"
#include "utils/background-task.h"
......
......@@ -23,7 +23,7 @@
#include "address/address-p.h"
#include "basic-to-client-group-chat-room.h"
#include "chat/encryption/lime-v2.h"
#include "chat/encryption/lime-x3dh-encryption-engine.h"
#include "c-wrapper/c-wrapper.h"
#include "client-group-chat-room-p.h"
#include "conference/handlers/remote-conference-event-handler-p.h"
......@@ -757,8 +757,6 @@ void ClientGroupChatRoom::onSecurityEvent (const shared_ptr<ConferenceSecurityEv
}
finalEvent = cleanEvent ? cleanEvent : event;
// Add security events or alerts based on the type of security event
d->addEvent(event);
LinphoneChatRoom *cr = d->getCChatRoom();
......@@ -795,50 +793,15 @@ void ClientGroupChatRoom::onParticipantDeviceAdded (const shared_ptr<ConferenceP
return;
}
// Get LIMEv2 context if enabled and get the new device status
LimeV2 *limeV2Engine = nullptr;
shared_ptr<ConferenceSecurityEvent> securityEvent;
bool securityLevelDegraded = false;
if (getCore()->limeV2Enabled()) {
limeV2Engine = static_cast<LimeV2 *>(getCore()->getEncryptionEngine());
lime::PeerDeviceStatus newDeviceStatus = limeV2Engine->getLimeManager()->get_peerDeviceStatus(event->getDeviceAddress().asString());
// If the new device degrades the chatroom security level it must be notified to the user
if (getSecurityLevel() == SecurityLevel::Safe && newDeviceStatus != lime::PeerDeviceStatus::trusted)
securityLevelDegraded = true;
}
ChatRoom::SecurityLevel currentSecurityLevel = getSecurityLevel();
participant->getPrivate()->addDevice(event->getDeviceAddress());
if (limeV2Engine) {
int nbDevice = int(participant->getPrivate()->getDevices().size());
int maxNbDevicesPerParticipant = linphone_config_get_int(linphone_core_get_config(L_GET_C_BACK_PTR(getCore())), "lime", "max_nb_device_per_participant", 1);
LimeV2 *limeV2Engine = static_cast<LimeV2 *>(getCore()->getEncryptionEngine());
// Check if the new participant device is unexpected in which case a security alert is created
if (nbDevice > maxNbDevicesPerParticipant) {
lWarning() << "LIMEv2 maximum number of devices exceeded for " << participant->getAddress();
securityEvent = make_shared<ConferenceSecurityEvent>(
time(nullptr),
d->conferenceId,
ConferenceSecurityEvent::SecurityEventType::MultideviceParticipantDetected,
event->getDeviceAddress()
);
limeV2Engine->getLimeManager()->set_peerDeviceStatus(event->getDeviceAddress().asString(), lime::PeerDeviceStatus::unsafe);
}
// Otherwise if the chatroom security level was degraded a corresponding security event is created
else {
if (securityLevelDegraded) {
lInfo() << "LIMEv2 chat room security level degraded by " << event->getDeviceAddress().asString();
securityEvent = make_shared<ConferenceSecurityEvent>(
time(nullptr),
d->conferenceId,
ConferenceSecurityEvent::SecurityEventType::SecurityLevelDowngraded,
event->getDeviceAddress()
);
}
}
}
// Check if new device degrades the chatroom security level and return corresponding security event
shared_ptr<ConferenceSecurityEvent> securityEvent = nullptr;
auto encryptionEngine = getCore()->getEncryptionEngine();
if (encryptionEngine)
securityEvent = encryptionEngine->onDeviceAdded(event->getDeviceAddress(), participant, getSharedFromThis(), currentSecurityLevel);
if (isFullState)
return;
......
......@@ -35,7 +35,7 @@ class LINPHONE_PUBLIC ClientGroupChatRoom : public ChatRoom, public RemoteConfer
friend class ClientGroupToBasicChatRoomPrivate;
friend class Core;
friend class CorePrivate;
friend class LimeV2;
friend class LimeX3DHEncryptionEngine;
friend class MediaSessionPrivate;
public:
......
/*
* cpim-chat-message-modifier.h
* encryption-engine.h
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
......@@ -17,14 +17,16 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _L_ENCRYPTION_ENGINE_LISTENER_H_
#define _L_ENCRYPTION_ENGINE_LISTENER_H_
#ifndef _L_ENCRYPTION_ENGINE_H_
#define _L_ENCRYPTION_ENGINE_H_
#include <memory>
#include "chat/chat-room/abstract-chat-room.h"
#include "chat/chat-room/client-group-chat-room.h"
#include "chat/modifier/chat-message-modifier.h"
#include "core/core-accessor.h"
#include "linphone/lpconfig.h"
#include "sal/sal.h"
// =============================================================================
......@@ -33,32 +35,94 @@ LINPHONE_BEGIN_NAMESPACE
class AbstractChatRoom;
class ChatMessage;
class EncryptionEngineListener {
using EncryptionParameter = std::pair<std::string, std::string>;
class EncryptionEngine : public CoreAccessor {
public:
enum class EngineType {
Undefined = -1,
LimeV2 = 0,
//Another = 1,
//YetAnother = 2
LimeX3DH = 0,
};
virtual ~EncryptionEngineListener () = default;
virtual ChatMessageModifier::Result processOutgoingMessage (const std::shared_ptr<ChatMessage> &message, int &errorCode) { return ChatMessageModifier::Result::Skipped; }
virtual ChatMessageModifier::Result processIncomingMessage (const std::shared_ptr<ChatMessage> &message, int &errorCode) { return ChatMessageModifier::Result::Skipped; }
virtual void update (LinphoneConfig *lpconfig) {};
virtual bool encryptionEnabledForFileTransfer (const std::shared_ptr<AbstractChatRoom> &ChatRoom) { return false; }
virtual void generateFileTransferKey (const std::shared_ptr<AbstractChatRoom> &ChatRoom, const std::shared_ptr<ChatMessage> &message) {}
virtual int downloadingFile (const std::shared_ptr<ChatMessage> &message, size_t offset, const uint8_t *buffer, size_t size, uint8_t *decryptedBuffer) { return 0; }
virtual int uploadingFile (const std::shared_ptr<ChatMessage> &message, size_t offset, const uint8_t *buffer, size_t *size, uint8_t *encryptedBuffer) { return 0; }
virtual EncryptionEngineListener::EngineType getEngineType () { return EngineType::Undefined; }
virtual AbstractChatRoom::SecurityLevel getSecurityLevel (const std::string &deviceId) const { return AbstractChatRoom::SecurityLevel::Unsafe; }
virtual ~EncryptionEngine () = default;
virtual ChatMessageModifier::Result processOutgoingMessage (
const std::shared_ptr<ChatMessage> &message,
int &errorCode
) { return ChatMessageModifier::Result::Skipped; }
virtual ChatMessageModifier::Result processIncomingMessage (
const std::shared_ptr<ChatMessage> &message,
int &errorCode
) { return ChatMessageModifier::Result::Skipped; }
virtual bool encryptionEnabledForFileTransfer (
const std::shared_ptr<AbstractChatRoom> &ChatRoom
) { return false; }
virtual void generateFileTransferKey (
const std::shared_ptr<AbstractChatRoom> &ChatRoom,
const std::shared_ptr<ChatMessage> &message
) {}
virtual int downloadingFile (
const std::shared_ptr<ChatMessage> &message,
size_t offset,
const uint8_t *buffer,
size_t size,
uint8_t *decryptedBuffer
) { return 0; }
virtual int uploadingFile (
const std::shared_ptr<ChatMessage> &message,
size_t offset,
const uint8_t *buffer,
size_t *size,
uint8_t *encryptedBuffer
) { return 0; }
virtual void mutualAuthentication (
MSZrtpContext *zrtpContext,
SalMediaDescription *localMediaDescription,
SalMediaDescription *remoteMediaDescription,
LinphoneCallDir direction
) {}
virtual void authenticationVerified (
MSZrtpContext *zrtpContext,
SalMediaDescription *remoteMediaDescription,
const char *peerDeviceId
) {}
virtual void authenticationRejected (
SalMediaDescription *remoteMediaDescription,
const char *peerDeviceId
) {}
virtual void addSecurityEventInChatrooms (
const IdentityAddress &peerDeviceAddr,
ConferenceSecurityEvent::SecurityEventType securityEventType
) {}
virtual std::shared_ptr<ConferenceSecurityEvent> onDeviceAdded (
const IdentityAddress &newDeviceAddr,
std::shared_ptr<Participant> participant,
const std::shared_ptr<AbstractChatRoom> &chatRoom,
ChatRoom::SecurityLevel currentSecurityLevel
) { return nullptr; }
virtual void cleanDb () {}
virtual void update () {}
virtual EngineType getEngineType () { return EngineType::Undefined; }
virtual AbstractChatRoom::SecurityLevel getSecurityLevel (const std::string &deviceId) const { return AbstractChatRoom::SecurityLevel::ClearText; }
virtual std::list<EncryptionParameter> getEncryptionParameters () { return std::list<EncryptionParameter>(); }
protected:
EncryptionEngineListener::EngineType engineType;
EncryptionEngine (const std::shared_ptr<Core> &core) : CoreAccessor(core) {}
EngineType engineType;
};
LINPHONE_END_NAMESPACE
#endif // #define _L_ENCRYPTION_ENGINELISTENER_H_
#endif // #define _L_ENCRYPTION_ENGINE_H_
/*
* encryption-chat-message-modifier.cpp
* lime-legacy-encryption-engine.cpp
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
......@@ -23,7 +23,7 @@
#include "chat/chat-room/abstract-chat-room.h"
#include "core/core.h"
#include "c-wrapper/c-wrapper.h"
#include "lime-backwards-compatible.h"
#include "lime-legacy-encryption-engine.h"
// =============================================================================
......@@ -31,7 +31,9 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
ChatMessageModifier::Result LimeBackwardsCompatible::processOutgoingMessage (const shared_ptr<ChatMessage> &message, int &errorCode) {
LimeLegacyEncryptionEngine::LimeLegacyEncryptionEngine (const shared_ptr<Core> &core) : EncryptionEngine(core) {}
ChatMessageModifier::Result LimeLegacyEncryptionEngine::processOutgoingMessage (const shared_ptr<ChatMessage> &message, int &errorCode) {
shared_ptr<AbstractChatRoom> chatRoom = message->getChatRoom();
LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(chatRoom->getCore()->getCCore());
if (!imee)
......@@ -59,7 +61,7 @@ ChatMessageModifier::Result LimeBackwardsCompatible::processOutgoingMessage (con
return ChatMessageModifier::Result::Done;
}
ChatMessageModifier::Result LimeBackwardsCompatible::processIncomingMessage (const shared_ptr<ChatMessage> &message, int &errorCode) {
ChatMessageModifier::Result LimeLegacyEncryptionEngine::processIncomingMessage (const shared_ptr<ChatMessage> &message, int &errorCode) {
shared_ptr<AbstractChatRoom> chatRoom = message->getChatRoom();
LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(chatRoom->getCore()->getCCore());
if (!imee)
......@@ -87,7 +89,7 @@ ChatMessageModifier::Result LimeBackwardsCompatible::processIncomingMessage (con
return ChatMessageModifier::Result::Done;
}
bool LimeBackwardsCompatible::encryptionEnabledForFileTransfer (const shared_ptr<AbstractChatRoom> &chatRoom) {
bool LimeLegacyEncryptionEngine::encryptionEnabledForFileTransfer (const shared_ptr<AbstractChatRoom> &chatRoom) {
LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(chatRoom->getCore()->getCCore());
LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee);
LinphoneImEncryptionEngineCbsIsEncryptionEnabledForFileTransferCb is_encryption_enabled_for_file_transfer_cb =
......@@ -98,7 +100,7 @@ bool LimeBackwardsCompatible::encryptionEnabledForFileTransfer (const shared_ptr
return false;
}
void LimeBackwardsCompatible::generateFileTransferKey (const shared_ptr<AbstractChatRoom> &chatRoom, const shared_ptr<ChatMessage> &message) {
void LimeLegacyEncryptionEngine::generateFileTransferKey (const shared_ptr<AbstractChatRoom> &chatRoom, const shared_ptr<ChatMessage> &message) {
LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(chatRoom->getCore()->getCCore());
LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee);
LinphoneImEncryptionEngineCbsGenerateFileTransferKeyCb generate_file_transfer_key_cb =
......@@ -108,7 +110,7 @@ void LimeBackwardsCompatible::generateFileTransferKey (const shared_ptr<Abstract
}
}
int LimeBackwardsCompatible::downloadingFile (const shared_ptr<ChatMessage> &message, size_t offset, const uint8_t *buffer, size_t size, uint8_t *decryptedBuffer) {
int LimeLegacyEncryptionEngine::downloadingFile (const shared_ptr<ChatMessage> &message, size_t offset, const uint8_t *buffer, size_t size, uint8_t *decryptedBuffer) {
shared_ptr<AbstractChatRoom> chatRoom = message->getChatRoom();
LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(chatRoom->getCore()->getCCore());
LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee);
......@@ -119,7 +121,7 @@ int LimeBackwardsCompatible::downloadingFile (const shared_ptr<ChatMessage> &mes
return -1;
}
int LimeBackwardsCompatible::uploadingFile (const shared_ptr<ChatMessage> &message, size_t offset, const uint8_t *buffer, size_t *size, uint8_t *encryptedBuffer) {
int LimeLegacyEncryptionEngine::uploadingFile (const shared_ptr<ChatMessage> &message, size_t offset, const uint8_t *buffer, size_t *size, uint8_t *encryptedBuffer) {
shared_ptr<AbstractChatRoom> chatRoom = message->getChatRoom();
LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(chatRoom->getCore()->getCCore());
LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee);
......@@ -130,6 +132,4 @@ int LimeBackwardsCompatible::uploadingFile (const shared_ptr<ChatMessage> &messa
return -1;
}
void LimeBackwardsCompatible::cleanDb () {}
LINPHONE_END_NAMESPACE
/*
* cpim-chat-message-modifier.h
* lime-legacy-encryption-engine.h
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
......@@ -17,26 +17,27 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _L_LIME_BACKWARDS_COMPATIBLE_H_
#define _L_LIME_BACKWARDS_COMPATIBLE_H_
#ifndef _L_LIME_LEGACY_ENCRYPTION_ENGINE_H_
#define _L_LIME_LEGACY_ENCRYPTION_ENGINE_H_
#include "encryption-engine-listener.h"
#include "encryption-engine.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class LimeBackwardsCompatible : public EncryptionEngineListener {
class LimeLegacyEncryptionEngine : public EncryptionEngine {
public:
LimeLegacyEncryptionEngine (const std::shared_ptr<Core> &core);
ChatMessageModifier::Result processIncomingMessage (const std::shared_ptr<ChatMessage> &message, int &errorCode) override;
ChatMessageModifier::Result processOutgoingMessage (const std::shared_ptr<ChatMessage> &message, int &errorCode) override;
bool encryptionEnabledForFileTransfer (const std::shared_ptr<AbstractChatRoom> &ChatRoom) override;
void generateFileTransferKey (const std::shared_ptr<AbstractChatRoom> &ChatRoom, const std::shared_ptr<ChatMessage> &message) override;
int downloadingFile (const std::shared_ptr<ChatMessage> &message, size_t offset, const uint8_t *buffer, size_t size, uint8_t *decrypted_buffer) override;
int uploadingFile (const std::shared_ptr<ChatMessage> &message, size_t offset, const uint8_t *buffer, size_t *size, uint8_t *encrypted_buffer) override;
void cleanDb () override;
};
LINPHONE_END_NAMESPACE
#endif // ifndef _L_LIME_BACKWARDS_COMPATIBLE_H_
#endif // ifndef _L_LIME_LEGACY_ENCRYPTION_ENGINE_H_
/*
* lime-v2.h
* lime-x3dh-encryption-engine.h
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
......@@ -17,38 +17,38 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _L_LIME_V2_H_
#define _L_LIME_V2_H_
#ifndef _L_LIME_X3DH_ENCRYPTION_ENGINE_H_
#define _L_LIME_X3DH_ENCRYPTION_ENGINE_H_
#include "belle-sip/belle-sip.h"
#include "belle-sip/http-listener.h"
#include "carddav.h"
#include "core/core-listener.h"
#include "encryption-engine-listener.h"
#include "encryption-engine.h"
#include "lime/lime.hpp"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
inline std::vector<uint8_t> encodeBase64 (const std::vector<uint8_t> &input) {
inline std::string encodeBase64 (const std::vector<uint8_t> &input) {
const unsigned char *inputBuffer = input.data();
size_t inputLength = input.size();
size_t encodedLength = 0;
bctbx_base64_encode(NULL, &encodedLength, inputBuffer, inputLength); // set encodedLength to the correct value
unsigned char* encodedBuffer = new unsigned char[encodedLength]; // allocate encoded buffer with correct length
unsigned char *encodedBuffer = new unsigned char[encodedLength]; // allocate encoded buffer with correct length
bctbx_base64_encode(encodedBuffer, &encodedLength, inputBuffer, inputLength); // real encoding
std::vector<uint8_t> output(encodedBuffer, encodedBuffer + encodedLength);
std::string output((char*)encodedBuffer);
delete[] encodedBuffer;
return output;
}
inline std::vector<uint8_t> decodeBase64 (const std::vector<uint8_t> &input) {
const unsigned char *inputBuffer = input.data();
inline std::vector<uint8_t> decodeBase64 (const std::string &input) {
const unsigned char *inputBuffer = (const unsigned char*)input.data();
size_t inputLength = input.size();
size_t decodedLength = 0;
bctbx_base64_decode(NULL, &decodedLength, inputBuffer, inputLength); // set decodedLength to the correct value
unsigned char* decodedBuffer = new unsigned char[decodedLength]; // allocate decoded buffer with correct length
unsigned char *decodedBuffer = new unsigned char[decodedLength]; // allocate decoded buffer with correct length
bctbx_base64_decode(decodedBuffer, &decodedLength, inputBuffer, inputLength); // real decoding
std::vector<uint8_t> output(decodedBuffer, decodedBuffer + decodedLength);
delete[] decodedBuffer;
......@@ -65,29 +65,99 @@ private:
static void processAuthRequested (void *data, belle_sip_auth_event_t *event) noexcept;
};
class LimeV2 : public EncryptionEngineListener, public CoreListener {
class LimeX3DHEncryptionEngine : public EncryptionEngine, public CoreListener {
public:
LimeV2 (const std::string &db_access, belle_http_provider_t *prov, LinphoneCore *lc);
LimeX3DHEncryptionEngine (
const std::string &db_access,
belle_http_provider_t *prov,
const std::shared_ptr<Core> core
);
std::shared_ptr<BelleSipLimeManager> getLimeManager ();
lime::limeCallback setLimeCallback (std::string operation);
std::string getX3dhServerUrl () const;
lime::CurveId getCurveId () const;
// EncryptionEngineListener overrides
ChatMessageModifier::Result processIncomingMessage (const std::shared_ptr<ChatMessage> &message, int &errorCode) override;
ChatMessageModifier::Result processOutgoingMessage (const std::shared_ptr<ChatMessage> &message, int &errorCode) override;
void update (LinphoneConfig *lpconfig) override;
// EncryptionEngine overrides
ChatMessageModifier::Result processIncomingMessage (
const std::shared_ptr<ChatMessage> &message,
int &errorCode
) override;
ChatMessageModifier::Result processOutgoingMessage (
const std::shared_ptr<ChatMessage> &message,
int &errorCode
) override;
void generateFileTransferKey (
const std::shared_ptr<AbstractChatRoom> &ChatRoom,
const std::shared_ptr<ChatMessage> &message
) override;
int downloadingFile (
const std::shared_ptr<ChatMessage> &message,
size_t offset,