Browse Source

Added signature duplicates detection when updtating keys

master
Edouard Tisserant 7 years ago
parent
commit
a644a6aea9
1 changed files with 68 additions and 24 deletions
  1. +68
    -24
      dist/src/lib/keyring.c

+ 68
- 24
dist/src/lib/keyring.c View File

@ -1370,8 +1370,22 @@ unsigned pgp_add_directsig(
pgp_sig_info_t *siginfo)
{
pgp_directsig_t *directsigp;
unsigned directsigidx;
/* Detect duplicate direct sig */
directsigp = key->directsigs;
for (directsigidx = 0 ; directsigidx < key->directsigc;
directsigidx++, directsigp++)
{
if( directsigp->packet.length == sigpkt->length &&
memcmp(directsigp->packet.raw, sigpkt->raw, sigpkt->length) == 0)
{
/* signature already exist */
return 1;
}
}
/* TODO detect duplicate sig */
EXPAND_ARRAY(key, directsig);
directsigp = &key->directsigs[key->directsigc++];
@ -1389,35 +1403,51 @@ unsigned pgp_update_userid(
const pgp_subpacket_t *sigpkt,
pgp_sig_info_t *siginfo)
{
unsigned idx = 0;
unsigned uididx = 0;
unsigned uidsigidx = 0;
uint8_t **uidp;
pgp_uidsig_t *uidsig;
pgp_uidsig_t *uidsigp;
/* Try to find identical userID */
uidp = key->uids;
for (idx = 0 ; idx < key->uidc; idx++, uidp++) {
if (strcmp((char *)*uidp, (char *)userid) == 0) {
for (uididx = 0 ; uididx < key->uidc; uididx++, uidp++)
{
if (strcmp((char *)*uidp, (char *)userid) == 0)
{
/* Found one. check for duplicate uidsig */
uidsigp = key->uidsigs;
for (uidsigidx = 0 ; uidsigidx < key->uidsigc;
uidsigidx++, uidsigp++)
{
if(uidsigp->uid == uididx &&
uidsigp->packet.length == sigpkt->length &&
memcmp(uidsigp->packet.raw, sigpkt->raw,
sigpkt->length) == 0)
{
/* signature already exists */
return 1;
}
}
break;
}
}
/* Add a new one if none found */
if(idx==key->uidc){
if(uididx==key->uidc){
EXPAND_ARRAY(key, uid);
uidp = &key->uids[key->uidc++];
*uidp = NULL;
pgp_copy_userid(uidp, userid);
}
/* TODO detect duplicate sig */
/* Add uid sig info, pointing to that uid */
EXPAND_ARRAY(key, uidsig);
uidsig = &key->uidsigs[key->uidsigc++];
uidsig->uid = idx;
uidsigp = &key->uidsigs[key->uidsigc++];
uidsigp->uid = uididx;
/* store sig info and packet */
copy_sig_info(&uidsig->siginfo, siginfo);
pgp_copy_packet(&uidsig->packet, sigpkt);
copy_sig_info(&uidsigp->siginfo, siginfo);
pgp_copy_packet(&uidsigp->packet, sigpkt);
return 0;
}
@ -1429,9 +1459,10 @@ unsigned pgp_update_subkey(
const pgp_subpacket_t *sigpkt,
pgp_sig_info_t *siginfo)
{
unsigned idx = 0;
unsigned subkeyidx = 0;
unsigned subkeysigidx = 0;
pgp_subkey_t *subkeyp;
pgp_subkeysig_t *subkeysig;
pgp_subkeysig_t *subkeysigp;
uint8_t subkeyid[PGP_KEY_ID_SIZE];
pgp_keyid(subkeyid, PGP_KEY_ID_SIZE,
@ -1441,14 +1472,29 @@ unsigned pgp_update_subkey(
/* Try to find identical subkey ID */
subkeyp = key->subkeys;
for (idx = 0 ; idx < key->subkeyc; idx++, subkeyp++) {
if(memcmp(subkeyid, subkeyp->id,
PGP_KEY_ID_SIZE) == 0 ){
for (subkeyidx = 0 ; subkeyidx < key->subkeyc; subkeyidx++, subkeyp++)
{
if(memcmp(subkeyid, subkeyp->id, PGP_KEY_ID_SIZE) == 0 )
{
/* Found same subkey. Detect duplicate sig */
for (subkeysigidx = 0 ; subkeysigidx < key->subkeysigc;
subkeysigidx++, subkeysigp++)
{
if(subkeysigp->subkey == subkeyidx &&
subkeysigp->packet.length == sigpkt->length &&
memcmp(subkeysigp->packet.raw, sigpkt->raw,
sigpkt->length) == 0)
{
/* signature already exists */
return 1;
}
}
break;
}
}
/* Add a new one if none found */
if(idx==key->subkeyc){
if(subkeyidx==key->subkeyc){
if(subkeytype == PGP_PTAG_CT_PUBLIC_KEY &&
key->type != PGP_PTAG_CT_PUBLIC_KEY){
/* cannot create secret subkey from public */
@ -1471,17 +1517,15 @@ unsigned pgp_update_subkey(
memcpy(subkeyp->id, subkeyid, PGP_KEY_ID_SIZE);
}
/* TODO detect duplicate sig */
/* Add subkey sig info, pointing to that subkey */
EXPAND_ARRAY(key, subkeysig);
subkeysig = &key->subkeysigs[key->subkeysigc++];
subkeysig->subkey = idx;
subkeysigp = &key->subkeysigs[key->subkeysigc++];
subkeysigp->subkey = subkeyidx;
/* store sig info and packet */
copy_sig_info(&subkeysig->siginfo,
copy_sig_info(&subkeysigp->siginfo,
siginfo);
pgp_copy_packet(&subkeysig->packet, sigpkt);
pgp_copy_packet(&subkeysigp->packet, sigpkt);
return 0;
}


Loading…
Cancel
Save