diff --git a/TaskNote.pro b/TaskNote.pro index cf05ddd..9443911 100755 --- a/TaskNote.pro +++ b/TaskNote.pro @@ -19,7 +19,7 @@ win32 { QMAKE_CXXFLAGS_RELEASE += -favor:INTEL64 } RC_ICONS = icon.ico - VERSION = 1.1.0.0 + VERSION = 1.2.0.0 QMAKE_TARGET_COMPANY = "Aurelie Delhaie" QMAKE_TARGET_PRODUCT = "TaskNote" QMAKE_TARGET_DESCRIPTION = "TaskNote" @@ -37,14 +37,18 @@ macx { message("CPU Architecture : aarch64") QMAKE_CXXFLAGS_RELEASE += -mcpu=apple-a14 } - VERSION = 1.1.0 + VERSION = 1.2.0 } linux-g++* { message("Build for Linux") + + LIBS += -L/usr/lib/crypto++ -lcrypto++ + INCS += -I/usr/include/crypto++ + QMAKE_CXXFLAGS_RELEASE *= -O3 QMAKE_CXXFLAGS_RELEASE += -march=skylake - VERSION = 1.1.0 + VERSION = 1.2.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..d162e94 100755 --- a/TaskNote.pro.user +++ b/TaskNote.pro.user @@ -1,14 +1,14 @@ - + EnvironmentId - {f1407b1e-b4d5-4aac-ba0d-b38072a0dfb8} + {23c6a5b6-2840-4c04-84d4-91387dc9bb9f} 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,56 +129,15 @@ 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 - - - true - QtProjectManager.QMakeBuildStep - false - - arm-darwin-generic-mach_o-64bit - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 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-Release + /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Release true @@ -192,7 +149,7 @@ true Qt4ProjectManager.MakeStep - 2 + 2 Build Build ProjectExplorer.BuildSteps.Build @@ -203,7 +160,7 @@ Qt4ProjectManager.MakeStep clean - 1 + 1 Clean Clean ProjectExplorer.BuildSteps.Clean @@ -211,6 +168,48 @@ 2 false + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + /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 + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 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,21 @@ 2 - Qt4ProjectManager.Qt4RunConfiguration:/Users/alexis/TaskNote/TaskNote.pro - /Users/alexis/TaskNote/TaskNote.pro + Qt4ProjectManager.Qt4RunConfiguration:/home/aurelie/src/TaskNote/TaskNote.pro + /home/aurelie/src/TaskNote/TaskNote.pro false true true false true - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Release/TaskNote.app/Contents/MacOS + /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Debug - 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.ui b/src/frames/aboutdialog.ui index 9565d03..4e04184 100755 --- a/src/frames/aboutdialog.ui +++ b/src/frames/aboutdialog.ui @@ -71,7 +71,7 @@ - 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..2b17b1f 100755 --- a/src/frames/mainwindow.cpp +++ b/src/frames/mainwindow.cpp @@ -14,6 +14,7 @@ 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); + connect(ui->actionEncrypt, &QAction::triggered, this, &MainWindow::encryptNote); const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); ui->contentEdit->setFont(fixedFont); this->savemng = new SaveManager(); @@ -55,8 +56,13 @@ void MainWindow::selectionChanged(int i) ui->titleEdit->setDisabled(false); ui->contentEdit->setDisabled(false); ui->titleEdit->setText(n->getTitle()); - ui->contentEdit->setPlainText(n->getContent()); - ui->markdownViewer->setMarkdown(n->getContent()); + if (n->isEncrypted()) + { + ui->contentEdit->setPlainText(n->getEncryptedContent("azertyuiop")); + } else { + ui->contentEdit->setPlainText(n->getContent()); + } + ui->markdownViewer->setMarkdown(ui->contentEdit->toPlainText()); } void MainWindow::removeSelected() @@ -71,6 +77,7 @@ void MainWindow::removeSelected() void MainWindow::save() { + ui->actionSave->setDisabled(true); if (this->currentIndex > -1) { Note *n = this->savemng->getNoteByIndex(this->currentIndex); @@ -89,6 +96,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 +107,16 @@ void MainWindow::showAboutBox() dialog.exec(); } +void MainWindow::encryptNote() +{ + if (this->currentIndex > -1) + { + Note *n = this->savemng->getNoteByIndex(this->currentIndex); + n->encrypt("azertyuiop"); + savemng->flushSave(); + } +} + void MainWindow::contentChanged() { timer->stop(); @@ -108,6 +126,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..0f9d008 100755 --- a/src/frames/mainwindow.h +++ b/src/frames/mainwindow.h @@ -30,6 +30,7 @@ private slots: void contentChanged(); void titleChanged(); void showAboutBox(); + void encryptNote(); private: Ui::MainWindow *ui; diff --git a/src/frames/mainwindow.ui b/src/frames/mainwindow.ui index 49e7fb4..ce9b996 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,45 @@ - :/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 + + + + + + :/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..59be5be 100755 --- a/src/models/note.cpp +++ b/src/models/note.cpp @@ -2,27 +2,35 @@ 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; - + o["encrypted"] = this->encrypted; 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,7 +38,47 @@ QString Note::getTitle() QString Note::getContent() { - return content; + if (!this->encrypted) + { + return content; + } + return ""; +} + +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; } void Note::setTitle(QString value) @@ -40,6 +88,57 @@ void Note::setTitle(QString value) void Note::setContent(QString value) { + if (!this->encrypted) { this->content = value; + } +} + +// 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; + } + } } diff --git a/src/models/note.h b/src/models/note.h index a22a546..ee4aa47 100755 --- a/src/models/note.h +++ b/src/models/note.h @@ -1,8 +1,25 @@ #ifndef NOTE_H #define NOTE_H +#define TAG_SIZE 12 + +#include +#include + #include #include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include class Note { @@ -12,15 +29,23 @@ public: QJsonObject toJson(); static Note* fromJson(QJsonObject o); + QString getUuid(); QString getTitle(); QString getContent(); + QString getEncryptedContent(QString passwd); + bool isEncrypted(); void setTitle(QString value); void setContent(QString value); + bool setEncryptedContent(QString value, QString passwd); + + void encrypt(QString password); 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()