Browse Source

Various recent code cleanup. Added secret counterpart to get_enckey and get_sigkey :

get_deckey and get_certkey

Note : get_certkey is for the secret part of the signing key
       get_sigkey if for the public part of the signing key
       renaming cert->sign and sig->valid would be less confusing
master
Edouard Tisserant 7 years ago
parent
commit
598f6290e6
4 changed files with 68 additions and 27 deletions
  1. +45
    -0
      dist/src/lib/keyring.c
  2. +3
    -0
      dist/src/lib/keyring.h
  3. +0
    -6
      dist/src/lib/netpgpsdk.h
  4. +20
    -21
      dist/src/lib/validate.c

+ 45
- 0
dist/src/lib/keyring.c View File

@ -399,6 +399,13 @@ pgp_key_get_subpubkey(const pgp_key_t *key, int32_t subkeyidx)
&key->subkeys[subkeyidx].key.seckey.pubkey;
}
const pgp_seckey_t *
pgp_key_get_subseckey(const pgp_key_t *key, int32_t subkeyidx)
{
return (key->type == PGP_PTAG_CT_SECRET_KEY) ?
&key->subkeys[subkeyidx].key.seckey :
NULL;
}
static const pgp_pubkey_t *
key_get_pubkey_from_subidx(
const pgp_key_t *key,
@ -420,6 +427,27 @@ key_get_pubkey_from_subidx(
return pgp_key_get_pubkey(key);
}
static const pgp_seckey_t *
key_get_seckey_from_subidx(
const pgp_key_t *key,
const uint8_t **id,
int32_t subkeyidx)
{
if(subkeyidx != -1)
{
if(id)
*id = key->subkeys[subkeyidx].id;
return pgp_key_get_subseckey(key, subkeyidx);
}
if(id)
*id = key->pubkeyid;
return pgp_get_seckey(key);
}
static unsigned is_signing_role(const pgp_sig_info_t *siginfo)
{
return siginfo->key_flags & PGP_KEYFLAG_SIGN_DATA;
@ -433,6 +461,14 @@ pgp_key_get_sigkey(const pgp_key_t *key)
return key_get_pubkey_from_subidx(key, NULL, subkeyidx);
}
const pgp_seckey_t *
pgp_key_get_certkey(const pgp_key_t *key)
{
int32_t subkeyidx =
pgp_key_find_key_conds(key, NULL, NULL, &is_signing_role);
return key_get_seckey_from_subidx(key, NULL, subkeyidx);
}
static unsigned is_encryption_role(const pgp_sig_info_t *siginfo)
{
return siginfo->key_flags & PGP_KEYFLAG_ENC_COMM;
@ -447,6 +483,15 @@ pgp_key_get_enckey(const pgp_key_t *key, const uint8_t **id)
return key_get_pubkey_from_subidx(key, id, subkeyidx);
}
const pgp_seckey_t *
pgp_key_get_deckey(const pgp_key_t *key, const uint8_t **id)
{
int32_t subkeyidx =
pgp_key_find_key_conds(key, NULL, NULL, &is_encryption_role);
return key_get_seckey_from_subidx(key, id, subkeyidx);
}
static unsigned primary_uid_sigcond(const pgp_sig_info_t *siginfo)
{
return siginfo->primary_userid;


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

@ -200,7 +200,10 @@ uint8_t * pgp_copy_userid(uint8_t **dst, const uint8_t *src);
const int32_t pgp_key_get_uid0(const pgp_key_t *keydata);
const pgp_pubkey_t * pgp_key_get_sigkey(const pgp_key_t *key);
const pgp_seckey_t * pgp_key_get_certkey(const pgp_key_t *key);
const pgp_pubkey_t * pgp_key_get_enckey(const pgp_key_t *key, const uint8_t **id);
const pgp_seckey_t * pgp_key_get_deckey(const pgp_key_t *key, const uint8_t **id);
const int32_t
pgp_key_find_uid_cond(


+ 0
- 6
dist/src/lib/netpgpsdk.h View File

@ -51,12 +51,6 @@ typedef struct pgp_validation_t {
void pgp_validate_result_free(pgp_validation_t *);
unsigned
pgp_validate_key_sigs(pgp_validation_t *,
const pgp_key_t *,
const pgp_keyring_t *,
pgp_cb_ret_t cb(const pgp_packet_t *, pgp_cbdata_t *));
unsigned
pgp_validate_all_sigs(pgp_validation_t *,
const pgp_keyring_t *,


+ 20
- 21
dist/src/lib/validate.c View File

@ -298,6 +298,8 @@ pgp_validate_key_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
vdata->last_seen = LS_SUBKEY;
return PGP_KEEP_MEMORY;
}else{
(void) fprintf(io->errs,
"pgp_validate_key_cb: unexpected public subkey packet");
vdata->last_seen = LS_UNKNOWN;
return PGP_RELEASE_MEMORY;
}
@ -313,6 +315,8 @@ pgp_validate_key_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
vdata->last_seen = LS_SUBKEY;
return PGP_KEEP_MEMORY;
}else{
(void) fprintf(io->errs,
"pgp_validate_key_cb: unexpected secret subkey packet");
vdata->last_seen = LS_UNKNOWN;
return PGP_RELEASE_MEMORY;
}
@ -328,9 +332,10 @@ pgp_validate_key_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
vdata->last_seen = LS_ID;
return PGP_KEEP_MEMORY;
}else{
(void) fprintf(io->errs,
"pgp_validate_key_cb: unexpected userID\n");
return PGP_FINISHED;
(void) fprintf(io->errs,
"pgp_validate_key_cb: unexpected userID packet");
vdata->last_seen = LS_UNKNOWN;
return PGP_RELEASE_MEMORY;
}
case PGP_PTAG_CT_USER_ATTR:
@ -339,8 +344,9 @@ pgp_validate_key_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
vdata->last_seen == LS_ID){
if (content->userattr.len == 0) {
(void) fprintf(io->errs,
"pgp_validate_key_cb: user attribute length 0");
return PGP_FINISHED;
"pgp_validate_key_cb: user attribute length 0");
vdata->last_seen = LS_UNKNOWN;
return PGP_RELEASE_MEMORY;
}
(void) fprintf(io->outs, "user attribute, length=%d\n",
(int) content->userattr.len);
@ -353,7 +359,8 @@ pgp_validate_key_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
}else{
(void) fprintf(io->errs,
"pgp_validate_key_cb: unexpected user attribute\n");
return PGP_FINISHED;
vdata->last_seen = LS_UNKNOWN;
return PGP_RELEASE_MEMORY;
}
case PGP_PTAG_CT_SIGNATURE: /* V3 sigs */
case PGP_PTAG_CT_SIGNATURE_FOOTER:{ /* V4 sigs */
@ -499,26 +506,18 @@ pgp_validate_key_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
/* ignore these */
case PGP_PARSER_PTAG:
case PGP_PTAG_CT_SIGNATURE_HEADER:
break;
case PGP_GET_PASSPHRASE:
if (vdata->getpassphrase) {
return vdata->getpassphrase(pkt, cbinfo);
}
break;
case PGP_PTAG_CT_TRUST:
/* 1 byte for level (depth), 1 byte for trust amount */
printf("trust dump\n");
printf("Got trust\n");
//hexdump(stdout, (const uint8_t *)content->trust.data, 10, " ");
//hexdump(stdout, (const uint8_t *)&content->ss_trust, 2, " ");
//printf("Trust level %d, amount %d\n", vdata->trust.level, vdata->trust.amount);
break;
// case PGP_GET_PASSPHRASE:
// if (vdata->getpassphrase) {
// return vdata->getpassphrase(pkt, cbinfo);
// }
// break;
default:
(void) fprintf(stderr, "unexpected tag=0x%x\n", pkt->tag);
return PGP_FINISHED;
return PGP_RELEASE_MEMORY;
}
return PGP_RELEASE_MEMORY;
}


Loading…
Cancel
Save