diff options
author | Werner Koch <[email protected]> | 2013-11-15 14:54:31 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2013-11-15 14:54:31 +0000 |
commit | 5499942571a88a1223a7318992605c6d29858866 (patch) | |
tree | 6ee1f5c177484beed5e6142bb11d7ac7179fc0a9 /kbx/keybox-update.c | |
parent | Fix minor compiler warnings. (diff) | |
download | gnupg-5499942571a88a1223a7318992605c6d29858866.tar.gz gnupg-5499942571a88a1223a7318992605c6d29858866.zip |
kbx: Implement update operation for OpenPGP keyblocks.
* kbx/keybox-update.c (keybox_update_keyblock): Implement.
* kbx/keybox-search.c (get_blob_flags): Move to ...
* kbx/keybox-defs.h (blob_get_type): here.
* kbx/keybox-file.c (_keybox_read_blob2): Fix calling without R_BLOB.
* g10/keydb.c (build_keyblock_image): Allow calling without
R_SIGSTATUS.
(keydb_update_keyblock): Implement for keybox.
* kbx/keybox-dump.c (_keybox_dump_blob): Fix printing of the unhashed
size. Print "does not expire" also on 64 bit platforms.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'kbx/keybox-update.c')
-rw-r--r-- | kbx/keybox-update.c | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/kbx/keybox-update.c b/kbx/keybox-update.c index 1fdf4351c..6ade9e79c 100644 --- a/kbx/keybox-update.c +++ b/kbx/keybox-update.c @@ -425,10 +425,47 @@ keybox_insert_keyblock (KEYBOX_HANDLE hd, const void *image, size_t imagelen, gpg_error_t keybox_update_keyblock (KEYBOX_HANDLE hd, const void *image, size_t imagelen) { - (void)hd; - (void)image; - (void)imagelen; - return gpg_error (GPG_ERR_NOT_IMPLEMENTED); + gpg_error_t err; + const char *fname; + off_t off; + KEYBOXBLOB blob; + size_t nparsed; + struct _keybox_openpgp_info info; + + if (!hd || !image || !imagelen) + return gpg_error (GPG_ERR_INV_VALUE); + if (!hd->found.blob) + return gpg_error (GPG_ERR_NOTHING_FOUND); + if (blob_get_type (hd->found.blob) != BLOBTYPE_PGP) + return gpg_error (GPG_ERR_WRONG_BLOB_TYPE); + fname = hd->kb->fname; + if (!fname) + return gpg_error (GPG_ERR_INV_HANDLE); + + off = _keybox_get_blob_fileoffset (hd->found.blob); + if (off == (off_t)-1) + return gpg_error (GPG_ERR_GENERAL); + + /* Close this the file so that we do no mess up the position for a + next search. */ + _keybox_close_file (hd); + + /* Build a new blob. */ + err = _keybox_parse_openpgp (image, imagelen, &nparsed, &info); + if (err) + return err; + assert (nparsed <= imagelen); + err = _keybox_create_openpgp_blob (&blob, &info, image, imagelen, + NULL, hd->ephemeral); + _keybox_destroy_openpgp_info (&info); + + /* Update the keyblock. */ + if (!err) + { + err = blob_filecopy (FILECOPY_UPDATE, fname, blob, hd->secret, off); + _keybox_release_blob (blob); + } + return err; } |