Skip to content
This repository has been archived by the owner on Jun 11, 2020. It is now read-only.

Data File Encryption #90

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
959180e
Added scrypt-jane for scrypt support
ybhvf Dec 24, 2013
02b7a25
Changed scrypt mixer/hash settings
ybhvf Dec 24, 2013
ff310c7
Added Profile class for saving tox messengers
ybhvf Dec 24, 2013
c369390
Cleaned up Core::Profile::changePassword()
ybhvf Dec 24, 2013
dd5a3d3
Fleshed out Core::Profile::changeName()
ybhvf Dec 24, 2013
4725b02
Fixed profile saving
ybhvf Dec 24, 2013
fe69642
Big bug hunt; saving/loading now work as expected
ybhvf Dec 25, 2013
25f6877
Moved and simplified the Profile class
ybhvf Dec 25, 2013
a38653b
Added profile.cpp/hpp to Qt project file
ybhvf Dec 26, 2013
6fcc8cd
Merge branch 'master' into data-saving
ybhvf Jan 2, 2014
0f6cfb4
Cleaned up comments and tidied up code
ybhvf Jan 2, 2014
a2c8fbe
Modified Profile to save name string in UTF-8
ybhvf Jan 2, 2014
2032899
Fixed Profile saving & loading
ybhvf Jan 2, 2014
6b1d062
Modified code into libtoxdata
ybhvf Jan 8, 2014
fc3bf97
Added compile flag for scrypt-jane/clang support
ybhvf Jan 9, 2014
f9a87c9
Removed unnecessary documentation
ybhvf Jan 9, 2014
119b445
Fixed compiler flags to work with gcc
ybhvf Jan 9, 2014
742427b
Updated submodule revision
ybhvf Jan 9, 2014
2914752
Updated submodule revision
ybhvf Jan 9, 2014
e287fd5
Updated submodule revision
ybhvf Jan 9, 2014
0708332
Updated Profile documentation
ybhvf Jan 9, 2014
38edf4c
Update .travis.yml to pull nested submodule
ybhvf Jan 9, 2014
bd7a351
Replaced exceptions
ybhvf Jan 10, 2014
7dd3c59
Improved brokenProfile()
ybhvf Jan 10, 2014
2bbadaf
Abstracted Profile Messenger functions
ybhvf Jan 10, 2014
a4f3be8
Merge branch 'data-saving' of github.com:jencka/ProjectTox-Qt-GUI int…
ybhvf Jan 10, 2014
956fb08
Updated to use latest revision of libtoxdata
ybhvf Jan 10, 2014
17db025
Updated include for revised tox_data.h
ybhvf Jan 10, 2014
730687e
Removed use of tmpnam()
ybhvf Jan 10, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "submodules/ProjectTox-Core"]
path = submodules/ProjectTox-Core
url = https://github.com/irungentoo/ProjectTox-Core.git
[submodule "submodules/ProjectTox-libtoxdata"]
path = submodules/ProjectTox-libtoxdata
url = https://github.com/jencka/ProjectTox-libtoxdata
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ before_install:
- sudo make install
- sudo ldconfig
- cd ..
- git submodule update --init --recursive

script:
- ~/Qt5.2.0/5.2.0/gcc_64/bin/qmake -v
Expand All @@ -35,4 +36,4 @@ notifications:
- "chat.freenode.net#Tox-Qt-GUI"
on_success: always
on_failure: always


24 changes: 21 additions & 3 deletions projectfiles/QtCreator/TOX-Qt-GUI.pro
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ TEMPLATE = app

CONFIG += c++11

INCLUDEPATH += ../../src/ ../../submodules/ProjectTox-Core/toxcore/
INCLUDEPATH += \
../../src/ ../../submodules/ProjectTox-Core/toxcore/ \
../../submodules/ProjectTox-libtoxdata/ \
../../submodules/ProjectTox-libtoxdata/submodules/scrypt-jane/
win32:INCLUDEPATH += ../../libs/sodium/include/
macx:INCLUDEPATH += /usr/local/include

Expand All @@ -50,6 +53,11 @@ win32 {
}

win32:DEFINES += WIN32
DEFINES += SCRYPT_SALSA SCRYPT_SHA256

contains(QMAKE_CC, clang) {
QMAKE_CFLAGS += -no-integrated-as
}

SOURCES += \
../../src/main.cpp \
Expand Down Expand Up @@ -92,7 +100,8 @@ SOURCES += \
../../src/frienditemdelegate.cpp \
../../src/editablelabelwidget.cpp \
../../src/esclineedit.cpp \
../../src/copyableelidelabel.cpp
../../src/copyableelidelabel.cpp \
../../src/profile.cpp

HEADERS += \
../../src/mainwindow.hpp \
Expand Down Expand Up @@ -135,7 +144,8 @@ HEADERS += \
../../src/frienditemdelegate.hpp \
../../src/editablelabelwidget.hpp \
../../src/esclineedit.hpp \
../../src/copyableelidelabel.hpp
../../src/copyableelidelabel.hpp \
../../src/profile.hpp

