Skip to content

Commit

Permalink
securedht: check public key
Browse files Browse the repository at this point in the history
  • Loading branch information
aberaud committed Apr 5, 2018
1 parent 1acace1 commit 20ab71a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 0 additions & 2 deletions include/opendht/securedht.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,6 @@ class OPENDHT_PUBLIC SecureDht final : public DhtInterface {
std::map<InfoHash, Sp<crypto::Certificate>> nodesCertificates_ {};
std::map<InfoHash, Sp<const crypto::PublicKey>> nodesPubKeys_ {};

std::uniform_int_distribution<Value::Id> rand_id {};

std::atomic_bool forward_all_ {false};
};

Expand Down
14 changes: 9 additions & 5 deletions src/securedht.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,13 @@ SecureDht::findPublicKey(const InfoHash& node, std::function<void(const Sp<const
findCertificate(node, [=](const Sp<crypto::Certificate> crt) {
if (crt && *crt) {
auto pk = std::make_shared<crypto::PublicKey>(crt->getPublicKey());
nodesPubKeys_[pk->getId()] = pk;
if (cb) cb(pk);
} else {
if (cb) cb(nullptr);
if (*pk) {
nodesPubKeys_[pk->getId()] = pk;
if (cb) cb(pk);
return;
}
}
if (cb) cb(nullptr);
});
}

Expand All @@ -236,7 +238,8 @@ SecureDht::checkValue(const Sp<Value>& v)
try {
Value decrypted_val (decrypt(*v));
if (decrypted_val.recipient == getId()) {
nodesPubKeys_[decrypted_val.owner->getId()] = decrypted_val.owner;
if (decrypted_val.owner)
nodesPubKeys_[decrypted_val.owner->getId()] = decrypted_val.owner;
return std::make_shared<Value>(std::move(decrypted_val));
}
// Ignore values belonging to other people
Expand Down Expand Up @@ -317,6 +320,7 @@ SecureDht::putSigned(const InfoHash& hash, Sp<Value> val, DoneCallback callback,
{
if (val->id == Value::INVALID_ID) {
crypto::random_device rdev;
std::uniform_int_distribution<Value::Id> rand_id;
val->id = rand_id(rdev);
}

Expand Down

0 comments on commit 20ab71a

Please sign in to comment.