Commit 8780df8b authored by Matthieu Tanon's avatar Matthieu Tanon
Browse files

Add conference security event and use it when encrypting message for multidevice participant

parent e9443fd4
......@@ -35,6 +35,7 @@
F(ConferenceParticipantUnsetAdmin /**< Conference participant (unset admin) event */) \
F(ConferenceParticipantDeviceAdded /**< Conference participant device (added) event */) \
F(ConferenceParticipantDeviceRemoved /**< Conference participant device (removed) event */) \
F(ConferenceSecurityAlert /**< Conference security alert event*/) \
F(ConferenceSubjectChanged /**< Conference subject event */) \
#endif // ifndef _L_EVENT_LOG_ENUMS_H_
......@@ -191,6 +191,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
event-log/conference/conference-participant-device-event.h
event-log/conference/conference-participant-event-p.h
event-log/conference/conference-participant-event.h
event-log/conference/conference-security-event.h
event-log/conference/conference-subject-event.h
event-log/event-log-p.h
event-log/event-log.h
......@@ -322,6 +323,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
event-log/conference/conference-notified-event.cpp
event-log/conference/conference-participant-device-event.cpp
event-log/conference/conference-participant-event.cpp
event-log/conference/conference-security-event.cpp
event-log/conference/conference-subject-event.cpp
event-log/event-log.cpp
hacks/hacks.cpp
......
......@@ -62,6 +62,7 @@
F(EventLog, ConferenceNotifiedEvent) \
F(EventLog, ConferenceParticipantDeviceEvent) \
F(EventLog, ConferenceParticipantEvent) \
F(EventLog, ConferenceSecurityEvent) \
F(EventLog, ConferenceSubjectEvent)
// =============================================================================
......
......@@ -715,6 +715,13 @@ void ClientGroupChatRoom::onParticipantSetAdmin (const shared_ptr<ConferencePart
_linphone_chat_room_notify_participant_admin_status_changed(cr, L_GET_C_BACK_PTR(event));
}
void ClientGroupChatRoom::onSecurityAlert (const shared_ptr<ConferenceSecurityEvent> &event) {
L_D();
cout << "onSecurityAlert() securityAlert = " << event->getSecurityAlert() << endl;
d->addEvent(event);
}
void ClientGroupChatRoom::onSubjectChanged (const shared_ptr<ConferenceSubjectEvent> &event, bool isFullState) {
L_D();
......
......@@ -31,6 +31,7 @@ class ClientGroupChatRoomPrivate;
enum class SecurityLevel;
class LINPHONE_PUBLIC ClientGroupChatRoom : public ChatRoom, public RemoteConference {
friend class LimeV2;
friend class BasicToClientGroupChatRoomPrivate;
friend class ClientGroupToBasicChatRoomPrivate;
friend class Core;
......@@ -105,6 +106,7 @@ private:
void onConferenceCreated (const IdentityAddress &addr) override;
void onConferenceKeywordsChanged (const std::vector<std::string> &keywords) override;
void onConferenceTerminated (const IdentityAddress &addr) override;
void onSecurityAlert (const std::shared_ptr<ConferenceSecurityEvent> &event) override;
void onFirstNotifyReceived (const IdentityAddress &addr) override;
void onParticipantAdded (const std::shared_ptr<ConferenceParticipantEvent> &event, bool isFullState) override;
void onParticipantDeviceAdded (const std::shared_ptr<ConferenceParticipantDeviceEvent> &event, bool isFullState) override;
......
......@@ -18,7 +18,7 @@
*/
#include "chat/chat-message/chat-message-p.h"
#include "chat/chat-room/chat-room.h"
#include "chat/chat-room/chat-room-p.h"
#include "content/content-manager.h"
#include "content/header/header-param.h"
#include "conference/participant-p.h"
......@@ -30,6 +30,9 @@
// TODO remove me
#include "lime.h"
#include "event-log/conference/conference-security-event.h"
#include "chat/chat-room/client-group-chat-room.h"
using namespace std;
LINPHONE_BEGIN_NAMESPACE
......@@ -159,6 +162,13 @@ ChatMessageModifier::Result LimeV2::processOutgoingMessage (const shared_ptr<Cha
if (isMultidevice) {
// TODO add policies to adapt behaviour when multiple devices
lWarning() << "Sending encrypted message to multidevice participant";
// TODO if multidevice is forbidden send a ConferenceSecurityEvent
time_t securityAlertTime = time(nullptr);
const string &securityAlert = "Sending encrypted message to multidevice participant";
shared_ptr<ConferenceSecurityEvent> securityEvent = make_shared<ConferenceSecurityEvent>(securityAlertTime, chatRoom->getConferenceId(), securityAlert);
shared_ptr<ClientGroupChatRoom> confListener = static_pointer_cast<ClientGroupChatRoom>(chatRoom); // WARNING invalid static_cast
confListener->onSecurityAlert(securityEvent);
}
const string &plainStringMessage = message->getInternalContent().getBodyAsUtf8String();
......
......@@ -35,6 +35,8 @@ public:
virtual void onConferenceCreated (const IdentityAddress &addr) {}
virtual void onConferenceKeywordsChanged (const std::vector<std::string> &keywords) {}
virtual void onConferenceTerminated (const IdentityAddress &addr) {}
virtual void onSecurityAlert (const std::shared_ptr<ConferenceSecurityEvent> &event) {}
virtual void onFirstNotifyReceived (const IdentityAddress &addr) {}
virtual void onParticipantAdded (const std::shared_ptr<ConferenceParticipantEvent> &event, bool isFullState) {}
virtual void onParticipantRemoved (const std::shared_ptr<ConferenceParticipantEvent> &event, bool isFullState) {}
......
......@@ -134,6 +134,12 @@ private:
const soci::row &row
) const;
std::shared_ptr<EventLog> selectConferenceSecurityEvent (
const ConferenceId &conferenceId,
EventLog::Type type,
const soci::row &row
) const;
std::shared_ptr<EventLog> selectConferenceSubjectEvent (
const ConferenceId &conferenceId,
EventLog::Type type,
......@@ -149,6 +155,7 @@ private:
long long insertConferenceParticipantEvent (const std::shared_ptr<EventLog> &eventLog, long long *conferenceId = nullptr);
long long insertConferenceParticipantDeviceEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceSubjectEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceSecurityEvent (const std::shared_ptr<EventLog> &eventLog);
void setChatMessageParticipantState (
const std::shared_ptr<EventLog> &eventLog,
......
......@@ -526,7 +526,18 @@ shared_ptr<EventLog> MainDbPrivate::selectGenericConferenceEvent (
long long eventId = getConferenceEventIdFromRow(row);
shared_ptr<EventLog> eventLog = getEventFromCache(eventId);
if (!eventLog) {
eventLog = selectConferenceChatMessageEvent(chatRoom, type, row);
EventLog::Type type = EventLog::Type(row.get<int>(1));
switch (type) {
case EventLog::Type::ConferenceChatMessage:
eventLog = selectConferenceChatMessageEvent(chatRoom, type, row);
break;
case EventLog::Type::ConferenceSecurityAlert:
eventLog = selectConferenceSecurityEvent(chatRoom->getConferenceId(), type, row);
break;
default:
return nullptr;
}
if (eventLog)
cache(eventLog, eventId);
}
......@@ -573,6 +584,10 @@ shared_ptr<EventLog> MainDbPrivate::selectGenericConferenceNotifiedEvent (
eventLog = selectConferenceParticipantDeviceEvent(conferenceId, type, row);
break;
case EventLog::Type::ConferenceSecurityAlert:
eventLog = selectConferenceSecurityEvent(conferenceId, type, row);
break;
case EventLog::Type::ConferenceSubjectChanged:
eventLog = selectConferenceSubjectEvent(conferenceId, type, row);
break;
......@@ -675,6 +690,18 @@ shared_ptr<EventLog> MainDbPrivate::selectConferenceParticipantDeviceEvent (
);
}
shared_ptr<EventLog> MainDbPrivate::selectConferenceSecurityEvent (
const ConferenceId &conferenceId,
EventLog::Type type,
const soci::row &row
) const {
return make_shared<ConferenceSecurityEvent>(
getConferenceEventCreationTimeFromRow(row),
conferenceId,
row.get<string>(13)
);
}
shared_ptr<EventLog> MainDbPrivate::selectConferenceSubjectEvent (
const ConferenceId &conferenceId,
EventLog::Type type,
......@@ -908,6 +935,23 @@ long long MainDbPrivate::insertConferenceParticipantDeviceEvent (const shared_pt
return eventId;
}
long long MainDbPrivate::insertConferenceSecurityEvent (const shared_ptr<EventLog> &eventLog) {
long long conferenceId;
const long long &eventId = insertConferenceEvent(eventLog, &conferenceId);
if (eventId < 0)
return -1;
const string &securityAlert = static_pointer_cast<ConferenceSecurityEvent>(eventLog)->getSecurityAlert();
// insert security event into new table "conference_security_event"
soci::session *session = dbSession.getBackendSession();
*session << "INSERT INTO conference_security_event (event_id, security_alert)"
" VALUES (:eventId, :securityAlert)", soci::use(eventId), soci::use(securityAlert);
return eventId;
}
long long MainDbPrivate::insertConferenceSubjectEvent (const shared_ptr<EventLog> &eventLog) {
long long conferenceId;
const long long &eventId = insertConferenceNotifiedEvent(eventLog, &conferenceId);
......@@ -1507,6 +1551,17 @@ void MainDb::init () {
" ON DELETE CASCADE"
") " + charset;
*session <<
"CREATE TABLE IF NOT EXISTS conference_security_event ("
" event_id" + primaryKeyStr("BIGINT UNSIGNED") + ","
" security_alert VARCHAR(255) NOT NULL,"
" FOREIGN KEY (event_id)"
" REFERENCES conference_event(event_id)"
" ON DELETE CASCADE"
") " + charset;
*session <<
"CREATE TABLE IF NOT EXISTS conference_subject_event ("
" event_id" + primaryKeyStr("BIGINT UNSIGNED") + ","
......@@ -1718,6 +1773,11 @@ bool MainDb::addEvent (const shared_ptr<EventLog> &eventLog) {
eventId = d->insertConferenceParticipantDeviceEvent(eventLog);
break;
case EventLog::Type::ConferenceSecurityAlert:
cout << "adding security event to db" << endl;
eventId = d->insertConferenceSecurityEvent(eventLog);
break;
case EventLog::Type::ConferenceSubjectChanged:
eventId = d->insertConferenceSubjectEvent(eventLog);
break;
......@@ -1764,6 +1824,7 @@ bool MainDb::updateEvent (const shared_ptr<EventLog> &eventLog) {
case EventLog::Type::ConferenceParticipantUnsetAdmin:
case EventLog::Type::ConferenceParticipantDeviceAdded:
case EventLog::Type::ConferenceParticipantDeviceRemoved:
case EventLog::Type::ConferenceSecurityAlert:
case EventLog::Type::ConferenceSubjectChanged:
return false;
}
......
/*
* conference-security-event.cpp
* Copyright (C) 2010-2018 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "conference-event-p.h"
#include "conference-security-event.h"
// =============================================================================
using namespace std;
LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
class ConferenceSecurityEventPrivate : public ConferenceEventPrivate {
public:
string securityAlert;
};
// -----------------------------------------------------------------------------
ConferenceSecurityEvent::ConferenceSecurityEvent (
time_t creationTime,
const ConferenceId &conferenceId,
const string &securityAlert
) : ConferenceEvent(
*new ConferenceSecurityEventPrivate,
Type::ConferenceSecurityAlert,
creationTime,
conferenceId
) {
L_D();
d->securityAlert = securityAlert;
}
const string &ConferenceSecurityEvent::getSecurityAlert () const {
L_D();
return d->securityAlert;
}
LINPHONE_END_NAMESPACE
/*
* conference-security-event.h
* Copyright (C) 2010-2018 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _L_CONFERENCE_SECURITY_EVENT_H_
#define _L_CONFERENCE_SECURITY_EVENT_H_
#include <string>
#include "conference-event.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class ConferenceSecurityEventPrivate;
class LINPHONE_PUBLIC ConferenceSecurityEvent : public ConferenceEvent {
public:
ConferenceSecurityEvent (
time_t creationTime,
const ConferenceId &conferenceId,
const std::string &securityAlert
);
const std::string &getSecurityAlert () const;
private:
L_DECLARE_PRIVATE(ConferenceSecurityEvent);
L_DISABLE_COPY(ConferenceSecurityEvent);
};
LINPHONE_END_NAMESPACE
#endif // ifndef _L_CONFERENCE_SECURITY_EVENT_H_
......@@ -23,6 +23,7 @@
#include "conference/conference-call-event.h"
#include "conference/conference-chat-message-event.h"
#include "conference/conference-participant-device-event.h"
#include "conference/conference-security-event.h"
#include "conference/conference-subject-event.h"
#endif // ifndef _L_EVENTS_H_
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