88 lines
2.8 KiB
C++
88 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include <QByteArray>
|
|
#include <QObject>
|
|
#include <QProcess>
|
|
#include <QString>
|
|
|
|
class ProvisioningBackend final : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
|
|
Q_PROPERTY(bool passwordDone READ passwordDone NOTIFY stateChanged)
|
|
Q_PROPERTY(bool pinDone READ pinDone NOTIFY stateChanged)
|
|
Q_PROPERTY(bool complete READ complete NOTIFY stateChanged)
|
|
Q_PROPERTY(QString currentUser READ currentUser CONSTANT)
|
|
Q_PROPERTY(QString targetUser READ targetUser CONSTANT)
|
|
Q_PROPERTY(bool authorizedUser READ authorizedUser CONSTANT)
|
|
|
|
public:
|
|
explicit ProvisioningBackend(QString targetUser, QObject *parent = nullptr);
|
|
~ProvisioningBackend() override;
|
|
|
|
bool busy() const { return m_busy; }
|
|
bool passwordDone() const { return m_passwordDone; }
|
|
bool pinDone() const { return m_pinDone; }
|
|
bool complete() const { return m_passwordDone && m_pinDone; }
|
|
QString currentUser() const { return m_currentUser; }
|
|
QString targetUser() const { return m_targetUser; }
|
|
bool authorizedUser() const;
|
|
|
|
QString stateDirectory() const;
|
|
QString diagnosticLogPath() const;
|
|
QString passwordMarker() const;
|
|
QString pinMarker() const;
|
|
|
|
static QString effectiveUserName();
|
|
|
|
Q_INVOKABLE void changePassword(const QString ¤tPassword,
|
|
const QString &newPassword,
|
|
const QString &confirmation);
|
|
|
|
Q_INVOKABLE void changePin(const QString ¤tPin,
|
|
const QString &newPin,
|
|
const QString &confirmation);
|
|
|
|
signals:
|
|
void busyChanged();
|
|
void stateChanged();
|
|
void passwordChangeFinished(bool success, const QString &message);
|
|
void pinChangeFinished(bool success, const QString &message);
|
|
|
|
private:
|
|
enum class Operation {
|
|
Password,
|
|
Pin
|
|
};
|
|
|
|
void startHelper(Operation operation,
|
|
const QString &helperPath,
|
|
const QString &firstSecret,
|
|
const QString &secondSecret,
|
|
const QString &thirdSecret);
|
|
|
|
void setBusy(bool busy);
|
|
void refreshState();
|
|
bool ensureStateWritable();
|
|
bool createMarker(const QString &path);
|
|
void appendLog(const QString &message) const;
|
|
|
|
QString safeMessageForFailure(Operation operation,
|
|
int exitCode,
|
|
const QByteArray &output,
|
|
bool timedOut) const;
|
|
|
|
static void secureClear(QByteArray &data);
|
|
static QString operationName(Operation operation);
|
|
|
|
bool m_busy = false;
|
|
bool m_passwordDone = false;
|
|
bool m_pinDone = false;
|
|
bool m_helperTimedOut = false;
|
|
QString m_currentUser;
|
|
QString m_targetUser;
|
|
QProcess *m_process = nullptr;
|
|
QByteArray m_pendingPayload;
|
|
};
|