1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

partial work towards core encryption functionality

This commit is contained in:
dubslow 2014-10-11 16:54:25 -05:00
parent 4e9d802d1f
commit bee852a28c
3 changed files with 53 additions and 2 deletions

View File

@ -10,7 +10,7 @@ INSTALL_DIR=libs
# just for convenience
BASE_DIR=${SCRIPT_DIR}/${INSTALL_DIR}
SODIUM_VER=0.7.0
SODIUM_VER=1.0.0
# directory names of cloned repositories
SODIUM_DIR=libsodium-$SODIUM_VER

View File

@ -21,6 +21,7 @@
#include "widget/widget.h"
#include <tox/tox.h>
#include <tox/toxencryptsave.h>
#include <ctime>
#include <functional>
@ -110,6 +111,12 @@ Core::~Core()
alcCloseDevice(alOutDev);
if (alInDev)
alcCaptureCloseDevice(alInDev);
if (pwhash)
{
delete[] pwhash;
pwhash = nullptr;
}
}
Core* Core::getInstance()
@ -1117,7 +1124,7 @@ void Core::saveConfiguration()
return;
}
qDebug() << "Core: Saving";
qDebug() << "Core: Saving";
uint32_t fileSize = tox_size(tox);
if (fileSize > 0 && fileSize <= INT32_MAX) {
@ -1405,3 +1412,43 @@ QList<CString> Core::splitMessage(const QString &message)
return splittedMsgs;
}
void Core::setPassword(QString& password)
{
if (!pwhash)
pwhash = new uint8_t[TOX_HASH_LENGTH];
CString str(password);
tox_hash(pwhash, str.data(), str.size());
password.clear();
}
bool Core::encryptFile(const QString& path)
{
QFile file(path);
if (!file.exists()) {
qWarning() << "Core::encryptFile: file" << path << "DNE";
return false;
}
if (!file.open(QIODevice::ReadOnly)) {
qCritical() << "Core::encryptFile:" << path << " cannot be opened";
return false;
}
QByteArray data = file.readAll();
file.close();
uint8_t[] out = new uint8_t[data.size() + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
if (tox_pass_encrypt(data.data(), data.size(), pwhash, TOX_HASH_LENGTH, out)
== -1)
{
qWarning() << "Core::encryptFile:" << "encryption of" << path << "failed";
return false;
}
if (!file.open(QIODevice::WriteOnly)) {
qCritical() << "Core::encryptFile:" << path << " cannot be opened for writing";
return false;
}
file.write(reinterpret_cast<char*>out, data.size() + TOX_PASS_ENCRYPTION_EXTRA_LENGTH);
file.close();
return true;
}

4
core.h
View File

@ -94,6 +94,9 @@ public slots:
void micMuteToggle(int callId);
void setPassword(QString& password);
bool encryptFile(const QString& path);
signals:
void connected();
void disconnected();
@ -231,6 +234,7 @@ private:
int dhtServerId;
static QList<ToxFile> fileSendQueue, fileRecvQueue;
static ToxCall calls[];
uint8_t* pwhash = nullptr; // use the pw's hash as the "pw"
static const QString CONFIG_FILE_NAME;
static const int videobufsize;