| 1 | /* pinentry.h - The interface for the PIN entry support library. |
| 2 | Copyright (C) 2002, 2003 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, write to the Free Software |
| 18 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA |
| 19 | 02110-1301, USA */ |
| 20 | |
| 21 | #ifndef PINENTRY_H |
| 22 | #define PINENTRY_H |
| 23 | |
| 24 | #ifdef __cplusplus |
| 25 | extern "C" { |
| 26 | #if 0 |
| 27 | } |
| 28 | #endif |
| 29 | #endif |
| 30 | |
| 31 | typedef enum { |
| 32 | PINENTRY_COLOR_NONE, PINENTRY_COLOR_DEFAULT, |
| 33 | PINENTRY_COLOR_BLACK, PINENTRY_COLOR_RED, |
| 34 | PINENTRY_COLOR_GREEN, PINENTRY_COLOR_YELLOW, |
| 35 | PINENTRY_COLOR_BLUE, PINENTRY_COLOR_MAGENTA, |
| 36 | PINENTRY_COLOR_CYAN, PINENTRY_COLOR_WHITE |
| 37 | } pinentry_color_t; |
| 38 | |
| 39 | struct pinentry |
| 40 | { |
| 41 | /* The description to display, or NULL. */ |
| 42 | char *description; |
| 43 | /* The error message to display, or NULL. */ |
| 44 | char *error; |
| 45 | /* The prompt to display, or NULL. */ |
| 46 | char *prompt; |
| 47 | /* The OK button text to display, or NULL. */ |
| 48 | char *ok; |
| 49 | /* The Cancel button text to display, or NULL. */ |
| 50 | char *cancel; |
| 51 | /* The buffer to store the secret into. */ |
| 52 | char *pin; |
| 53 | /* The length of the buffer. */ |
| 54 | int pin_len; |
| 55 | |
| 56 | /* The name of the X display to use if X is available and supported. */ |
| 57 | char *display; |
| 58 | /* The name of the terminal node to open if X not available or supported. */ |
| 59 | char *ttyname; |
| 60 | /* The type of the terminal. */ |
| 61 | char *ttytype; |
| 62 | /* The LC_CTYPE value for the terminal. */ |
| 63 | char *lc_ctype; |
| 64 | /* The LC_MESSAGES value for the terminal. */ |
| 65 | char *lc_messages; |
| 66 | |
| 67 | /* True if debug mode is requested. */ |
| 68 | int debug; |
| 69 | /* True if enhanced mode is requested. */ |
| 70 | int enhanced; |
| 71 | /* True if caller should grab the keyboard. */ |
| 72 | int grab; |
| 73 | /* The window ID of the parent window over which the pinentry window |
| 74 | should be displayed. */ |
| 75 | int parent_wid; |
| 76 | |
| 77 | /* The name of an optional file which will be touched after a curses |
| 78 | entry has been displayed. */ |
| 79 | char *touch_file; |
| 80 | |
| 81 | /* The user should set this to -1 if the user canceled the request, |
| 82 | and to the length of the PIN stored in pin otherwise. */ |
| 83 | int result; |
| 84 | |
| 85 | /* The user should set this to true if an error with the local |
| 86 | conversion occured. */ |
| 87 | int locale_err; |
| 88 | |
| 89 | /* The caller should set this to true if only one button is |
| 90 | required. This is useful for notification dialogs where only a |
| 91 | dismiss button is required. */ |
| 92 | int one_button; |
| 93 | |
| 94 | /* If this is not NULL, a passphrase quality indicator is shown. |
| 95 | There will also be an inquiry back to the caller to get an |
| 96 | indication of the quality for the passphrase entered so far. The |
| 97 | string is used as a labe for the auality bar. */ |
| 98 | char *quality_bar; |
| 99 | |
| 100 | /* The tooltip to be show for the qualitybar. Malloced or NULL. */ |
| 101 | char *quality_bar_tt; |
| 102 | |
| 103 | /* For the curses pinentry, the color of error messages. */ |
| 104 | pinentry_color_t color_fg; |
| 105 | int color_fg_bright; |
| 106 | pinentry_color_t color_bg; |
| 107 | pinentry_color_t color_so; |
| 108 | int color_so_bright; |
| 109 | |
| 110 | /* Fo the quality indicator we need to do an inquiry. Thus we need |
| 111 | to save the assuan ctx. */ |
| 112 | void *ctx_assuan; |
| 113 | }; |
| 114 | typedef struct pinentry *pinentry_t; |
| 115 | |
| 116 | |
| 117 | /* The pinentry command handler type processes the pinentry request |
| 118 | PIN. If PIN->pin is zero, request a confirmation, otherwise a PIN |
| 119 | entry. On confirmation, the function should return TRUE if |
| 120 | confirmed, and FALSE otherwise. On PIN entry, the function should |
| 121 | return -1 if cancelled and the length of the secret otherwise. */ |
| 122 | typedef int (*pinentry_cmd_handler_t) (pinentry_t pin); |
| 123 | |
| 124 | /* Start the pinentry event loop. The program will start to process |
| 125 | Assuan commands until it is finished or an error occurs. If an |
| 126 | error occurs, -1 is returned and errno indicates the type of an |
| 127 | error. Otherwise, 0 is returned. */ |
| 128 | int pinentry_loop (void); |
| 129 | |
| 130 | |
| 131 | /* Convert the UTF-8 encoded string TEXT to the encoding given in |
| 132 | LC_CTYPE. Return NULL on error. */ |
| 133 | char *pinentry_utf8_to_local (char *lc_ctype, char *text); |
| 134 | |
| 135 | /* Convert TEXT which is encoded according to LC_CTYPE to UTF-8. With |
| 136 | SECURE set to true, use secure memory for the returned buffer. |
| 137 | Return NULL on error. */ |
| 138 | char *pinentry_local_to_utf8 (char *lc_ctype, char *text, int secure); |
| 139 | |
| 140 | |
| 141 | /* Run a quality inquiry for PASSPHRASE of LENGTH. */ |
| 142 | int pinentry_inq_quality (pinentry_t pin, |
| 143 | const char *passphrase, size_t length); |
| 144 | |
| 145 | /* Try to make room for at least LEN bytes for the pin in the pinentry |
| 146 | PIN. Returns new buffer on success and 0 on failure. */ |
| 147 | char *pinentry_setbufferlen (pinentry_t pin, int len); |
| 148 | |
| 149 | /* Initialize the secure memory subsystem, drop privileges and |
| 150 | return. Must be called early. */ |
| 151 | void pinentry_init (const char *pgmname); |
| 152 | |
| 153 | /* Return true if either DISPLAY is set or ARGV contains the string |
| 154 | "--display". */ |
| 155 | int pinentry_have_display (int argc, char **argv); |
| 156 | |
| 157 | /* Parse the command line options. Returns 1 if user should print |
| 158 | version and exit. Can exit the program if only help output is |
| 159 | requested. */ |
| 160 | int pinentry_parse_opts (int argc, char *argv[]); |
| 161 | |
| 162 | |
| 163 | /* The caller must define this variable to process assuan commands. */ |
| 164 | extern pinentry_cmd_handler_t pinentry_cmd_handler; |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | #ifdef HAVE_W32_SYSTEM |
| 171 | /* Windows declares sleep as obsolete, but provides a definition for |
| 172 | _sleep but non for the still existing sleep. */ |
| 173 | #define sleep(a) _sleep ((a)) |
| 174 | #endif /*HAVE_W32_SYSTEM*/ |
| 175 | |
| 176 | |
| 177 | |
| 178 | #if 0 |
| 179 | { |
| 180 | #endif |
| 181 | #ifdef __cplusplus |
| 182 | } |
| 183 | #endif |
| 184 | |
| 185 | #endif /* PINENTRY_H */ |