|
|
|
@ -136,15 +136,71 @@ pgp_keydata_free(pgp_key_t *keydata)
|
|
|
|
|
keydata->packets = NULL;
|
|
|
|
|
keydata->packetc = 0;
|
|
|
|
|
|
|
|
|
|
/* XXX subsigs revokes ? */
|
|
|
|
|
|
|
|
|
|
if (keydata->type == PGP_PTAG_CT_PUBLIC_KEY) {
|
|
|
|
|
pgp_pubkey_free(&keydata->key.pubkey);
|
|
|
|
|
} else {
|
|
|
|
|
pgp_seckey_free(&keydata->key.seckey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* XXX sigkey enckey ? */
|
|
|
|
|
|
|
|
|
|
free(keydata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
pgp_keydata_dup(pgp_key_t *dst, pgp_key_t *src, unsigned make_public)
|
|
|
|
|
{
|
|
|
|
|
unsigned n;
|
|
|
|
|
int res = 0;
|
|
|
|
|
unsigned pktcpyof = 0;
|
|
|
|
|
|
|
|
|
|
memcpy(dst, src, sizeof(pgp_key_t));
|
|
|
|
|
|
|
|
|
|
if (src->type == PGP_PTAG_CT_PUBLIC_KEY) {
|
|
|
|
|
res = pgp_pubkey_dup(&dst->key.pubkey, &src->key.pubkey);
|
|
|
|
|
} else if (make_public && (
|
|
|
|
|
res = pgp_pubkey_dup(&dst->key.pubkey,
|
|
|
|
|
&src->key.seckey.pubkey))) {
|
|
|
|
|
pgp_output_t *output = NULL;
|
|
|
|
|
pgp_memory_t *mem = NULL;
|
|
|
|
|
|
|
|
|
|
dst->type = PGP_PTAG_CT_PUBLIC_KEY;
|
|
|
|
|
|
|
|
|
|
/* update first packet to reflect change in key type */
|
|
|
|
|
pgp_setup_memory_write(&output, &mem, 128);
|
|
|
|
|
|
|
|
|
|
if (pgp_write_struct_pubkey(output, &dst->key.pubkey)) {
|
|
|
|
|
pgp_subpacket_t pubkeypacket;
|
|
|
|
|
pubkeypacket.length = pgp_mem_len(mem);
|
|
|
|
|
pubkeypacket.raw = pgp_mem_data(mem);
|
|
|
|
|
pgp_add_subpacket(dst, &pubkeypacket);
|
|
|
|
|
pktcpyof++;
|
|
|
|
|
res = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pgp_writer_close(output);
|
|
|
|
|
pgp_teardown_memory_write(output, mem);
|
|
|
|
|
} else {
|
|
|
|
|
res = pgp_seckey_dup(&dst->key.seckey, &src->key.seckey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TODO sigkey enckey ? */
|
|
|
|
|
|
|
|
|
|
for (n = pktcpyof; n < src->packetc; ++n) {
|
|
|
|
|
pgp_add_subpacket(dst,&src->packets[n]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (n = 0; n < src->uidc; ++n) {
|
|
|
|
|
pgp_add_userid(dst,src->uids[n]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TODO subsigs revokes ? */
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
\ingroup HighLevel_KeyGeneral
|
|
|
|
|
|
|
|
|
@ -276,7 +332,7 @@ decrypt_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
|
|
|
|
|
return PGP_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
decrypt->seckey->checkhash = calloc(1, PGP_CHECKHASH_SIZE);
|
|
|
|
|
*decrypt->seckey = content->seckey;
|
|
|
|
|
*decrypt->seckey = content->seckey; /* XXX WTF ? */
|
|
|
|
|
return PGP_KEEP_MEMORY;
|
|
|
|
|
|
|
|
|
|
case PGP_PARSER_PACKET_END:
|
|
|
|
@ -480,6 +536,21 @@ pgp_add_subpacket(pgp_key_t *keydata, const pgp_subpacket_t *packet)
|
|
|
|
|
return copy_packet(subpktp, packet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pgp_subpacket_t *
|
|
|
|
|
pgp_replace_subpacket(
|
|
|
|
|
pgp_key_t *keydata,
|
|
|
|
|
const pgp_subpacket_t *packet,
|
|
|
|
|
unsigned index)
|
|
|
|
|
{
|
|
|
|
|
pgp_subpacket_t *subpktp;
|
|
|
|
|
|
|
|
|
|
if (keydata->packetc > index) {
|
|
|
|
|
subpktp = &keydata->packets[index];
|
|
|
|
|
pgp_subpacket_free(subpktp);
|
|
|
|
|
return copy_packet(subpktp, packet);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
\ingroup Core_Keys
|
|
|
|
|
\brief Add selfsigned User ID to key
|
|
|
|
@ -492,19 +563,30 @@ pgp_add_selfsigned_userid(pgp_key_t *key, uint8_t *userid)
|
|
|
|
|
{
|
|
|
|
|
pgp_create_sig_t *sig;
|
|
|
|
|
pgp_subpacket_t sigpacket;
|
|
|
|
|
pgp_subpacket_t useridpacket;
|
|
|
|
|
pgp_memory_t *mem_userid = NULL;
|
|
|
|
|
pgp_output_t *useridoutput = NULL;
|
|
|
|
|
pgp_memory_t *mem_sig = NULL;
|
|
|
|
|
pgp_output_t *sigoutput = NULL;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* create signature packet for this userid
|
|
|
|
|
*/
|
|
|
|
|
/* add userid to key */
|
|
|
|
|
(void) pgp_add_userid(key, userid);
|
|
|
|
|
|
|
|
|
|
/* create userid pkt */
|
|
|
|
|
pgp_setup_memory_write(&useridoutput, &mem_userid, 128);
|
|
|
|
|
pgp_write_struct_userid(useridoutput, userid);
|
|
|
|
|
|
|
|
|
|
/* set packet content */
|
|
|
|
|
useridpacket.length = pgp_mem_len(mem_userid);
|
|
|
|
|
useridpacket.raw = pgp_mem_data(mem_userid);
|
|
|
|
|
|
|
|
|
|
/* add userid pkt to key */
|
|
|
|
|
(void) pgp_add_subpacket(key, &useridpacket);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* create signature packet for this userid
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* create sig for this pkt */
|
|
|
|
|
sig = pgp_create_sig_new();
|
|
|
|
|
pgp_sig_start_key_sig(sig, &key->key.seckey.pubkey, userid, PGP_CERT_POSITIVE);
|
|
|
|
@ -520,8 +602,7 @@ pgp_add_selfsigned_userid(pgp_key_t *key, uint8_t *userid)
|
|
|
|
|
sigpacket.length = pgp_mem_len(mem_sig);
|
|
|
|
|
sigpacket.raw = pgp_mem_data(mem_sig);
|
|
|
|
|
|
|
|
|
|
/* add userid to key */
|
|
|
|
|
(void) pgp_add_userid(key, userid);
|
|
|
|
|
/* add signature to key */
|
|
|
|
|
(void) pgp_add_subpacket(key, &sigpacket);
|
|
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
|