aboutsummaryrefslogtreecommitdiff
path: root/src/keyring.h
blob: 42cf992b7822056028e823ad37cceeaf87637bfa (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
#pragma once

#include <QAbstractTableModel>
#include <QFont>
#include <QString>

#include "ext_packet.h"

// The sole reason I use a class here is because Qt demands it. At least, that's
// my impression after reading the documentation.
class KeyringModel : public QAbstractTableModel
{
  Q_OBJECT
public:
  explicit KeyringModel(QObject *parent = nullptr);
  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

  void load_keys(void);
  static constexpr int KeyIDRole = 0x0100;

private:
  struct KeyInfo
  {
    QByteArray id;
    QString name;
    QString bytes;
  };

  QVector<KeyInfo> m_keys;
};

enum class ResponseResult
{
  success,
  invalid_password,
  inaccessible_keyring,
  corrupted_entry,
  unsupported_version,
  derivation_failed,
  decryption_failed,
  bad_curve_point,
  hardware_fault,
  invalid_pin,
  hardware_lockout,
  incompatible_arguments,
};

enum class KeyringStorageType
{
  invalid,
  software,
  hardware,
};

struct KeyringKey
{
  KeyringStorageType type = KeyringStorageType::invalid;
  QByteArray id;
  QByteArray public_key;
  QByteArray protected_secret;
  QString name;
};

int keyring_initialize(void);
int keyring_hardware_available(void);
int generate_software_key(QStringView name, const QByteArray &password);
int generate_hardware_key(QStringView name, const QByteArray &pin);
KeyringKey acquire_keyring_key(QByteArrayView key_id);
void delete_key(const QByteArray &key_id);
ResponseResult unlock_and_auth(const KeyringKey &key, QByteArrayView password, QByteArrayView ephemeral_key, QByteArrayView username, AuthResponse &out);