Skip to content
Snippets Groups Projects
Commit 20ab71ab authored by Adrien Béraud's avatar Adrien Béraud
Browse files

securedht: check public key

parent 1acace1b
No related branches found
No related tags found
No related merge requests found
...@@ -346,8 +346,6 @@ private: ...@@ -346,8 +346,6 @@ private:
std::map<InfoHash, Sp<crypto::Certificate>> nodesCertificates_ {}; std::map<InfoHash, Sp<crypto::Certificate>> nodesCertificates_ {};
std::map<InfoHash, Sp<const crypto::PublicKey>> nodesPubKeys_ {}; std::map<InfoHash, Sp<const crypto::PublicKey>> nodesPubKeys_ {};
std::uniform_int_distribution<Value::Id> rand_id {};
std::atomic_bool forward_all_ {false}; std::atomic_bool forward_all_ {false};
}; };
......
...@@ -213,11 +213,13 @@ SecureDht::findPublicKey(const InfoHash& node, std::function<void(const Sp<const ...@@ -213,11 +213,13 @@ SecureDht::findPublicKey(const InfoHash& node, std::function<void(const Sp<const
findCertificate(node, [=](const Sp<crypto::Certificate> crt) { findCertificate(node, [=](const Sp<crypto::Certificate> crt) {
if (crt && *crt) { if (crt && *crt) {
auto pk = std::make_shared<crypto::PublicKey>(crt->getPublicKey()); auto pk = std::make_shared<crypto::PublicKey>(crt->getPublicKey());
if (*pk) {
nodesPubKeys_[pk->getId()] = pk; nodesPubKeys_[pk->getId()] = pk;
if (cb) cb(pk); if (cb) cb(pk);
} else { return;
if (cb) cb(nullptr);
} }
}
if (cb) cb(nullptr);
}); });
} }
...@@ -236,6 +238,7 @@ SecureDht::checkValue(const Sp<Value>& v) ...@@ -236,6 +238,7 @@ SecureDht::checkValue(const Sp<Value>& v)
try { try {
Value decrypted_val (decrypt(*v)); Value decrypted_val (decrypt(*v));
if (decrypted_val.recipient == getId()) { if (decrypted_val.recipient == getId()) {
if (decrypted_val.owner)
nodesPubKeys_[decrypted_val.owner->getId()] = decrypted_val.owner; nodesPubKeys_[decrypted_val.owner->getId()] = decrypted_val.owner;
return std::make_shared<Value>(std::move(decrypted_val)); return std::make_shared<Value>(std::move(decrypted_val));
} }
...@@ -317,6 +320,7 @@ SecureDht::putSigned(const InfoHash& hash, Sp<Value> val, DoneCallback callback, ...@@ -317,6 +320,7 @@ SecureDht::putSigned(const InfoHash& hash, Sp<Value> val, DoneCallback callback,
{ {
if (val->id == Value::INVALID_ID) { if (val->id == Value::INVALID_ID) {
crypto::random_device rdev; crypto::random_device rdev;
std::uniform_int_distribution<Value::Id> rand_id;
val->id = rand_id(rdev); val->id = rand_id(rdev);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment