~ubuntu-branches/ubuntu/jaunty/gnupg2/jaunty

« back to all changes in this revision

Viewing changes to agent/agent.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Mueller
  • Date: 2005-03-29 10:30:32 UTC
  • Revision ID: james.westby@ubuntu.com-20050329103032-sj42n2ain3ipx310
Tags: upstream-1.9.15
ImportĀ upstreamĀ versionĀ 1.9.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* agent.h - Global definitions for the agent
 
2
 *      Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
 
3
 *
 
4
 * This file is part of GnuPG.
 
5
 *
 
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.
 
10
 *
 
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.
 
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
19
 */
 
20
 
 
21
#ifndef AGENT_H
 
22
#define AGENT_H
 
23
 
 
24
#ifdef GPG_ERR_SOURCE_DEFAULT
 
25
#error GPG_ERR_SOURCE_DEFAULT already defined
 
26
#endif
 
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))
 
31
#include <errno.h>
 
32
 
 
33
#include <gcrypt.h>
 
34
#include "../common/util.h"
 
35
#include "../common/errors.h"
 
36
#include "membuf.h"
 
37
 
 
38
/* Convenience function to be used instead of returning the old
 
39
   GNUPG_Out_Of_Core. */
 
40
static __inline__ gpg_error_t
 
41
out_of_core (void)
 
42
{
 
43
  return gpg_error (gpg_err_code_from_errno (errno));
 
44
}
 
45
 
 
46
#define MAX_DIGEST_LEN 24 
 
47
 
 
48
/* A large struct name "opt" to keep global flags */
 
49
struct {
 
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 */
 
56
  const char *pinentry_program; 
 
57
  const char *scdaemon_program; 
 
58
  int no_grab;      /* don't let the pinentry grab the keyboard */
 
59
  unsigned long def_cache_ttl;
 
60
  unsigned long max_cache_ttl;
 
61
 
 
62
  int running_detached; /* we are running detached from the tty. */
 
63
 
 
64
  int ignore_cache_for_signing;
 
65
  int allow_mark_trusted;
 
66
  int allow_preset_passphrase;
 
67
  int keep_tty;  /* don't switch the TTY (for pinentry) on request */
 
68
  int keep_display;  /* don't switch the DISPLAY (for pinentry) on request */
 
69
} opt;
 
70
 
 
71
 
 
72
#define DBG_COMMAND_VALUE 1     /* debug commands i/o */
 
73
#define DBG_MPI_VALUE     2     /* debug mpi details */
 
74
#define DBG_CRYPTO_VALUE  4     /* debug low level crypto */
 
75
#define DBG_MEMORY_VALUE  32    /* debug memory allocation stuff */
 
76
#define DBG_CACHE_VALUE   64    /* debug the caching */
 
77
#define DBG_MEMSTAT_VALUE 128   /* show memory statistics */
 
78
#define DBG_HASHING_VALUE 512   /* debug hashing operations */
 
79
#define DBG_ASSUAN_VALUE 1024   
 
80
 
 
81
#define DBG_COMMAND (opt.debug & DBG_COMMAND_VALUE)
 
82
#define DBG_CRYPTO  (opt.debug & DBG_CRYPTO_VALUE)
 
83
#define DBG_MEMORY  (opt.debug & DBG_MEMORY_VALUE)
 
84
#define DBG_CACHE   (opt.debug & DBG_CACHE_VALUE)
 
85
#define DBG_HASHING (opt.debug & DBG_HASHING_VALUE)
 
86
#define DBG_ASSUAN  (opt.debug & DBG_ASSUAN_VALUE)
 
87
 
 
88
struct server_local_s;
 
89
 
 
90
struct server_control_s {
 
91
  struct server_local_s *server_local;
 
92
  int   connection_fd; /* -1 or an identifier for the current connection. */
 
93
  char *display;
 
94
  char *ttyname;
 
95
  char *ttytype;
 
96
  char *lc_ctype;
 
97
  char *lc_messages;
 
98
  struct {
 
99
    int algo;
 
100
    unsigned char value[MAX_DIGEST_LEN];
 
101
    int valuelen;
 
102
    int raw_value: 1;
 
103
  } digest;
 
104
  char keygrip[20];
 
105
  int have_keygrip;
 
106
 
 
107
};
 
