chiark / gitweb /
gpg agent lockup fix: Interrupt main loop when active_connections_value==0
[gnupg2.git] / g10 / call-agent.h
1 /* call-agent.h - Divert operations to the agent
2  * Copyright (C) 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 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 #ifndef GNUPG_G10_CALL_AGENT_H
20 #define GNUPG_G10_CALL_AGENT_H
21
22
23 struct agent_card_info_s
24 {
25   int error;         /* private. */
26   char *reader;      /* Reader information.  */
27   char *apptype;     /* Malloced application type string.  */
28   char *serialno;    /* malloced hex string. */
29   char *disp_name;   /* malloced. */
30   char *disp_lang;   /* malloced. */
31   int  disp_sex;     /* 0 = unspecified, 1 = male, 2 = female */
32   char *pubkey_url;  /* malloced. */
33   char *login_data;  /* malloced. */
34   char *private_do[4]; /* malloced. */
35   char cafpr1valid;
36   char cafpr2valid;
37   char cafpr3valid;
38   char cafpr1[20];
39   char cafpr2[20];
40   char cafpr3[20];
41   char fpr1valid;
42   char fpr2valid;
43   char fpr3valid;
44   char fpr1[20];
45   char fpr2[20];
46   char fpr3[20];
47   u32  fpr1time;
48   u32  fpr2time;
49   u32  fpr3time;
50   unsigned long sig_counter;
51   int chv1_cached;   /* True if a PIN is not required for each
52                         signing.  Note that the gpg-agent might cache
53                         it anyway. */
54   int is_v2;         /* True if this is a v2 card.  */
55   int chvmaxlen[3];  /* Maximum allowed length of a CHV. */
56   int chvretry[3];   /* Allowed retries for the CHV; 0 = blocked. */
57   struct {           /* Array with key attributes.  */
58     int algo;              /* Algorithm identifier.  */
59     union {
60       unsigned int nbits;  /* Supported keysize.  */
61       const char *curve;   /* Name of curve.  */
62     };
63   } key_attr[3];
64   struct {
65     unsigned int ki:1;     /* Key import available.  */
66     unsigned int aac:1;    /* Algorithm attributes are changeable.  */
67   } extcap;
68   unsigned int status_indicator;
69 };
70
71
72
73 /* Release the card info structure. */
74 void agent_release_card_info (struct agent_card_info_s *info);
75
76 /* Return card info. */
77 int agent_scd_learn (struct agent_card_info_s *info, int force);
78
79 /* Send an APDU to the card.  */
80 gpg_error_t agent_scd_apdu (const char *hexapdu, unsigned int *r_sw);
81
82 /* Update INFO with the attribute NAME. */
83 int agent_scd_getattr (const char *name, struct agent_card_info_s *info);
84
85 /* Send the KEYTOCARD command. */
86 int agent_keytocard (const char *hexgrip, int keyno, int force,
87                      const char *serialno, const char *timestamp);
88
89 /* Send a SETATTR command to the SCdaemon. */
90 int agent_scd_setattr (const char *name,
91                        const unsigned char *value, size_t valuelen,
92                        const char *serialno);
93
94 /* Send a WRITECERT command to the SCdaemon. */
95 int agent_scd_writecert (const char *certidstr,
96                           const unsigned char *certdata, size_t certdatalen);
97
98 /* Send a WRITEKEY command to the SCdaemon. */
99 int agent_scd_writekey (int keyno, const char *serialno,
100                         const unsigned char *keydata, size_t keydatalen);
101
102 /* Send a GENKEY command to the SCdaemon. */
103 int agent_scd_genkey (int keyno, int force, u32 *createtime);
104
105 /* Send a READKEY command to the SCdaemon. */
106 int agent_scd_readcert (const char *certidstr,
107                         void **r_buf, size_t *r_buflen);
108
109 /* Change the PIN of an OpenPGP card or reset the retry counter. */
110 int agent_scd_change_pin (int chvno, const char *serialno);
111
112 /* Send the CHECKPIN command to the SCdaemon. */
113 int agent_scd_checkpin  (const char *serialno);
114
115 /* Dummy function, only implemented by gpg 1.4. */
116 void agent_clear_pin_cache (const char *sn);
117
118
119 /* Send the GET_PASSPHRASE command to the agent.  */
120 gpg_error_t agent_get_passphrase (const char *cache_id,
121                                   const char *err_msg,
122                                   const char *prompt,
123                                   const char *desc_msg,
124                                   int repeat,
125                                   int check,
126                                   char **r_passphrase);
127
128 /* Send the CLEAR_PASSPHRASE command to the agent.  */
129 gpg_error_t agent_clear_passphrase (const char *cache_id);
130
131 /* Present the prompt DESC and ask the user to confirm.  */
132 gpg_error_t gpg_agent_get_confirmation (const char *desc);
133
134 /* Return the S2K iteration count as computed by gpg-agent.  */
135 gpg_error_t agent_get_s2k_count (unsigned long *r_count);
136
137 /* Check whether a secret key for public key PK is available.  Returns
138    0 if the secret key is available. */
139 gpg_error_t agent_probe_secret_key (ctrl_t ctrl, PKT_public_key *pk);
140
141 /* Ask the agent whether a secret key is availabale for any of the
142    keys (primary or sub) in KEYBLOCK.  Returns 0 if available.  */
143 gpg_error_t agent_probe_any_secret_key (ctrl_t ctrl, kbnode_t keyblock);
144
145
146 /* Return infos about the secret key with HEXKEYGRIP.  */
147 gpg_error_t agent_get_keyinfo (ctrl_t ctrl, const char *hexkeygrip,
148                                char **r_serialno, int *r_cleartext);
149
150 /* Generate a new key.  */
151 gpg_error_t agent_genkey (ctrl_t ctrl,
152                           char **cache_nonce_addr, char **passwd_nonce_addr,
153                           const char *keyparms, int no_protection,
154                           const char *passphrase,
155                           gcry_sexp_t *r_pubkey);
156
157 /* Read a public key.  */
158 gpg_error_t agent_readkey (ctrl_t ctrl, int fromcard, const char *hexkeygrip,
159                            unsigned char **r_pubkey);
160
161 /* Create a signature.  */
162 gpg_error_t agent_pksign (ctrl_t ctrl, const char *cache_nonce,
163                           const char *hexkeygrip, const char *desc,
164                           u32 *keyid, u32 *mainkeyid, int pubkey_algo,
165                           unsigned char *digest, size_t digestlen,
166                           int digestalgo,
167                           gcry_sexp_t *r_sigval);
168
169 /* Decrypt a ciphertext.  */
170 gpg_error_t agent_pkdecrypt (ctrl_t ctrl, const char *keygrip, const char *desc,
171                              u32 *keyid, u32 *mainkeyid, int pubkey_algo,
172                              gcry_sexp_t s_ciphertext,
173                              unsigned char **r_buf, size_t *r_buflen,
174                              int *r_padding);
175
176 /* Retrieve a key encryption key.  */
177 gpg_error_t agent_keywrap_key (ctrl_t ctrl, int forexport,
178                                void **r_kek, size_t *r_keklen);
179
180 /* Send a key to the agent.  */
181 gpg_error_t agent_import_key (ctrl_t ctrl, const char *desc,
182                               char **cache_nonce_addr, const void *key,
183                               size_t keylen, int unattended, int force);
184
185 /* Receive a key from the agent.  */
186 gpg_error_t agent_export_key (ctrl_t ctrl, const char *keygrip,
187                               const char *desc, int openpgp_protected,
188                               char **cache_nonce_addr,
189                               unsigned char **r_result, size_t *r_resultlen);
190
191 /* Delete a key from the agent.  */
192 gpg_error_t agent_delete_key (ctrl_t ctrl, const char *hexkeygrip,
193                               const char *desc, int force);
194
195 /* Change the passphrase of a key.  */
196 gpg_error_t agent_passwd (ctrl_t ctrl, const char *hexkeygrip, const char *desc,
197                           int verify,
198                           char **cache_nonce_addr, char **passwd_nonce_addr);
199 /* Get the version reported by gpg-agent.  */
200 gpg_error_t agent_get_version (ctrl_t ctrl, char **r_version);
201
202
203 #endif /*GNUPG_G10_CALL_AGENT_H*/