Storage encryption support in progress

This commit is contained in:
Nicolas Mailloux 2021-10-08 23:37:32 -04:00
parent 4723b3ae4c
commit 116868f615
9 changed files with 455 additions and 113 deletions

View file

@ -62,5 +62,6 @@
<file>resources/wifi-standby.png</file>
<file>resources/zoom-in.png</file>
<file>resources/zoom-out.png</file>
<file>resources/encryption.png</file>
</qresource>
</RCC>

104
encryptionmanager.cpp Normal file
View file

@ -0,0 +1,104 @@
#include "encryptionmanager.h"
#include "ui_encryptionmanager.h"
#include <QFile>
#include <QScreen>
#include <QDebug>
#include <QDir>
#include "functions.h"
encryptionManager::encryptionManager(QWidget *parent) :
QWidget(parent),
ui(new Ui::encryptionManager)
{
ui->setupUi(this);
// Stylesheet
QFile stylesheetFile(":/resources/eink.qss");
stylesheetFile.open(QFile::ReadOnly);
this->setStyleSheet(stylesheetFile.readAll());
stylesheetFile.close();
ui->encryptionSetupLabel->setStyleSheet("font-size: 15pt");
ui->descriptionLabel->setStyleSheet("font-size: 9pt");
ui->setupContinueBtn->setStyleSheet("font-size: 10pt; padding: 10px; font-weight: bold; background: lightGrey");
ui->setupAbortBtn->setStyleSheet("font-size: 10pt; padding: 10px; font-weight: bold; background: lightGrey");
// Getting the screen's size
float sW = QGuiApplication::screens()[0]->size().width();
float sH = QGuiApplication::screens()[0]->size().height();
float stdIconWidth = sW / 1.50;
float stdIconHeight = sH / 1.50;
QPixmap pixmap(":/resources/encryption.png");
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
ui->encryptionImageLabel->setPixmap(scaledPixmap);
}
encryptionManager::~encryptionManager()
{
delete ui;
}
void encryptionManager::on_setupContinueBtn_clicked()
{
ui->activityWidget->hide();
this->setStyleSheet("background-color: black");
global::keyboard::keyboardDialog = true;
global::keyboard::encfsDialog = true;
global::keyboard::keyboardText = "";
generalDialogWindow = new generalDialog();
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
connect(generalDialogWindow, SIGNAL(refreshScreen()), SLOT(refreshScreen()));
connect(generalDialogWindow, SIGNAL(destroyed(QObject*)), SLOT(setupEncryptedStorage()));
connect(generalDialogWindow, SIGNAL(showToast(QString)), SLOT(showToast(QString)));
generalDialogWindow->show();
}
void encryptionManager::on_setupAbortBtn_clicked()
{
setDefaultWorkDir();
string_writeconfig(".config/18-encrypted_storage/config", "false");
quit_restart();
}
void encryptionManager::quit_restart() {
QProcess process;
process.startDetached("inkbox", QStringList());
qApp->quit();
}
void encryptionManager::refreshScreen() {
this->repaint();
}
void encryptionManager::showToast(QString messageToDisplay) {
global::toast::message = messageToDisplay;
toastWindow = new toast(this);
toastWindow->setAttribute(Qt::WA_DeleteOnClose);
connect(toastWindow, SIGNAL(refreshScreen()), SLOT(refreshScreen()));
toastWindow->show();
}
void encryptionManager::setupEncryptedStorage() {
mkEncfsDirs();
std::string bootstrapPassphrase = global::encfs::passphrase.toStdString();
global::encfs::passphrase = "";
string_writeconfig("/external_root/run/encfs/encrypted_storage_create", "true");
string_writeconfig("/external_root/run/encfs/encrypted_storage_bootstrap_files_location", "/data/onboard/encfs-dropbox");
string_writeconfig("/external_root/run/encfs/encrypted_storage_bootstrap_archive_location", "/data/onboard/data.encfs");
string_writeconfig("/external_root/run/encfs/encrypted_storage_bootstrap_passphrase", bootstrapPassphrase);
string_writeconfig("/opt/ibxd", "encfs_restart\n");
}
void encryptionManager::mkEncfsDirs() {
QDir encfsDir;
QString encfsPath("/external_root/run/encfs");
encfsDir.mkpath(encfsPath);
QDir dumpDir;
QString dumpPath("/mnt/onboard/onboard/encfs-dropbox");
dumpDir.mkpath(dumpPath);
QDir decDir;
QString decPath("/mnt/onboard/onboard/encfs-decrypted");
}

35
encryptionmanager.h Normal file
View file

@ -0,0 +1,35 @@
#ifndef ENCRYPTIONMANAGER_H
#define ENCRYPTIONMANAGER_H
#include <QWidget>
#include "generaldialog.h"
#include "toast.h"
namespace Ui {
class encryptionManager;
}
class encryptionManager : public QWidget
{
Q_OBJECT
public:
explicit encryptionManager(QWidget *parent = nullptr);
~encryptionManager();
private slots:
void on_setupContinueBtn_clicked();
void on_setupAbortBtn_clicked();
void quit_restart();
void refreshScreen();
void showToast(QString messageToDisplay);
void setupEncryptedStorage();
void mkEncfsDirs();
private:
Ui::encryptionManager *ui;
generalDialog * generalDialogWindow;
toast * toastWindow;
};
#endif // ENCRYPTIONMANAGER_H

