Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2c090b3a0 | ||
|
|
658f4d860c |
16
TaskNote.pro
16
TaskNote.pro
@@ -4,8 +4,8 @@ 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
|
||||
win32:VERSION = 1.1.2.0 # major.minor.patch.build
|
||||
else:VERSION = 1.1.2 # major.minor.patch
|
||||
|
||||
DEFINES += APP_VERSION=\"\\\"$${VERSION}\\\"\"
|
||||
DEFINES += APP_NAME=\"\\\"TaskNote\\\"\"
|
||||
@@ -41,22 +41,14 @@ macx {
|
||||
QMAKE_CXXFLAGS_RELEASE -= -O1
|
||||
QMAKE_CXXFLAGS_RELEASE -= -O2
|
||||
QMAKE_CXXFLAGS_RELEASE *= -O3
|
||||
QMAKE_APPLE_DEVICE_ARCHS = x86_64 arm64
|
||||
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
|
||||
}
|
||||
DEFINES += APP_ARCH=\"\\\"universal\\\"\"
|
||||
}
|
||||
|
||||
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\\\"\"
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
<property name="windowTitle">
|
||||
<string>About TaskNote</string>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
|
||||
@@ -14,9 +14,6 @@ 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();
|
||||
@@ -54,21 +51,19 @@ void MainWindow::selectionChanged(int i)
|
||||
clearAndDisableFields();
|
||||
return;
|
||||
}
|
||||
ui->actionRemove->setDisabled(false);
|
||||
|
||||
ui->contentEdit->blockSignals(true);
|
||||
ui->titleEdit->blockSignals(true);
|
||||
|
||||
ui->titleEdit->setDisabled(false);
|
||||
ui->contentEdit->setDisabled(false);
|
||||
ui->actionRemove->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());
|
||||
#endif
|
||||
ui->markdownViewer->setMarkdown(ui->contentEdit->toPlainText());
|
||||
|
||||
ui->contentEdit->blockSignals(false);
|
||||
ui->titleEdit->blockSignals(false);
|
||||
}
|
||||
|
||||
void MainWindow::removeSelected()
|
||||
@@ -113,18 +108,6 @@ 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();
|
||||
@@ -149,6 +132,9 @@ void MainWindow::updateListView()
|
||||
|
||||
void MainWindow::clearAndDisableFields()
|
||||
{
|
||||
ui->contentEdit->blockSignals(true);
|
||||
ui->titleEdit->blockSignals(true);
|
||||
|
||||
this->currentIndex = -1;
|
||||
ui->actionRemove->setDisabled(true);
|
||||
ui->titleEdit->setDisabled(true);
|
||||
@@ -156,5 +142,8 @@ void MainWindow::clearAndDisableFields()
|
||||
ui->titleEdit->clear();
|
||||
ui->contentEdit->clear();
|
||||
ui->markdownViewer->clear();
|
||||
|
||||
ui->contentEdit->blockSignals(false);
|
||||
ui->titleEdit->blockSignals(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,9 +30,6 @@ private slots:
|
||||
void contentChanged();
|
||||
void titleChanged();
|
||||
void showAboutBox();
|
||||
#ifdef __SECURED
|
||||
void encryptNote();
|
||||
#endif
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
<string>TaskNote</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QListWidget" name="noteList">
|
||||
@@ -63,55 +63,65 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Markdown editor</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Viewer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="contentEdit">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="markdownViewer">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoFormatting">
|
||||
<set>QTextEdit::AutoAll</set>
|
||||
</property>
|
||||
<property name="lineWrapMode">
|
||||
<enum>QTextEdit::WidgetWidth</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="acceptRichText">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="childrenCollapsible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<widget class="QPlainTextEdit" name="contentEdit">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<kerning>false</kerning>
|
||||
</font>
|
||||
</property>
|
||||
<property name="lineWrapMode">
|
||||
<enum>QPlainTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTextEdit" name="markdownViewer">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoFormatting">
|
||||
<set>QTextEdit::AutoAll</set>
|
||||
</property>
|
||||
<property name="lineWrapMode">
|
||||
<enum>QTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="acceptRichText">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
@@ -129,6 +139,9 @@
|
||||
<height>96</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::PreventContextMenu</enum>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>toolBar</string>
|
||||
</property>
|
||||
@@ -138,6 +151,9 @@
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||
</property>
|
||||
<property name="floatable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
@@ -149,10 +165,6 @@
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionSave"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionLock"/>
|
||||
<addaction name="actionUnlock"/>
|
||||
<addaction name="actionEncrypt"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionAbout"/>
|
||||
</widget>
|
||||
<action name="actionAdd">
|
||||
@@ -197,42 +209,6 @@
|
||||
<string>About</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLock">
|
||||
<property name="icon">
|
||||
<iconset resource="../../icons.qrc">
|
||||
<normaloff>:/icon/resources/outline_lock_black_48dp.png</normaloff>:/icon/resources/outline_lock_black_48dp.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Lock</string>
|
||||
</property>
|
||||
<property name="visible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionUnlock">
|
||||
<property name="icon">
|
||||
<iconset resource="../../icons.qrc">
|
||||
<normaloff>:/icon/resources/outline_lock_open_black_48dp.png</normaloff>:/icon/resources/outline_lock_open_black_48dp.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Unlock</string>
|
||||
</property>
|
||||
<property name="visible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEncrypt">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../icons.qrc">
|
||||
<normaloff>:/icon/resources/outline_shield_black_48dp.png</normaloff>:/icon/resources/outline_shield_black_48dp.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Encrypt</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../icons.qrc"/>
|
||||
|
||||
@@ -12,9 +12,6 @@ QJsonObject Note::toJson()
|
||||
o["uuid"] = this->uuid;
|
||||
o["title"] = this->title;
|
||||
o["content"] = this->content;
|
||||
#ifdef __SECURED
|
||||
o["encrypted"] = this->encrypted;
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
|
||||
@@ -46,43 +43,6 @@ QString Note::getContent()
|
||||
}
|
||||
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;
|
||||
@@ -94,53 +54,3 @@ void Note::setContent(QString value)
|
||||
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<AES>::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
|
||||
|
||||
@@ -11,18 +11,6 @@
|
||||
#include <QUuid>
|
||||
#include <QMessageBox>
|
||||
|
||||
#ifdef __SECURED
|
||||
#include <crypto++/modes.h>
|
||||
#include <crypto++/aes.h>
|
||||
#include <crypto++/filters.h>
|
||||
#include <crypto++/cryptlib.h>
|
||||
#include <crypto++/sha.h>
|
||||
#include <crypto++/hkdf.h>
|
||||
#include <crypto++/osrng.h>
|
||||
#include <crypto++/gcm.h>
|
||||
#include <crypto++/rijndael.h>
|
||||
#endif
|
||||
|
||||
class Note
|
||||
{
|
||||
public:
|
||||
@@ -35,18 +23,8 @@ public:
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user