aboutsummaryrefslogtreecommitdiff
path: root/src/auth_flow.h
blob: 4a89673473ffff6643a4c446ffbf9a232365a3f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once

#include <QString>
#include <QLineEdit>

#include "ext_packet.h"
#include "keyring.h"
#include "saved_auth.h"

class KeySelectDialog : public QDialog
{
  Q_OBJECT

public:
  explicit KeySelectDialog(KeyringModel *model, QStringView username, QStringView hostname, QWidget *parent = nullptr);

private:
  KeyringModel *m_model;

signals:
  void key_selected(KeyringKey key);
};

class KeyActivationDialog : public QDialog
{
  Q_OBJECT

public:
  enum class Mode {
    none,
    passphrase,
    pin,
  };
  explicit KeyActivationDialog(Mode mode, QStringView key_name, QWidget *parent = nullptr);
  void display_error(ResponseResult error) const;

private:
  QLabel *m_err_lbl;
  QLineEdit *m_line;

signals:
  void input_submitted(QByteArrayView input);
};

// The only reason this inherits QObject is signals.
class AuthFlow : public QObject
{
  Q_OBJECT

public:
  void initialize(KeyringModel *model);
  void start(QString user, QString host);
  bool awaiting_challenge(void) const;
  void respond(const AuthChallenge &challenge);

private:
  enum class FlowMode
  {
    Default,
    Saved
  };

  enum class AuthPhase {
    none,
    requested,
  };

  QString m_username;
  QString m_hostname;
  FlowMode m_mode;
  AuthChallenge m_challenge;
  KeySelectDialog *m_key_dlg = nullptr;
  KeyActivationDialog *m_input_dlg = nullptr;
  AuthPhase m_phase = AuthPhase::none;
  SavedAuth m_saved_auth;
  KeyringKey m_key;
  KeyringModel *m_model;

  void on_key_selected(KeyringKey key);
  void call_input_dialog(KeyActivationDialog::Mode mode);
  void authenticate(QByteArrayView input);
  void reject_and_select_new_key(void);
  void reset(void);

signals:
  void request_ready(AuthRequest req);
  void response_ready(AuthResponse response);
};