diff --git a/TaskNote.pro b/TaskNote.pro index cf05ddd..2e57e34 100755 --- a/TaskNote.pro +++ b/TaskNote.pro @@ -4,25 +4,33 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++17 +win32:VERSION = 1.1.1.0 # major.minor.patch.build +else:VERSION = 1.1.1 # major.minor.patch + +DEFINES += APP_VERSION=\"\\\"$${VERSION}\\\"\" +DEFINES += APP_NAME=\"\\\"TaskNote\\\"\" + # remove possible other optimization flags win32 { message("Build for Windows") QMAKE_CXXFLAGS_RELEASE -= -O QMAKE_CXXFLAGS_RELEASE -= -O1 QMAKE_CXXFLAGS_RELEASE *= -O2 + DEFINES += APP_OS=\"\\\"Windows\\\"\" + DEFINES += APP_OS_VERSION=\"\\\"$$system(wmic os get version /value)\\\"\" equals(QMAKE_TARGET.arch, arm64) { message("CPU Architecture : aarch64") - # Add specific arm stuff here + DEFINES += APP_ARCH=\"\\\"arm64\\\"\" } equals(QMAKE_TARGET.arch, x86_64) { message("CPU Architecture : x64") QMAKE_CXXFLAGS_RELEASE += -favor:INTEL64 + DEFINES += APP_ARCH=\"\\\"x64\\\"\" } RC_ICONS = icon.ico - VERSION = 1.1.0.0 QMAKE_TARGET_COMPANY = "Aurelie Delhaie" QMAKE_TARGET_PRODUCT = "TaskNote" - QMAKE_TARGET_DESCRIPTION = "TaskNote" + QMAKE_TARGET_DESCRIPTION = "Simple note-taking workbook" } macx { @@ -33,18 +41,27 @@ macx { QMAKE_CXXFLAGS_RELEASE -= -O1 QMAKE_CXXFLAGS_RELEASE -= -O2 QMAKE_CXXFLAGS_RELEASE *= -O3 + DEFINES += APP_OS=\"\\\"macOS\\\"\" + DEFINES += APP_OS_VERSION=\"\\\"$$system(uname -r)\\\"\" equals(QMAKE_APPLE_DEVICE_ARCHS, arm64) { message("CPU Architecture : aarch64") + DEFINES += APP_ARCH=\"\\\"aarch64\\\"\" QMAKE_CXXFLAGS_RELEASE += -mcpu=apple-a14 } - VERSION = 1.1.0 } linux-g++* { message("Build for Linux") + + #LIBS += -L/usr/lib/crypto++ -lcrypto++ + #INCS += -I/usr/include/crypto++ + + #DEFINES += __SECURED=1 + DEFINES += APP_OS=\"\\\"$$system(cat /etc/issue | cut -d\' \' -f1)\\\"\" + DEFINES += APP_OS_VERSION=\"\\\"$$system(uname -r)\\\"\" + DEFINES += APP_ARCH=\"\\\"amd64\\\"\" QMAKE_CXXFLAGS_RELEASE *= -O3 QMAKE_CXXFLAGS_RELEASE += -march=skylake - VERSION = 1.1.0 } # You can make your code fail to compile if it uses deprecated APIs. diff --git a/TaskNote.pro.user b/TaskNote.pro.user index 97c2f07..618b18e 100755 --- a/TaskNote.pro.user +++ b/TaskNote.pro.user @@ -1,14 +1,14 @@ - + EnvironmentId - {f1407b1e-b4d5-4aac-ba0d-b38072a0dfb8} + {dbe9fba1-e5a9-4d98-85bf-f46da0900eba} ProjectExplorer.Project.ActiveTarget - 0 + 0 ProjectExplorer.Project.EditorSettings @@ -28,7 +28,7 @@ QmlJSGlobal - 2 + 2 UTF-8 false 4 @@ -77,7 +77,7 @@ true true Builtin.DefaultTidyAndClazy - 4 + 8 @@ -89,30 +89,28 @@ ProjectExplorer.Project.Target.0 Desktop - Qt 6.2.0 for macOS - Qt 6.2.0 for macOS - qt.qt6.620.clang_64_kit - 1 - 0 - 0 + Desktop Qt 6.2.3 GCC 64bit + Desktop Qt 6.2.3 GCC 64bit + qt.qt6.623.gcc_64_kit + 0 + 0 + 0 0 - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Debug - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Debug + /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Debug + /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Debug true QtProjectManager.QMakeBuildStep false - - arm-darwin-generic-mach_o-64bit - + true Qt4ProjectManager.MakeStep - 2 + 2 Build Build ProjectExplorer.BuildSteps.Build @@ -123,7 +121,7 @@ Qt4ProjectManager.MakeStep clean - 1 + 1 Clean Clean ProjectExplorer.BuildSteps.Clean @@ -131,28 +129,27 @@ 2 false + false Debug Qt4ProjectManager.Qt4BuildConfiguration 2 - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Release - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Release + /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Release + /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Release true QtProjectManager.QMakeBuildStep false - - arm-darwin-generic-mach_o-64bit - + true Qt4ProjectManager.MakeStep - 2 + 2 Build Build ProjectExplorer.BuildSteps.Build @@ -163,7 +160,7 @@ Qt4ProjectManager.MakeStep clean - 1 + 1 Clean Clean ProjectExplorer.BuildSteps.Clean @@ -171,6 +168,7 @@ 2 false + false Release Qt4ProjectManager.Qt4BuildConfiguration @@ -179,20 +177,20 @@ 0 - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Profile - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Profile + /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Profile + /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Profile true QtProjectManager.QMakeBuildStep - true + false true Qt4ProjectManager.MakeStep - 2 + 2 Build Build ProjectExplorer.BuildSteps.Build @@ -203,7 +201,7 @@ Qt4ProjectManager.MakeStep clean - 1 + 1 Clean Clean ProjectExplorer.BuildSteps.Clean @@ -211,6 +209,7 @@ 2 false + false Profile Qt4ProjectManager.Qt4BuildConfiguration @@ -218,10 +217,10 @@ 0 0 - 3 + 3 - 0 + 0 Deploy Deploy ProjectExplorer.BuildSteps.Deploy @@ -231,7 +230,7 @@ false ProjectExplorer.DefaultDeployConfiguration - 1 + 1 true true @@ -239,21 +238,19 @@ 2 - Qt4ProjectManager.Qt4RunConfiguration:/Users/alexis/TaskNote/TaskNote.pro - /Users/alexis/TaskNote/TaskNote.pro + ProjectExplorer.CustomExecutableRunConfiguration + false true - true false true - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Release/TaskNote.app/Contents/MacOS - 1 + 1 ProjectExplorer.Project.TargetCount - 1 + 1 ProjectExplorer.Project.Updater.FileVersion diff --git a/icons.qrc b/icons.qrc index c5e844d..a1df688 100755 --- a/icons.qrc +++ b/icons.qrc @@ -1,9 +1,12 @@ - resources/outline_add_circle_outline_black_18dp.png - resources/outline_delete_forever_black_18dp.png - resources/outline_save_black_18dp.png - resources/outline_help_outline_black_18dp.png + resources/outline_add_circle_outline_black_48dp.png + resources/outline_delete_forever_black_48dp.png + resources/outline_help_outline_black_48dp.png + resources/outline_lock_black_48dp.png + resources/outline_save_black_48dp.png + resources/outline_shield_black_48dp.png + resources/outline_lock_open_black_48dp.png resources/logo.png diff --git a/resources/outline_add_circle_outline_black_18dp.png b/resources/outline_add_circle_outline_black_18dp.png deleted file mode 100755 index 59e2fa2..0000000 Binary files a/resources/outline_add_circle_outline_black_18dp.png and /dev/null differ diff --git a/resources/outline_add_circle_outline_black_48dp.png b/resources/outline_add_circle_outline_black_48dp.png new file mode 100644 index 0000000..c6ecf98 Binary files /dev/null and b/resources/outline_add_circle_outline_black_48dp.png differ diff --git a/resources/outline_delete_forever_black_18dp.png b/resources/outline_delete_forever_black_18dp.png deleted file mode 100755 index c89a0ff..0000000 Binary files a/resources/outline_delete_forever_black_18dp.png and /dev/null differ diff --git a/resources/outline_delete_forever_black_48dp.png b/resources/outline_delete_forever_black_48dp.png new file mode 100644 index 0000000..b10bb2c Binary files /dev/null and b/resources/outline_delete_forever_black_48dp.png differ diff --git a/resources/outline_help_outline_black_18dp.png b/resources/outline_help_outline_black_18dp.png deleted file mode 100755 index 200b15c..0000000 Binary files a/resources/outline_help_outline_black_18dp.png and /dev/null differ diff --git a/resources/outline_help_outline_black_48dp.png b/resources/outline_help_outline_black_48dp.png new file mode 100644 index 0000000..5089584 Binary files /dev/null and b/resources/outline_help_outline_black_48dp.png differ diff --git a/resources/outline_lock_black_48dp.png b/resources/outline_lock_black_48dp.png new file mode 100644 index 0000000..4817e2e Binary files /dev/null and b/resources/outline_lock_black_48dp.png differ diff --git a/resources/outline_lock_open_black_48dp.png b/resources/outline_lock_open_black_48dp.png new file mode 100644 index 0000000..99d1f07 Binary files /dev/null and b/resources/outline_lock_open_black_48dp.png differ diff --git a/resources/outline_save_black_18dp.png b/resources/outline_save_black_18dp.png deleted file mode 100755 index f6cd4ca..0000000 Binary files a/resources/outline_save_black_18dp.png and /dev/null differ diff --git a/resources/outline_save_black_48dp.png b/resources/outline_save_black_48dp.png new file mode 100644 index 0000000..bbda264 Binary files /dev/null and b/resources/outline_save_black_48dp.png differ diff --git a/resources/outline_shield_black_48dp.png b/resources/outline_shield_black_48dp.png new file mode 100644 index 0000000..dd9f8f8 Binary files /dev/null and b/resources/outline_shield_black_48dp.png differ diff --git a/src/frames/aboutdialog.cpp b/src/frames/aboutdialog.cpp index 13933b3..3ad17a1 100755 --- a/src/frames/aboutdialog.cpp +++ b/src/frames/aboutdialog.cpp @@ -6,7 +6,8 @@ AboutDialog::AboutDialog(QWidget *parent) : ui(new Ui::AboutDialog) { ui->setupUi(this); - ui->appNameLabel->setText(QString("TaskNote (%1)").arg(QSysInfo::currentCpuArchitecture())); + ui->appNameLabel->setText(QString("%1 (%2)").arg(APP_NAME, APP_ARCH)); + ui->versionLabel->setText(QString("Version %1").arg(APP_VERSION)); } AboutDialog::~AboutDialog() diff --git a/src/frames/aboutdialog.ui b/src/frames/aboutdialog.ui index 9565d03..b1082e9 100755 --- a/src/frames/aboutdialog.ui +++ b/src/frames/aboutdialog.ui @@ -69,9 +69,9 @@ - + - Version 1.1.0.0 + Version 1.2.0.0 Qt::AlignCenter diff --git a/src/frames/mainwindow.cpp b/src/frames/mainwindow.cpp index 0bdcd15..dfb7ee8 100755 --- a/src/frames/mainwindow.cpp +++ b/src/frames/mainwindow.cpp @@ -14,6 +14,9 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->noteList, &QListWidget::currentRowChanged, this, &MainWindow::selectionChanged); connect(ui->titleEdit, &QLineEdit::textChanged, this, &MainWindow::titleChanged); connect(ui->contentEdit, &QPlainTextEdit::textChanged, this, &MainWindow::contentChanged); + #ifdef __SECURED + connect(ui->actionEncrypt, &QAction::triggered, this, &MainWindow::encryptNote); + #endif const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); ui->contentEdit->setFont(fixedFont); this->savemng = new SaveManager(); @@ -55,8 +58,17 @@ void MainWindow::selectionChanged(int i) ui->titleEdit->setDisabled(false); ui->contentEdit->setDisabled(false); ui->titleEdit->setText(n->getTitle()); +#ifdef __SECURED + if (n->isEncrypted()) + { + ui->contentEdit->setPlainText(n->getEncryptedContent("azertyuiop")); + } else { + ui->contentEdit->setPlainText(n->getContent()); + } +#else ui->contentEdit->setPlainText(n->getContent()); - ui->markdownViewer->setMarkdown(n->getContent()); +#endif + ui->markdownViewer->setMarkdown(ui->contentEdit->toPlainText()); } void MainWindow::removeSelected() @@ -71,6 +83,7 @@ void MainWindow::removeSelected() void MainWindow::save() { + ui->actionSave->setDisabled(true); if (this->currentIndex > -1) { Note *n = this->savemng->getNoteByIndex(this->currentIndex); @@ -89,6 +102,7 @@ void MainWindow::titleChanged() n->setTitle(ui->titleEdit->text()); ui->noteList->item(this->currentIndex)->setText(ui->titleEdit->text()); } + ui->actionSave->setDisabled(false); timer->start(1000); } @@ -99,6 +113,18 @@ void MainWindow::showAboutBox() dialog.exec(); } +#ifdef __SECURED +void MainWindow::encryptNote() +{ + if (this->currentIndex > -1) + { + Note *n = this->savemng->getNoteByIndex(this->currentIndex); + n->encrypt("azertyuiop"); + savemng->flushSave(); + } +} +#endif + void MainWindow::contentChanged() { timer->stop(); @@ -108,6 +134,7 @@ void MainWindow::contentChanged() n->setContent(ui->contentEdit->toPlainText()); ui->markdownViewer->setMarkdown(ui->contentEdit->toPlainText()); } + ui->actionSave->setDisabled(false); timer->start(1000); } diff --git a/src/frames/mainwindow.h b/src/frames/mainwindow.h index 644b7a9..0c39b5c 100755 --- a/src/frames/mainwindow.h +++ b/src/frames/mainwindow.h @@ -30,6 +30,9 @@ private slots: void contentChanged(); void titleChanged(); void showAboutBox(); +#ifdef __SECURED + void encryptNote(); +#endif private: Ui::MainWindow *ui; diff --git a/src/frames/mainwindow.ui b/src/frames/mainwindow.ui index 49e7fb4..0d2b1d0 100755 --- a/src/frames/mainwindow.ui +++ b/src/frames/mainwindow.ui @@ -120,15 +120,24 @@ + + true + 16777215 - 33 + 96 toolBar + + false + + + Qt::ToolButtonTextUnderIcon + TopToolBarArea @@ -140,12 +149,16 @@ + + + + - :/icon/resources/outline_add_circle_outline_black_18dp.png:/icon/resources/outline_add_circle_outline_black_18dp.png + :/icon/resources/outline_add_circle_outline_black_48dp.png:/icon/resources/outline_add_circle_outline_black_48dp.png Add @@ -157,16 +170,19 @@ - :/icon/resources/outline_delete_forever_black_18dp.png:/icon/resources/outline_delete_forever_black_18dp.png + :/icon/resources/outline_delete_forever_black_48dp.png:/icon/resources/outline_delete_forever_black_48dp.png Remove + + false + - :/icon/resources/outline_save_black_18dp.png:/icon/resources/outline_save_black_18dp.png + :/icon/resources/outline_save_black_48dp.png:/icon/resources/outline_save_black_48dp.png Save @@ -175,12 +191,48 @@ - :/icon/resources/outline_help_outline_black_18dp.png:/icon/resources/outline_help_outline_black_18dp.png + :/icon/resources/outline_help_outline_black_48dp.png:/icon/resources/outline_help_outline_black_48dp.png About + + + + :/icon/resources/outline_lock_black_48dp.png:/icon/resources/outline_lock_black_48dp.png + + + Lock + + + false + + + + + + :/icon/resources/outline_lock_open_black_48dp.png:/icon/resources/outline_lock_open_black_48dp.png + + + Unlock + + + false + + + + + false + + + + :/icon/resources/outline_shield_black_48dp.png:/icon/resources/outline_shield_black_48dp.png + + + Encrypt + + diff --git a/src/models/note.cpp b/src/models/note.cpp index 7200a04..fbfd6dd 100755 --- a/src/models/note.cpp +++ b/src/models/note.cpp @@ -2,27 +2,37 @@ Note::Note() { - + QUuid uid = QUuid::createUuid(); + this->uuid = uid.toString(QUuid::StringFormat::WithoutBraces); } QJsonObject Note::toJson() { QJsonObject o; - + o["uuid"] = this->uuid; o["title"] = this->title; o["content"] = this->content; - + #ifdef __SECURED + o["encrypted"] = this->encrypted; + #endif return o; } Note *Note::fromJson(QJsonObject o) { Note *n = new Note(); + n->uuid = o["uuid"].toString(n->uuid); n->title = o["title"].toString(); n->content = o["content"].toString(); + n->encrypted = o["encrypted"].toBool(false); return n; } +QString Note::getUuid() +{ + return uuid; +} + QString Note::getTitle() { return title; @@ -30,9 +40,49 @@ QString Note::getTitle() QString Note::getContent() { - return content; + if (!this->encrypted) + { + return content; + } + return ""; +} +#ifdef __SECURED +QString Note::getEncryptedContent(QString passwd) +{ + if (this->encrypted) + { + using namespace CryptoPP; + std::string password = passwd.toStdString(); + QString bytes = QByteArray::fromBase64(QByteArray::fromStdString(this->content.toStdString())); + std::string encoded = bytes.toStdString(); + std::string iv = encoded.substr(0, TAG_SIZE); + std::string cipher = encoded.substr(TAG_SIZE + 1, encoded.length()); + std::string recovered; + + try { + GCM< AES >::Decryption d; + d.SetKeyWithIV((const unsigned char*)password.c_str(), sizeof(password.c_str()), (const unsigned char*)iv.c_str(), sizeof(iv.c_str())); + + AuthenticatedDecryptionFilter df( d, + new StringSink(recovered), + AuthenticatedDecryptionFilter::DEFAULT_FLAGS, TAG_SIZE + ); + StringSource ss2(cipher, true, + new Redirector(df) + ); + return QString::fromStdString(recovered); + } catch (CryptoPP::Exception& e) { + std::cout << e.GetWhat() << "\n"; + } + } + return ""; } +bool Note::isEncrypted() +{ + return this->encrypted; +} +#endif void Note::setTitle(QString value) { this->title = value; @@ -40,6 +90,57 @@ void Note::setTitle(QString value) void Note::setContent(QString value) { + if (!this->encrypted) { this->content = value; + } +} +#ifdef __SECURED +// TODO encrypt avec le mot de passe +bool Note::setEncryptedContent(QString value, QString passwd) +{ + if (this->encrypted) { + using namespace CryptoPP; + AutoSeededRandomPool prng; + std::string password = passwd.toStdString(); + std::string pdata = value.toStdString(); + std::string cipher, encoded; + + SecByteBlock key(AES::MAX_KEYLENGTH + AES::BLOCKSIZE); + SecByteBlock iv(AES::BLOCKSIZE); + prng.GenerateBlock(iv, iv.size()); + try + { + GCM::Encryption e; + e.SetKeyWithIV(key, sizeof(key), iv, sizeof(iv)); + + StringSource ss1(pdata, true, + new AuthenticatedEncryptionFilter(e, + new StringSink(cipher), false, TAG_SIZE + ) + ); + std::string s(reinterpret_cast< char const* >(iv.data())) ; + encoded = s + cipher; + auto bytes = QByteArray::fromStdString(encoded); + this->content = bytes.toBase64(); + return true; + } + catch(CryptoPP::Exception& e) + { + std::cout << e.GetWhat() << "\n"; + return false; + } + } + return false; } +void Note::encrypt(QString password) +{ + if (!this->encrypted && (password.length() >= 6)) { + this->encrypted = true; + if (!setEncryptedContent(this->content, password)) + { + this->encrypted = false; + } + } +} +#endif diff --git a/src/models/note.h b/src/models/note.h index a22a546..81f4b95 100755 --- a/src/models/note.h +++ b/src/models/note.h @@ -1,8 +1,27 @@ #ifndef NOTE_H #define NOTE_H +#define TAG_SIZE 12 + +#include +#include + #include #include +#include +#include + +#ifdef __SECURED +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif class Note { @@ -12,15 +31,27 @@ public: QJsonObject toJson(); static Note* fromJson(QJsonObject o); + QString getUuid(); QString getTitle(); QString getContent(); + #ifdef __SECURED + QString getEncryptedContent(QString passwd); + bool isEncrypted(); + #endif + void setTitle(QString value); void setContent(QString value); + #ifdef __SECURED + bool setEncryptedContent(QString value, QString passwd); + void encrypt(QString password); + #endif private: + QString uuid; QString title; QString content; + bool encrypted; }; #endif // NOTE_H diff --git a/src/services/savemanager.cpp b/src/services/savemanager.cpp index 63d7787..27a4884 100755 --- a/src/services/savemanager.cpp +++ b/src/services/savemanager.cpp @@ -8,6 +8,10 @@ SaveManager::SaveManager() SaveManager::~SaveManager() { flushSave(); + foreach (Note *n, notes) + { + delete n; + } } void SaveManager::flushSave()