Commit 982f665d authored by Matthieu Tanon's avatar Matthieu Tanon

Fix crash when X3DH server url is empty and clean code

parent dc894b7f
......@@ -52,7 +52,7 @@ public:
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 (std::string deviceId) const { return AbstractChatRoom::SecurityLevel::Unsafe; }
virtual AbstractChatRoom::SecurityLevel getSecurityLevel (const std::string &deviceId) const { return AbstractChatRoom::SecurityLevel::Unsafe; }
virtual void cleanDb () {}
protected:
......
......@@ -111,10 +111,12 @@ BelleSipLimeManager::BelleSipLimeManager (const string &dbAccess, belle_http_pro
LimeV2::LimeV2 (const std::string &dbAccess, belle_http_provider_t *prov, LinphoneCore *lc) {
engineType = EncryptionEngineListener::EngineType::LimeV2;
curve = lime::CurveId::c25519; // c448
x3dhServerUrl = linphone_config_get_string(linphone_core_get_config(lc), "lime", "x3dh_server_url", "");
_dbAccess = dbAccess;
belleSipLimeManager = unique_ptr<BelleSipLimeManager>(new BelleSipLimeManager(dbAccess, prov, lc));
lastLimeUpdate = linphone_config_get_int(lc->config, "lime", "last_lime_update_time", 0);
x3dhServerUrl = linphone_config_get_string(linphone_core_get_config(lc), "lime", "x3dh_server_url", "");
if (x3dhServerUrl.empty())
lError() << "LIMEv2 X3DH server URL unavailable for encryption engine";
}
string LimeV2::getX3dhServerUrl () const {
......@@ -469,7 +471,7 @@ EncryptionEngineListener::EngineType LimeV2::getEngineType () {
return engineType;
}
AbstractChatRoom::SecurityLevel LimeV2::getSecurityLevel (string deviceId) const {
AbstractChatRoom::SecurityLevel LimeV2::getSecurityLevel (const string &deviceId) const {
lime::PeerDeviceStatus status = belleSipLimeManager->get_peerDeviceStatus(deviceId);
switch (status) {
case lime::PeerDeviceStatus::unknown:
......@@ -509,6 +511,11 @@ lime::limeCallback LimeV2::setLimeCallback (string operation) {
void LimeV2::onRegistrationStateChanged (LinphoneProxyConfig *cfg, LinphoneRegistrationState state, const string &message) {
if (state == LinphoneRegistrationState::LinphoneRegistrationOk) {
if (x3dhServerUrl.empty()) {
lError() << "LIMEv2 X3DH server URL unavailable for encryption engine: can't create lime user";
return;
}
char *contactAddress = linphone_address_as_string_uri_only(linphone_proxy_config_get_contact(cfg));
IdentityAddress identityAddress = IdentityAddress(contactAddress);
string localDeviceId = identityAddress.asString();
......@@ -520,7 +527,7 @@ void LimeV2::onRegistrationStateChanged (LinphoneProxyConfig *cfg, LinphoneRegis
lime::limeCallback callback = setLimeCallback(operation.str());
LinphoneConfig *lpconfig = linphone_core_get_config(linphone_proxy_config_get_core(cfg));
lastLimeUpdate = linphone_config_get_int(lpconfig, "lime", "last_lime_update_time", -1); // TODO should be done by the tester
lastLimeUpdate = linphone_config_get_int(lpconfig, "lime", "last_lime_update_time", -1);
try {
// create user if not exist
......
......@@ -82,7 +82,7 @@ public:
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;
EncryptionEngineListener::EngineType getEngineType () override;
AbstractChatRoom::SecurityLevel getSecurityLevel (std::string deviceId) const override;
AbstractChatRoom::SecurityLevel getSecurityLevel (const std::string &deviceId) const override;
void cleanDb () override;
// CoreListener overrides
......
......@@ -2824,7 +2824,7 @@ void MediaSessionPrivate::startAudioStream (CallSession::State targetState, bool
const char *charRemoteIk = sal_custom_sdp_attribute_find(op->getRemoteMediaDescription()->custom_sdp_attributes, "Ik");
// If LIMEv2 is disabled there might not be identity keys
if (charLocalIk != NULL && charRemoteIk != NULL) {
if (charLocalIk && charRemoteIk) {
const string &stringB64LocalIk(charLocalIk);
const string &stringB64RemoteIk(charRemoteIk);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment