GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
pinentry.h
1 /* pinentry.h - The interface for the PIN entry support library.
2  * Copyright (C) 2002, 2003, 2010, 2015, 2021 g10 Code GmbH
3  *
4  * This file is part of PINENTRY.
5  *
6  * PINENTRY is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * PINENTRY is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see <https://www.gnu.org/licenses/>.
18  * SPDX-License-Identifier: GPL-2.0+
19  */
20 
21 #ifndef PINENTRY_H
22 #define PINENTRY_H
23 
24 #include <cstdint>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #if 0
29 }
30 #endif
31 #endif
32 
33 typedef enum {
34  PINENTRY_COLOR_NONE,
35  PINENTRY_COLOR_DEFAULT,
36  PINENTRY_COLOR_BLACK,
37  PINENTRY_COLOR_RED,
38  PINENTRY_COLOR_GREEN,
39  PINENTRY_COLOR_YELLOW,
40  PINENTRY_COLOR_BLUE,
41  PINENTRY_COLOR_MAGENTA,
42  PINENTRY_COLOR_CYAN,
43  PINENTRY_COLOR_WHITE
44 } pinentry_color_t;
45 
46 struct pinentry {
47  /* The window title, or NULL. (Assuan: "SETTITLE TITLE".) */
48  char *title;
49  /* The description to display, or NULL. (Assuan: "SETDESC
50  DESC".) */
51  char *description;
52  /* The error message to display, or NULL. (Assuan: "SETERROR
53  MESSAGE".) */
54  char *error;
55  /* The prompt to display, or NULL. (Assuan: "SETPROMPT
56  prompt".) */
57  char *prompt;
58  /* The OK button text to display, or NULL. (Assuan: "SETOK
59  OK".) */
60  char *ok;
61  /* The Not-OK button text to display, or NULL. This is the text for
62  the alternative option shown by the third button. (Assuan:
63  "SETNOTOK NOTOK".) */
64  char *notok;
65  /* The Cancel button text to display, or NULL. (Assuan: "SETCANCEL
66  CANCEL".) */
67  char *cancel;
68 
69  /* The buffer to store the secret into. */
70  char *pin;
71  /* The length of the buffer. */
72  int pin_len;
73  /* Whether the pin was read from an external cache (1) or entered by
74  the user (0). */
75  int pin_from_cache;
76 
77  /* The name of the X display to use if X is available and supported.
78  (Assuan: "OPTION display DISPLAY".) */
79  char *display;
80  /* The name of the terminal node to open if X not available or
81  supported. (Assuan: "OPTION ttyname TTYNAME".) */
82  char *ttyname;
83  /* The type of the terminal. (Assuan: "OPTION ttytype TTYTYPE".) */
84  char *ttytype_l;
85  /* Set the alert mode (none, beep or flash). */
86  char *ttyalert;
87  /* The LC_CTYPE value for the terminal. (Assuan: "OPTION lc-ctype
88  LC_CTYPE".) */
89  char *lc_ctype;
90  /* The LC_MESSAGES value for the terminal. (Assuan: "OPTION
91  lc-messages LC_MESSAGES".) */
92  char *lc_messages;
93 
94  /* True if debug mode is requested. */
95  int debug;
96 
97  /* The number of seconds before giving up while waiting for user input. */
98  int timeout;
99 
100  /* True if caller should grab the keyboard. (Assuan: "OPTION grab"
101  or "OPTION no-grab".) */
102  int grab;
103 
104  /* The PID of the owner or 0 if not known. The owner is the process
105  * which actually triggered the the pinentry. For example gpg. */
106  unsigned long owner_pid;
107 
108  /* The numeric uid (user ID) of the owner process or -1 if not
109  * known. */
110  int owner_uid;
111 
112  /* The malloced hostname of the owner or NULL. */
113  char *owner_host;
114 
115  /* The window ID of the parent window over which the pinentry window
116  should be displayed. (Assuan: "OPTION parent-wid WID".) */
117  int parent_wid;
118 
119  /* The name of an optional file which will be touched after a curses
120  entry has been displayed. (Assuan: "OPTION touch-file
121  FILENAME".) */
122  char *touch_file;
123 
124  /* The frontend should set this to -1 if the user canceled the
125  request, and to the length of the PIN stored in pin
126  otherwise. */
127  int result;
128 
129  /* The frontend should set this if the NOTOK button was pressed. */
130  int canceled;
131 
132  /* The frontend should set this to true if an error with the local
133  conversion occurred. */
134  int locale_err;
135 
136  /* The frontend should set this to a gpg-error so that commands are
137  able to return specific error codes. This is an ugly hack due to
138  the fact that pinentry_cmd_handler_t returns the length of the
139  passphrase or a negative error code. */
140  int specific_err;
141 
142  /* The frontend may store a string with the error location here. */
143  const char *specific_err_loc;
144 
145  /* The frontend may store a malloced string here to emit an ERROR
146  * status code with this extra info along with SPECIFIC_ERR. */
147  char *specific_err_info;
148 
149  /* The frontend should set this to true if the window close button
150  has been used. This flag is used in addition to a regular return
151  value. */
152  int close_button;
153 
154  /* The caller should set this to true if only one button is
155  required. This is useful for notification dialogs where only a
156  dismiss button is required. */
157  int one_button;
158 
159  /* Whether this is a CONFIRM pinentry. */
160  int confirm;
161 
162  /* If true a second prompt for the passphrase is shown and the user
163  is expected to enter the same passphrase again. Pinentry checks
164  that both match. (Assuan: "SETREPEAT".) */
165  char *repeat_passphrase;
166 
167  /* The string to show if a repeated passphrase does not match.
168  (Assuan: "SETREPEATERROR ERROR".) */
169  char *repeat_error_string;
170 
171  /* The string to show if a repeated passphrase does match.
172  (Assuan: "SETREPEATOK STRING".) */
173  char *repeat_ok_string;
174 
175  /* Set to true if the passphrase has been entered a second time and
176  matches the first passphrase. */
177  int repeat_okay;
178 
179  /* If this is not NULL, a passphrase quality indicator is shown.
180  There will also be an inquiry back to the caller to get an
181  indication of the quality for the passphrase entered so far. The
182  string is used as a label for the quality bar. (Assuan:
183  "SETQUALITYBAR LABEL".) */
184  char *quality_bar;
185 
186  /* The tooltip to be shown for the qualitybar. Malloced or NULL.
187  (Assuan: "SETQUALITYBAR_TT TOOLTIP".) */
188  char *quality_bar_tt;
189 
190  /* If this is not NULL, a generate action should be shown.
191  There will be an inquiry back to the caller to get such a
192  PIN. generate action. Malloced or NULL.
193  (Assuan: "SETGENPIN LABEL" .) */
194  char *genpin_label;
195 
196  /* The tooltip to be shown for the generate action. Malloced or NULL.
197  (Assuan: "SETGENPIN_TT TOOLTIP".) */
198  char *genpin_tt;
199 
200  /* Specifies whether passphrase formatting should be enabled.
201  (Assuan: "OPTION formatted-passphrase") */
202  int formatted_passphrase;
203 
204  /* A hint to be shown near the passphrase input field if passphrase
205  formatting is enabled. Malloced or NULL.
206  (Assuan: "OPTION formatted-passphrase-hint=HINT".) */
207  char *formatted_passphrase_hint;
208 
209  /* For the curses pinentry, the color of error messages. */
210  pinentry_color_t color_fg;
211  int color_fg_bright;
212  pinentry_color_t color_bg;
213  pinentry_color_t color_so;
214  int color_so_bright;
215  pinentry_color_t color_ok;
216  int color_ok_bright;
217  pinentry_color_t color_qualitybar;
218  int color_qualitybar_bright;
219 
220  /* Malloced and i18ned default strings or NULL. These strings may
221  include an underscore character to indicate an accelerator key.
222  A double underscore represents a plain one. */
223  /* (Assuan: "OPTION default-ok OK"). */
224  char *default_ok;
225  /* (Assuan: "OPTION default-cancel CANCEL"). */
226  char *default_cancel;
227  /* (Assuan: "OPTION default-prompt PROMPT"). */
228  char *default_prompt;
229  /* (Assuan: "OPTION default-pwmngr
230  SAVE_PASSWORD_WITH_PASSWORD_MANAGER?"). */
231  char *default_pwmngr;
232  /* (Assuan: "OPTION default-cf-visi
233  Do you really want to make your passphrase visible?"). */
234  char *default_cf_visi;
235  /* (Assuan: "OPTION default-tt-visi
236  Make passphrase visible?"). */
237  char *default_tt_visi;
238  /* (Assuan: "OPTION default-tt-hide
239  Hide passphrase"). */
240  char *default_tt_hide;
241  /* (Assuan: "OPTION default-capshint
242  Caps Lock is on"). */
243  char *default_capshint;
244 
245  /* Whether we are allowed to read the password from an external
246  cache. (Assuan: "OPTION allow-external-password-cache") */
247  int allow_external_password_cache;
248 
249  /* We only try the cache once. */
250  int tried_password_cache;
251 
252  /* A stable identifier for the key. (Assuan: "SETKEYINFO
253  KEYINFO".) */
254  char *keyinfo;
255 
256  /* Whether we may cache the password (according to the user). */
257  int may_cache_password;
258 
259  /* NOTE: If you add any additional fields to this structure, be sure
260  to update the initializer in pinentry/pinentry.c!!! */
261 
262  /* For the quality indicator and genpin we need to do an inquiry.
263  Thus we need to save the assuan ctx. */
264  void *ctx_assuan;
265 
266  /* An UTF-8 string with an invisible character used to override the
267  default in some pinentries. Only the first character is
268  used. */
269  char *invisible_char;
270 
271  /* Whether the passphrase constraints are enforced by gpg-agent.
272  (Assuan: "OPTION constraints-enforce") */
273  int constraints_enforce;
274 
275  /* A short translated hint for the user with the constraints for new
276  passphrases to be displayed near the passphrase input field.
277  Malloced or NULL.
278  (Assuan: "OPTION constraints-hint-short=At least 8 characters".) */
279  char *constraints_hint_short;
280 
281  /* A longer translated hint for the user with the constraints for new
282  passphrases to be displayed for example as tooltip. Malloced or NULL.
283  (Assuan: "OPTION constraints-hint-long=The passphrase must ...".) */
284  char *constraints_hint_long;
285 
286  /* A short translated title for an error dialog informing the user about
287  unsatisfied passphrase constraints. Malloced or NULL.
288  (Assuan: "OPTION constraints-error-title=Passphrase Not Allowed".) */
289  char *constraints_error_title;
290 };
291 typedef struct pinentry *pinentry_t;
292 
293 /* The pinentry command handler type processes the pinentry request
294  PIN. If PIN->pin is zero, request a confirmation, otherwise a PIN
295  entry. On confirmation, the function should return TRUE if
296  confirmed, and FALSE otherwise. On PIN entry, the function should
297  return -1 if an error occurred or the user cancelled the operation
298  and 1 otherwise. */
299 typedef int (*pinentry_cmd_handler_t)(pinentry_t pin);
300 
301 const char *pinentry_get_pgmname(void);
302 
303 char *pinentry_get_title(pinentry_t pe);
304 
305 /* Run a quality inquiry for PASSPHRASE of LENGTH. */
306 int pinentry_inq_quality(const QString &passphrase);
307 
308 /* Run a genpin iquriry. Returns a malloced string or NULL */
309 char *pinentry_inq_genpin(pinentry_t pin);
310 
311 /* Try to make room for at least LEN bytes for the pin in the pinentry
312  PIN. Returns new buffer on success and 0 on failure. */
313 char *pinentry_setbufferlen(pinentry_t pin, int len);
314 
315 /* Return true if either DISPLAY is set or ARGV contains the string
316  "--display". */
317 int pinentry_have_display(int argc, char **argv);
318 
319 /* Parse the command line options. May exit the program if only help
320  or version output is requested. */
321 void pinentry_parse_opts(int argc, char *argv[]);
322 
323 /* Set the optional flag used with getinfo. */
324 void pinentry_set_flavor_flag(const char *string);
325 
326 #ifdef WINDOWS
327 /* Windows declares sleep as obsolete, but provides a definition for
328  _sleep but non for the still existing sleep. */
329 #define sleep(a) _sleep((a))
330 #endif /*WINDOWS*/
331 
332 #if 0
333 {
334 #endif
335 #ifdef __cplusplus
336 }
337 #endif
338 
339 #endif /* PINENTRY_H */
Definition: pinentry.h:46