mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-23 10:29:58 +01:00
Re-indent code and use test macros for betetr readability
This commit is contained in:
parent
7d0aa53f7f
commit
d766978c0e
@ -1,3 +1,8 @@
|
|||||||
|
2010-05-07 Werner Koch <wk@g10code.com>
|
||||||
|
|
||||||
|
* import.c (chk_self_sigs): Re-indent and slighly re-arrange code.
|
||||||
|
Use test macros for the sig class.
|
||||||
|
|
||||||
2010-03-12 Werner Koch <wk@g10code.com>
|
2010-03-12 Werner Koch <wk@g10code.com>
|
||||||
|
|
||||||
* plaintext.c (setup_plaintext_name): Do not encode pipe like
|
* plaintext.c (setup_plaintext_name): Do not encode pipe like
|
||||||
|
172
g10/import.c
172
g10/import.c
@ -1348,8 +1348,8 @@ import_revoke_cert( const char *fname, KBNODE node, struct stats_s *stats )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************
|
/*
|
||||||
* loop over the keyblock and check all self signatures.
|
* Loop over the keyblock and check all self signatures.
|
||||||
* Mark all user-ids with a self-signature by setting flag bit 0.
|
* Mark all user-ids with a self-signature by setting flag bit 0.
|
||||||
* Mark all user-ids with an invalid self-signature by setting bit 1.
|
* Mark all user-ids with an invalid self-signature by setting bit 1.
|
||||||
* This works also for subkeys, here the subkey is marked. Invalid or
|
* This works also for subkeys, here the subkey is marked. Invalid or
|
||||||
@ -1361,169 +1361,177 @@ static int
|
|||||||
chk_self_sigs( const char *fname, KBNODE keyblock,
|
chk_self_sigs( const char *fname, KBNODE keyblock,
|
||||||
PKT_public_key *pk, u32 *keyid, int *non_self )
|
PKT_public_key *pk, u32 *keyid, int *non_self )
|
||||||
{
|
{
|
||||||
KBNODE n,knode=NULL;
|
KBNODE n, knode = NULL;
|
||||||
PKT_signature *sig;
|
PKT_signature *sig;
|
||||||
int rc;
|
int rc;
|
||||||
u32 bsdate=0,rsdate=0;
|
u32 bsdate=0,rsdate=0;
|
||||||
KBNODE bsnode=NULL,rsnode=NULL;
|
KBNODE bsnode = NULL, rsnode = NULL;
|
||||||
|
|
||||||
(void)fname;
|
(void)fname;
|
||||||
(void)pk;
|
(void)pk;
|
||||||
|
|
||||||
for( n=keyblock; (n = find_next_kbnode(n, 0)); ) {
|
for (n=keyblock; (n = find_next_kbnode (n, 0)); )
|
||||||
if(n->pkt->pkttype==PKT_PUBLIC_SUBKEY)
|
|
||||||
{
|
{
|
||||||
knode=n;
|
if (n->pkt->pkttype == PKT_PUBLIC_SUBKEY)
|
||||||
bsdate=0;
|
{
|
||||||
rsdate=0;
|
knode = n;
|
||||||
bsnode=NULL;
|
bsdate = 0;
|
||||||
rsnode=NULL;
|
rsdate = 0;
|
||||||
|
bsnode = NULL;
|
||||||
|
rsnode = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if( n->pkt->pkttype != PKT_SIGNATURE )
|
|
||||||
|
if ( n->pkt->pkttype != PKT_SIGNATURE )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sig = n->pkt->pkt.signature;
|
sig = n->pkt->pkt.signature;
|
||||||
if( keyid[0] == sig->keyid[0] && keyid[1] == sig->keyid[1] ) {
|
if ( keyid[0] != sig->keyid[0] || keyid[1] != sig->keyid[1] )
|
||||||
|
{
|
||||||
|
*non_self = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* This just caches the sigs for later use. That way we
|
/* This just caches the sigs for later use. That way we
|
||||||
import a fully-cached key which speeds things up. */
|
import a fully-cached key which speeds things up. */
|
||||||
if(!opt.no_sig_cache)
|
if (!opt.no_sig_cache)
|
||||||
check_key_signature(keyblock,n,NULL);
|
check_key_signature (keyblock, n, NULL);
|
||||||
|
|
||||||
if( IS_UID_SIG(sig) || IS_UID_REV(sig) )
|
if ( IS_UID_SIG(sig) || IS_UID_REV(sig) )
|
||||||
{
|
{
|
||||||
KBNODE unode = find_prev_kbnode( keyblock, n, PKT_USER_ID );
|
KBNODE unode = find_prev_kbnode( keyblock, n, PKT_USER_ID );
|
||||||
if( !unode )
|
if ( !unode )
|
||||||
{
|
{
|
||||||
log_error( _("key %s: no user ID for signature\n"),
|
log_error( _("key %s: no user ID for signature\n"),
|
||||||
keystr(keyid));
|
keystr(keyid));
|
||||||
return -1; /* the complete keyblock is invalid */
|
return -1; /* The complete keyblock is invalid. */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If it hasn't been marked valid yet, keep trying */
|
/* If it hasn't been marked valid yet, keep trying. */
|
||||||
if(!(unode->flag&1)) {
|
if (!(unode->flag&1))
|
||||||
rc = check_key_signature( keyblock, n, NULL);
|
|
||||||
if( rc )
|
|
||||||
{
|
{
|
||||||
if( opt.verbose )
|
rc = check_key_signature (keyblock, n, NULL);
|
||||||
|
if ( rc )
|
||||||
{
|
{
|
||||||
char *p=utf8_to_native(unode->pkt->pkt.user_id->name,
|
if ( opt.verbose )
|
||||||
strlen(unode->pkt->pkt.user_id->name),0);
|
{
|
||||||
log_info( rc == G10ERR_PUBKEY_ALGO ?
|
char *p = utf8_to_native
|
||||||
|
(unode->pkt->pkt.user_id->name,
|
||||||
|
strlen (unode->pkt->pkt.user_id->name),0);
|
||||||
|
log_info (gpg_err_code(rc) == G10ERR_PUBKEY_ALGO ?
|
||||||
_("key %s: unsupported public key "
|
_("key %s: unsupported public key "
|
||||||
"algorithm on user ID \"%s\"\n"):
|
"algorithm on user ID \"%s\"\n"):
|
||||||
_("key %s: invalid self-signature "
|
_("key %s: invalid self-signature "
|
||||||
"on user ID \"%s\"\n"),
|
"on user ID \"%s\"\n"),
|
||||||
keystr(keyid),p);
|
keystr (keyid),p);
|
||||||
xfree(p);
|
xfree (p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
unode->flag |= 1; /* mark that signature checked */
|
unode->flag |= 1; /* Mark that signature checked. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if( sig->sig_class == 0x18 ) {
|
else if ( IS_SUBKEY_SIG (sig) )
|
||||||
/* Note that this works based solely on the timestamps
|
|
||||||
like the rest of gpg. If the standard gets
|
|
||||||
revocation targets, this may need to be revised. */
|
|
||||||
|
|
||||||
if( !knode )
|
|
||||||
{
|
{
|
||||||
if(opt.verbose)
|
/* Note that this works based solely on the timestamps like
|
||||||
log_info( _("key %s: no subkey for key binding\n"),
|
the rest of gpg. If the standard gets revocation
|
||||||
keystr(keyid));
|
targets, this may need to be revised. */
|
||||||
|
|
||||||
|
if ( !knode )
|
||||||
|
{
|
||||||
|
if (opt.verbose)
|
||||||
|
log_info (_("key %s: no subkey for key binding\n"),
|
||||||
|
keystr (keyid));
|
||||||
n->flag |= 4; /* delete this */
|
n->flag |= 4; /* delete this */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rc = check_key_signature( keyblock, n, NULL);
|
rc = check_key_signature (keyblock, n, NULL);
|
||||||
if( rc )
|
if ( rc )
|
||||||
{
|
{
|
||||||
if(opt.verbose)
|
if (opt.verbose)
|
||||||
log_info(rc == G10ERR_PUBKEY_ALGO ?
|
log_info (gpg_err_code (rc) == G10ERR_PUBKEY_ALGO ?
|
||||||
_("key %s: unsupported public key"
|
_("key %s: unsupported public key"
|
||||||
" algorithm\n"):
|
" algorithm\n"):
|
||||||
_("key %s: invalid subkey binding\n"),
|
_("key %s: invalid subkey binding\n"),
|
||||||
keystr(keyid));
|
keystr (keyid));
|
||||||
n->flag|=4;
|
n->flag |= 4;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* It's valid, so is it newer? */
|
/* It's valid, so is it newer? */
|
||||||
if(sig->timestamp>=bsdate) {
|
if (sig->timestamp >= bsdate)
|
||||||
knode->flag |= 1; /* the subkey is valid */
|
|
||||||
if(bsnode)
|
|
||||||
{
|
{
|
||||||
bsnode->flag|=4; /* Delete the last binding
|
knode->flag |= 1; /* The subkey is valid. */
|
||||||
sig since this one is
|
if (bsnode)
|
||||||
newer */
|
{
|
||||||
if(opt.verbose)
|
/* Delete the last binding sig since this
|
||||||
log_info(_("key %s: removed multiple subkey"
|
one is newer */
|
||||||
|
bsnode->flag |= 4;
|
||||||
|
if (opt.verbose)
|
||||||
|
log_info (_("key %s: removed multiple subkey"
|
||||||
" binding\n"),keystr(keyid));
|
" binding\n"),keystr(keyid));
|
||||||
}
|
}
|
||||||
|
|
||||||
bsnode=n;
|
bsnode = n;
|
||||||
bsdate=sig->timestamp;
|
bsdate = sig->timestamp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
n->flag|=4; /* older */
|
n->flag |= 4; /* older */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if( sig->sig_class == 0x28 ) {
|
else if ( IS_SUBKEY_REV (sig) )
|
||||||
/* We don't actually mark the subkey as revoked right
|
|
||||||
now, so just check that the revocation sig is the
|
|
||||||
most recent valid one. Note that we don't care if
|
|
||||||
the binding sig is newer than the revocation sig.
|
|
||||||
See the comment in getkey.c:merge_selfsigs_subkey for
|
|
||||||
more */
|
|
||||||
if( !knode )
|
|
||||||
{
|
{
|
||||||
if(opt.verbose)
|
/* We don't actually mark the subkey as revoked right now,
|
||||||
log_info( _("key %s: no subkey for key revocation\n"),
|
so just check that the revocation sig is the most recent
|
||||||
|
valid one. Note that we don't care if the binding sig is
|
||||||
|
newer than the revocation sig. See the comment in
|
||||||
|
getkey.c:merge_selfsigs_subkey for more. */
|
||||||
|
if ( !knode )
|
||||||
|
{
|
||||||
|
if (opt.verbose)
|
||||||
|
log_info (_("key %s: no subkey for key revocation\n"),
|
||||||
keystr(keyid));
|
keystr(keyid));
|
||||||
n->flag |= 4; /* delete this */
|
n->flag |= 4; /* delete this */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rc = check_key_signature( keyblock, n, NULL);
|
rc = check_key_signature (keyblock, n, NULL);
|
||||||
if( rc )
|
if ( rc )
|
||||||
{
|
{
|
||||||
if(opt.verbose)
|
if(opt.verbose)
|
||||||
log_info(rc == G10ERR_PUBKEY_ALGO ?
|
log_info (gpg_err_code (rc) == G10ERR_PUBKEY_ALGO ?
|
||||||
_("key %s: unsupported public"
|
_("key %s: unsupported public"
|
||||||
" key algorithm\n"):
|
" key algorithm\n"):
|
||||||
_("key %s: invalid subkey revocation\n"),
|
_("key %s: invalid subkey revocation\n"),
|
||||||
keystr(keyid));
|
keystr(keyid));
|
||||||
n->flag|=4;
|
n->flag |= 4;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* It's valid, so is it newer? */
|
/* It's valid, so is it newer? */
|
||||||
if(sig->timestamp>=rsdate)
|
if (sig->timestamp >= rsdate)
|
||||||
{
|
{
|
||||||
if(rsnode)
|
if (rsnode)
|
||||||
{
|
{
|
||||||
rsnode->flag|=4; /* Delete the last revocation
|
/* Delete the last revocation sig since
|
||||||
sig since this one is
|
this one is newer. */
|
||||||
newer */
|
rsnode->flag |= 4;
|
||||||
if(opt.verbose)
|
if (opt.verbose)
|
||||||
log_info(_("key %s: removed multiple subkey"
|
log_info (_("key %s: removed multiple subkey"
|
||||||
" revocation\n"),keystr(keyid));
|
" revocation\n"),keystr(keyid));
|
||||||
}
|
}
|
||||||
|
|
||||||
rsnode=n;
|
rsnode = n;
|
||||||
rsdate=sig->timestamp;
|
rsdate = sig->timestamp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
n->flag|=4; /* older */
|
n->flag |= 4; /* older */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
*non_self=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user