161
encryptionmanager.ui Normal file
View file

@ -0,0 +1,161 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>encryptionManager</class>
<widget class="QWidget" name="encryptionManager">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>460</width>
<height>467</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QStackedWidget" name="activityWidget">
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<widget class="QLabel" name="encryptionImageLabel">
<property name="text">
<string>Encryption image</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="6" column="0">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="0">
<widget class="QLabel" name="descriptionLabel">
<property name="text">
<string>Encrypted storage permits you to keep your most important files and data safe from anyone else than you.
Would you want to enable it?</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QPushButton" name="setupAbortBtn">
<property name="text">
<string>No</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="setupContinueBtn">
<property name="text">
<string>Yes</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="encryptionSetupLabel">
<property name="font">
<font>
<family>Inter</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Setup encrypted storage</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="8" column="0">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2"/>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -66,6 +66,7 @@ namespace global {
inline bool keyboardDialog;
inline bool keypadDialog;
inline bool searchDialog;
inline bool encfsDialog;
inline bool vncDialog;
inline bool wifiPassphraseDialog;
inline QString keyboardText;
@ -88,6 +89,9 @@ namespace global {
inline bool isUpdateOta;
inline bool downloadOta;
}
namespace encfs {
inline QString passphrase;
}
inline QString systemInfoText;
inline bool forbidOpenSearchDialog;
inline bool isN705;

View file

@ -323,7 +323,7 @@ void generalDialog::on_okBtn_clicked()
}
}
else if(global::keyboard::vncDialog == true) {
if(global::keyboard::keyboardText != "") {
if(!global::keyboard::keyboardText.isEmpty()) {
if(vncServerSet != true) {
vncServerAddress = global::keyboard::keyboardText;
vncServerSet = true;
@ -349,7 +349,7 @@ void generalDialog::on_okBtn_clicked()
}
}
else if(global::keyboard::wifiPassphraseDialog == true) {
if(global::keyboard::keyboardText != "") {
if(!global::keyboard::keyboardText.isEmpty()) {
this->hide();
wifiPassphrase = global::keyboard::keyboardText;
global::toast::indefiniteToast = true;
@ -363,6 +363,18 @@ void generalDialog::on_okBtn_clicked()
QMessageBox::critical(this, tr("Invalid argument"), tr("Please type in the required argument."));
}
}
else if(global::keyboard::encfsDialog == true) {
if(!global::keyboard::keyboardText.isEmpty()) {
this->close();
global::encfs::passphrase = global::keyboard::keyboardText;
global::keyboard::encfsDialog = false;
global::keyboard::keyboardText = "";
global::keyboard::keyboardDialog = false;
}
else {
QMessageBox::critical(this, tr("Invalid argument"), tr("Please type in the required argument."));
}
}
else {
global::keyboard::keyboardDialog = false;
generalDialog::close();
@ -428,6 +440,11 @@ void generalDialog::setupKeyboardDialog() {
ui->okBtn->setText("Connect");
ui->cancelBtn->setText("Cancel");
}
else if(global::keyboard::encfsDialog == true) {
ui->headerLabel->setText("Enter a new encryption key");
ui->okBtn->setText("OK");
ui->cancelBtn->setText("Cancel");
}
else {
ui->headerLabel->setText("Enter a string");
ui->okBtn->setText("OK");

View file

@ -16,6 +16,7 @@ SOURCES += \
brightnessdialog.cpp \
calendarapp.cpp \
dictionarywidget.cpp \
encryptionmanager.cpp \
generaldialog.cpp \
koboxappsdialog.cpp \
koboxsettings.cpp \
@ -41,6 +42,7 @@ HEADERS += \
brightnessdialog.h \
calendarapp.h \
dictionarywidget.h \
encryptionmanager.h \
functions.h \
generaldialog.h \
koboxappsdialog.h \
@ -66,6 +68,7 @@ FORMS += \
brightnessdialog.ui \
calendarapp.ui \
dictionarywidget.ui \
encryptionmanager.ui \
generaldialog.ui \
koboxappsdialog.ui \
koboxsettings.ui \

View file

@ -20,6 +20,7 @@
#include "generaldialog.h"
#include "functions.h"
#include "reader.h"
#include "encryptionmanager.h"
#include <QApplication>
#include <QFile>
@ -30,6 +31,21 @@
int main(int argc, char *argv[])
{
setDefaultWorkDir();
string_checkconfig_ro(".config/18-encrypted_storage/status");
if(checkconfig_str_val.isEmpty() == true) {
string_writeconfig(".config/18-encrypted_storage/status", "true");
}
if(checkconfig(".config/18-encrypted_storage/status") == true and checkconfig("/run/encfs_mounted") == false) {
// Open Encryption Manager to unlock encrypted storage
QApplication a(argc, argv);
encryptionManager w;
const QScreen * screen = qApp->primaryScreen();
w.setGeometry(QRect(QPoint(0,0), screen->geometry().size()));
w.show();
return a.exec();
}
else {
// Tell scripts that we're currently running
string_writeconfig("/tmp/inkbox_running", "true");
@ -161,3 +177,4 @@ int main(int argc, char *argv[])
return a.exec();
}
}
}

BIN
resources/encryption.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB