41 |
BOOL CALLBACK keycache_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam); |
BOOL CALLBACK keycache_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam); |
42 |
void progress_cleanup (progress_filter_s * pfx); |
void progress_cleanup (progress_filter_s * pfx); |
43 |
|
|
44 |
|
/* Global GPG key cache contexts. */ |
45 |
static gpg_keycache_t pub = NULL; |
static gpg_keycache_t pub = NULL; |
46 |
static gpg_keycache_t sec = NULL; |
static gpg_keycache_t sec = NULL; |
47 |
static char *gpg_secring = NULL; |
static char *gpg_secring = NULL; |
81 |
gpg_keycache_release (sec); |
gpg_keycache_release (sec); |
82 |
sec = NULL; |
sec = NULL; |
83 |
} |
} |
84 |
if (cleanup) { |
if (cleanup) |
85 |
if (gpg_secring) |
safe_free (gpg_secring); |
|
free (gpg_secring); |
|
|
gpg_secring = NULL; |
|
|
} |
|
86 |
} |
} |
87 |
|
|
88 |
|
|
166 |
|
|
167 |
/* Get the GPG key with keyid @keyid from the cache. Return it |
/* Get the GPG key with keyid @keyid from the cache. Return it |
168 |
in @r_key on success. */ |
in @r_key on success. */ |
169 |
static int |
static gpgme_error_t |
170 |
get_key_from_cache (const char *keyid, gpgme_key_t *r_key, |
get_key_from_cache (const char *keyid, gpgme_key_t *r_key, |
171 |
struct keycache_s **c, int secret) |
struct keycache_s **c, int secret) |
172 |
{ |
{ |
175 |
int mode = secret? KEYCACHE_PRV : KEYCACHE_PUB; |
int mode = secret? KEYCACHE_PRV : KEYCACHE_PUB; |
176 |
|
|
177 |
if (!keyid) |
if (!keyid) |
178 |
return WPTERR_GENERAL; |
return gpg_error (GPG_ERR_INV_VALUE); |
179 |
if (r_key) |
if (r_key) |
180 |
*r_key = NULL; |
*r_key = NULL; |
181 |
cache = keycache_get_ctx (mode); |
cache = keycache_get_ctx (mode); |
|
if (!cache) |
|
|
BUG (0); |
|
182 |
if (!c) |
if (!c) |
183 |
err = gpg_keycache_find_key (cache, keyid, 0, r_key); |
err = gpg_keycache_find_key (cache, keyid, 0, r_key); |
184 |
else |
else |
185 |
err = gpg_keycache_find_key2 (cache, keyid, 0, r_key, c); |
err = gpg_keycache_find_key2 (cache, keyid, 0, r_key, c); |
186 |
return err? WPTERR_GENERAL : 0; |
return err; |
187 |
} |
} |
188 |
|
|
189 |
|
|
190 |
/* Get GPG key with keyid @keyid directly from GPG and return |
/* Get GPG key with keyid @keyid directly from GPG and return |
191 |
it in @r_key on success. */ |
it in @r_key on success. */ |
192 |
static int |
static gpgme_error_t |
193 |
get_key_directly (const char *keyid, gpgme_key_t *r_key, int secret) |
get_key_directly (const char *keyid, gpgme_key_t *r_key, int secret) |
194 |
{ |
{ |
195 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
197 |
|
|
198 |
err = gpgme_new (&ctx); |
err = gpgme_new (&ctx); |
199 |
if (err) |
if (err) |
200 |
return WPTERR_GENERAL; |
return err; |
201 |
err = gpgme_get_key (ctx, keyid, r_key, secret); |
err = gpgme_get_key (ctx, keyid, r_key, secret); |
202 |
gpgme_release (ctx); |
gpgme_release (ctx); |
203 |
return err? WPTERR_GENERAL : 0; |
return err; |
204 |
} |
} |
205 |
|
|
206 |
|
|
207 |
/* Search the public key with @keyid as the keyid in the cache and |
/* Search the public key with @keyid as the keyid in the cache and |
208 |
return the item in @k. */ |
return the item in @k. */ |
209 |
int |
gpgme_error_t |
210 |
winpt_get_pubkey (const char *keyid, winpt_key_s *k) |
winpt_get_pubkey (const char *keyid, winpt_key_s *k) |
211 |
{ |
{ |
212 |
int rc; |
gpgme_error_t err; |
213 |
|
|
214 |
rc = get_key_from_cache (keyid, &k->ctx, &k->ext, 0); |
err = get_key_from_cache (keyid, &k->ctx, &k->ext, 0); |
215 |
if (rc) |
if (err) |
216 |
return rc; |
return err; |
217 |
k->is_v3 = k->ctx->subkeys->pubkey_algo == GPGME_PK_RSA && |
k->is_v3 = k->ctx->subkeys->pubkey_algo == GPGME_PK_RSA && |
218 |
strlen (k->ctx->subkeys->fpr) == 32; |
strlen (k->ctx->subkeys->fpr) == 32; |
219 |
k->is_protected = k->ext->gloflags.is_protected; |
k->is_protected = k->ext->gloflags.is_protected; |
220 |
k->keyid = k->ctx->subkeys->keyid; |
k->keyid = k->ctx->subkeys->keyid; |
221 |
k->uid = k->ctx->uids->uid; |
k->uid = k->ctx->uids->uid; |
222 |
return rc; |
return 0; |
223 |
} |
} |
224 |
|
|
225 |
|
|
226 |
int |
gpgme_error_t |
227 |
winpt_get_seckey (const char *keyid, winpt_key_s *k) |
winpt_get_seckey (const char *keyid, winpt_key_s *k) |
228 |
{ |
{ |
229 |
int rc; |
gpgme_error_t err; |
230 |
rc = get_key_from_cache (keyid, &k->ctx, &k->ext, 1); |
|
231 |
if (rc) |
err = get_key_from_cache (keyid, &k->ctx, &k->ext, 1); |
232 |
return rc; |
if (err) |
233 |
|
return err; |
234 |
k->is_v3 = k->ctx->subkeys->pubkey_algo == GPGME_PK_RSA && |
k->is_v3 = k->ctx->subkeys->pubkey_algo == GPGME_PK_RSA && |
235 |
strlen (k->ctx->subkeys->fpr) == 32; |
strlen (k->ctx->subkeys->fpr) == 32; |
236 |
k->is_protected = k->ext->gloflags.is_protected; |
k->is_protected = k->ext->gloflags.is_protected; |
237 |
k->keyid = k->ctx->subkeys->keyid; |
k->keyid = k->ctx->subkeys->keyid; |
238 |
k->uid = k->ctx->uids->uid; |
k->uid = k->ctx->uids->uid; |
239 |
return rc; |
return 0; |
240 |
} |
} |
241 |
|
|
242 |
|
|
243 |
int |
gpgme_error_t |
244 |
get_pubkey (const char *keyid, gpgme_key_t *ret_key) |
get_pubkey (const char *keyid, gpgme_key_t *ret_key) |
245 |
{ |
{ |
246 |
int rc; |
gpgme_error_t rc; |
247 |
|
|
248 |
if (pub && sec) |
if (pub && sec) |
249 |
rc = get_key_from_cache (keyid, ret_key, NULL, 0); |
rc = get_key_from_cache (keyid, ret_key, NULL, 0); |
253 |
} |
} |
254 |
|
|
255 |
|
|
256 |
int |
gpgme_error_t |
257 |
get_seckey (const char *keyid, gpgme_key_t *ret_skey) |
get_seckey (const char *keyid, gpgme_key_t *ret_skey) |
258 |
{ |
{ |
259 |
int rc; |
gpgme_error_t rc; |
260 |
|
|
261 |
if (pub && sec) |
if (pub && sec) |
262 |
rc = get_key_from_cache (keyid, ret_skey, NULL, 1); |
rc = get_key_from_cache (keyid, ret_skey, NULL, 1); |
276 |
int n=0; |
int n=0; |
277 |
|
|
278 |
pc = keycache_get_ctx (1); |
pc = keycache_get_ctx (1); |
|
if (!pc) |
|
|
BUG (0); |
|
279 |
while (!gpg_keycache_next_key (pc, 0, &key)) { |
while (!gpg_keycache_next_key (pc, 0, &key)) { |
280 |
if (key->subkeys->pubkey_algo == GPGME_PK_ELG) |
if (key->subkeys->pubkey_algo == GPGME_PK_ELG) |
281 |
n++; |
n++; |