Browse Source

keyring : better error handling on recent code added pgp_keyring_purge. create : workaround problems when outputing key data

master
Edouard Tisserant 7 years ago
parent
commit
25ddf15144
4 changed files with 54 additions and 24 deletions
  1. +1
    -0
      dist/src/lib/Makefile.am
  2. +36
    -18
      dist/src/lib/create.c
  3. +16
    -6
      dist/src/lib/keyring.c
  4. +1
    -0
      dist/src/lib/keyring.h

+ 1
- 0
dist/src/lib/Makefile.am View File

@ -38,6 +38,7 @@ pkginclude_HEADERS = \
packet-show.h \
signature.h \
types.h \
readerwriter.h \
writer.h \
validate.h


+ 36
- 18
dist/src/lib/create.c View File

@ -504,7 +504,7 @@ pgp_write_xfer_pubkey(pgp_output_t *output,
const pgp_key_t *key,
const unsigned armoured)
{
unsigned i, j;
unsigned /*i,*/ j;
if (armoured) {
pgp_writer_push_armoured(output, PGP_PGP_PUBLIC_KEY_BLOCK);
@ -516,16 +516,25 @@ pgp_write_xfer_pubkey(pgp_output_t *output,
/* TODO: revocation signatures go here */
/* user ids and corresponding signatures */
for (i = 0; i < key->uidc; i++) {
if (!pgp_write_struct_userid(output, key->uids[i])) {
/* TODO : fix this */
// /* user ids and corresponding signatures */
// for (i = 0; i < key->uidc; i++) {
// if (!pgp_write_struct_userid(output, key->uids[i])) {
// return 0;
// }
// for (j = 0; j < key->packetc; j++) {
// if (!pgp_write(output, key->packets[j].raw, (unsigned)key->packets[j].length)) {
// return 0;
// }
// }
// }
/* until fixed, output all raw subpackets, except 1st, the key itself */
for (j = 1; j < key->packetc; j++) {
if (!pgp_write(output, key->packets[j].raw,
(unsigned)key->packets[j].length)) {
return 0;
}
for (j = 0; j < key->packetc; j++) {
if (!pgp_write(output, key->packets[j].raw, (unsigned)key->packets[j].length)) {
return 0;
}
}
}
/* TODO: user attributes and corresponding signatures */
@ -562,7 +571,7 @@ pgp_write_xfer_seckey(pgp_output_t *output,
const size_t pplen,
unsigned armoured)
{
unsigned i, j;
unsigned /*i,*/ j;
if (armoured) {
pgp_writer_push_armoured(output, PGP_PGP_PRIVATE_KEY_BLOCK);
@ -575,16 +584,25 @@ pgp_write_xfer_seckey(pgp_output_t *output,
/* TODO: revocation signatures go here */
/* user ids and corresponding signatures */
for (i = 0; i < key->uidc; i++) {
if (!pgp_write_struct_userid(output, key->uids[i])) {
/* TODO : fix this */
// /* user ids and corresponding signatures */
// for (i = 0; i < key->uidc; i++) {
// if (!pgp_write_struct_userid(output, key->uids[i])) {
// return 0;
// }
// for (j = 0; j < key->packetc; j++) {
// if (!pgp_write(output, key->packets[j].raw, (unsigned)key->packets[j].length)) {
// return 0;
// }
// }
// }
/* until fixed, output all raw subpackets, except 1st, the key itself */
for (j = 1; j < key->packetc; j++) {
if (!pgp_write(output, key->packets[j].raw,
(unsigned)key->packets[j].length)) {
return 0;
}
for (j = 0; j < key->packetc; j++) {
if (!pgp_write(output, key->packets[j].raw, (unsigned)key->packets[j].length)) {
return 0;
}
}
}
/* TODO: user attributes and corresponding signatures */


+ 16
- 6
dist/src/lib/keyring.c View File

@ -188,9 +188,8 @@ pgp_keydata_dup(pgp_key_t *dst, pgp_key_t *src, unsigned make_public)
pgp_subpacket_t pubkeypacket;
pubkeypacket.length = pgp_mem_len(mem);
pubkeypacket.raw = pgp_mem_data(mem);
pgp_add_subpacket(dst, &pubkeypacket);
res = (pgp_add_subpacket(dst, &pubkeypacket) != NULL);
pktcpyof++;
res = 1;
}
pgp_writer_close(output);
@ -201,12 +200,12 @@ pgp_keydata_dup(pgp_key_t *dst, pgp_key_t *src, unsigned make_public)
/* TODO sigkey enckey ? */
for (n = pktcpyof; n < src->packetc; ++n) {
pgp_add_subpacket(dst,&src->packets[n]);
for (n = pktcpyof; res && n < src->packetc; ++n) {
res = (pgp_add_subpacket(dst,&src->packets[n]) != NULL);
}
for (n = 0; n < src->uidc; ++n) {
pgp_add_userid(dst,src->uids[n]);
for (n = 0; res && n < src->uidc; ++n) {
res = (pgp_add_userid(dst,src->uids[n]) != NULL);
}
/* TODO subsigs revokes ? */
@ -897,6 +896,17 @@ pgp_keyring_free(pgp_keyring_t *keyring)
keyring->keyc = keyring->keyvsize = 0;
}
void
pgp_keyring_purge(pgp_keyring_t *keyring)
{
pgp_key_t *keyp;
unsigned c;
for (keyp = keyring->keys; c < keyring->keyc; c++, keyp++) {
pgp_key_free(keyp);
}
pgp_keyring_free(keyring);
}
static unsigned
deletekey( pgp_keyring_t *keyring, pgp_key_t *key, unsigned from)
{


+ 1
- 0
dist/src/lib/keyring.h View File

@ -101,6 +101,7 @@ void pgp_key_free(pgp_key_t *);
void pgp_keydata_free(pgp_key_t *);
int pgp_keydata_dup(pgp_key_t *, pgp_key_t *, unsigned);
void pgp_keyring_free(pgp_keyring_t *);
void pgp_keyring_purge(pgp_keyring_t *);
void pgp_dump_keyring(const pgp_keyring_t *);
const pgp_pubkey_t *pgp_get_pubkey(const pgp_key_t *);
unsigned pgp_is_key_secret(const pgp_key_t *);


Loading…
Cancel
Save