1 /* app-common.h - Common declarations for all card applications
2 * Copyright (C) 2003, 2005, 2008 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 <https://www.gnu.org/licenses/>.
22 #ifndef GNUPG_SCD_APP_COMMON_H
23 #define GNUPG_SCD_APP_COMMON_H
29 #define APP_CHANGE_FLAG_RESET 1
30 #define APP_CHANGE_FLAG_NULLPIN 2
32 /* Bit flags set by the decipher function into R_INFO. */
33 #define APP_DECIPHER_INFO_NOPAD 1 /* Padding has been removed. */
36 struct app_local_s; /* Defined by all app-*.c. */
39 struct app_ctx_s *next;
43 /* Number of connections currently using this application context.
44 If this is not 0 the application has been initialized and the
45 function pointers may be used. Note that for unsupported
46 operations the particular function pointer is set to NULL */
47 unsigned int ref_count;
49 /* Used reader slot. */
52 unsigned char *serialno; /* Serialnumber in raw form, allocated. */
53 size_t serialnolen; /* Length in octets of serialnumber. */
55 unsigned int card_version;
56 unsigned int card_status;
57 unsigned int require_get_status:1;
58 unsigned int did_chv1:1;
59 unsigned int force_chv1:1; /* True if the card does not cache CHV1. */
60 unsigned int did_chv2:1;
61 unsigned int did_chv3:1;
62 struct app_local_s *app_local; /* Local to the application. */
64 void (*deinit) (app_t app);
65 gpg_error_t (*learn_status) (app_t app, ctrl_t ctrl, unsigned int flags);
66 gpg_error_t (*readcert) (app_t app, const char *certid,
67 unsigned char **cert, size_t *certlen);
68 gpg_error_t (*readkey) (app_t app, int advanced, const char *certid,
69 unsigned char **pk, size_t *pklen);
70 gpg_error_t (*getattr) (app_t app, ctrl_t ctrl, const char *name);
71 gpg_error_t (*setattr) (app_t app, const char *name,
72 gpg_error_t (*pincb)(void*, const char *, char **),
74 const unsigned char *value, size_t valuelen);
75 gpg_error_t (*sign) (app_t app,
76 const char *keyidstr, int hashalgo,
77 gpg_error_t (*pincb)(void*, const char *, char **),
79 const void *indata, size_t indatalen,
80 unsigned char **outdata, size_t *outdatalen );
81 gpg_error_t (*auth) (app_t app, const char *keyidstr,
82 gpg_error_t (*pincb)(void*, const char *, char **),
84 const void *indata, size_t indatalen,
85 unsigned char **outdata, size_t *outdatalen);
86 gpg_error_t (*decipher) (app_t app, const char *keyidstr,
87 gpg_error_t (*pincb)(void*, const char *, char **),
89 const void *indata, size_t indatalen,
90 unsigned char **outdata, size_t *outdatalen,
91 unsigned int *r_info);
92 gpg_error_t (*writecert) (app_t app, ctrl_t ctrl,
94 gpg_error_t (*pincb)(void*,const char *,char **),
96 const unsigned char *data, size_t datalen);
97 gpg_error_t (*writekey) (app_t app, ctrl_t ctrl,
98 const char *keyid, unsigned int flags,
99 gpg_error_t (*pincb)(void*,const char *,char **),
101 const unsigned char *pk, size_t pklen);
102 gpg_error_t (*genkey) (app_t app, ctrl_t ctrl,
103 const char *keynostr, unsigned int flags,
105 gpg_error_t (*pincb)(void*, const char *, char **),
107 gpg_error_t (*change_pin) (app_t app, ctrl_t ctrl,
108 const char *chvnostr, unsigned int flags,
109 gpg_error_t (*pincb)(void*, const char *, char **),
111 gpg_error_t (*check_pin) (app_t app, const char *keyidstr,
112 gpg_error_t (*pincb)(void*, const char *, char **),
118 unsigned int app_help_count_bits (const unsigned char *a, size_t len);
119 gpg_error_t app_help_get_keygrip_string (ksba_cert_t cert, char *hexkeygrip);
120 size_t app_help_read_length_of_cert (int slot, int fid, size_t *r_certoff);
124 app_t app_list_start (void);
125 void app_list_finish (void);
126 void app_send_card_list (ctrl_t ctrl);
127 char *app_get_serialno (app_t app);
129 void app_dump_state (void);
130 void application_notify_card_reset (int slot);
131 gpg_error_t check_application_conflict (const char *name, app_t app);
132 gpg_error_t app_reset (app_t app, ctrl_t ctrl, int send_reset);
133 gpg_error_t select_application (ctrl_t ctrl, const char *name, app_t *r_app,
134 int scan, const unsigned char *serialno_bin,
135 size_t serialno_bin_len);
136 char *get_supported_applications (void);
137 void release_application (app_t app);
138 gpg_error_t app_munge_serialno (app_t app);
139 gpg_error_t app_write_learn_status (app_t app, ctrl_t ctrl,
141 gpg_error_t app_readcert (app_t app, ctrl_t ctrl, const char *certid,
142 unsigned char **cert, size_t *certlen);
143 gpg_error_t app_readkey (app_t app, ctrl_t ctrl, int advanced,
144 const char *keyid, unsigned char **pk, size_t *pklen);
145 gpg_error_t app_getattr (app_t app, ctrl_t ctrl, const char *name);
146 gpg_error_t app_setattr (app_t app, ctrl_t ctrl, const char *name,
147 gpg_error_t (*pincb)(void*, const char *, char **),
149 const unsigned char *value, size_t valuelen);
150 gpg_error_t app_sign (app_t app, ctrl_t ctrl, const char *keyidstr, int hashalgo,
151 gpg_error_t (*pincb)(void*, const char *, char **),
153 const void *indata, size_t indatalen,
154 unsigned char **outdata, size_t *outdatalen );
155 gpg_error_t app_auth (app_t app, ctrl_t ctrl, const char *keyidstr,
156 gpg_error_t (*pincb)(void*, const char *, char **),
158 const void *indata, size_t indatalen,
159 unsigned char **outdata, size_t *outdatalen);
160 gpg_error_t app_decipher (app_t app, ctrl_t ctrl, const char *keyidstr,
161 gpg_error_t (*pincb)(void*, const char *, char **),
163 const void *indata, size_t indatalen,
164 unsigned char **outdata, size_t *outdatalen,
165 unsigned int *r_info);
166 gpg_error_t app_writecert (app_t app, ctrl_t ctrl,
167 const char *certidstr,
168 gpg_error_t (*pincb)(void*, const char *, char **),
170 const unsigned char *keydata, size_t keydatalen);
171 gpg_error_t app_writekey (app_t app, ctrl_t ctrl,
172 const char *keyidstr, unsigned int flags,
173 gpg_error_t (*pincb)(void*, const char *, char **),
175 const unsigned char *keydata, size_t keydatalen);
176 gpg_error_t app_genkey (app_t app, ctrl_t ctrl,
177 const char *keynostr, unsigned int flags,
179 gpg_error_t (*pincb)(void*, const char *, char **),
181 gpg_error_t app_get_challenge (app_t app, ctrl_t ctrl, size_t nbytes,
182 unsigned char *buffer);
183 gpg_error_t app_change_pin (app_t app, ctrl_t ctrl,
184 const char *chvnostr, int reset_mode,
185 gpg_error_t (*pincb)(void*, const char *, char **),
187 gpg_error_t app_check_pin (app_t app, ctrl_t ctrl, const char *keyidstr,
188 gpg_error_t (*pincb)(void*, const char *, char **),
192 /*-- app-openpgp.c --*/
193 gpg_error_t app_select_openpgp (app_t app);
196 gpg_error_t app_select_nks (app_t app);
198 /*-- app-dinsig.c --*/
199 gpg_error_t app_select_dinsig (app_t app);
202 gpg_error_t app_select_p15 (app_t app);
204 /*-- app-geldkarte.c --*/
205 gpg_error_t app_select_geldkarte (app_t app);
207 /*-- app-sc-hsm.c --*/
208 gpg_error_t app_select_sc_hsm (app_t app);
211 #endif /*GNUPG_SCD_APP_COMMON_H*/