1 /* agent.h - Global definitions for the agent
2 * Copyright (C) 2001 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
25 #include "../common/util.h"
26 #include "../common/errors.h"
28 #define MAX_DIGEST_LEN 24
30 /* A large struct name "opt" to keep global flags */
32 unsigned int debug; /* debug flags (DBG_foo_VALUE) */
33 int verbose; /* verbosity level */
34 int quiet; /* be as quiet as possible */
35 int dry_run; /* don't change any persistent data */
36 int batch; /* batch mode */
37 const char *homedir; /* configuration directory name */
38 const char *pinentry_program;
44 const char *scdaemon_program;
45 int no_grab; /* don't let the pinentry grab the keyboard */
46 unsigned long def_cache_ttl;
48 int running_detached; /* we are running detached from the tty. */
53 #define DBG_COMMAND_VALUE 1 /* debug commands i/o */
54 #define DBG_MPI_VALUE 2 /* debug mpi details */
55 #define DBG_CRYPTO_VALUE 4 /* debug low level crypto */
56 #define DBG_MEMORY_VALUE 32 /* debug memory allocation stuff */
57 #define DBG_CACHE_VALUE 64 /* debug the caching */
58 #define DBG_MEMSTAT_VALUE 128 /* show memory statistics */
59 #define DBG_HASHING_VALUE 512 /* debug hashing operations */
60 #define DBG_ASSUAN_VALUE 1024
62 #define DBG_COMMAND (opt.debug & DBG_COMMAND_VALUE)
63 #define DBG_CRYPTO (opt.debug & DBG_CRYPTO_VALUE)
64 #define DBG_MEMORY (opt.debug & DBG_MEMORY_VALUE)
65 #define DBG_CACHE (opt.debug & DBG_CACHE_VALUE)
66 #define DBG_HASHING (opt.debug & DBG_HASHING_VALUE)
67 #define DBG_ASSUAN (opt.debug & DBG_ASSUAN_VALUE)
69 struct server_local_s;
71 struct server_control_s {
72 struct server_local_s *server_local;
75 unsigned char value[MAX_DIGEST_LEN];
82 typedef struct server_control_s *CTRL;
85 struct pin_entry_info_s {
86 int min_digits; /* min. number of digits required or 0 for freeform entry */
87 int max_digits; /* max. number of allowed digits allowed*/
90 int (*check_cb)(struct pin_entry_info_s *); /* CB used to check the PIN */
91 void *check_cb_arg; /* optional argument which might be of use in the CB */
92 const char *cb_errtext; /* used by the cb to displaye a specific error */
93 size_t max_length; /* allocated length of the buffer */
99 PRIVATE_KEY_UNKNOWN = 0,
100 PRIVATE_KEY_CLEAR = 1,
101 PRIVATE_KEY_PROTECTED = 2,
102 PRIVATE_KEY_SHADOWED = 3
105 /*-- gpg-agent.c --*/
106 void agent_exit (int rc); /* also implemented in other tools */
109 const char *trans (const char *text);
112 void start_command_handler (int, int);
115 int agent_write_private_key (const unsigned char *grip,
116 const void *buffer, size_t length, int force);
117 GCRY_SEXP agent_key_from_file (const unsigned char *grip,
118 unsigned char **shadow_info);
119 int agent_key_available (const unsigned char *grip);
122 int agent_askpin (const char *desc_text, struct pin_entry_info_s *pininfo);
123 int agent_get_passphrase (char **retpass,
124 const char *desc, const char *prompt,
125 const char *errtext);
126 int agent_get_confirmation (const char *desc, const char *ok,
130 int agent_put_cache (const char *key, const char *data, int ttl);
131 const char *agent_get_cache (const char *key, void **cache_id);
132 void agent_unlock_cache_entry (void **cache_id);
136 int agent_pksign (CTRL ctrl, FILE *outfp);
138 /*-- pkdecrypt.c --*/
139 int agent_pkdecrypt (CTRL ctrl, const char *ciphertext, size_t ciphertextlen,
143 int agent_genkey (CTRL ctrl,
144 const char *keyparam, size_t keyparmlen, FILE *outfp);
147 int agent_protect (const unsigned char *plainkey, const char *passphrase,
148 unsigned char **result, size_t *resultlen);
149 int agent_unprotect (const unsigned char *protectedkey, const char *passphrase,
150 unsigned char **result, size_t *resultlen);
151 int agent_private_key_type (const unsigned char *privatekey);
152 int agent_shadow_key (const unsigned char *pubkey,
153 const unsigned char *shadow_info,
154 unsigned char **result);
155 int agent_get_shadow_info (const unsigned char *shadowkey,
156 unsigned char const **shadow_info);
159 /*-- trustlist.c --*/
160 int agent_istrusted (const char *fpr);
161 int agent_listtrusted (void *assuan_context);
162 int agent_marktrusted (const char *name, const char *fpr, int flag);
165 /*-- divert-scd.c --*/
166 int divert_pksign (const unsigned char *digest, size_t digestlen, int algo,
167 const unsigned char *shadow_info, unsigned char **r_sig);
168 int divert_pkdecrypt (const unsigned char *cipher,
169 const unsigned char *shadow_info,
170 char **r_buf, size_t *r_len);
173 int agent_card_learn (void (*kpinfo_cb)(void*, const char *),
174 void *kpinfo_cb_arg);
175 int agent_card_serialno (char **r_serialno);
176 int agent_card_pksign (const char *keyid,
177 int (*getpin_cb)(void *, const char *, char*, size_t),
179 const unsigned char *indata, size_t indatalen,
180 char **r_buf, size_t *r_buflen);
181 int agent_card_pkdecrypt (const char *keyid,
182 int (*getpin_cb)(void *, const char *, char*,size_t),
184 const unsigned char *indata, size_t indatalen,
185 char **r_buf, size_t *r_buflen);
186 int agent_card_readcert (const char *id, char **r_buf, size_t *r_buflen);
187 int agent_card_readkey (const char *id, unsigned char **r_buf);
190 /*-- learncard.c --*/
191 int agent_handle_learn (void *assuan_context);