1 /* call-agent.h - Divert operations to the agent
2 * Copyright (C) 2003 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/>.
19 #ifndef GNUPG_G10_CALL_AGENT_H
20 #define GNUPG_G10_CALL_AGENT_H
23 struct agent_card_info_s
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. */
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
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. */
60 unsigned int nbits; /* Supported keysize. */
61 const char *curve; /* Name of curve. */
65 unsigned int ki:1; /* Key import available. */
66 unsigned int aac:1; /* Algorithm attributes are changeable. */
68 unsigned int status_indicator;
73 /* Release the card info structure. */
74 void agent_release_card_info (struct agent_card_info_s *info);
76 /* Return card info. */
77 int agent_scd_learn (struct agent_card_info_s *info, int force);
79 /* Send an APDU to the card. */
80 gpg_error_t agent_scd_apdu (const char *hexapdu, unsigned int *r_sw);
82 /* Update INFO with the attribute NAME. */
83 int agent_scd_getattr (const char *name, struct agent_card_info_s *info);
85 /* Send the KEYTOCARD command. */
86 int agent_keytocard (const char *hexgrip, int keyno, int force,
87 const char *serialno, const char *timestamp);
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);
94 /* Send a WRITECERT command to the SCdaemon. */
95 int agent_scd_writecert (const char *certidstr,
96 const unsigned char *certdata, size_t certdatalen);
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);
102 /* Send a GENKEY command to the SCdaemon. */
103 int agent_scd_genkey (int keyno, int force, u32 *createtime);
105 /* Send a READKEY command to the SCdaemon. */
106 int agent_scd_readcert (const char *certidstr,
107 void **r_buf, size_t *r_buflen);
109 /* Change the PIN of an OpenPGP card or reset the retry counter. */
110 int agent_scd_change_pin (int chvno, const char *serialno);
112 /* Send the CHECKPIN command to the SCdaemon. */
113 int agent_scd_checkpin (const char *serialno);
115 /* Dummy function, only implemented by gpg 1.4. */
116 void agent_clear_pin_cache (const char *sn);
119 /* Send the GET_PASSPHRASE command to the agent. */
120 gpg_error_t agent_get_passphrase (const char *cache_id,
123 const char *desc_msg,
126 char **r_passphrase);
128 /* Send the CLEAR_PASSPHRASE command to the agent. */
129 gpg_error_t agent_clear_passphrase (const char *cache_id);
131 /* Present the prompt DESC and ask the user to confirm. */
132 gpg_error_t gpg_agent_get_confirmation (const char *desc);
134 /* Return the S2K iteration count as computed by gpg-agent. */
135 gpg_error_t agent_get_s2k_count (unsigned long *r_count);
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);
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);
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);
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);
157 /* Read a public key. */
158 gpg_error_t agent_readkey (ctrl_t ctrl, int fromcard, const char *hexkeygrip,
159 unsigned char **r_pubkey);
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,
167 gcry_sexp_t *r_sigval);
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,
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);
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);
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);
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);
195 /* Change the passphrase of a key. */
196 gpg_error_t agent_passwd (ctrl_t ctrl, const char *hexkeygrip, const char *desc,
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);
203 #endif /*GNUPG_G10_CALL_AGENT_H*/