2008-02-09 Marcus Brinkmann <marcus@g10code.de>
[gnupg.git] / scd / app-common.h
blob5ddf0c0dc5e8d7ff584ce6acad188437f2d518b1
1 /* app-common.h - Common declarations for all card applications
2 * Copyright (C) 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/>.
19 * $Id$
22 #ifndef GNUPG_SCD_APP_COMMON_H
23 #define GNUPG_SCD_APP_COMMON_H
25 #if GNUPG_MAJOR_VERSION == 1
26 # ifdef ENABLE_AGENT_SUPPORT
27 # include "assuan.h"
28 # endif
29 #else
30 # include <ksba.h>
31 #endif
34 struct app_local_s; /* Defined by all app-*.c. */
36 struct app_ctx_s {
37 int initialized; /* The application has been initialied and the
38 function pointers may be used. Note that for
39 unsupported operations the particular
40 function pointer is set to NULL */
42 int ref_count; /* Number of connections currently using this
43 application context. fixme: We might want to
44 merg this witghn INITIALIZED above. */
46 int slot; /* Used reader. */
48 /* If this is used by GnuPG 1.4 we need to know the assuan context
49 in case we need to divert the operation to an already running
50 agent. This if ASSUAN_CTX is not NULL we take this as indication
51 that all operations are diverted to gpg-agent. */
52 #if GNUPG_MAJOR_VERSION == 1
53 assuan_context_t assuan_ctx;
54 #endif /*GNUPG_MAJOR_VERSION == 1*/
56 unsigned char *serialno; /* Serialnumber in raw form, allocated. */
57 size_t serialnolen; /* Length in octets of serialnumber. */
58 const char *apptype;
59 unsigned int card_version;
60 int did_chv1;
61 int force_chv1; /* True if the card does not cache CHV1. */
62 int did_chv2;
63 int did_chv3;
64 struct app_local_s *app_local; /* Local to the application. */
65 struct {
66 void (*deinit) (app_t app);
67 gpg_error_t (*learn_status) (app_t app, ctrl_t ctrl);
68 gpg_error_t (*readcert) (app_t app, const char *certid,
69 unsigned char **cert, size_t *certlen);
70 gpg_error_t (*readkey) (app_t app, const char *certid,
71 unsigned char **pk, size_t *pklen);
72 gpg_error_t (*getattr) (app_t app, ctrl_t ctrl, const char *name);
73 gpg_error_t (*setattr) (app_t app, const char *name,
74 gpg_error_t (*pincb)(void*, const char *, char **),
75 void *pincb_arg,
76 const unsigned char *value, size_t valuelen);
77 gpg_error_t (*sign) (app_t app,
78 const char *keyidstr, int hashalgo,
79 gpg_error_t (*pincb)(void*, const char *, char **),
80 void *pincb_arg,
81 const void *indata, size_t indatalen,
82 unsigned char **outdata, size_t *outdatalen );
83 gpg_error_t (*auth) (app_t app, const char *keyidstr,
84 gpg_error_t (*pincb)(void*, const char *, char **),
85 void *pincb_arg,
86 const void *indata, size_t indatalen,
87 unsigned char **outdata, size_t *outdatalen);
88 gpg_error_t (*decipher) (app_t app, const char *keyidstr,
89 gpg_error_t (*pincb)(void*, const char *, char **),
90 void *pincb_arg,
91 const void *indata, size_t indatalen,
92 unsigned char **outdata, size_t *outdatalen);
93 gpg_error_t (*writekey) (app_t app, ctrl_t ctrl,
94 const char *certid, unsigned int flags,
95 gpg_error_t (*pincb)(void*,const char *,char **),
96 void *pincb_arg,
97 const unsigned char *pk, size_t pklen);
98 gpg_error_t (*genkey) (app_t app, ctrl_t ctrl,
99 const char *keynostr, unsigned int flags,
100 time_t createtime,
101 gpg_error_t (*pincb)(void*, const char *, char **),
102 void *pincb_arg);
103 gpg_error_t (*change_pin) (app_t app, ctrl_t ctrl,
104 const char *chvnostr, int reset_mode,
105 gpg_error_t (*pincb)(void*, const char *, char **),
106 void *pincb_arg);
107 gpg_error_t (*check_pin) (app_t app, const char *keyidstr,
108 gpg_error_t (*pincb)(void*, const char *, char **),
109 void *pincb_arg);
110 } fnc;
114 #if GNUPG_MAJOR_VERSION == 1
115 gpg_error_t app_select_openpgp (app_t app);
116 gpg_error_t app_get_serial_and_stamp (app_t app, char **serial, time_t *stamp);
117 gpg_error_t app_openpgp_storekey (app_t app, int keyno,
118 unsigned char *template, size_t template_len,
119 time_t created_at,
120 const unsigned char *m, size_t mlen,
121 const unsigned char *e, size_t elen,
122 gpg_error_t (*pincb)(void*, const char *, char **),
123 void *pincb_arg);
124 #else
125 /*-- app-help.c --*/
126 gpg_error_t app_help_get_keygrip_string (ksba_cert_t cert, char *hexkeygrip);
127 size_t app_help_read_length_of_cert (int slot, int fid, size_t *r_certoff);
130 /*-- app.c --*/
131 void app_dump_state (void);
132 void application_notify_card_removed (int slot);
133 gpg_error_t check_application_conflict (ctrl_t ctrl, const char *name);
134 gpg_error_t select_application (ctrl_t ctrl, int slot, const char *name,
135 app_t *r_app);
136 void release_application (app_t app);
137 gpg_error_t app_munge_serialno (app_t app);
138 gpg_error_t app_get_serial_and_stamp (app_t app, char **serial, time_t *stamp);
139 gpg_error_t app_write_learn_status (app_t app, ctrl_t ctrl);
140 gpg_error_t app_readcert (app_t app, const char *certid,
141 unsigned char **cert, size_t *certlen);
142 gpg_error_t app_readkey (app_t app, const char *keyid,
143 unsigned char **pk, size_t *pklen);
144 gpg_error_t app_getattr (app_t app, ctrl_t ctrl, const char *name);
145 gpg_error_t app_setattr (app_t app, const char *name,
146 gpg_error_t (*pincb)(void*, const char *, char **),
147 void *pincb_arg,
148 const unsigned char *value, size_t valuelen);
149 gpg_error_t app_sign (app_t app, const char *keyidstr, int hashalgo,
150 gpg_error_t (*pincb)(void*, const char *, char **),
151 void *pincb_arg,
152 const void *indata, size_t indatalen,
153 unsigned char **outdata, size_t *outdatalen );
154 gpg_error_t app_auth (app_t app, const char *keyidstr,
155 gpg_error_t (*pincb)(void*, const char *, char **),
156 void *pincb_arg,
157 const void *indata, size_t indatalen,
158 unsigned char **outdata, size_t *outdatalen);
159 gpg_error_t app_decipher (app_t app, const char *keyidstr,
160 gpg_error_t (*pincb)(void*, const char *, char **),
161 void *pincb_arg,
162 const void *indata, size_t indatalen,
163 unsigned char **outdata, size_t *outdatalen );
164 gpg_error_t app_writekey (app_t app, ctrl_t ctrl,
165 const char *keyidstr, unsigned int flags,
166 gpg_error_t (*pincb)(void*, const char *, char **),
167 void *pincb_arg,
168 const unsigned char *keydata, size_t keydatalen);
169 gpg_error_t app_genkey (app_t app, ctrl_t ctrl,
170 const char *keynostr, unsigned int flags,
171 time_t createtime,
172 gpg_error_t (*pincb)(void*, const char *, char **),
173 void *pincb_arg);
174 gpg_error_t app_get_challenge (app_t app, size_t nbytes,
175 unsigned char *buffer);
176 gpg_error_t app_change_pin (app_t app, ctrl_t ctrl,
177 const char *chvnostr, int reset_mode,
178 gpg_error_t (*pincb)(void*, const char *, char **),
179 void *pincb_arg);
180 gpg_error_t app_check_pin (app_t app, const char *keyidstr,
181 gpg_error_t (*pincb)(void*, const char *, char **),
182 void *pincb_arg);
185 /*-- app-openpgp.c --*/
186 gpg_error_t app_select_openpgp (app_t app);
188 /*-- app-nks.c --*/
189 gpg_error_t app_select_nks (app_t app);
191 /*-- app-dinsig.c --*/
192 gpg_error_t app_select_dinsig (app_t app);
194 /*-- app-p15.c --*/
195 gpg_error_t app_select_p15 (app_t app);
198 #endif
202 #endif /*GNUPG_SCD_APP_COMMON_H*/