Updated the german translation
[gnupg.git] / agent / agent.h
blobc7d8e02dd105d421336e90c426a1b8dcad242d06
1 /* agent.h - Global definitions for the agent
2 * Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef AGENT_H
21 #define AGENT_H
23 #ifdef GPG_ERR_SOURCE_DEFAULT
24 #error GPG_ERR_SOURCE_DEFAULT already defined
25 #endif
26 #define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_GPGAGENT
27 #include <gpg-error.h>
28 #define map_assuan_err(a) \
29 map_assuan_err_with_source (GPG_ERR_SOURCE_DEFAULT, (a))
30 #include <errno.h>
32 #include <gcrypt.h>
33 #include "../common/util.h"
34 #include "../common/membuf.h"
35 #include "../common/sysutils.h" /* (gnupg_fd_t) */
36 #include "../common/session-env.h"
38 /* To convey some special hash algorithms we use algorithm numbers
39 reserved for application use. */
40 #ifndef GCRY_MODULE_ID_USER
41 #define GCRY_MODULE_ID_USER 1024
42 #endif
43 #define MD_USER_TLS_MD5SHA1 (GCRY_MODULE_ID_USER+1)
45 /* Maximum length of a digest. */
46 #define MAX_DIGEST_LEN 64
48 /* A large struct name "opt" to keep global flags */
49 struct
51 unsigned int debug; /* Debug flags (DBG_foo_VALUE) */
52 int verbose; /* Verbosity level */
53 int quiet; /* Be as quiet as possible */
54 int dry_run; /* Don't change any persistent data */
55 int batch; /* Batch mode */
56 const char *homedir; /* Configuration directory name */
58 /* Environment setting gathered at program start or changed using the
59 Assuan command UPDATESTARTUPTTY. */
60 session_env_t startup_env;
61 char *startup_lc_ctype;
62 char *startup_lc_messages;
65 const char *pinentry_program; /* Filename of the program to start as
66 pinentry. */
67 const char *scdaemon_program; /* Filename of the program to handle
68 smartcard tasks. */
69 int disable_scdaemon; /* Never use the SCdaemon. */
70 int no_grab; /* Don't let the pinentry grab the keyboard */
72 /* The name of the file pinentry shall tocuh before exiting. If
73 this is not set the filoe name of the standard socket is used. */
74 const char *pinentry_touch_file;
76 /* The default and maximum TTL of cache entries. */
77 unsigned long def_cache_ttl; /* Default. */
78 unsigned long def_cache_ttl_ssh; /* for SSH. */
79 unsigned long max_cache_ttl; /* Default. */
80 unsigned long max_cache_ttl_ssh; /* for SSH. */
82 /* Flag disallowing bypassing of the warning. */
83 int enforce_passphrase_constraints;
84 /* The require minmum length of a passphrase. */
85 unsigned int min_passphrase_len;
86 /* The minimum number of non-alpha characters in a passphrase. */
87 unsigned int min_passphrase_nonalpha;
88 /* File name with a patternfile or NULL if not enabled. */
89 const char *check_passphrase_pattern;
90 /* If not 0 the user is asked to change his passphrase after these
91 number of days. */
92 unsigned int max_passphrase_days;
93 /* If set, a passphrase history will be written and checked at each
94 passphrase change. */
95 int enable_passhrase_history;
97 int running_detached; /* We are running detached from the tty. */
99 int ignore_cache_for_signing;
100 int allow_mark_trusted;
101 int allow_preset_passphrase;
102 int keep_tty; /* Don't switch the TTY (for pinentry) on request */
103 int keep_display; /* Don't switch the DISPLAY (for pinentry) on request */
104 int ssh_support; /* Enable ssh-agent emulation. */
105 } opt;
108 #define DBG_COMMAND_VALUE 1 /* debug commands i/o */
109 #define DBG_MPI_VALUE 2 /* debug mpi details */
110 #define DBG_CRYPTO_VALUE 4 /* debug low level crypto */
111 #define DBG_MEMORY_VALUE 32 /* debug memory allocation stuff */
112 #define DBG_CACHE_VALUE 64 /* debug the caching */
113 #define DBG_MEMSTAT_VALUE 128 /* show memory statistics */
114 #define DBG_HASHING_VALUE 512 /* debug hashing operations */
115 #define DBG_ASSUAN_VALUE 1024
117 #define DBG_COMMAND (opt.debug & DBG_COMMAND_VALUE)
118 #define DBG_CRYPTO (opt.debug & DBG_CRYPTO_VALUE)
119 #define DBG_MEMORY (opt.debug & DBG_MEMORY_VALUE)
120 #define DBG_CACHE (opt.debug & DBG_CACHE_VALUE)
121 #define DBG_HASHING (opt.debug & DBG_HASHING_VALUE)
122 #define DBG_ASSUAN (opt.debug & DBG_ASSUAN_VALUE)
124 struct server_local_s;
125 struct scd_local_s;
127 /* Collection of data per session (aka connection). */
128 struct server_control_s
130 /* Private data used to fire up the connection thread. We use this
131 structure do avoid an extra allocation for just a few bytes. */
132 struct {
133 gnupg_fd_t fd;
134 } thread_startup;
136 /* Private data of the server (command.c). */
137 struct server_local_s *server_local;
139 /* Private data of the SCdaemon (call-scd.c). */
140 struct scd_local_s *scd_local;
142 session_env_t session_env;
143 char *lc_ctype;
144 char *lc_messages;
146 struct {
147 int algo;
148 unsigned char value[MAX_DIGEST_LEN];
149 int valuelen;
150 int raw_value: 1;
151 } digest;
152 unsigned char keygrip[20];
153 int have_keygrip;
155 int use_auth_call; /* Hack to send the PKAUTH command instead of the
156 PKSIGN command to the scdaemon. */
157 int in_passwd; /* Hack to inhibit enforced passphrase change
158 during an explicit passwd command. */
162 struct pin_entry_info_s
164 int min_digits; /* min. number of digits required or 0 for freeform entry */
165 int max_digits; /* max. number of allowed digits allowed*/
166 int max_tries;
167 int failed_tries;
168 int with_qualitybar; /* Set if the quality bar should be displayed. */
169 int (*check_cb)(struct pin_entry_info_s *); /* CB used to check the PIN */
170 void *check_cb_arg; /* optional argument which might be of use in the CB */
171 const char *cb_errtext; /* used by the cb to displaye a specific error */
172 size_t max_length; /* allocated length of the buffer */
173 char pin[1];
177 enum
179 PRIVATE_KEY_UNKNOWN = 0,
180 PRIVATE_KEY_CLEAR = 1,
181 PRIVATE_KEY_PROTECTED = 2,
182 PRIVATE_KEY_SHADOWED = 3
186 /* Values for the cache_mode arguments. */
187 typedef enum
189 CACHE_MODE_IGNORE = 0, /* Special mode to bypass the cache. */
190 CACHE_MODE_ANY, /* Any mode except ignore matches. */
191 CACHE_MODE_NORMAL, /* Normal cache (gpg-agent). */
192 CACHE_MODE_USER, /* GET_PASSPHRASE related cache. */
193 CACHE_MODE_SSH /* SSH related cache. */
195 cache_mode_t;
198 /* The type of a function to lookup a TTL by a keygrip. */
199 typedef int (*lookup_ttl_t)(const char *hexgrip);
202 /*-- gpg-agent.c --*/
203 void agent_exit (int rc) JNLIB_GCC_A_NR; /* Also implemented in other tools */
204 const char *get_agent_socket_name (void);
205 const char *get_agent_ssh_socket_name (void);
206 #ifdef HAVE_W32_SYSTEM
207 void *get_agent_scd_notify_event (void);
208 #endif
209 void agent_sighup_action (void);
211 /*-- command.c --*/
212 gpg_error_t agent_inq_pinentry_launched (ctrl_t ctrl, unsigned long pid);
213 gpg_error_t agent_write_status (ctrl_t ctrl, const char *keyword, ...)
214 GNUPG_GCC_A_SENTINEL(0);
215 void bump_key_eventcounter (void);
216 void bump_card_eventcounter (void);
217 void start_command_handler (ctrl_t, gnupg_fd_t, gnupg_fd_t);
219 /*-- command-ssh.c --*/
220 void start_command_handler_ssh (ctrl_t, gnupg_fd_t);
222 /*-- findkey.c --*/
223 int agent_write_private_key (const unsigned char *grip,
224 const void *buffer, size_t length, int force);
225 gpg_error_t agent_key_from_file (ctrl_t ctrl,
226 const char *desc_text,
227 const unsigned char *grip,
228 unsigned char **shadow_info,
229 cache_mode_t cache_mode,
230 lookup_ttl_t lookup_ttl,
231 gcry_sexp_t *result);
232 gpg_error_t agent_public_key_from_file (ctrl_t ctrl,
233 const unsigned char *grip,
234 gcry_sexp_t *result);
235 int agent_key_available (const unsigned char *grip);
236 gpg_error_t agent_key_info_from_file (ctrl_t ctrl, const unsigned char *grip,
237 int *r_keytype,
238 unsigned char **r_shadow_info);
240 /*-- call-pinentry.c --*/
241 void initialize_module_call_pinentry (void);
242 void agent_query_dump_state (void);
243 void agent_reset_query (ctrl_t ctrl);
244 int pinentry_active_p (ctrl_t ctrl, int waitseconds);
245 int agent_askpin (ctrl_t ctrl,
246 const char *desc_text, const char *prompt_text,
247 const char *inital_errtext,
248 struct pin_entry_info_s *pininfo);
249 int agent_get_passphrase (ctrl_t ctrl, char **retpass,
250 const char *desc, const char *prompt,
251 const char *errtext, int with_qualitybar);
252 int agent_get_confirmation (ctrl_t ctrl, const char *desc, const char *ok,
253 const char *notokay, int with_cancel);
254 int agent_show_message (ctrl_t ctrl, const char *desc, const char *ok_btn);
255 int agent_popup_message_start (ctrl_t ctrl,
256 const char *desc, const char *ok_btn);
257 void agent_popup_message_stop (ctrl_t ctrl);
260 /*-- cache.c --*/
261 void agent_flush_cache (void);
262 int agent_put_cache (const char *key, cache_mode_t cache_mode,
263 const char *data, int ttl);
264 const char *agent_get_cache (const char *key, cache_mode_t cache_mode,
265 void **cache_id);
266 void agent_unlock_cache_entry (void **cache_id);
269 /*-- pksign.c --*/
270 int agent_pksign_do (ctrl_t ctrl, const char *desc_text,
271 gcry_sexp_t *signature_sexp,
272 cache_mode_t cache_mode, lookup_ttl_t lookup_ttl);
273 int agent_pksign (ctrl_t ctrl, const char *desc_text,
274 membuf_t *outbuf, cache_mode_t cache_mode);
276 /*-- pkdecrypt.c --*/
277 int agent_pkdecrypt (ctrl_t ctrl, const char *desc_text,
278 const unsigned char *ciphertext, size_t ciphertextlen,
279 membuf_t *outbuf);
281 /*-- genkey.c --*/
282 int check_passphrase_constraints (ctrl_t ctrl, const char *pw, int silent);
283 int agent_genkey (ctrl_t ctrl,
284 const char *keyparam, size_t keyparmlen, membuf_t *outbuf);
285 int agent_protect_and_store (ctrl_t ctrl, gcry_sexp_t s_skey);
287 /*-- protect.c --*/
288 int agent_protect (const unsigned char *plainkey, const char *passphrase,
289 unsigned char **result, size_t *resultlen);
290 int agent_unprotect (const unsigned char *protectedkey, const char *passphrase,
291 gnupg_isotime_t protected_at,
292 unsigned char **result, size_t *resultlen);
293 int agent_private_key_type (const unsigned char *privatekey);
294 unsigned char *make_shadow_info (const char *serialno, const char *idstring);
295 int agent_shadow_key (const unsigned char *pubkey,
296 const unsigned char *shadow_info,
297 unsigned char **result);
298 int agent_get_shadow_info (const unsigned char *shadowkey,
299 unsigned char const **shadow_info);
300 gpg_error_t parse_shadow_info (const unsigned char *shadow_info,
301 char **r_hexsn, char **r_idstr);
304 /*-- trustlist.c --*/
305 void initialize_module_trustlist (void);
306 gpg_error_t agent_istrusted (ctrl_t ctrl, const char *fpr, int *r_disabled);
307 gpg_error_t agent_listtrusted (void *assuan_context);
308 gpg_error_t agent_marktrusted (ctrl_t ctrl, const char *name,
309 const char *fpr, int flag);
310 void agent_reload_trustlist (void);
313 /*-- divert-scd.c --*/
314 int divert_pksign (ctrl_t ctrl,
315 const unsigned char *digest, size_t digestlen, int algo,
316 const unsigned char *shadow_info, unsigned char **r_sig);
317 int divert_pkdecrypt (ctrl_t ctrl,
318 const unsigned char *cipher,
319 const unsigned char *shadow_info,
320 char **r_buf, size_t *r_len);
321 int divert_generic_cmd (ctrl_t ctrl,
322 const char *cmdline, void *assuan_context);
325 /*-- call-scd.c --*/
326 void initialize_module_call_scd (void);
327 void agent_scd_dump_state (void);
328 int agent_scd_check_running (void);
329 void agent_scd_check_aliveness (void);
330 int agent_reset_scd (ctrl_t ctrl);
331 int agent_card_learn (ctrl_t ctrl,
332 void (*kpinfo_cb)(void*, const char *),
333 void *kpinfo_cb_arg,
334 void (*certinfo_cb)(void*, const char *),
335 void *certinfo_cb_arg,
336 void (*sinfo_cb)(void*, const char *,
337 size_t, const char *),
338 void *sinfo_cb_arg);
339 int agent_card_serialno (ctrl_t ctrl, char **r_serialno);
340 int agent_card_pksign (ctrl_t ctrl,
341 const char *keyid,
342 int (*getpin_cb)(void *, const char *, char*, size_t),
343 void *getpin_cb_arg,
344 const unsigned char *indata, size_t indatalen,
345 unsigned char **r_buf, size_t *r_buflen);
346 int agent_card_pkdecrypt (ctrl_t ctrl,
347 const char *keyid,
348 int (*getpin_cb)(void *, const char *, char*,size_t),
349 void *getpin_cb_arg,
350 const unsigned char *indata, size_t indatalen,
351 char **r_buf, size_t *r_buflen);
352 int agent_card_readcert (ctrl_t ctrl,
353 const char *id, char **r_buf, size_t *r_buflen);
354 int agent_card_readkey (ctrl_t ctrl, const char *id, unsigned char **r_buf);
355 gpg_error_t agent_card_getattr (ctrl_t ctrl, const char *name, char **result);
356 int agent_card_scd (ctrl_t ctrl, const char *cmdline,
357 int (*getpin_cb)(void *, const char *, char*, size_t),
358 void *getpin_cb_arg, void *assuan_context);
361 /*-- learncard.c --*/
362 int agent_handle_learn (ctrl_t ctrl, void *assuan_context);
365 #endif /*AGENT_H*/