Beispiel #1
0
//Hah. This "password" actually doesn't give any real security. The idea was that me (the programmer) would distribute a hash to the host which would allow only one person to become a server.
//In reality, this never got implemented correctly, so all it does is prevent the client becomming a server without a correct hash file / password pair
void Widget::checkPassword(QByteArray pass)
{
#ifndef DEBUG
    QCryptographicHash * hash = new QCryptographicHash(QCryptographicHash::Md5);
    QFile * password = new QFile("password.hash", this);
    if(password->open(QIODevice::ReadOnly))
    {
        QByteArray hashSt = password->readAll();
        hash->addData(pass);
        QByteArray hashTs = hash->result().toHex();
        QString test = QString(hashTs);
        if(hashSt == hashTs)
        {
#endif
            startServer();
#ifndef DEBUG
        }
        else
        {
            QMessageBox::information(mainWindow, "Password", "That password does not hash to the one stored in password.hash");
        }
    }
    else
    {
        QMessageBox::information(mainWindow, "Password", "password.hash Not found");
    }
#endif
}
Beispiel #2
0
int Auth::loginUser(QString username, QString passwd)
{
    token.clear();

    int r;
    // Database successfully opened;
    QString qstr = QString( "SELECT fullname, id FROM users WHERE username='******' AND userpass = '******';").arg(username).arg(passwd);
    QSqlQuery query(qstr);
    if(query.isActive())
    {
	query.next();
	fullname = query.value(0).toString();
	QDateTime now = QDateTime::currentDateTime();
	QCryptographicHash *t = new QCryptographicHash(QCryptographicHash::Sha1);
	t->addData(username.toAscii());
	t->addData(QString("%1").arg(now.toTime_t()).toAscii());
	token = token.append(t->result().toBase64());
	if(query.size()>0)
	    r = 0;
	else
	    r = -1;
    }
    else
    {
	qDebug() << "Query Error";
    }

    return r;
}
void ImportKey::addToHash(QCryptographicHash &hash) const
{
    hash.addData(reinterpret_cast<const char *>(&type), sizeof(type));
    hash.addData(reinterpret_cast<const char *>(&majorVersion), sizeof(majorVersion));
    hash.addData(reinterpret_cast<const char *>(&minorVersion), sizeof(minorVersion));
    foreach (const QString &s, splitPath) {
        hash.addData("/", 1);
        hash.addData(reinterpret_cast<const char *>(s.constData()), sizeof(QChar) * s.size());
    }
void FakeMetaEnum::addToHash(QCryptographicHash &hash) const
{
    int len = m_name.size();
    hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
    hash.addData(reinterpret_cast<const char *>(m_name.constData()), len * sizeof(QChar));
    len = m_keys.size();
    hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
    foreach (const QString &key, m_keys) {
        len = key.size();
        hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
        hash.addData(reinterpret_cast<const char *>(key.constData()), len * sizeof(QChar));
    }
Beispiel #5
0
void Dialog::on_pushButton_5_clicked()
{
    QCryptographicHash* hash;
    QByteArray bArray;
    QBuffer buffer( &bArray );
    buffer.open( QIODevice::WriteOnly );
    pix.save( &buffer, "PNG",0 );
    //pix.loadFromData(bArray,"PNG");
    QByteArray by2 = qCompress(bArray,9); //qUncompress(by); //
    QByteArray result = hash->hash(bArray,QCryptographicHash::Md5);
    ui->label_5->setText(QString::number(bArray.size())+"  :  "+QString::number(by2.size()));

    ui->label_6->setText(result.toHex());
}
Beispiel #6
0
void NovenaTestEngine::getSerial(void)
{
    QCryptographicHash *hash = new QCryptographicHash(QCryptographicHash::Sha1);
    int mem_fd = 0;
    quint32 *mem_32 = NULL;
    int mem_range = 0x021b0000;

    _serialNumber = "no-serial";

    mem_fd = open("/dev/mem", O_RDWR);
    if (mem_fd < 0) {
        updateTestState("system", TEST_INFO, 0, "Couldn't open /dev/mem");
        goto out;
    }

    mem_32 = (quint32 *)mmap(0, 0xffff, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, mem_range&~0xFFFF);
    if (-1 == (int)mem_32) {
        updateTestState("system", TEST_INFO, 0, QString() + "Couldn't mmap /dev/mem: " + strerror(errno));
        goto out;
    }

    hash->addData((const char *)&mem_32[0xc400], 4);
    hash->addData((const char *)&mem_32[0xc410], 4);
    hash->addData((const char *)&mem_32[0xc420], 4);
    hash->addData((const char *)&mem_32[0xc430], 4);
    hash->addData((const char *)&mem_32[0xc440], 4);
    hash->addData((const char *)&mem_32[0xc450], 4);
    hash->addData((const char *)&mem_32[0xc460], 4);
    hash->addData((const char *)&mem_32[0xc470], 4);
    hash->addData((const char *)&mem_32[0xc480], 4);
    hash->addData((const char *)&mem_32[0xc490], 4);
    hash->addData((const char *)&mem_32[0xc4a0], 4);
    hash->addData((const char *)&mem_32[0xc4b0], 4);
    hash->addData((const char *)&mem_32[0xc4c0], 4);
    hash->addData((const char *)&mem_32[0xc4d0], 4);
    hash->addData((const char *)&mem_32[0xc4e0], 4);
    hash->addData((const char *)&mem_32[0xc4f0], 4);

    _serialNumber = hash->result().toHex();
    delete hash;

    updateTestState("system", TEST_INFO, 0, QString() + "Serial number: " + _serialNumber);

out:
    if (mem_fd)
        close(mem_fd);
    if (mem_32)
        munmap(mem_32, 0xFFFF);
}
void UFHeader::addToHash(QCryptographicHash& hash) const 
{
    QByteArray data;
    QDataStream stream( &data, QIODevice::WriteOnly );
    stream << *this;
    hash.addData(data);
}
void UFEntry::addToHash(QCryptographicHash& hash) const 
{
    QByteArray data;
    QDataStream stream( &data, QIODevice::WriteOnly );
    stream.setVersion( QDataStream::Qt_4_2 );
    stream << *this;
    hash.addData(data);
}
QString md5hash (const QString &fileName)
{
	QFile file (fileName);

	if (!file.open (QIODevice::ReadOnly)) {
		return QString ();
	}

	QCryptographicHash hash (QCryptographicHash::Md5);

	while (!file.atEnd()) {
		const QByteArray &buf = file.read (bufferSize);
		hash.addData (buf);
	}

	return hash.result().toHex();
}
Beispiel #10
0
QVariant
CDeviceGIT::getInfo (DeviceInfo _what)
{
	QVariant res;

	switch (_what)
	{
		case PATH:
		{
			res = m_git_url.urledPath ();
			break;
		}

		case IDENTITY:
		{
			QCryptographicHash hash (QCryptographicHash::Sha1);
			hash.addData (m_data);
			res = QString (hash.result ().toHex ());
			break;
		}

		case CONTENT_TYPE:
		{
			res = OAF::CMimeDatabase::instance ().lookupMimeTypes (m_git_url.fileExt (),
																   m_buffer->size (), m_buffer);
			break;
		}

		case LAST_MODIFIED:
		{
			//
			// За дату последнего изменения файла примем дату создания коммита,
			// которому он принадлежит
			//
			res = fileInRevisionDate (m_git_url);
			break;
		}

		default:
			break;
	}

	return res;
}
Beispiel #11
0
void Registration::rejestruj()
{
    if(checkLogin() && checkEmail() && passwdCmp())
    {
        QByteArray haslo = ui->edit_haslo->text().toUtf8();
        QCryptographicHash *hash = new QCryptographicHash(QCryptographicHash::Md5);
        hash->addData(haslo);
        QSqlQuery zapytanie("INSERT INTO users(login, password, email) VALUES ('"+ ui->edit_login->text()+"','"+hash->result().toHex()+"','"+ui->edit_email->text()+"');");
        this->close();
        if(zapytanie.numRowsAffected()!=0)
        {
            QMessageBox::information(0,"rejestracja","dodano nowego uzytkownika\n zalogowano automatycznie");
            Wydatnik::getInstance()->zaloguj(ui->edit_login->text(),hash->result().toHex());
        }
        else
        {
            QMessageBox::warning(0,"rejestracja","rejestracja nie powiodla sie");
        }
    }
    else
        Wydatnik::getInstance()->Error("Podano niepoprawne dane");
}
void ComponentVersion::addToHash(QCryptographicHash &hash) const
{
    hash.addData(reinterpret_cast<const char *>(&_major), sizeof(_major));
    hash.addData(reinterpret_cast<const char *>(&_minor), sizeof(_minor));
}
void CreateTorrentWindow::createFile(QString filename) {
    //Setup progress bar
    ui->progressBar->setVisible(true);
    ui->progressBar->setRange(0, 100);
    ui->progressBar->setValue(0);

    QFile ifile(filename);
    QByteArray read;
    ifile.open(QIODevice::ReadOnly);

    QCryptographicHash *h = new QCryptographicHash(QCryptographicHash::Md5);
    h->addData(ifile.readAll().constData());

    //Setting filename as hash of the file
    QString fname1 = QString(h->result().toHex()) + ".torrent";
    QFile tfile(fname1.toUtf8().constData());
    ifile.seek(0);
    if(!(tfile.open(QIODevice::Append)))
    {
       qDebug("File cannot be opened.");
       exit(0);
    }

    //Writing "name " followed by the source filename
    tfile.write("name ");
    QString name = this->clnt->editName(ifile.fileName());

    tfile.write(name.toUtf8().constData());
    tfile.write(QString(tr("\n")).toUtf8().constData());

    //Writing "piece-length " followed by length og the piece which is 256000
    tfile.write("piece-length ");
    tfile.write("256000");
    tfile.write(QString(tr("\n")).toUtf8().constData());

    //Writing "size " followed by size of file
    tfile.write("size ");
    tfile.write(QString::number(ifile.size()).toUtf8().constData());
    tfile.write(QString(tr("\n")).toUtf8().constData());

    //Writing number of pieces and piece hashes of all the pieces
    tfile.write("piece-hash ");
    qint64 pieces = ifile.size()/256000;
    if (pieces % 256000 != 0 || pieces == 0)
        pieces++;
    tfile.write(QString::number(pieces).toUtf8().constData());
    tfile.write(QString(tr("\n")).toUtf8().constData());

    int i;
    for (i = 0; i < pieces; i++) {
        ui->progressBar->setValue((i+1/pieces)*100);                                    //Updating progress bar
        read = ifile.read(256000);
        QCryptographicHash *ha = new QCryptographicHash(QCryptographicHash::Md5);
        ha->addData(read.constData());
        //ha->reset();
        QString hash = QString(ha->result().toHex());
        tfile.write(hash.toUtf8().constData());
        tfile.write(QString(tr("\n")).toUtf8().constData());
    }
    ui->progressBar->setValue((i/pieces)*100);
    tfile.close();
    QString finish = " F " + getAddress() + " " + fname1 + " ";                         //Notifying central server about creation
    this->clnt->socket->write(finish.toUtf8());
    this->clnt->socket->waitForBytesWritten();
    //qDebug() << finish ;
}
Beispiel #14
0
QString VerifierPrivate::calculatePartialChecksum(QFile *file, const QString &type, KIO::fileoffset_t startOffset, int pieceLength, KIO::filesize_t fileSize)
{
    if (!file)
    {
        return QString();
    }

    if (!fileSize)
    {
        fileSize = file->size();
    }
    //longer than the file, so adapt it
    if (static_cast<KIO::fileoffset_t>(fileSize) < startOffset + pieceLength)
    {
        pieceLength = fileSize - startOffset;
    }

    if (type != MD5 && type != SHA1) {
        return QString();
    }

    //we only read 512kb each time, to save RAM
    int numData = pieceLength / PARTSIZE;
    KIO::fileoffset_t dataRest = pieceLength % PARTSIZE;

    if (!numData && !dataRest)
    {
        return QString();
    }

    QCryptographicHash *hash = 0;
    if (type == MD5) {
        hash = new QCryptographicHash(QCryptographicHash::Md5);
    } else if (type == SHA1) {
        hash = new QCryptographicHash(QCryptographicHash::Sha1);
    }
    int k = 0;
    for (k = 0; k < numData; ++k)
    {
        if (!file->seek(startOffset + PARTSIZE * k))
        {
            return QString();
        }

        QByteArray data = file->read(PARTSIZE);
        hash->addData(data);
    }

    //now read the rest
    if (dataRest)
    {
        if (!file->seek(startOffset + PARTSIZE * k))
        {
            return QString();
        }

        QByteArray data = file->read(dataRest);
        hash->addData(data);
    }

    return QString(hash->result().toHex());
}
//SLOT to readyRead. Called upon data arrival
void MiniServer::readyRead() {
    QTcpSocket *socket = (QTcpSocket *)sender();                                //Get the socket that sent data
    int p = 0, len = socDataList.size();
    socketData *socDes = NULL;
    for ( ; p < len; p++) {                                                     //Get socDes according to that socket
        if (socDataList.at(p)->socketDesciptor == socket->socketDescriptor()) {
            socDes = socDataList.at(p);
            break;
        }
    }
    QByteArray Data = socket->readAll();                //Read data from the buffer that comes on the socket
    int i = 0;

    //Process the message which will start with start byte and then data
    for (i = 0; i < Data.size(); i++) {
        //If dataRead is on then read data into buffer till buffer's size is matched to expected size
        if (!socDes->readingStart && socDes->dataRead && socDes->buffer.size() < (socDes->end-(qint64)(socDes->start.toLong())+1)) {
            socDes->buffer.append(Data[i]);
            continue;
        }

        //If expected data is in buffer then ....
        if ((socDes->buffer.size() == (socDes->end - (qint64)(socDes->start.toLong()) + 1)) && socDes->dataRead) {
            //qDebug() << "got";
            fstream file;
            file.open(this->filename.toUtf8().constData(), ios::in | ios::out | ios::ate);
            if (!map[(qint64)(socDes->start.toLong())]) {           //If data is already not written

                QCryptographicHash *ha = new QCryptographicHash(QCryptographicHash::Md5);
                ha->addData(socDes->buffer.constData());
                QString hash = QString(ha->result().toHex());

                if (!hash.compare(this->pieceHashes.at(((qint64)socDes->start.toLong())/this->pieceSize))) {        //Check hash of the piece
                    //Mark it as data written and write data and emit signal that data is written
                    map[(qint64)(socDes->start.toLong())] = true;
                    file.seekp(socDes->start.toLong(), ios::beg);
                    file.write(socDes->buffer.constData(), socDes->buffer.size());
                    this->numberOfBytesWritten += socDes->buffer.size();    //Update number of bytes written
                    emit dataGot();
                    if (this->numberOfBytesWritten == this->size) {
                        file.close();                                       //Check if file transfer is done
                        emit fileTransferDone();
                    }
                } else {

                    //If piece is dirty then ask the request the next client to send data.
                    qint64 end = this->size-1 < ((qint64)socDes->start.toLong() + this->pieceSize - 1) ? this->size-1 : ((qint64)socDes->start.toLong() + this->pieceSize - 1);
                    QString request = " R " + QString::number((qint64)socDes->start.toLong()) + " " + QString::number(end) + " ";

                    int i = 0;
                    for ( ; i < clientList.size(); i++) {
                        if (clientList.at(i)->socketDescriptor() == socket->socketDescriptor())
                            break;
                    }
                    i = (i + 1) % clientList.size();
                    clientList.at(i)->write(request.toUtf8());
                    clientList.at(i)->waitForBytesWritten();
                    file.close();
                    continue;
                }
            }

            //Issue next request till sizechk is less than size
            if(this->sizechk < this->size) {
                qint64 end = this->size-1 < (this->sizechk + this->pieceSize - 1) ? this->size-1 : (this->sizechk + this->pieceSize - 1);
                QString request = " R " + QString::number(this->sizechk) + " " + QString::number(end) + " ";
                this->sizechk = end + 1;
                socket->write(request.toUtf8());
                socket->waitForBytesWritten();
            } else {

                //Else check if there is some data missing and request that data
                qint64 start = 0;
                while (start < this->size) {
                    if (!map[start]) {
                        qint64 end = this->size-1 < (start + this->pieceSize - 1) ? (this->size - 1) : (start + this->pieceSize - 1);
                        QString request = " R " + QString::number(start) + " " + QString::number(end) + " ";
                        socket->write(request.toUtf8());
                        socket->waitForBytesWritten();
                        break;
                    }
                    start += this->pieceSize;
                }
            }

            file.close();
            socDes->buffer.clear();
            socDes->dataRead = false;
            continue;
        }
        if (!socDes->readingStart) {                    //Start reading start byte
            socDes->start.clear();
            socDes->readingStart = true;
            socDes->dataRead = false;
            continue;
        }
        if (socDes->readingStart) {                     //start reading start till ' ' comes
            if (char(Data[i]) != ' ') {
                socDes->start.append(Data[i]);
                continue;
            }
            else {
                socDes->readingStart = false;           //Decide end byte and make dataRead true
                socDes->end = (this->size - 1) < ((qint64)(socDes->start.toLong()) + this->pieceSize - 1) ? (this->size - 1) : (qint64)(socDes->start.toLong()) + this->pieceSize - 1;
                socDes->dataRead = true;
                continue;
            }
        }
    }
}
Beispiel #16
-1
QString AccountList::getPasswordAt(int i, int start = -1, int stop = -1)
{
	QCryptographicHash *hash = new QCryptographicHash(QCryptographicHash::Sha1);
	QString accString = this->accounts.at(i).name + this->password;
	hash->addData(accString.toUtf8());
	QString pass = hash->result().toBase64();
	if(start == -1)
	{
		start = accounts.at(i).start;
	}
	if(stop == -1)
	{
		stop = accounts.at(i).stop;
	}

	if(stop < 28)
	{
		pass.remove(stop, pass.length() - 1);
	}
	if(start > 1)
	{
		pass.remove(0, start - 2);
	}


	return pass;
}