예제 #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;
}
예제 #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);
}
예제 #3
0
파일: Hash.cpp 프로젝트: PowerKiKi/D-LAN
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();
}
예제 #4
0
파일: MainWindow.cpp 프로젝트: Fafou/D-LAN
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");
   }
}
예제 #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);
}
예제 #6
0
파일: Socket.cpp 프로젝트: Zorvalt/D-LAN
/**
  * 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();
   }
}
예제 #7
0
파일: File.cpp 프로젝트: 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);
   }
}
예제 #8
0
파일: Hash.cpp 프로젝트: PowerKiKi/D-LAN
Common::Hash Hasher::hash(const Common::Hash& hash)
{
   Hasher hasher;
   hasher.addData(hash.getData(), Hash::HASH_SIZE);
   return hasher.getResult();
}