108
typedef struct server_control_s *CTRL;
 
109
typedef struct server_control_s *ctrl_t;
 
110
 
 
111
 
 
112
struct pin_entry_info_s {
 
113
  int min_digits; /* min. number of digits required or 0 for freeform entry */
 
114
  int max_digits; /* max. number of allowed digits allowed*/
 
115
  int max_tries;
 
116
  int failed_tries;
 
117
  int (*check_cb)(struct pin_entry_info_s *); /* CB used to check the PIN */
 
118
  void *check_cb_arg;  /* optional argument which might be of use in the CB */
 
119
  const char *cb_errtext; /* used by the cb to displaye a specific error */
 
120
  size_t max_length; /* allocated length of the buffer */
 
121
  char pin[1];
 
122
};
 
123
 
 
124
 
 
125
enum {
 
126
  PRIVATE_KEY_UNKNOWN = 0,
 
127
  PRIVATE_KEY_CLEAR = 1,
 
128
  PRIVATE_KEY_PROTECTED = 2,
 
129
  PRIVATE_KEY_SHADOWED = 3
 
130
};
 
131
 
 
132
/*-- gpg-agent.c --*/
 
133
void agent_exit (int rc); /* also implemented in other tools */
 
134
void agent_init_default_ctrl (struct server_control_s *ctrl);
 
135
 
 
136
/*-- command.c --*/
 
137
void start_command_handler (int, int);
 
138
 
 
139
/*-- findkey.c --*/
 
140
int agent_write_private_key (const unsigned char *grip,
 
141
                             const void *buffer, size_t length, int force);
 
142
gpg_error_t agent_key_from_file (ctrl_t ctrl, 
 
143
                                 const char *desc_text,
 
144
                                 const unsigned char *grip,
 
145
                                 unsigned char **shadow_info,
 
146
                                 int ignore_cache, gcry_sexp_t *result);
 
147
int agent_key_available (const unsigned char *grip);
 
148
 
 
149
/*-- query.c --*/
 
150
void initialize_module_query (void);
 
151
int agent_askpin (ctrl_t ctrl,
 
152
                  const char *desc_text, const char *inital_errtext,
 
153
                  struct pin_entry_info_s *pininfo);
 
154
int agent_get_passphrase (ctrl_t ctrl, char **retpass,
 
155
                          const char *desc, const char *prompt,
 
156
                          const char *errtext);
 
157
int agent_get_confirmation (ctrl_t ctrl, const char *desc, const char *ok,
 
158
                            const char *cancel);
 
159
 
 
160
/*-- cache.c --*/
 
161
void agent_flush_cache (void);
 
162
int agent_put_cache (const char *key, const char *data, int ttl);
 
163
const char *agent_get_cache (const char *key, void **cache_id);
 
164
void agent_unlock_cache_entry (void **cache_id);
 
165
 
 
166
 
 
167
/*-- pksign.c --*/
 
168
int agent_pksign_do (CTRL ctrl, const char *desc_text,
 
169
                     gcry_sexp_t *signature_sexp, int ignore_cache);
 
170
int agent_pksign (ctrl_t ctrl, const char *desc_text,
 
171
                  membuf_t *outbuf, int ignore_cache);
 
172
 
 
173
/*-- pkdecrypt.c --*/
 
174
int agent_pkdecrypt (ctrl_t ctrl, const char *desc_text,
 
175
                     const unsigned char *ciphertext, size_t ciphertextlen,
 
176
                     membuf_t *outbuf);
 
177
 
 
178
/*-- genkey.c --*/
 
179
int agent_genkey (ctrl_t ctrl, 
 
180
                  const char *keyparam, size_t keyparmlen, membuf_t *outbuf);
 
