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 2 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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
24 #ifdef GPG_ERR_SOURCE_DEFAULT
25 #error GPG_ERR_SOURCE_DEFAULT already defined
27 #define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_GPGAGENT
28 #include <gpg-error.h>
29 #define map_assuan_err(a) \
30 map_assuan_err_with_source (GPG_ERR_SOURCE_DEFAULT, (a))
34 #include "../common/util.h"
35 #include "../common/errors.h"
38 /* Convenience function to be used instead of returning the old
40 static __inline__ gpg_error_t
43 return gpg_error (gpg_err_code_from_errno (errno));
46 #define MAX_DIGEST_LEN 24
48 /* A large struct name "opt" to keep global flags */
50 unsigned int debug; /* Debug flags (DBG_foo_VALUE) */
51 int verbose; /* Verbosity level */
52 int quiet; /* Be as quiet as possible */
53 int dry_run; /* Don't change any persistent data */
54 int batch; /* Batch mode */
55 const char *homedir; /* Configuration directory name */
57 /* Environment setting gathred at program start. */
58 const char *startup_display;
59 const char *startup_ttyname;
60 const char *startup_ttytype;
61 const char *startup_lc_ctype;
62 const char *startup_lc_messages;
65 const char *pinentry_program; /* Filename of the program to start as
67 const char *scdaemon_program; /* Filename of the program to handle
69 int disable_scdaemon; /* Never use the SCdaemon. */
70 int no_grab; /* Don't let the pinentry grab the keyboard */
71 unsigned long def_cache_ttl;
72 unsigned long max_cache_ttl;
74 int running_detached; /* We are running detached from the tty. */
76 int ignore_cache_for_signing;
77 int allow_mark_trusted;
78 int allow_preset_passphrase;
79 int keep_tty; /* Don't switch the TTY (for pinentry) on request */
80 int keep_display; /* Don't switch the DISPLAY (for pinentry) on request */
81 int ssh_support; /* Enable ssh-agent emulation. */
85 #define DBG_COMMAND_VALUE 1 /* debug commands i/o */
86 #define DBG_MPI_VALUE 2 /* debug mpi details */
87 #define DBG_CRYPTO_VALUE 4 /* debug low level crypto */
88 #define DBG_MEMORY_VALUE 32 /* debug memory allocation stuff */
89 #define DBG_CACHE_VALUE 64 /* debug the caching */
90 #define DBG_MEMSTAT_VALUE 128 /* show memory statistics */
91 #define DBG_HASHING_VALUE 512 /* debug hashing operations */
92 #define DBG_ASSUAN_VALUE 1024
94 #define DBG_COMMAND (opt.debug & DBG_COMMAND_VALUE)
95 #define DBG_CRYPTO (opt.debug & DBG_CRYPTO_VALUE)
96 #define DBG_MEMORY (opt.debug & DBG_MEMORY_VALUE)
97 #define DBG_CACHE (opt.debug & DBG_CACHE_VALUE)
98 #define DBG_HASHING (opt.debug & DBG_HASHING_VALUE)
99 #define DBG_ASSUAN (opt.debug & DBG_ASSUAN_VALUE)
101 struct server_local_s;
104 /* Collection of data per session (aka connection). */
105 struct server_control_s {
107 /* Private data of the server (command.c). */
108 struct server_local_s *server_local;
110 /* Private data of the SCdaemon (call-scd.c). */
111 struct scd_local_s *scd_local;
113 int connection_fd; /* -1 or an identifier for the current connection. */
122 unsigned char value[MAX_DIGEST_LEN];
129 int use_auth_call; /* Hack to send the PKAUTH command instead of the
130 PKSIGN command tro scdaemon. */
132 typedef struct server_control_s *CTRL;
133 typedef struct server_control_s *ctrl_t;
136 struct pin_entry_info_s {
137 int min_digits; /* min. number of digits required or 0 for freeform entry */
138 int max_digits; /* max. number of allowed digits allowed*/
141 int (*check_cb)(struct pin_entry_info_s *); /* CB used to check the PIN */
142 void *check_cb_arg; /* optional argument which might be of use in the CB */
143 const char *cb_errtext; /* used by the cb to displaye a specific error */
144 size_t max_length; /* allocated length of the buffer */
150 PRIVATE_KEY_UNKNOWN = 0,
151 PRIVATE_KEY_CLEAR = 1,
152 PRIVATE_KEY_PROTECTED = 2,
153 PRIVATE_KEY_SHADOWED = 3
156 /*-- gpg-agent.c --*/
157 void agent_exit (int rc) JNLIB_GCC_A_NR; /* Also implemented in other tools */
158 void agent_init_default_ctrl (struct server_control_s *ctrl);
161 void start_command_handler (int, int);
163 /*-- command-ssh.c --*/
164 void start_command_handler_ssh (int);
167 int agent_write_private_key (const unsigned char *grip,
168 const void *buffer, size_t length, int force);
169 gpg_error_t agent_key_from_file (ctrl_t ctrl,
170 const char *desc_text,
171 const unsigned char *grip,
172 unsigned char **shadow_info,
173 int ignore_cache, gcry_sexp_t *result);
174 gpg_error_t agent_public_key_from_file (ctrl_t ctrl,
175 const unsigned char *grip,
176 gcry_sexp_t *result);
177 int agent_key_available (const unsigned char *grip);
180 void initialize_module_query (void);
181 int agent_askpin (ctrl_t ctrl,
182 const char *desc_text, const char *inital_errtext,
183 struct pin_entry_info_s *pininfo);
184 int agent_get_passphrase (ctrl_t ctrl, char **retpass,
185 const char *desc, const char *prompt,
186 const char *errtext);
187 int agent_get_confirmation (ctrl_t ctrl, const char *desc, const char *ok,
191 void agent_flush_cache (void);
192 int agent_put_cache (const char *key, const char *data, int ttl);
193 const char *agent_get_cache (const char *key, void **cache_id);
194 void agent_unlock_cache_entry (void **cache_id);
198 int agent_pksign_do (CTRL ctrl, const char *desc_text,
199 gcry_sexp_t *signature_sexp, int ignore_cache);
200 int agent_pksign (ctrl_t ctrl, const char *desc_text,
201 membuf_t *outbuf, int ignore_cache);
203 /*-- pkdecrypt.c --*/
204 int agent_pkdecrypt (ctrl_t ctrl, const char *desc_text,
205 const unsigned char *ciphertext, size_t ciphertextlen,
209 int agent_genkey (ctrl_t ctrl,
210 const char *keyparam, size_t keyparmlen, membuf_t *outbuf);
211 int agent_protect_and_store (ctrl_t ctrl, gcry_sexp_t s_skey);
214 int agent_protect (const unsigned char *plainkey, const char *passphrase,
215 unsigned char **result, size_t *resultlen);
216 int agent_unprotect (const unsigned char *protectedkey, const char *passphrase,
217 unsigned char **result, size_t *resultlen);
218 int agent_private_key_type (const unsigned char *privatekey);
219 unsigned char *make_shadow_info (const char *serialno, const char *idstring);
220 int agent_shadow_key (const unsigned char *pubkey,
221 const unsigned char *shadow_info,
222 unsigned char **result);
223 int agent_get_shadow_info (const unsigned char *shadowkey,
224 unsigned char const **shadow_info);
227 /*-- trustlist.c --*/
228 int agent_istrusted (const char *fpr);
229 int agent_listtrusted (void *assuan_context);
230 int agent_marktrusted (ctrl_t ctrl, const char *name,
231 const char *fpr, int flag);
232 void agent_trustlist_housekeeping (void);
233 void agent_reload_trustlist (void);
236 /*-- divert-scd.c --*/
237 int divert_pksign (ctrl_t ctrl,
238 const unsigned char *digest, size_t digestlen, int algo,
239 const unsigned char *shadow_info, unsigned char **r_sig);
240 int divert_pkdecrypt (ctrl_t ctrl,
241 const unsigned char *cipher,
242 const unsigned char *shadow_info,
243 char **r_buf, size_t *r_len);
244 int divert_generic_cmd (ctrl_t ctrl,
245 const char *cmdline, void *assuan_context);
249 void initialize_module_call_scd (void);
250 int agent_reset_scd (ctrl_t ctrl);
251 int agent_card_learn (ctrl_t ctrl,
252 void (*kpinfo_cb)(void*, const char *),
254 void (*certinfo_cb)(void*, const char *),
255 void *certinfo_cb_arg,
256 void (*sinfo_cb)(void*, const char *,
257 size_t, const char *),
259 int agent_card_serialno (ctrl_t ctrl, char **r_serialno);
260 int agent_card_pksign (ctrl_t ctrl,
262 int (*getpin_cb)(void *, const char *, char*, size_t),
264 const unsigned char *indata, size_t indatalen,
265 char **r_buf, size_t *r_buflen);
266 int agent_card_pkdecrypt (ctrl_t ctrl,
268 int (*getpin_cb)(void *, const char *, char*,size_t),
270 const unsigned char *indata, size_t indatalen,
271 char **r_buf, size_t *r_buflen);
272 int agent_card_readcert (ctrl_t ctrl,
273 const char *id, char **r_buf, size_t *r_buflen);
274 int agent_card_readkey (ctrl_t ctrl, const char *id, unsigned char **r_buf);
275 gpg_error_t agent_card_getattr (ctrl_t ctrl, const char *name, char **result);
276 int agent_card_scd (ctrl_t ctrl, const char *cmdline,
277 int (*getpin_cb)(void *, const char *, char*, size_t),
278 void *getpin_cb_arg, void *assuan_context);
281 /*-- learncard.c --*/
282 int agent_handle_learn (ctrl_t ctrl, void *assuan_context);