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

Encrypted Logs: part 1

This commit is contained in:
apprb 2014-10-15 22:48:08 +09:00
parent e3d5853ca3
commit 172f1181c5
No known key found for this signature in database
GPG Key ID: B001911B5B22FB9B
7 changed files with 251 additions and 2 deletions

View File

@ -139,7 +139,10 @@ HEADERS += src/widget/form/addfriendform.h \
src/cameraworker.h \
src/widget/videosurface.h \
src/widget/form/loadhistorydialog.h \
src/historykeeper.h
src/historykeeper.h \
src/misc/db/genericddinterface.h \
src/misc/db/plaindb.h \
src/misc/db/encrypteddb.h
SOURCES += \
src/widget/form/addfriendform.cpp \
@ -188,4 +191,7 @@ SOURCES += \
src/cameraworker.cpp \
src/widget/videosurface.cpp \
src/widget/form/loadhistorydialog.cpp \
src/historykeeper.cpp
src/historykeeper.cpp \
src/misc/db/genericddinterface.cpp \
src/misc/db/plaindb.cpp \
src/misc/db/encrypteddb.cpp

View File

@ -0,0 +1,60 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#include "encrypteddb.h"
#include "src/misc/settings.h"
#include <QDir>
#include <QSqlQuery>
EncryptedDb::EncryptedDb(const QString &fname, const QString &key) :
key(key), encrFile(fname), PlainDb(":memory:")
{
QList<QString> sqlCommands = decryptFile();
for (const QString &cmd : sqlCommands)
{
PlainDb::exec(true, cmd);
}
}
EncryptedDb::~EncryptedDb()
{
// save to file if necessary
}
QSqlQuery EncryptedDb::exec(bool keep, const QString &query)
{
QSqlQuery ret = PlainDb::exec(keep, query);
if (keep)
appendToEncrypted(query);
return ret;
}
bool EncryptedDb::save()
{
return true;
}
QList<QString> EncryptedDb::decryptFile()
{
return QList<QString>();
}
void EncryptedDb::appendToEncrypted(const QString &sql)
{
Q_UNUSED(sql)
}

44
src/misc/db/encrypteddb.h Normal file
View File

@ -0,0 +1,44 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#ifndef ENCRYPTEDDB_H
#define ENCRYPTEDDB_H
#include "plaindb.h"
#include <QList>
class EncryptedDb : public PlainDb
{
public:
EncryptedDb(const QString& fname, const QString &key);
virtual ~EncryptedDb();
virtual QSqlQuery exec(bool keep, const QString &query);
virtual bool save();
private:
QString getFileName(){return encrFile;}
QString getKey(){return key;}
QList<QString> decryptFile();
void appendToEncrypted(const QString &sql);
QString key;
QString encrFile;
};
#endif // ENCRYPTEDDB_H

View File

@ -0,0 +1,21 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#include "genericddinterface.h"
GenericDdInterface::~GenericDdInterface()
{
}

View File

@ -0,0 +1,32 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#ifndef GENERICDDINTERFACE_H
#define GENERICDDINTERFACE_H
class QSqlQuery;
class QString;
class GenericDdInterface
{
public:
virtual ~GenericDdInterface();
virtual QSqlQuery exec(bool keep, const QString &query) = 0;
virtual bool save() = 0;
};
#endif // GENERICDDINTERFACE_H

49
src/misc/db/plaindb.cpp Normal file
View File

@ -0,0 +1,49 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#include "plaindb.h"
#include <QDebug>
#include <QSqlQuery>
#include <QString>
PlainDb::PlainDb(const QString &db_name)
{
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(db_name);
if (!db.open())
{
qWarning() << QString("Can't open file: %1, history will not be saved!").arg(db_name);
db.setDatabaseName(":memory:");
db.open();
}
}
PlainDb::~PlainDb()
{
db.close();
}
QSqlQuery PlainDb::exec(bool keep, const QString &query)
{
Q_UNUSED(keep)
return db.exec(query);
}
bool PlainDb::save()
{
return true;
}

37
src/misc/db/plaindb.h Normal file
View File

@ -0,0 +1,37 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#ifndef PLAINDB_H
#define PLAINDB_H
#include "genericddinterface.h"
#include <QSqlDatabase>
class PlainDb : public GenericDdInterface
{
public:
PlainDb(const QString &db_name);
virtual ~PlainDb();
virtual QSqlQuery exec(bool keep, const QString &query);
virtual bool save();
private:
QSqlDatabase db;
};
#endif // PLAINDB_H