gpg: Read the UBID from the keybox and detect wrong blob type.

* g10/keydb-private.h (struct keydb_handle_s): Add fields for UBID.
* g10/call-keyboxd.c (search_status_cb): New.
(keydb_search): Set new UBID fields.
--

The UBID is not yet used but may come handy later.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2019-10-01 20:11:54 +02:00
parent c7293a4d12
commit 63dbc817e7
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
2 changed files with 46 additions and 7 deletions

View File

@ -779,6 +779,7 @@ keydb_update_keyblock (ctrl_t ctrl, KEYDB_HANDLE hd, kbnode_t kb)
* came is used. If there was no previous search result (or
* keydb_search_reset was called), then the keyring / keybox where the
* next search would start is used (i.e., the current file position).
* In keyboxd mode the keyboxd decides where to store it.
*
* Note: this doesn't do anything if --dry-run was specified.
*
@ -853,7 +854,7 @@ keydb_search_reset (KEYDB_HANDLE hd)
goto leave;
}
/* All we need todo is to tell search that a reset is pending. Noet
/* All we need todo is to tell search that a reset is pending. Note
* that keydb_new sets this flag as well. */
hd->kbl->need_search_reset = 1;
err = 0;
@ -863,6 +864,35 @@ keydb_search_reset (KEYDB_HANDLE hd)
}
/* Status callback for SEARCH and NEXT operaions. */
static gpg_error_t
search_status_cb (void *opaque, const char *line)
{
KEYDB_HANDLE hd = opaque;
gpg_error_t err = 0;
const char *s;
if ((s = has_leading_keyword (line, "PUBKEY_INFO")))
{
if (atoi (s) != PUBKEY_TYPE_OPGP)
err = gpg_error (GPG_ERR_WRONG_BLOB_TYPE);
else
{
hd->last_ubid_valid = 0;
while (*s && !spacep (s))
s++;
if (hex2fixedbuf (s, hd->last_ubid, sizeof hd->last_ubid))
hd->last_ubid_valid = 1;
else
err = gpg_error (GPG_ERR_INV_VALUE);
}
}
return err;
}
/* Search the database for keys matching the search description. If
* the DB contains any legacy keys, these are silently ignored.
*
@ -1040,19 +1070,20 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
}
do_search:
hd->last_ubid_valid = 0;
if (hd->kbl->datastream.fp)
{
/* log_debug ("Sending command '%s'\n", line); */
err = assuan_transact (hd->kbl->ctx, line,
NULL, NULL,
NULL, NULL,
NULL, NULL);
search_status_cb, hd);
if (err)
{
/* log_debug ("Finished command with error: %s\n", gpg_strerror (err)); */
/* Fixme: On unexpected errors we need a way to cancek the
* data stream. Probly it will be best to closeand reopen
* it. */
/* Fixme: On unexpected errors we need a way to cancel the
* data stream. Probably it will be best to close and
* reopen it. */
}
else
{
@ -1086,7 +1117,7 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
err = assuan_transact (hd->kbl->ctx, line,
put_membuf_cb, &data,
NULL, NULL,
NULL, NULL);
search_status_cb, hd);
if (err)
{
xfree (get_membuf (&data, &len));
@ -1104,6 +1135,8 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
xfree (buffer);
}
/* if (hd->last_ubid_valid) */
/* log_printhex (hd->last_ubid, 20, "found UBID:"); */
leave:
if (DBG_CLOCK)

View File

@ -92,10 +92,16 @@ struct keydb_handle_s
/* A shallow pointer with the CTRL used to create this handle. */
ctrl_t ctrl;
/* Connection info which also keep the local state. (This is points
/* Connection info which also keeps the local state. (This points
* into the CTRL->keybox_local list.) */
keyboxd_local_t kbl;
/* Various flags. */
unsigned int last_ubid_valid:1;
/* The UBID of the last returned keyblock. */
unsigned char last_ubid[20];
/* END USE_KEYBOXD */
/* BEGIN !USE_KEYBOXD */