SOURCES += \
../../submodules/ProjectTox-Core/toxcore/DHT.c \
Expand Down Expand Up @@ -166,6 +176,14 @@ HEADERS += \
../../submodules/ProjectTox-Core/toxcore/group_chats.h \
../../submodules/ProjectTox-Core/toxcore/assoc.h

SOURCES += \
../../submodules/ProjectTox-libtoxdata/tox_data.c \
../../submodules/ProjectTox-libtoxdata/submodules/scrypt-jane/scrypt-jane.c

HEADERS += \
../../submodules/ProjectTox-libtoxdata/tox_data.h \
../../submodules/ProjectTox-libtoxdata/submodules/scrypt-jane/scrypt-jane.h

RESOURCES += \
../../resources/resources.qrc

Expand Down
89 changes: 89 additions & 0 deletions src/profile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include "profile.hpp"

Profile::Profile(QString filePath)
{
pData = data_init_load((char*)filePath.toLocal8Bit().constData());
if (pData == NULL)
brokenProfile();
}

Profile::Profile(QString filePath, QString name, QString password)
{
pData = data_init_new((char*)filePath.toLocal8Bit().constData(), (uint8_t*)name.toUtf8().constData(), (uint8_t*)password.toUtf8().constData());
if (pData == NULL)
brokenProfile();
}

Profile::~Profile()
{
if(!pData->locked)
data_lock(pData);
data_close(pData);
}

int Profile::unlock(QString password)
{
return data_unlock(pData, (uint8_t*)password.toUtf8().constData());
}

void Profile::changeName(QString newName)
{
free(pData->name);
pData->name = (uint8_t*)malloc(newName.toUtf8().size());
memcpy(pData->name, newName.toUtf8().constData(), newName.toUtf8().size());
}

QString Profile::getName()
{
return QString::fromLocal8Bit((const char*)pData->name);
}

QDateTime Profile::getSaveTime()
{
return QDateTime::fromMSecsSinceEpoch(pData->time_saved);
}

bool Profile::isLocked()
{
return pData->locked;
}

int Profile::lock()
{
return data_lock(pData);
}

int Profile::changePassword(QString oldPassword, QString newPassword)
{
return data_change_key(pData, (uint8_t*)oldPassword.toUtf8().constData(), (uint8_t*)newPassword.toUtf8().constData());
}

int Profile::loadMessenger(Tox *tox)
{
size_t size = data_messenger_size(pData);
uint8_t buffer[size];
data_read_messenger(pData, buffer);
if(tox_load(tox, buffer, size) != 0)
return -1;
return 0;
}

int Profile::saveMessenger(Tox *tox)
{
size_t size = tox_size(tox);
uint8_t buffer[size];
tox_save(tox, buffer);
return data_write_messenger(pData, buffer, size);
}

int Profile::flush()
{
return data_flush(pData);
}

void Profile::brokenProfile()
{
//Create a profile that won't be unlocked. This will probably never be called.
QString path = QDir::tempPath() + "/" + QCoreApplication::applicationName() + "." + QString::number(qrand());
pData = data_init_new((char*)path.toLocal8Bit().constData(), (uint8_t*)"Broken Profile!", (uint8_t*)"don'tlogin");
}
67 changes: 67 additions & 0 deletions src/profile.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#ifndef PROFILE_H
#define PROFILE_H

#include <tox.h>
#include <util.h>
#include <sodium.h>
#include <tox_data.h>

#include <QObject>
#include <QFile>
#include <QDateTime>
#include <QDir>
#include <QCoreApplication>

class Profile : public QObject
{
Q_OBJECT
public:
/* See tox_data.h for full documentation on function return values & behavior. */

/* Loads a profile from the given path.
* Throws an exception (0) if the profile can't be loaded.
*/
Profile(QString filePath);
/* Creates a new profile.
* This profile isn't saved to disk until lock() or save() are called.
*/
Profile(QString filePath, QString name, QString password);
~Profile();

int unlock(QString password);

/* Changes the saved name for the profile. */
void changeName(QString newName);
/* Returns the profile's name. */
QString getName();
/* Returns the last date that the profile was saved. */
QDateTime getSaveTime();

/* Checks if the profile is locked. */
bool isLocked();

/* ------------- REQUIRES UNLOCKING ------------- */

int lock();
int changePassword(QString oldPassword, QString newPassword);

/* Loads the given messenger
*
* returns 0 if success
*/
int loadMessenger(Tox *tox);

/* Saves the given messenger
*
* returns 0 if success
*/
int saveMessenger(Tox *tox);

int flush();

private:
void brokenProfile();
tox_data *pData;
};

#endif // PROFILE_H
1 change: 1 addition & 0 deletions submodules/ProjectTox-libtoxdata
Submodule ProjectTox-libtoxdata added at 6bd257