GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
pinentrydialog.h
1 /* pinentrydialog.h - A (not yet) secure Qt 4 dialog for PIN entry.
2  * Copyright (C) 2002, 2008 Klarälvdalens Datakonsult AB (KDAB)
3  * Copyright 2007 Ingo Klöcker
4  * Copyright 2016 Intevation GmbH
5  * Copyright (C) 2021, 2022 g10 Code GmbH
6  *
7  * Written by Steffen Hansen <steffen@klaralvdalens-datakonsult.se>.
8  * Modified by Andre Heinecke <aheinecke@intevation.de>
9  * Software engineering by Ingo Klöcker <dev@ingo-kloecker.de>
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License as
13  * published by the Free Software Foundation; either version 2 of the
14  * License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, see <https://www.gnu.org/licenses/>.
23  * SPDX-License-Identifier: GPL-2.0+
24  */
25 
26 #ifndef __PINENTRYDIALOG_H__
27 #define __PINENTRYDIALOG_H__
28 
29 #include <QAccessible>
30 #include <QDialog>
31 #include <QStyle>
32 #include <QTimer>
33 
34 #include "core/function/SecureMemoryAllocator.h"
35 #include "pinentry.h"
36 
37 class QIcon;
38 class QLabel;
39 class QPushButton;
40 class QLineEdit;
41 class PinLineEdit;
42 class QString;
43 class QProgressBar;
44 class QCheckBox;
45 class QAction;
46 
47 QPixmap applicationIconPixmap(const QIcon &overlayIcon = {});
48 
49 void raiseWindow(QWidget *w);
50 
51 class PinEntryDialog : public QDialog {
52  Q_OBJECT
53 
54  Q_PROPERTY(QString description READ description WRITE setDescription)
55  Q_PROPERTY(QString error READ error WRITE setError)
56  Q_PROPERTY(QString pin READ pin WRITE setPin)
57  Q_PROPERTY(QString prompt READ prompt WRITE setPrompt)
58  public:
60  bool formatPassphrase;
61  QString hint;
62  };
64  bool enforce;
65  QString shortHint;
66  QString longHint;
67  QString errorTitle;
68  };
69 
70  explicit PinEntryDialog(QWidget *parent = 0, const char *name = 0,
71  int timeout = 0, bool modal = false,
72  bool enable_quality_bar = false,
73  const QString &repeatString = QString(),
74  const QString &visibiltyTT = QString(),
75  const QString &hideTT = QString());
76 
77  void setDescription(const QString &);
78  QString description() const;
79 
80  void setError(const QString &);
81  QString error() const;
82 
83  void setPin(const QString &);
84  QString pin() const;
85 
86  QString repeatedPin() const;
87  void setRepeatErrorText(const QString &);
88 
89  void setPrompt(const QString &);
90  QString prompt() const;
91 
92  void setOkText(const QString &);
93  void setCancelText(const QString &);
94 
95  void setQualityBar(const QString &);
96  void setQualityBarTT(const QString &);
97 
98  void setGenpinLabel(const QString &);
99  void setGenpinTT(const QString &);
100 
101  void setCapsLockHint(const QString &);
102 
103  void setFormattedPassphrase(const FormattedPassphraseOptions &options);
104 
105  void setConstraintsOptions(const ConstraintsOptions &options);
106 
107  void setPinentryInfo(struct pinentry);
108 
109  bool timedOut() const;
110 
111  protected Q_SLOTS:
112  void updateQuality(const QString &);
113  void slotTimeout();
114  void textChanged(const QString &);
115  void focusChanged(QWidget *old, QWidget *now);
116  void toggleVisibility();
117  void onBackspace();
118  void generatePin();
119  void toggleFormattedPassphrase();
120 
121  protected:
122  void keyPressEvent(QKeyEvent *event) override;
123  void keyReleaseEvent(QKeyEvent *event) override;
124  void showEvent(QShowEvent *event) override;
125 
126  private Q_SLOTS:
127  void cancelTimeout();
128  void checkCapsLock();
129  void onAccept();
130 
131  private:
132  enum PassphraseCheckResult {
133  PassphraseNotChecked = -1,
134  PassphraseNotOk = 0,
135  PassphraseOk
136  };
137 
138  QLabel *_icon = nullptr;
139  QLabel *_desc = nullptr;
140  QLabel *_error = nullptr;
141  QLabel *_prompt = nullptr;
142  QLabel *_quality_bar_label = nullptr;
143  QProgressBar *_quality_bar = nullptr;
144  PinLineEdit *_edit = nullptr;
145  PinLineEdit *mRepeat = nullptr;
146  QLabel *mRepeatError = nullptr;
147  QPushButton *_ok = nullptr;
148  QPushButton *_cancel = nullptr;
149  bool _grabbed = false;
150  bool _have_quality_bar = false;
151  bool _timed_out = false;
152  bool _disable_echo_allowed = true;
153  bool mEnforceConstraints = false;
154  bool mFormatPassphrase = false;
155 
156  GpgFrontend::SecureUniquePtr<struct pinentry> _pinentry_info = nullptr;
157  QTimer *_timer = nullptr;
158  QString mVisibilityTT;
159  QString mHideTT;
160  QAction *mVisiActionEdit = nullptr;
161  QPushButton *mGenerateButton = nullptr;
162  QCheckBox *mVisiCB = nullptr;
163  QLabel *mFormattedPassphraseHint = nullptr;
164  QLabel *mFormattedPassphraseHintSpacer = nullptr;
165  QLabel *mCapsLockHint = nullptr;
166  QLabel *mConstraintsHint = nullptr;
167  QString mConstraintsErrorTitle;
168 };
169 
170 #endif // __PINENTRYDIALOG_H__
Definition: pinentrydialog.h:51
Definition: pinlineedit.h:27
Definition: pinentrydialog.h:63
Definition: pinentrydialog.h:59
Definition: pinentry.h:46