Skip to content
Permalink
Browse files

Detect tails, support data persistence

Co-authored-by: Thotbot <thotbot@protonmail.com>
Co-authored-by: Selsta <selsta@sent.at>
  • Loading branch information...
3 people committed Jul 3, 2019
1 parent 035b89e commit 257fd4e909bc172238565daffa5817534ebef5ef
Showing with 187 additions and 14 deletions.
  1. +4 −0 Logger.cpp
  2. BIN images/tails-grey.png
  3. +29 −8 main.cpp
  4. +6 −0 main.qml
  5. +4 −2 monero-wallet-gui.pro
  6. +35 −0 pages/settings/SettingsInfo.qml
  7. +1 −0 qml.qrc
  8. +75 −0 src/qt/TailsOS.cpp
  9. +21 −0 src/qt/TailsOS.h
  10. +11 −4 src/qt/utils.cpp
  11. +1 −0 src/qt/utils.h
@@ -34,6 +34,7 @@
#include <QDebug>

#include "Logger.h"
#include "src/qt/TailsOS.h"
#include "wallet/api/wallet2_api.h"

// default log path by OS (should be writable)
@@ -66,6 +67,9 @@ const QString getLogPath(const QString logPath)
{
const QFileInfo fi(logPath);

if(TailsOS::detect() && TailsOS::usePersistence)
return QDir::homePath() + "/Persistent/Monero/logs/" + defaultLogName;

if(!logPath.isEmpty() && !fi.isDir())
return fi.absoluteFilePath();
else {
BIN +7.69 KB images/tails-grey.png
Binary file not shown.
@@ -65,6 +65,7 @@
#include "qt/ipc.h"
#include "qt/utils.h"
#include "qt/mime.h"
#include "src/qt/TailsOS.h"
#include "src/qt/KeysFiles.h"
#include "src/qt/MoneroSettings.h"
#include "qt/prices.h"
@@ -83,6 +84,7 @@ bool isAndroid = false;
bool isWindows = false;
bool isMac = false;
bool isLinux = false;
bool isTails = false;
bool isDesktop = false;
bool isOpenGL = true;

@@ -102,6 +104,7 @@ int main(int argc, char *argv[])
bool isWindows = true;
#elif defined(Q_OS_LINUX)
bool isLinux = true;
bool isTails = TailsOS::detect();
#elif defined(Q_OS_MAC)
bool isMac = true;
#endif
@@ -123,25 +126,40 @@ int main(int argc, char *argv[])
// qDebug() << "High DPI auto scaling - enabled";
//#endif

MainApp app(argc, argv);

app.setApplicationName("monero-core");
app.setOrganizationDomain("getmonero.org");
app.setOrganizationName("monero-project");

// Ask to enable Tails OS persistence mode, it affects:
// - Log file location
// - QML Settings file location (monero-core.conf)
// - Default wallets path
// Target directory is: ~/Persistent/Monero
if (isTails) {
if (!TailsOS::detectDataPersistence())
TailsOS::showDataPersistenceDisabledWarning();
else
TailsOS::askPersistence();
}

QString moneroAccountsDir;
#if defined(Q_OS_WIN) || defined(Q_OS_IOS)
QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
#else
QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
#endif
if (!moneroAccountsRootDir.empty()) {

if(isTails && TailsOS::usePersistence){
moneroAccountsDir = QDir::homePath() + "/Persistent/Monero/wallets";
} else if (!moneroAccountsRootDir.empty()) {
moneroAccountsDir = moneroAccountsRootDir.at(0) + "/Monero/wallets";
} else {
qCritical() << "Error: accounts root directory could not be set";
return 1;
}

MainApp app(argc, argv);

app.setApplicationName("monero-core");
app.setOrganizationDomain("getmonero.org");
app.setOrganizationName("monero-project");

#if defined(Q_OS_LINUX)
if (isDesktop) app.setWindowIcon(QIcon(":/images/appicon.ico"));
#endif
@@ -316,6 +334,8 @@ int main(int argc, char *argv[])

engine.rootContext()->setContextProperty("walletLogPath", logPath);

engine.rootContext()->setContextProperty("tailsUsePersistence", TailsOS::usePersistence);

// Exclude daemon manager from IOS
#ifndef Q_OS_IOS
const QStringList arguments = (QStringList) QCoreApplication::arguments().at(0);
@@ -329,7 +349,7 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty("isIOS", isIOS);
engine.rootContext()->setContextProperty("isAndroid", isAndroid);
engine.rootContext()->setContextProperty("isOpenGL", isOpenGL);
engine.rootContext()->setContextProperty("isLinux", isLinux);
engine.rootContext()->setContextProperty("isTails", isTails);

engine.rootContext()->setContextProperty("screenWidth", geo.width());
engine.rootContext()->setContextProperty("screenHeight", geo.height());
@@ -353,6 +373,7 @@ int main(int argc, char *argv[])
accountName = "My monero Account";

engine.rootContext()->setContextProperty("defaultAccountName", accountName);
engine.rootContext()->setContextProperty("homePath", QDir::homePath());
engine.rootContext()->setContextProperty("applicationDirectory", QApplication::applicationDirPath());
engine.rootContext()->setContextProperty("idealThreadCount", QThread::idealThreadCount());

@@ -1343,6 +1343,12 @@ ApplicationWindow {

MoneroSettings {
id: persistentSettings
fileName: {
if(isTails && tailsUsePersistence)
return homePath + "/Persistent/Monero/monero-core.conf";
return "";
}

property string language
property string locale
property string account_name
@@ -69,7 +69,8 @@ HEADERS += \
src/qt/KeysFiles.h \
src/qt/utils.h \
src/qt/prices.h \
src/qt/MoneroSettings.h
src/qt/MoneroSettings.h \
src/qt/TailsOS.h

SOURCES += main.cpp \
filter.cpp \
@@ -104,7 +105,8 @@ SOURCES += main.cpp \
src/qt/KeysFiles.cpp \
src/qt/utils.cpp \
src/qt/prices.cpp \
src/qt/MoneroSettings.cpp
src/qt/MoneroSettings.cpp \
src/qt/TailsOS.cpp

CONFIG(DISABLE_PASS_STRENGTH_METER) {
HEADERS -= src/zxcvbn-c/zxcvbn.h
@@ -325,6 +325,41 @@ Rectangle {
font.pixelSize: 14
text: isOpenGL ? "OpenGL" : "Low graphics mode"
}

Rectangle {
visible: isTails
height: 1
Layout.topMargin: 2
Layout.bottomMargin: 2
Layout.fillWidth: true
color: MoneroComponents.Style.dividerColor
opacity: MoneroComponents.Style.dividerOpacity
}

Rectangle {
visible: isTails
height: 1
Layout.topMargin: 2
Layout.bottomMargin: 2
Layout.fillWidth: true
color: MoneroComponents.Style.dividerColor
opacity: MoneroComponents.Style.dividerOpacity
}

MoneroComponents.TextBlock {
visible: isTails
Layout.fillWidth: true
font.pixelSize: 14
text: qsTr("Tails: ") + translationManager.emptyString
}

MoneroComponents.TextBlock {
visible: isTails
Layout.fillWidth: true
color: MoneroComponents.Style.dimmedFontColor
font.pixelSize: 14
text: tailsUsePersistence ? qsTr("persistent") + translationManager.emptyString : qsTr("persistence disabled") + translationManager.emptyString;
}
}

// Copy info to clipboard
@@ -253,5 +253,6 @@
<file>images/copy.svg</file>
<file>images/edit.svg</file>
<file>images/arrow-right-in-circle-outline-medium-white.svg</file>
<file>images/tails-grey.png</file>
</qresource>
</RCC>
@@ -0,0 +1,75 @@
#include <QRegExp>
#include <QMessageBox>
#include <QPixmap>
#include <QTranslator>

#include "TailsOS.h"
#include "utils.h"

bool TailsOS::usePersistence = false;

bool TailsOS::detect()
{
if (!fileExists("/etc/os-release"))
return false;

QByteArray data = fileOpen("/etc/os-release");
QRegularExpression re("TAILS_PRODUCT_NAME=\"Tails\"");
QRegularExpressionMatch os_match = re.match(data);
bool matched = os_match.hasMatch();
#ifdef QT_DEBUG
if (matched)
qDebug() << "Tails OS detected";
#endif
return matched;
}

bool TailsOS::detectDataPersistence()
{
return QDir(QDir::homePath() + "/Persistent").exists();
}

bool TailsOS::detectDotPersistence()
{
return QDir("/live/persistence/TailsData_unlocked/dotfiles").exists();
}

void TailsOS::showDataPersistenceDisabledWarning()
{
QMessageBox msgBox;
msgBox.setText(QObject::tr("Warning: persistence disabled"));
msgBox.setWindowTitle(QObject::tr("Warning: persistence disabled"));
msgBox.setInformativeText(
QObject::tr("Monero GUI has detected that Tails persistence is "
"currently disabled. Any configurations you make inside "
"the Monero GUI will not be saved."
"\n\n"
"In addition, make sure to not save your wallet on the "
"filesystem, as it will be lost at shutdown."
"\n\n"
"To enable Tails persistence, setup an encrypted volume "
"and restart Tails. To gain a startup menu item, "
"enable the Tails \"dotfiles\" feature."));

msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setIconPixmap(QPixmap(":/images/tails-grey.png"));
msgBox.exec();
}

void TailsOS::askPersistence()
{
QMessageBox msgBox;
msgBox.setWindowTitle(QObject::tr("Monero GUI"));
msgBox.setText(QObject::tr("Use Tails persistence?"));
msgBox.setInformativeText(
QObject::tr("Persist wallet files and configuration?"
"\n\n"
"Will also create a persistence menu "
"shortcut if dotfiles persistence is enabled.\n"));

msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
msgBox.setIconPixmap(QPixmap(":/images/tails-grey.png"));
TailsOS::usePersistence = (msgBox.exec() == QMessageBox::Yes);
}
@@ -0,0 +1,21 @@
#ifndef TAILSOS_H
#define TAILSOS_H

#include <QApplication>


class TailsOS
{
public:
TailsOS();
static bool detect();
static bool detectDataPersistence();
static bool detectDotPersistence();

static void showDataPersistenceDisabledWarning();
static void askPersistence();

static bool usePersistence;
};

#endif // TAILSOS_H
@@ -32,10 +32,17 @@

bool fileExists(QString path) {
QFileInfo check_file(path);
if (check_file.exists() && check_file.isFile())
return true;
else
return false;
return check_file.exists() && check_file.isFile();
}

QByteArray fileOpen(QString path) {
QFile file(path);
if(!file.open(QFile::ReadOnly | QFile::Text))
return QByteArray();

QByteArray data = file.readAll();
file.close();
return data;
}

QString getAccountName(){
@@ -33,6 +33,7 @@
#include <QRegExp>

bool fileExists(QString path);
QByteArray fileOpen(QString path);
QString getAccountName();
const static QRegExp reURI = QRegExp("^\\w+:\\/\\/([\\w+\\-?\\-_\\-=\\-&]+)");
QString randomUserAgent();

0 comments on commit 257fd4e

Please sign in to comment.
You can’t perform that action at this time.