Encrypted storage: shut down device if "Cancel" pressed

This commit is contained in:
Nicolas Mailloux 2021-10-27 21:55:58 -04:00
parent 1177143f7d
commit e0578ee28a

View file

@ -167,80 +167,86 @@ void encryptionManager::setupEncryptedStorage() {
} }
void encryptionManager::unlockEncryptedStorage() { void encryptionManager::unlockEncryptedStorage() {
this->setStyleSheet("background-color: white"); if(global::encfs::cancelSetup == true) {
ui->activityWidget->show(); global::encfs::cancelSetup = false;
mkEncfsDirs(); poweroff(true);
std::string passphrase = global::encfs::passphrase.toStdString();
global::encfs::passphrase = "";
string_writeconfig("/external_root/run/encfs/encrypted_storage_archive", "/data/onboard/data.encfs");
string_writeconfig("/external_root/run/encfs/encrypted_storage_mountpoint", "/data/onboard/encfs-decrypted");
string_writeconfig("/external_root/run/encfs/encrypted_storage_bindmount", "/kobo/mnt/onboard/onboard/encfs-decrypted");
string_writeconfig("/external_root/run/encfs/encrypted_storage_passphrase", passphrase);
string_writeconfig("/opt/ibxd", "encfs_restart\n");
bool exitStatus;
string_checkconfig_ro("/inkbox/encryptedStoragePassphraseTries");
if(checkconfig_str_val.isEmpty()) {
passphraseTries = 0;
} }
else { else {
passphraseTries = checkconfig_str_val.toInt(); this->setStyleSheet("background-color: white");
passphraseTries++; ui->activityWidget->show();
} mkEncfsDirs();
std::string passphrase = global::encfs::passphrase.toStdString();
global::encfs::passphrase = "";
string_writeconfig("/external_root/run/encfs/encrypted_storage_archive", "/data/onboard/data.encfs");
string_writeconfig("/external_root/run/encfs/encrypted_storage_mountpoint", "/data/onboard/encfs-decrypted");
string_writeconfig("/external_root/run/encfs/encrypted_storage_bindmount", "/kobo/mnt/onboard/onboard/encfs-decrypted");
string_writeconfig("/external_root/run/encfs/encrypted_storage_passphrase", passphrase);
string_writeconfig("/opt/ibxd", "encfs_restart\n");
bool exitStatus;
ui->activityWidget->setCurrentIndex(3); string_checkconfig_ro("/inkbox/encryptedStoragePassphraseTries");
QTimer * t = new QTimer(this); if(checkconfig_str_val.isEmpty()) {
t->setInterval(1000); passphraseTries = 0;
connect(t, &QTimer::timeout, [&]() { }
if(QFile::exists("/external_root/run/encfs_mounted")) { else {
exitStatus = checkconfig("/external_root/run/encfs_mounted"); passphraseTries = checkconfig_str_val.toInt();
if(exitStatus == false) { passphraseTries++;
if(setupMessageBoxRan == false) { }
int delay = 0;
if(passphraseTries <= 3) {
if(passphraseTries == 0) {
string_writeconfig("/inkbox/encryptedStoragePassphraseTries", "0");
delay = 5000;
}
else if(passphraseTries == 1) {
string_writeconfig("/inkbox/encryptedStoragePassphraseTries", "1");
delay = 10000;
}
else if(passphraseTries == 2) {
string_writeconfig("/inkbox/encryptedStoragePassphraseTries", "2");
delay = 20000;
}
else if(passphraseTries >= 3) {
string_writeconfig("/inkbox/encryptedStoragePassphraseTries", "3");
unsigned long currentEpoch = QDateTime::currentSecsSinceEpoch();
currentEpoch += 86400;
std::string unlockTime_str = to_string(currentEpoch);
global::encfs::unlockTime = QDateTime::fromTime_t(currentEpoch).toString();
QString message = "FATAL: 4 invalid passphrase tries, locking down device until " + global::encfs::unlockTime;
qDebug() << message;
string_writeconfig("/external_root/boot/flags/ENCRYPT_LOCK", unlockTime_str);
global::encfs::lockdown = true;
setupMessageBoxRan = true;
alertWindow = new alert(); ui->activityWidget->setCurrentIndex(3);
alertWindow->setAttribute(Qt::WA_DeleteOnClose); QTimer * t = new QTimer(this);
alertWindow->showFullScreen(); t->setInterval(1000);
poweroff(false); connect(t, &QTimer::timeout, [&]() {
} if(QFile::exists("/external_root/run/encfs_mounted")) {
exitStatus = checkconfig("/external_root/run/encfs_mounted");
if(exitStatus == false) {
if(setupMessageBoxRan == false) {
int delay = 0;
if(passphraseTries <= 3) {
if(passphraseTries == 0) {
string_writeconfig("/inkbox/encryptedStoragePassphraseTries", "0");
delay = 5000;
}
else if(passphraseTries == 1) {
string_writeconfig("/inkbox/encryptedStoragePassphraseTries", "1");
delay = 10000;
}
else if(passphraseTries == 2) {
string_writeconfig("/inkbox/encryptedStoragePassphraseTries", "2");
delay = 20000;
}
else if(passphraseTries >= 3) {
string_writeconfig("/inkbox/encryptedStoragePassphraseTries", "3");
unsigned long currentEpoch = QDateTime::currentSecsSinceEpoch();
currentEpoch += 86400;
std::string unlockTime_str = to_string(currentEpoch);
global::encfs::unlockTime = QDateTime::fromTime_t(currentEpoch).toString();
QString message = "FATAL: 4 invalid passphrase tries, locking down device until " + global::encfs::unlockTime;
qDebug() << message;
string_writeconfig("/external_root/boot/flags/ENCRYPT_LOCK", unlockTime_str);
global::encfs::lockdown = true;
setupMessageBoxRan = true;
if(passphraseTries <= 2) { alertWindow = new alert();
QTimer::singleShot(delay, this, SLOT(setupFailedAuthenticationMessageBox())); alertWindow->setAttribute(Qt::WA_DeleteOnClose);
setupMessageBoxRan = true; alertWindow->showFullScreen();
poweroff(false);
}
if(passphraseTries <= 2) {
QTimer::singleShot(delay, this, SLOT(setupFailedAuthenticationMessageBox()));
setupMessageBoxRan = true;
}
} }
} }
} }
else {
quit_restart();
}
} }
else { } );
quit_restart(); t->start();
} }
}
} );
t->start();
} }
void encryptionManager::mkEncfsDirs() { void encryptionManager::mkEncfsDirs() {