Commit 5abe6b57 authored by Adrien Béraud's avatar Adrien Béraud

ring: attach payload to trust requests

Allows to attach arbitrary payloads to a trust request.
This would be used by clients to exchange profiles.

Refs #76856
Refs #77549

Change-Id: I8f0de246285416f48b2f1cdc14e94ac5cd31cc0f
parent 646dd5cd
......@@ -936,6 +936,8 @@
</arg>
<arg type="s" name="from">
</arg>
<arg type="ay" name="payload">
</arg>
<arg type="t" name="receiveTime">
</arg>
</signal>
......@@ -946,6 +948,8 @@
</arg>
<arg type="s" name="to" direction="in">
</arg>
<arg type="ay" name="payload" direction="in">
</arg>
</method>
<method name="getAddrFromInterfaceName" tp:name-for-bindings="getAddrFromInterfaceName">
......
......@@ -187,7 +187,7 @@ DBusClient::initLibrary(int flags)
exportable_callback<ConfigurationSignal::VolatileDetailsChanged>(bind(&DBusConfigurationManager::volatileAccountDetailsChanged, confM, _1, _2)),
exportable_callback<ConfigurationSignal::Error>(bind(&DBusConfigurationManager::errorAlert, confM, _1)),
exportable_callback<ConfigurationSignal::IncomingAccountMessage>(bind(&DBusConfigurationManager::incomingAccountMessage, confM, _1, _2, _3 )),
exportable_callback<ConfigurationSignal::IncomingTrustRequest>(bind(&DBusConfigurationManager::incomingTrustRequest, confM, _1, _2, _3 )),
exportable_callback<ConfigurationSignal::IncomingTrustRequest>(bind(&DBusConfigurationManager::incomingTrustRequest, confM, _1, _2, _3, _4 )),
exportable_callback<ConfigurationSignal::CertificatePinned>(bind(&DBusConfigurationManager::certificatePinned, confM, _1 )),
exportable_callback<ConfigurationSignal::CertificatePathPinned>(bind(&DBusConfigurationManager::certificatePathPinned, confM, _1, _2 )),
exportable_callback<ConfigurationSignal::CertificateExpired>(bind(&DBusConfigurationManager::certificateExpired, confM, _1 )),
......
......@@ -455,9 +455,9 @@ DBusConfigurationManager::discardTrustRequest(const std::string& accountId, cons
}
void
DBusConfigurationManager::sendTrustRequest(const std::string& accountId, const std::string& to)
DBusConfigurationManager::sendTrustRequest(const std::string& accountId, const std::string& to, const std::vector<uint8_t>& payload)
{
DRing::sendTrustRequest(accountId, to);
DRing::sendTrustRequest(accountId, to, payload);
}
auto
......
......@@ -143,7 +143,7 @@ class DBusConfigurationManager :
std::map<std::string, std::string> getTrustRequests(const std::string& accountId);
bool acceptTrustRequest(const std::string& accountId, const std::string& from);
bool discardTrustRequest(const std::string& accountId, const std::string& from);
void sendTrustRequest(const std::string& accountId, const std::string& to);
void sendTrustRequest(const std::string& accountId, const std::string& to, const std::vector<uint8_t>& payload);
};
#endif // __RING_DBUSCONFIGURATIONMANAGER_H__
# OPENDHT
OPENDHT_VERSION := e2004d69cb82edcbbf4f95af948cf6dd22cfdb62
OPENDHT_VERSION := 7729f9e283b19b7b0f2cba67490a6fc985fce57a
OPENDHT_URL := https://github.com/savoirfairelinux/opendht/archive/$(OPENDHT_VERSION).tar.gz
PKGS += opendht
......
......@@ -310,10 +310,10 @@ discardTrustRequest(const std::string& accountId, const std::string& from)
}
void
sendTrustRequest(const std::string& accountId, const std::string& to)
sendTrustRequest(const std::string& accountId, const std::string& to, const std::vector<uint8_t>& payload)
{
if (auto acc = ring::Manager::instance().getAccount<ring::RingAccount>(accountId))
acc->sendTrustRequest(to);
acc->sendTrustRequest(to, payload);
}
///This function is used as a base for new accounts for clients that support it
......
......@@ -156,7 +156,7 @@ std::map<std::string, std::string> getTrustRequests(const std::string& accountId
bool acceptTrustRequest(const std::string& accountId, const std::string& from);
bool discardTrustRequest(const std::string& accountId, const std::string& from);
void sendTrustRequest(const std::string& accountId, const std::string& to);
void sendTrustRequest(const std::string& accountId, const std::string& to, const std::vector<uint8_t>& payload = {});
// Configuration signal type definitions
struct ConfigurationSignal {
......@@ -192,7 +192,7 @@ struct ConfigurationSignal {
};
struct IncomingTrustRequest {
constexpr static const char* name = "IncomingTrustRequest";
using cb_type = void(const std::string& /*account_id*/, const std::string& /*from*/, time_t received);
using cb_type = void(const std::string& /*account_id*/, const std::string& /*from*/, const std::vector<uint8_t>& payload, time_t received);
};
struct CertificatePinned {
constexpr static const char* name = "CertificatePinned";
......
......@@ -819,13 +819,15 @@ void RingAccount::doRegister_()
if (req == this_.trustRequests_.end()) {
this_.trustRequests_.emplace_back(TrustRequest{
.from = v.from,
.received = std::chrono::system_clock::now()
.received = std::chrono::system_clock::now(),
.payload = v.payload
});
req = std::prev(this_.trustRequests_.end());
}
emitSignal<DRing::ConfigurationSignal::IncomingTrustRequest>(
this_.getAccountID(),
req->from.toString(),
req->payload,
std::chrono::system_clock::to_time_t(req->received)
);
return true;
......@@ -1188,12 +1190,12 @@ RingAccount::discardTrustRequest(const std::string& from)
}
void
RingAccount::sendTrustRequest(const std::string& to)
RingAccount::sendTrustRequest(const std::string& to, const std::vector<uint8_t>& payload)
{
setCertificateStatus(to, tls::TrustStore::Status::ALLOWED);
dht_.putEncrypted(dht::InfoHash::get("inbox:"+to),
dht::InfoHash(to),
dht::TrustRequest(DHT_TYPE_NS));
dht::TrustRequest(DHT_TYPE_NS, payload));
}
} // namespace ring
......@@ -258,7 +258,7 @@ class RingAccount : public SIPAccountBase {
bool acceptTrustRequest(const std::string& from);
bool discardTrustRequest(const std::string& from);
void sendTrustRequest(const std::string& to);
void sendTrustRequest(const std::string& to, const std::vector<uint8_t>& payload);
private:
......@@ -330,6 +330,7 @@ class RingAccount : public SIPAccountBase {
struct TrustRequest {
dht::InfoHash from;
std::chrono::system_clock::time_point received;
std::vector<uint8_t> payload;
};
std::vector<TrustRequest> trustRequests_;
......
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