Browse Source

Minor changes

Changing some indentions
master
David Lanzendörfer 12 months ago
parent
commit
48ff1cad8c
1 changed files with 36 additions and 114 deletions
  1. +36
    -114
      src/validate.c

+ 36
- 114
src/validate.c View File

@ -91,44 +91,6 @@ __RCSID("$NetBSD$");
#include <fcntl.h>
#endif
// FIXME to support seckey decryption again.
//
// static int
// keydata_reader(pgp_stream_t *stream, void *dest, size_t length, pgp_error_t **errors,
// pgp_reader_t *readinfo,
// pgp_cbdata_t *cbinfo)
// {
// validate_reader_t *reader = pgp_reader_get_arg(readinfo);
//
// __PGP_USED(stream);
// __PGP_USED(errors);
// __PGP_USED(cbinfo);
// if (reader->offset == reader->key->packets[reader->packet].length) {
// reader->packet += 1;
// reader->offset = 0;
// }
// if (reader->packet == reader->key->packetc) {
// return 0;
// }
//
// /*
// * we should never be asked to cross a packet boundary in a single
// * read
// */
// if (reader->key->packets[reader->packet].length <
// reader->offset + length) {
// (void) fprintf(stderr, "keydata_reader: weird length\n");
// return 0;
// }
//
// (void) memcpy(dest,
// &reader->key->packets[reader->packet].raw[reader->offset],
// length);
// reader->offset += (unsigned)length;
//
// return (int)length;
// }
static void
free_sig_info(pgp_sig_info_t *sig)
{
@ -199,8 +161,7 @@ check_binary_sig(const uint8_t *data,
case PGP_V4:
if (pgp_get_debug_level(__FILE__)) {
hexdump(stderr, "v4 hash", sig->info.v4_hashed,
sig->info.v4_hashlen);
hexdump(stderr, "v4 hash", sig->info.v4_hashed, sig->info.v4_hashlen);
}
hash.add(&hash, sig->info.v4_hashed, (unsigned)sig->info.v4_hashlen);
trailer[0] = 0x04; /* version */
@ -260,8 +221,7 @@ pgp_validate_key_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
io = cbinfo->io;
if (pgp_get_debug_level(__FILE__)) {
(void) fprintf(io->errs, "%s\n",
pgp_show_packet_tag(pkt->tag));
printf("%s\n", pgp_show_packet_tag(pkt->tag));
}
vdata = pgp_callback_arg(cbinfo);
errors = pgp_callback_errors(cbinfo);
@ -272,9 +232,7 @@ pgp_validate_key_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
case PGP_PTAG_CT_PUBLIC_KEY:
validate_key_cb_free(vdata);
vdata->key.pubkey = content->pubkey;
pgp_keyid(vdata->pubkeyid, PGP_KEY_ID_SIZE,
&vdata->key.pubkey, PGP_HASH_SHA1); /* TODO v3*/
pgp_keyid(vdata->pubkeyid, PGP_KEY_ID_SIZE, &vdata->key.pubkey, PGP_HASH_SHA1); /* TODO v3*/
vdata->last_seen = LS_PRIMARY;
vdata->type = PGP_PTAG_CT_PUBLIC_KEY;
vdata->not_commited = 1;
@ -284,8 +242,7 @@ pgp_validate_key_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
/* check pubkey seckey consistency */
validate_key_cb_free(vdata);
vdata->key.seckey = content->seckey;
pgp_keyid(vdata->pubkeyid, PGP_KEY_ID_SIZE,
&vdata->key.seckey.pubkey, PGP_HASH_SHA1); /* TODO v3*/
pgp_keyid(vdata->pubkeyid, PGP_KEY_ID_SIZE, &vdata->key.seckey.pubkey, PGP_HASH_SHA1); /* TODO v3*/
vdata->last_seen = LS_PRIMARY;
vdata->type = PGP_PTAG_CT_SECRET_KEY;
vdata->not_commited = 1;
@ -324,16 +281,14 @@ pgp_validate_key_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
}
case PGP_PTAG_CT_USER_ID:
if(vdata->last_seen == LS_PRIMARY ||
vdata->last_seen == LS_ATTRIBUTE ||
vdata->last_seen == LS_ID){
if(vdata->last_seen == LS_PRIMARY || vdata->last_seen == LS_ATTRIBUTE || vdata->last_seen == LS_ID) {
if (vdata->userid) {
pgp_userid_free(&vdata->userid);
}
vdata->userid = content->userid;
vdata->last_seen = LS_ID;
return PGP_KEEP_MEMORY;
}else{
} else {
(void) fprintf(io->errs,
"pgp_validate_key_cb: unexpected userID packet");
vdata->last_seen = LS_UNKNOWN;
@ -341,67 +296,54 @@ pgp_validate_key_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
}
case PGP_PTAG_CT_USER_ATTR:
if(vdata->last_seen == LS_PRIMARY ||
vdata->last_seen == LS_ATTRIBUTE ||
vdata->last_seen == LS_ID){
if(vdata->last_seen == LS_PRIMARY || vdata->last_seen == LS_ATTRIBUTE || vdata->last_seen == LS_ID) {
if (content->userattr.len == 0) {
(void) fprintf(io->errs,
"pgp_validate_key_cb: user attribute length 0");
(void) fprintf(io->errs, "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);
(void) fprintf(io->outs, "user attribute, length=%d\n", (int) content->userattr.len);
if (vdata->userattr.len) {
pgp_data_free(&vdata->userattr);
}
vdata->userattr = content->userattr;
vdata->last_seen = LS_ATTRIBUTE;
return PGP_KEEP_MEMORY;
}else{
(void) fprintf(io->errs,
"pgp_validate_key_cb: unexpected user attribute\n");
} else {
(void) fprintf(io->errs, "pgp_validate_key_cb: unexpected user attribute\n");
vdata->last_seen = LS_UNKNOWN;
return PGP_RELEASE_MEMORY;
}
case PGP_PTAG_CT_SIGNATURE: /* V3 sigs */
case PGP_PTAG_CT_SIGNATURE_FOOTER:{ /* V4 sigs */
case PGP_PTAG_CT_SIGNATURE: /* V3 sigs */
case PGP_PTAG_CT_SIGNATURE_FOOTER:{ /* V4 sigs */
pgp_pubkey_t *sigkey = NULL;
pgp_pubkey_t *primary_pubkey;
if(vdata->last_seen == LS_UNKNOWN)
if(vdata->last_seen == LS_UNKNOWN) {
break;
}
primary_pubkey =
(vdata->type == PGP_PTAG_CT_PUBLIC_KEY) ?
&vdata->key.pubkey:
&vdata->key.seckey.pubkey;
primary_pubkey = (vdata->type == PGP_PTAG_CT_PUBLIC_KEY) ? &vdata->key.pubkey : &vdata->key.seckey.pubkey;
if(vdata->keyring){
unsigned from;
unsigned from;
from = 0;
/* Returned key ignored, care about ID-targeted pubkey only */
pgp_getkeybyid(io, vdata->keyring,
content->sig.info.signer_id,
&from, &sigkey, NULL,
1, 0); /* reject revoked, accept expired */
pgp_getkeybyid(io, vdata->keyring, content->sig.info.signer_id, &from, &sigkey, NULL, 1, 0); /* reject revoked, accept expired */
} else {
/* If no keyring is given to check against
* then this is a self certification check.
* First ensure signature issuer ID is pubkey's ID*/
if(memcmp(vdata->pubkeyid,
content->sig.info.signer_id,
PGP_KEY_ID_SIZE) == 0){
hexdump(stdout,"vdata->pubkeyid", vdata->pubkeyid, PGP_KEY_ID_SIZE);
hexdump(stdout,"content->sig.info.signer_id", content->sig.info.signer_id, PGP_KEY_ID_SIZE);
if(memcmp(vdata->pubkeyid, content->sig.info.signer_id, PGP_KEY_ID_SIZE) == 0){
sigkey = primary_pubkey;
}
}
if (!sigkey) {
if (vdata->result && !add_sig_to_list(&content->sig.info,
&vdata->result->unknown_sigs,
&vdata->result->unknownc)) {
(void) fprintf(io->errs,
"pgp_validate_key_cb: out of memory");
return PGP_FINISHED;
if (vdata->result && !add_sig_to_list(&content->sig.info, &vdata->result->unknown_sigs, &vdata->result->unknownc)) {
printf("pgp_validate_key_cb: out of memory");
return PGP_FINISHED;
}
break;
}
@ -412,17 +354,9 @@ pgp_validate_key_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
case PGP_CERT_POSITIVE:
case PGP_SIG_REV_CERT:
if(vdata->last_seen == LS_ID){
valid = pgp_check_useridcert_sig(
primary_pubkey,
vdata->userid,
&content->sig,
sigkey);
valid = pgp_check_useridcert_sig(primary_pubkey, vdata->userid, &content->sig, sigkey);
} else if(vdata->last_seen == LS_ATTRIBUTE) {
valid = pgp_check_userattrcert_sig(
primary_pubkey,
&vdata->userattr,
&content->sig,
sigkey);
valid = pgp_check_userattrcert_sig(primary_pubkey, &vdata->userattr, &content->sig, sigkey);
}
break;
@ -432,10 +366,7 @@ pgp_validate_key_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
* we ensure that the signing key is the
* primary key we are validating, "vdata->pubkey".
*/
if(vdata->last_seen == LS_SUBKEY &&
memcmp(vdata->pubkeyid,
content->sig.info.signer_id,
PGP_KEY_ID_SIZE) == 0 )
if(vdata->last_seen == LS_SUBKEY && memcmp(vdata->pubkeyid, content->sig.info.signer_id, PGP_KEY_ID_SIZE) == 0 )
{
valid = pgp_check_subkey_sig(
primary_pubkey,
@ -450,10 +381,7 @@ pgp_validate_key_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
case PGP_SIG_REV_KEY:
case PGP_SIG_DIRECT:
if(vdata->last_seen == LS_PRIMARY){
valid = pgp_check_direct_sig(
primary_pubkey,
&content->sig,
sigkey);
valid = pgp_check_direct_sig(primary_pubkey, &content->sig, sigkey);
}
break;
@ -771,14 +699,13 @@ static pgp_cb_ret_t key_filter_cb (
if(vdata->not_commited){
if((filter->pubkey = pgp_ensure_pubkey(filter->destpubring,
(vdata->type == PGP_PTAG_CT_PUBLIC_KEY) ?
&vdata->key.pubkey :
&vdata->key.seckey.pubkey,
vdata->pubkeyid))==NULL){
return PGP_RELEASE_MEMORY;
}
if((filter->pubkey = pgp_ensure_pubkey(
filter->destpubring,
(vdata->type == PGP_PTAG_CT_PUBLIC_KEY) ? &vdata->key.pubkey : &vdata->key.seckey.pubkey,
vdata->pubkeyid)
)==NULL){
return PGP_RELEASE_MEMORY;
}
filter->seckey = NULL;
if (vdata->type == PGP_PTAG_CT_SECRET_KEY && filter->destsecring) {
if((filter->seckey = pgp_ensure_seckey(
@ -802,16 +729,12 @@ static pgp_cb_ret_t key_filter_cb (
switch(vdata->last_seen){
case LS_PRIMARY:
pgp_add_directsig(pubkey, sigpkt, &vdata->valid_sig_info);
if (seckey) {
pgp_add_directsig(seckey, sigpkt, &vdata->valid_sig_info);
}
break;
case LS_ID:
printf("%s...\n",__FUNCTION__);
pgp_update_userid(pubkey, vdata->userid, sigpkt, &vdata->valid_sig_info);
if (seckey) {
pgp_update_userid(seckey, vdata->userid, sigpkt, &vdata->valid_sig_info);
@ -1004,8 +927,7 @@ pgp_validate_file(pgp_io_t *io,
int cc;
if (stat(infile, &st) < 0) {
(void) fprintf(io->errs,
"pgp_validate_file: can't open '%s'\n", infile);
(void) fprintf(io->errs, "pgp_validate_file: can't open '%s'\n", infile);
return 0;
}
realarmour = user_says_armoured;


Loading…
Cancel
Save