Esempio n. 1
0
bool InternalCoreConnection::setCorePassword(const QString& newPassword, const QString& oldPassword)
{
   Protos::GUI::ChangePassword passMess;

   const quint64 newSalt = static_cast<quint64>(mtrand.randInt()) << 32 | mtrand.randInt();
   Common::Hash newPasswordHashed = Common::Hasher::hashWithSalt(newPassword, newSalt);

   passMess.mutable_new_password()->set_hash(newPasswordHashed.getData(), Common::Hash::HASH_SIZE);
   passMess.set_new_salt(newSalt);

   if (!oldPassword.isNull())
   {
      Common::Hash oldPasswordHashed = Common::Hasher::hashWithSalt(oldPassword, this->salt);
      if (!this->connectionInfo.password.isNull() && this->connectionInfo.password != oldPasswordHashed)
         return false;

      passMess.mutable_old_password()->set_hash(oldPasswordHashed.getData(), Common::Hash::HASH_SIZE);
   }

   this->connectionInfo.password = newPasswordHashed;
   this->salt = newSalt;

   this->send(Common::MessageHeader::GUI_CHANGE_PASSWORD, passMess);
   return true;
}
Esempio n. 2
0
void InternalCoreConnection::download(const Common::Hash& peerID, const Protos::Common::Entry& entry, const Common::Hash& sharedFolderID, const QString& path)
{
   // We cannot download our entries.
   if (peerID == this->getLocalID())
      return;

   Protos::GUI::Download downloadMessage;
   downloadMessage.mutable_peer_id()->set_hash(peerID.getData(), Common::Hash::HASH_SIZE);
   downloadMessage.mutable_entry()->CopyFrom(entry);
   if (!sharedFolderID.isNull())
      downloadMessage.mutable_destination_directory_id()->set_hash(sharedFolderID.getData(), Common::Hash::HASH_SIZE);
   Common::ProtoHelper::setStr(downloadMessage, &Protos::GUI::Download::set_destination_path, path);
   this->send(Common::MessageHeader::GUI_DOWNLOAD, downloadMessage);
}
Esempio n. 3
0
Common::Hash Hasher::hashWithSalt(const Common::Hash& hash, quint64 salt)
{
   Hasher hasher;
   hasher.addData(hash.getData(), Hash::HASH_SIZE);
   hasher.addSalt(salt);
   return hasher.getResult();
}
Esempio n. 4
0
void MainWindow::computeHash()
{
   QString error = this->checkPasswords();
   if (!error.isNull())
   {
      this->ui->txtResult->setText(error);
   }
   else
   {
      Common::Hash hash = Common::Hasher::hashWithRandomSalt(this->ui->txtPass1->text(), this->salt);

      Protos::Core::Settings settings;
      const google::protobuf::FieldDescriptor* passField = settings.GetDescriptor()->FindFieldByName("remote_password");
      const google::protobuf::FieldDescriptor* saltField = settings.GetDescriptor()->FindFieldByName("salt");

      settings.mutable_remote_password()->set_hash(hash.getData(), Common::Hash::HASH_SIZE);
      settings.set_salt(this->salt);

      std::string encodedHash;
      std::string encodedSalt;
      google::protobuf::TextFormat::PrintFieldValueToString(settings, passField, -1, &encodedHash);
      google::protobuf::TextFormat::PrintFieldValueToString(settings, saltField, -1, &encodedSalt);

      this->ui->txtResult->setText("remote_password {\n " % QString::fromStdString(encodedHash) % "}\nsalt: " % QString::fromStdString(encodedSalt) % "\n");
   }
}
Esempio n. 5
0
void InternalCoreConnection::download(const Common::Hash& peerID, const Protos::Common::Entry& entry)
{
   // We cannot download our entries.
   if (peerID == this->getLocalID())
      return;

   Protos::GUI::Download downloadMessage;
   downloadMessage.mutable_peer_id()->set_hash(peerID.getData(), Common::Hash::HASH_SIZE);
   downloadMessage.mutable_entry()->CopyFrom(entry);
   this->send(Common::MessageHeader::GUI_DOWNLOAD, downloadMessage);
}
Esempio n. 6
0
/**
  * When we ask to the fileManager some hashes for a given file this
  * slot will be called each time a new hash is available.
  */
void Socket::nextAskedHash(Common::Hash hash)
{
   Protos::Common::Hash hashProto;
   hashProto.set_hash(hash.getData(), Common::Hash::HASH_SIZE);
   this->send(Common::MessageHeader::CORE_HASH, hashProto);

   if (--this->nbHash == 0)
   {
      this->currentHashesResult.clear();
      this->finished();
   }
}
Esempio n. 7
0
File: File.cpp Progetto: Ummon/D-LAN
void File::populateEntry(Protos::Common::Entry* entry, bool setSharedDir, int maxHashes) const
{
   QMutexLocker locker(&this->mutex);

   Entry::populateEntry(entry, setSharedDir);

   entry->set_type(Protos::Common::Entry_Type_FILE);

   entry->clear_chunk();

   int nb = 0;
   for (QVectorIterator<QSharedPointer<Chunk>> i(this->chunks); i.hasNext();)
   {
      Protos::Common::Hash* protoHash = entry->add_chunk();

      Common::Hash hash = i.next()->getHash();
      if (!hash.isNull() && ++nb <= maxHashes)
         protoHash->set_hash(hash.getData(), Common::Hash::HASH_SIZE);
   }
}
Esempio n. 8
0
Common::Hash Hasher::hash(const Common::Hash& hash)
{
   Hasher hasher;
   hasher.addData(hash.getData(), Hash::HASH_SIZE);
   return hasher.getResult();
}