chiark / gitweb /
Replace use of variable-length-arrays.
[gnupg2.git] / scd / app-common.h
1 /* app-common.h - Common declarations for all card applications
2  * Copyright (C) 2003, 2005, 2008 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 3 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, see <https://www.gnu.org/licenses/>.
18  *
19  * $Id$
20  */
21
22 #ifndef GNUPG_SCD_APP_COMMON_H
23 #define GNUPG_SCD_APP_COMMON_H
24
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
32
33
34 #define APP_CHANGE_FLAG_RESET    1
35 #define APP_CHANGE_FLAG_NULLPIN  2
36
37 /* Bit flags set by the decipher function into R_INFO.  */
38 #define APP_DECIPHER_INFO_NOPAD  1  /* Padding has been removed.  */
39
40
41 struct app_local_s;  /* Defined by all app-*.c.  */
42
43 struct app_ctx_s {
44   /* Number of connections currently using this application context.
45      If this is not 0 the application has been initialized and the
46      function pointers may be used.  Note that for unsupported
47      operations the particular function pointer is set to NULL */
48   unsigned int ref_count;
49
50   /* Used reader slot. */
51   int slot;
52
53   /* If this is used by GnuPG 1.4 we need to know the assuan context
54      in case we need to divert the operation to an already running
55      agent.  This if ASSUAN_CTX is not NULL we take this as indication
56      that all operations are diverted to gpg-agent. */
57 #if GNUPG_MAJOR_VERSION == 1
58   assuan_context_t assuan_ctx;
59 #endif /*GNUPG_MAJOR_VERSION == 1*/
60
61   unsigned char *serialno; /* Serialnumber in raw form, allocated. */
62   size_t serialnolen;      /* Length in octets of serialnumber. */
63   const char *apptype;
64   unsigned int card_version;
65   unsigned int did_chv1:1;
66   unsigned int force_chv1:1;   /* True if the card does not cache CHV1. */
67   unsigned int did_chv2:1;
68   unsigned int did_chv3:1;
69   struct app_local_s *app_local;  /* Local to the application. */
70   struct {
71     void (*deinit) (app_t app);
72     gpg_error_t (*learn_status) (app_t app, ctrl_t ctrl, unsigned int flags);
73     gpg_error_t (*readcert) (app_t app, const char *certid,
74                      unsigned char **cert, size_t *certlen);
75     gpg_error_t (*readkey) (app_t app, int advanced, const char *certid,
76                     unsigned char **pk, size_t *pklen);
77     gpg_error_t (*getattr) (app_t app, ctrl_t ctrl, const char *name);
78     gpg_error_t (*setattr) (app_t app, const char *name,
79                     gpg_error_t (*pincb)(void*, const char *, char **),
80                     void *pincb_arg,
81                     const unsigned char *value, size_t valuelen);
82     gpg_error_t (*sign) (app_t app,
83                  const char *keyidstr, int hashalgo,
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 (*auth) (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 (*decipher) (app_t app, const char *keyidstr,
94                              gpg_error_t (*pincb)(void*, const char *, char **),
95                              void *pincb_arg,
96                              const void *indata, size_t indatalen,
97                              unsigned char **outdata, size_t *outdatalen,
98                              unsigned int *r_info);
99     gpg_error_t (*writecert) (app_t app, ctrl_t ctrl,
100                               const char *certid,
101                               gpg_error_t (*pincb)(void*,const char *,char **),
102                               void *pincb_arg,
103                               const unsigned char *data, size_t datalen);
104     gpg_error_t (*writekey) (app_t app, ctrl_t ctrl,
105                              const char *keyid, unsigned int flags,
106                              gpg_error_t (*pincb)(void*,const char *,char **),
107                              void *pincb_arg,
108                              const unsigned char *pk, size_t pklen);
109     gpg_error_t (*genkey) (app_t app, ctrl_t ctrl,
110                            const char *keynostr, unsigned int flags,
111                            time_t createtime,
112                            gpg_error_t (*pincb)(void*, const char *, char **),
113                            void *pincb_arg);
114     gpg_error_t (*change_pin) (app_t app, ctrl_t ctrl,
115                        const char *chvnostr, unsigned int flags,
116                        gpg_error_t (*pincb)(void*, const char *, char **),
117                        void *pincb_arg);
118     gpg_error_t (*check_pin) (app_t app, const char *keyidstr,
119                       gpg_error_t (*pincb)(void*, const char *, char **),
120                       void *pincb_arg);
121   } fnc;
122
123 };
124
125 #if GNUPG_MAJOR_VERSION == 1
126 gpg_error_t app_select_openpgp (app_t app);
127 gpg_error_t app_get_serial_and_stamp (app_t app, char **serial, time_t *stamp);
128 gpg_error_t app_openpgp_storekey (app_t app, int keyno,
129                           unsigned char *template, size_t template_len,
130                           time_t created_at,
131                           const unsigned char *m, size_t mlen,
132                           const unsigned char *e, size_t elen,
133                           gpg_error_t (*pincb)(void*, const char *, char **),
134                           void *pincb_arg);
135 #else
136 /*-- app-help.c --*/
137 unsigned int app_help_count_bits (const unsigned char *a, size_t len);
138 gpg_error_t app_help_get_keygrip_string (ksba_cert_t cert, char *hexkeygrip);
139 size_t app_help_read_length_of_cert (int slot, int fid, size_t *r_certoff);
140
141
142 /*-- app.c --*/
143 void app_dump_state (void);
144 void application_notify_card_reset (int slot);
145 gpg_error_t check_application_conflict (ctrl_t ctrl, int slot,
146                                         const char *name);
147 gpg_error_t select_application (ctrl_t ctrl, int slot, const char *name,
148                                 app_t *r_app);
149 char *get_supported_applications (void);
150 void release_application (app_t app);
151 gpg_error_t app_munge_serialno (app_t app);
152 gpg_error_t app_get_serial_and_stamp (app_t app, char **serial, time_t *stamp);
153 gpg_error_t app_write_learn_status (app_t app, ctrl_t ctrl,
154                                     unsigned int flags);
155 gpg_error_t app_readcert (app_t app, const char *certid,
156                   unsigned char **cert, size_t *certlen);
157 gpg_error_t app_readkey (app_t app, int advanced, const char *keyid,
158                  unsigned char **pk, size_t *pklen);
159 gpg_error_t app_getattr (app_t app, ctrl_t ctrl, const char *name);
160 gpg_error_t app_setattr (app_t app, const char *name,
161                  gpg_error_t (*pincb)(void*, const char *, char **),
162                  void *pincb_arg,
163                  const unsigned char *value, size_t valuelen);
164 gpg_error_t app_sign (app_t app, const char *keyidstr, int hashalgo,
165               gpg_error_t (*pincb)(void*, const char *, char **),
166               void *pincb_arg,
167               const void *indata, size_t indatalen,
168               unsigned char **outdata, size_t *outdatalen );
169 gpg_error_t app_auth (app_t app, const char *keyidstr,
170                       gpg_error_t (*pincb)(void*, const char *, char **),
171                       void *pincb_arg,
172                       const void *indata, size_t indatalen,
173                       unsigned char **outdata, size_t *outdatalen);
174 gpg_error_t app_decipher (app_t app, const char *keyidstr,
175                           gpg_error_t (*pincb)(void*, const char *, char **),
176                           void *pincb_arg,
177                           const void *indata, size_t indatalen,
178                           unsigned char **outdata, size_t *outdatalen,
179                           unsigned int *r_info);
180 gpg_error_t app_writecert (app_t app, ctrl_t ctrl,
181                            const char *certidstr,
182                            gpg_error_t (*pincb)(void*, const char *, char **),
183                            void *pincb_arg,
184                            const unsigned char *keydata, size_t keydatalen);
185 gpg_error_t app_writekey (app_t app, ctrl_t ctrl,
186                           const char *keyidstr, unsigned int flags,
187                           gpg_error_t (*pincb)(void*, const char *, char **),
188                           void *pincb_arg,
189                           const unsigned char *keydata, size_t keydatalen);
190 gpg_error_t app_genkey (app_t app, ctrl_t ctrl,
191                         const char *keynostr, unsigned int flags,
192                         time_t createtime,
193                         gpg_error_t (*pincb)(void*, const char *, char **),
194                         void *pincb_arg);
195 gpg_error_t app_get_challenge (app_t app, size_t nbytes,
196                                unsigned char *buffer);
197 gpg_error_t app_change_pin (app_t app, ctrl_t ctrl,
198                     const char *chvnostr, int reset_mode,
199                     gpg_error_t (*pincb)(void*, const char *, char **),
200                     void *pincb_arg);
201 gpg_error_t app_check_pin (app_t app, const char *keyidstr,
202                    gpg_error_t (*pincb)(void*, const char *, char **),
203                    void *pincb_arg);
204
205
206 /*-- app-openpgp.c --*/
207 gpg_error_t app_select_openpgp (app_t app);
208
209 /*-- app-nks.c --*/
210 gpg_error_t app_select_nks (app_t app);
211
212 /*-- app-dinsig.c --*/
213 gpg_error_t app_select_dinsig (app_t app);
214
215 /*-- app-p15.c --*/
216 gpg_error_t app_select_p15 (app_t app);
217
218 /*-- app-geldkarte.c --*/
219 gpg_error_t app_select_geldkarte (app_t app);
220
221 /*-- app-sc-hsm.c --*/
222 gpg_error_t app_select_sc_hsm (app_t app);
223
224
225 #endif
226
227
228
229 #endif /*GNUPG_SCD_APP_COMMON_H*/