Commit 75b134cf authored by Adrien Béraud's avatar Adrien Béraud Committed by Sébastien Blin

jamiaccount: split account management

Change-Id: I669bfcc6f0e3f7bd60c56f0046f8701ad14541ce
parent 25a6bd3f
......@@ -718,6 +718,8 @@
<ClCompile Include="..\src\im\instant_messaging.cpp" />
<ClCompile Include="..\src\im\message_engine.cpp" />
<ClCompile Include="..\src\ip_utils.cpp" />
<ClCompile Include="..\src\jamidht\account_manager.cpp" />
<ClCompile Include="..\src\jamidht\contact_list.cpp" />
<ClCompile Include="..\src\logger.cpp" />
<ClCompile Include="..\src\manager.cpp" />
<ClCompile Include="..\src\media\audio\audiobuffer.cpp" />
......@@ -876,6 +878,9 @@
<ClInclude Include="..\src\im\instant_messaging.h" />
<ClInclude Include="..\src\im\message_engine.h" />
<ClInclude Include="..\src\ip_utils.h" />
<ClInclude Include="..\src\jamidht\account_manager.h" />
<ClInclude Include="..\src\jamidht\contact_list.h" />
<ClInclude Include="..\src\jamidht\jami_contact.h" />
<ClInclude Include="..\src\logger.h" />
<ClInclude Include="..\src\manager.h" />
<ClInclude Include="..\src\map_utils.h" />
......
......@@ -421,6 +421,12 @@
<ClCompile Include="dlfcn.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\jamidht\account_manager.cpp">
<Filter>Source Files\jamidht</Filter>
</ClCompile>
<ClCompile Include="..\src\jamidht\contact_list.cpp">
<Filter>Source Files\jamidht</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\account.h">
......@@ -867,6 +873,15 @@
<ClInclude Include="dlfcn.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\src\jamidht\account_manager.h">
<Filter>Source Files\jamidht</Filter>
</ClInclude>
<ClInclude Include="..\src\jamidht\contact_list.h">
<Filter>Source Files\jamidht</Filter>
</ClInclude>
<ClInclude Include="..\src\jamidht\jami_contact.h">
<Filter>Source Files\jamidht</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\src\jamidht\eth\libdevcore\Makefile.am">
......
......@@ -34,6 +34,6 @@ dring_CXXFLAGS= -I$(top_srcdir)/src ${DBUSCPP_CFLAGS} \
dring_LDADD = dbus/libclient_dbus.la ${DBUSCPP_LIBS} $(top_builddir)/src/libring.la -ldl
endif
if RING_NODEJS
if ENABLE_NODEJS
SUBDIRS+=nodejs
endif
......@@ -421,16 +421,16 @@ AC_DEFINE_UNQUOTED([HAVE_RINGNS], `if test "x$enable_ringns" != "xno"; then echo
dnl nodejs module
AC_ARG_WITH([nodejs], AS_HELP_STRING([--with-nodejs], [Enable NodeJS module]))
AM_CONDITIONAL([RING_NODEJS], test "x$enable_nodejs" != "xno", [Define if you use the NodeJS module])
AM_CONDITIONAL([ENABLE_NODEJS], test "x$enable_nodejs" != "xno", [Define if you use the NodeJS module])
AC_DEFINE_UNQUOTED([HAVE_NODEJS], `if test "x$enable_ringns" != "xno"; then echo 1; else echo 0; fi`, [Define if you use the NodeJS module])
AS_IF([test "x$with_nodejs" = "xyes"], [
AC_PATH_PROG(SWIG, swig, "")
AS_AC_EXPAND(SBINDIR, $sbindir)
AC_SUBST(SBINDIR)
AC_CONFIG_FILES([bin/nodejs/Makefile])
AM_CONDITIONAL(RING_NODEJS, true)
AM_CONDITIONAL(ENABLE_NODEJS, true)
],
AM_CONDITIONAL(RING_NODEJS, false)
AM_CONDITIONAL(ENABLE_NODEJS, false)
);
AS_IF([test "x$enable_ringns" != "xno"], [
......
......@@ -211,7 +211,7 @@ MessageEngine::load()
}
JAMI_DBG("[Account %s] loaded %lu messages from %s", account_.getAccountID().c_str(), loaded, savePath_.c_str());
} catch (const std::exception& e) {
JAMI_ERR("[Account %s] couldn't load messages from %s: %s", account_.getAccountID().c_str(), savePath_.c_str(), e.what());
JAMI_DBG("[Account %s] couldn't load messages from %s: %s", account_.getAccountID().c_str(), savePath_.c_str(), e.what());
}
}
......
......@@ -19,10 +19,16 @@ libringacc_la_SOURCES = \
accountarchive.cpp \
accountarchive.h \
p2p.cpp \
p2p.h
p2p.h \
contact_list.h \
contact_list.cpp \
account_manager.h \
account_manager.cpp
if RINGNS
libringacc_la_SOURCES += \
namedirectory.cpp \
namedirectory.h
endif
nobase_include_HEADERS= jami_contact.h
This diff is collapsed.
This diff is collapsed.
......@@ -89,6 +89,7 @@ AccountArchive::serialize() const
if (ca_key and *ca_key)
root[Conf::RING_CA_KEY] = base64::encode(ca_key->serialize());
root[Conf::RING_ACCOUNT_KEY] = base64::encode(id.first->serialize());
root[Conf::RING_ACCOUNT_CERT] = base64::encode(id.second->getPacked());
root[Conf::ETH_KEY] = base64::encode(eth_key);
......
......@@ -17,7 +17,7 @@
*/
#pragma once
#include "ringcontact.h"
#include "jami_contact.h"
#include "fileutils.h"
#include <opendht/crypto.h>
......
This diff is collapsed.
/*
* Copyright (C) 2019 Savoir-faire Linux Inc.
*
* Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
*
* 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 3 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.
*/
#pragma once
#include "jami_contact.h"
#include "security/certstore.h"
#include <opendht/infohash.h>
#include <opendht/crypto.h>
#include <map>
#include <mutex>
#include <chrono>
namespace jami {
class ContactList {
public:
using clock = std::chrono::system_clock;
using time_point = clock::time_point;
using VerifyResult = dht::crypto::TrustList::VerifyResult;
using OnContactAdded = std::function<void(const std::string&, bool)>;
using OnContactRemoved = std::function<void(const std::string&, bool)>;
using OnIncomingTrustRequest = std::function<void(const std::string&, const std::vector<uint8_t>&, time_t)>;
using OnDevicesChanged = std::function<void()>;
struct OnChangeCallback {
OnContactAdded contactAdded;
OnContactRemoved contactRemoved;
OnIncomingTrustRequest trustRequest;
OnDevicesChanged devicesChanged;
};
ContactList(const std::shared_ptr<crypto::Certificate>& cert, const std::string& path, OnChangeCallback cb);
~ContactList();
void load();
void save();
/* Contacts */
std::map<std::string, std::string> getContactDetails(const dht::InfoHash&) const;
bool removeContact(const dht::InfoHash&, bool ban);
bool addContact(const dht::InfoHash&, bool confirmed = false);
bool setCertificateStatus(const std::string& cert_id, const tls::TrustStore::PermissionStatus status);
bool setCertificateStatus(const std::shared_ptr<crypto::Certificate>& cert, tls::TrustStore::PermissionStatus status, bool local = true);
tls::TrustStore::PermissionStatus getCertificateStatus(const std::string& cert_id) const {
return trust_.getCertificateStatus(cert_id);
}
std::vector<std::string> getCertificatesByStatus(tls::TrustStore::PermissionStatus status) const {
return trust_.getCertificatesByStatus(status);
}
bool isAllowed(const crypto::Certificate& crt, bool allowPublic) {
return trust_.isAllowed(crt, allowPublic);
}
VerifyResult isValidAccountDevice(const crypto::Certificate& crt) const {
return accountTrust_.verify(crt);
}
const std::map<dht::InfoHash, Contact>& getContacts() const;
void setContacts(const std::map<dht::InfoHash, Contact>&);
void updateContact(const dht::InfoHash&, const Contact&);
/* Contact requests */
/** Inform of a new contact request. Returns true if the request should be immediatly accepted (already a contact) */
bool onTrustRequest(const dht::InfoHash& peer_account, const dht::InfoHash& peer_device, time_t received, bool confirm, std::vector<uint8_t>&& payload);
std::vector<std::map<std::string, std::string>> getTrustRequests() const;
bool acceptTrustRequest(const dht::InfoHash& from);
bool discardTrustRequest(const dht::InfoHash& from);
/* Devices */
const std::map<dht::InfoHash, KnownDevice>& getKnownDevices() const { return knownDevices_; }
bool foundAccountDevice(const std::shared_ptr<dht::crypto::Certificate>& crt, const std::string& name = {}, const time_point& last_sync = time_point::min());
bool removeAccountDevice(const dht::InfoHash& device);
void setAccountDeviceName(const dht::InfoHash& device, const std::string& name);
DeviceSync getSyncData() const;
bool syncDevice(const dht::InfoHash& device, const time_point& syncDate);
//void onSyncData(DeviceSync&& device);
private:
mutable std::mutex lock;
std::map<dht::InfoHash, Contact> contacts_;
std::map<dht::InfoHash, TrustRequest> trustRequests_;
std::map<dht::InfoHash, KnownDevice> knownDevices_;
// Trust store with account main certificate as the only CA
dht::crypto::TrustList accountTrust_;
// Trust store for to match peer certificates
tls::TrustStore trust_;
std::string path_;
OnChangeCallback callbacks_;
void loadContacts();
void saveContacts() const;
void loadTrustRequests();
void saveTrustRequests() const;
void loadKnownDevices();
void saveKnownDevices() const;
};
}
......@@ -19,6 +19,10 @@
#include "string_utils.h"
#include <opendht/infohash.h>
#include <opendht/value.h>
#include <opendht/default_types.h>
#include <msgpack.hpp>
#include <json/json.h>
......@@ -108,4 +112,51 @@ struct Contact
MSGPACK_DEFINE_MAP(added, removed, confirmed, banned)
};
struct TrustRequest {
dht::InfoHash device;
time_t received;
std::vector<uint8_t> payload;
MSGPACK_DEFINE_MAP(device, received, payload)
};
struct DeviceAnnouncement : public dht::SignedValue<DeviceAnnouncement>
{
private:
using BaseClass = dht::SignedValue<DeviceAnnouncement>;
public:
static const constexpr dht::ValueType& TYPE = dht::ValueType::USER_DATA;
dht::InfoHash dev;
MSGPACK_DEFINE_MAP(dev);
};
struct DeviceSync : public dht::EncryptedValue<DeviceSync>
{
static const constexpr dht::ValueType& TYPE = dht::ValueType::USER_DATA;
uint64_t date;
std::string device_name;
std::map<dht::InfoHash, std::string> devices_known;
std::map<dht::InfoHash, Contact> peers;
std::map<dht::InfoHash, TrustRequest> trust_requests;
MSGPACK_DEFINE_MAP(date, device_name, devices_known, peers, trust_requests)
};
struct KnownDevice {
using clock = std::chrono::system_clock;
using time_point = clock::time_point;
/** Device certificate */
std::shared_ptr<dht::crypto::Certificate> certificate;
/** Device name */
std::string name {};
/** Time of last received device sync */
time_point last_sync {time_point::min()};
KnownDevice(const std::shared_ptr<dht::crypto::Certificate>& cert,
const std::string& n = {},
time_point sync = time_point::min())
: certificate(cert), name(n), last_sync(sync) {}
};
}
This diff is collapsed.
This diff is collapsed.
......@@ -51,6 +51,7 @@ public:
enum class Response : int { found = 0, invalidResponse, notFound, error };
enum class RegistrationResponse : int { success = 0,
invalidName,
invalidCredentials,
alreadyTaken,
error,
incompleteRequest,
......
......@@ -30,6 +30,7 @@
#include "peer_connection.h"
#include "security/tls_session.h"
#include "turn_transport.h"
#include "account_manager.h"
#include <opendht/default_types.h>
#include <opendht/rng.h>
......@@ -400,7 +401,7 @@ private:
// Send connection request through DHT
JAMI_DBG() << parent_.account << "[CNX] request connection to " << peer_;
parent_.account.dht().putEncrypted(
parent_.account.dht()->putEncrypted(
dht::InfoHash::get(PeerConnectionMsg::key_prefix + peer_.toString()), peer_, request);
// Wait for call to onResponse() operated by DHT
......@@ -674,7 +675,7 @@ DhtPeerConnector::Impl::onRequestMsg(PeerConnectionMsg&& request)
request.from,
[this, request=std::move(request)] (const std::shared_ptr<dht::crypto::Certificate>& cert) mutable {
dht::InfoHash peer_h;
if (account.foundPeerDevice(cert, peer_h))
if (AccountManager::foundPeerDevice(cert, peer_h))
onTrustedRequestMsg(std::move(request), cert, peer_h);
else
JAMI_WARN() << account << "[CNX] rejected untrusted connection request from "
......@@ -798,7 +799,7 @@ DhtPeerConnector::Impl::answerToRequest(PeerConnectionMsg&& request,
}
JAMI_DBG() << account << "[CNX] connection accepted, DHT reply to " << request.from;
account.dht().putEncrypted(
account.dht()->putEncrypted(
dht::InfoHash::get(PeerConnectionMsg::key_prefix + request.from.toString()),
request.from, request.respond(addresses));
......@@ -982,10 +983,10 @@ DhtPeerConnector::~DhtPeerConnector() = default;
void
DhtPeerConnector::onDhtConnected(const std::string& device_id)
{
pimpl_->account.dht().listen<PeerConnectionMsg>(
pimpl_->account.dht()->listen<PeerConnectionMsg>(
dht::InfoHash::get(PeerConnectionMsg::key_prefix + device_id),
[this](PeerConnectionMsg&& msg) {
if (msg.from == pimpl_->account.dht().getId())
if (msg.from == pimpl_->account.dht()->getId())
return true;
if (!pimpl_->account.isMessageTreated(msg.id)) {
if (msg.isRequest()) {
......@@ -1024,7 +1025,7 @@ DhtPeerConnector::requestConnection(const std::string& peer_id,
pimpl_->account.forEachDevice(
peer_h,
[this, addresses, connect_cb, tid](const dht::InfoHash& dev_h) {
if (dev_h == pimpl_->account.dht().getId()) {
if (dev_h == pimpl_->account.dht()->getId()) {
JAMI_ERR() << pimpl_->account.getAccountID() << "[CNX] no connection to yourself, bad person!";
return;
}
......@@ -1060,7 +1061,7 @@ DhtPeerConnector::closeConnection(const std::string& peer_id, const DRing::DataT
pimpl_->account.forEachDevice(
peer_h,
[this, tid](const dht::InfoHash& dev_h) {
if (dev_h == pimpl_->account.dht().getId()) {
if (dev_h == pimpl_->account.dht()->getId()) {
JAMI_ERR() << pimpl_->account.getAccountID() << "[CNX] no connection to yourself, bad person!";
return;
}
......
......@@ -487,7 +487,7 @@ TrustStore::getCertificateStatus(const std::string& cert_id) const
}
std::vector<std::string>
TrustStore::getCertificatesByStatus(TrustStore::PermissionStatus status)
TrustStore::getCertificatesByStatus(TrustStore::PermissionStatus status) const
{
std::vector<std::string> ret;
for (const auto& i : certStatus_)
......
......@@ -126,7 +126,7 @@ public:
PermissionStatus getCertificateStatus(const std::string& cert_id) const;
std::vector<std::string> getCertificatesByStatus(PermissionStatus status);
std::vector<std::string> getCertificatesByStatus(PermissionStatus status) const;
/**
* Check that the certificate is allowed (valid and permited) for contact.
......
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