181
int agent_protect_and_store (ctrl_t ctrl, gcry_sexp_t s_skey);
 
182
 
 
183
/*-- protect.c --*/
 
184
int agent_protect (const unsigned char *plainkey, const char *passphrase,
 
185
                   unsigned char **result, size_t *resultlen);
 
186
int agent_unprotect (const unsigned char *protectedkey, const char *passphrase,
 
187
                     unsigned char **result, size_t *resultlen);
 
188
int agent_private_key_type (const unsigned char *privatekey);
 
189
int agent_shadow_key (const unsigned char *pubkey,
 
190
                      const unsigned char *shadow_info,
 
191
                      unsigned char **result);
 
192
int agent_get_shadow_info (const unsigned char *shadowkey,
 
193
                           unsigned char const **shadow_info);
 
194
 
 
195
 
 
196
/*-- trustlist.c --*/
 
197
int agent_istrusted (const char *fpr);
 
198
int agent_listtrusted (void *assuan_context);
 
199
int agent_marktrusted (ctrl_t ctrl, const char *name,
 
200
                       const char *fpr, int flag);
 
201
void agent_trustlist_housekeeping (void);
 
202
void agent_reload_trustlist (void);
 
203
 
 
204
 
 
205
/*-- divert-scd.c --*/
 
206
int divert_pksign (ctrl_t ctrl, 
 
207
                   const unsigned char *digest, size_t digestlen, int algo,
 
208
                   const unsigned char *shadow_info, unsigned char **r_sig);
 
209
int divert_pkdecrypt (ctrl_t ctrl,
 
210
                      const unsigned char *cipher,
 
211
                      const unsigned char *shadow_info,
 
212
                      char **r_buf, size_t *r_len);
 
213
int divert_generic_cmd (ctrl_t ctrl,
 
214
                        const char *cmdline, void *assuan_context);
 
215
 
 
216
 
 
217
/*-- call-scd.c --*/
 
218
void initialize_module_call_scd (void);
 
219
int agent_reset_scd (ctrl_t ctrl);
 
220
int agent_card_learn (ctrl_t ctrl,
 
221
                      void (*kpinfo_cb)(void*, const char *),
 
222
                      void *kpinfo_cb_arg,
 
223
                      void (*certinfo_cb)(void*, const char *),
 
224
                      void *certinfo_cb_arg,
 
225
                      void (*sinfo_cb)(void*, const char *,
 
226
                                       size_t, const char *),
 
227
                      void *sinfo_cb_arg);
 
228
int agent_card_serialno (ctrl_t ctrl, char **r_serialno);
 
229
int agent_card_pksign (ctrl_t ctrl,
 
230
                       const char *keyid,
 
231
                       int (*getpin_cb)(void *, const char *, char*, size_t),
 
232
                       void *getpin_cb_arg,
 
233
                       const unsigned char *indata, size_t indatalen,
 
234
                       char **r_buf, size_t *r_buflen);
 
235
int agent_card_pkdecrypt (ctrl_t ctrl,
 
236
                          const char *keyid,
 
237
                          int (*getpin_cb)(void *, const char *, char*,size_t),
 
238
                          void *getpin_cb_arg,
 
239
                          const unsigned char *indata, size_t indatalen,
 
240
                          char **r_buf, size_t *r_buflen);
 
241
int agent_card_readcert (ctrl_t ctrl,
 
242
                         const char *id, char **r_buf, size_t *r_buflen);
 
243
int agent_card_readkey (ctrl_t ctrl, const char *id, unsigned char **r_buf);
 
244
int agent_card_scd (ctrl_t ctrl, const char *cmdline,
 
245
                    int (*getpin_cb)(void *, const char *, char*, size_t),
 
246
                    void *getpin_cb_arg, void *assuan_context);
 
247
 
 
248
 
 
249
/*-- learncard.c --*/
 
250
int agent_handle_learn (ctrl_t ctrl, void *assuan_context);
 
251
 
 
252
 
 
253
#endif /*AGENT_H*/