mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-17 15:44:34 +02:00
gpg: Change calling convention for a function in getkey.c
* g10/getkey.c (merge_selfsigs): Remove arg CTX. Add args REQ_USAGE and WANT_EXACT. (finish_lookup): Adjust caller. Set LOOKUP_NOT_SELECTED here... (lookup): and not here. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
5d1a9c4dc8
commit
9385dfeb9d
77
g10/getkey.c
77
g10/getkey.c
@ -3053,31 +3053,33 @@ merge_selfsigs (KBNODE keyblock)
|
|||||||
|
|
||||||
|
|
||||||
/* See whether the key satisfies any additional requirements specified
|
/* See whether the key satisfies any additional requirements specified
|
||||||
* in CTX. If so, return 1 and set CTX->FOUND_KEY to an appropriate
|
* in CTX. If so, return the node of an appropriate key or subkey.
|
||||||
* key or subkey. Otherwise, return 0 if there was no appropriate
|
* Otherwise, return NULL if there was no appropriate key.
|
||||||
* key.
|
|
||||||
*
|
*
|
||||||
* In case the primary key is not required, select a suitable subkey.
|
* In case the primary key is not required, select a suitable subkey.
|
||||||
* We need the primary key if PUBKEY_USAGE_CERT is set in
|
* We need the primary key if PUBKEY_USAGE_CERT is set in REQ_USAGE or
|
||||||
* CTX->REQ_USAGE or we are in PGP6 or PGP7 mode and PUBKEY_USAGE_SIG
|
* we are in PGP6 or PGP7 mode and PUBKEY_USAGE_SIG is set in
|
||||||
* is set in CTX->REQ_USAGE.
|
* REQ_USAGE.
|
||||||
*
|
*
|
||||||
* If any of PUBKEY_USAGE_SIG, PUBKEY_USAGE_ENC and PUBKEY_USAGE_CERT
|
* If any of PUBKEY_USAGE_SIG, PUBKEY_USAGE_ENC and PUBKEY_USAGE_CERT
|
||||||
* are set in CTX->REQ_USAGE, we filter by the key's function.
|
* are set in REQ_USAGE, we filter by the key's function. Concretely,
|
||||||
* Concretely, if PUBKEY_USAGE_SIG and PUBKEY_USAGE_CERT are set, then
|
* if PUBKEY_USAGE_SIG and PUBKEY_USAGE_CERT are set, then we only
|
||||||
* we only return a key if it is (at least) either a signing or a
|
* return a key if it is (at least) either a signing or a
|
||||||
* certification key.
|
* certification key.
|
||||||
*
|
*
|
||||||
* If CTX->REQ_USAGE is set, then we reject any keys that are not good
|
* If REQ_USAGE is set, then we reject any keys that are not good
|
||||||
* (i.e., valid, not revoked, not expired, etc.). This allows the
|
* (i.e., valid, not revoked, not expired, etc.). This allows the
|
||||||
* getkey functions to be used for plain key listings.
|
* getkey functions to be used for plain key listings.
|
||||||
*
|
*
|
||||||
* Sets the matched key's user id field (pk->user_id) to the user id
|
* Sets the matched key's user id field (pk->user_id) to the user id
|
||||||
* that matched the low-level search criteria or NULL. If R_FLAGS is
|
* that matched the low-level search criteria or NULL.
|
||||||
* not NULL set certain flags for more detailed error reporting. Used
|
*
|
||||||
* flags are:
|
* If R_FLAGS is not NULL set certain flags for more detailed error
|
||||||
|
* reporting. Used flags are:
|
||||||
|
*
|
||||||
* - LOOKUP_ALL_SUBKEYS_EXPIRED :: All Subkeys are expired or have
|
* - LOOKUP_ALL_SUBKEYS_EXPIRED :: All Subkeys are expired or have
|
||||||
* been revoked.
|
* been revoked.
|
||||||
|
* - LOOKUP_NOT_SELECTED :: No suitable key found
|
||||||
*
|
*
|
||||||
* This function needs to handle several different cases:
|
* This function needs to handle several different cases:
|
||||||
*
|
*
|
||||||
@ -3094,40 +3096,41 @@ merge_selfsigs (KBNODE keyblock)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static kbnode_t
|
static kbnode_t
|
||||||
finish_lookup (getkey_ctx_t ctx, kbnode_t keyblock, unsigned int *r_flags)
|
finish_lookup (kbnode_t keyblock, unsigned int req_usage, int want_exact,
|
||||||
|
unsigned int *r_flags)
|
||||||
{
|
{
|
||||||
kbnode_t k;
|
kbnode_t k;
|
||||||
|
|
||||||
/* If CTX->EXACT is set, the key or subkey that actually matched the
|
/* If WANT_EXACT is set, the key or subkey that actually matched the
|
||||||
low-level search criteria. */
|
low-level search criteria. */
|
||||||
kbnode_t foundk = NULL;
|
kbnode_t foundk = NULL;
|
||||||
/* The user id (if any) that matched the low-level search criteria. */
|
/* The user id (if any) that matched the low-level search criteria. */
|
||||||
PKT_user_id *foundu = NULL;
|
PKT_user_id *foundu = NULL;
|
||||||
|
|
||||||
#define USAGE_MASK (PUBKEY_USAGE_SIG|PUBKEY_USAGE_ENC|PUBKEY_USAGE_CERT)
|
|
||||||
unsigned int req_usage = (ctx->req_usage & USAGE_MASK);
|
|
||||||
|
|
||||||
/* Request the primary if we're certifying another key, and also
|
|
||||||
if signing data while --pgp6 or --pgp7 is on since pgp 6 and 7
|
|
||||||
do not understand signatures made by a signing subkey. PGP 8
|
|
||||||
does. */
|
|
||||||
int req_prim = ((ctx->req_usage & PUBKEY_USAGE_CERT)
|
|
||||||
|| ((PGP6 || PGP7) && (ctx->req_usage & PUBKEY_USAGE_SIG)));
|
|
||||||
|
|
||||||
u32 curtime = make_timestamp ();
|
|
||||||
|
|
||||||
u32 latest_date;
|
u32 latest_date;
|
||||||
kbnode_t latest_key;
|
kbnode_t latest_key;
|
||||||
PKT_public_key *pk;
|
PKT_public_key *pk;
|
||||||
|
int req_prim;
|
||||||
log_assert (keyblock->pkt->pkttype == PKT_PUBLIC_KEY);
|
u32 curtime = make_timestamp ();
|
||||||
|
|
||||||
if (r_flags)
|
if (r_flags)
|
||||||
*r_flags = 0;
|
*r_flags = 0;
|
||||||
|
|
||||||
|
#define USAGE_MASK (PUBKEY_USAGE_SIG|PUBKEY_USAGE_ENC|PUBKEY_USAGE_CERT)
|
||||||
|
req_usage &= USAGE_MASK;
|
||||||
|
|
||||||
|
/* Request the primary if we're certifying another key, and also if
|
||||||
|
* signing data while --pgp6 or --pgp7 is on since pgp 6 and 7 do
|
||||||
|
* not understand signatures made by a signing subkey. PGP 8 does. */
|
||||||
|
req_prim = ((req_usage & PUBKEY_USAGE_CERT)
|
||||||
|
|| ((PGP6 || PGP7) && (req_usage & PUBKEY_USAGE_SIG)));
|
||||||
|
|
||||||
|
|
||||||
|
log_assert (keyblock->pkt->pkttype == PKT_PUBLIC_KEY);
|
||||||
|
|
||||||
/* For an exact match mark the primary or subkey that matched the
|
/* For an exact match mark the primary or subkey that matched the
|
||||||
low-level search criteria. */
|
low-level search criteria. */
|
||||||
if (ctx->exact)
|
if (want_exact)
|
||||||
{
|
{
|
||||||
for (k = keyblock; k; k = k->next)
|
for (k = keyblock; k; k = k->next)
|
||||||
{
|
{
|
||||||
@ -3262,7 +3265,7 @@ finish_lookup (getkey_ctx_t ctx, kbnode_t keyblock, unsigned int *r_flags)
|
|||||||
* primary key, or,
|
* primary key, or,
|
||||||
*
|
*
|
||||||
* - we're just considering the primary key. */
|
* - we're just considering the primary key. */
|
||||||
if ((!latest_key && !ctx->exact) || foundk == keyblock || req_prim)
|
if ((!latest_key && !want_exact) || foundk == keyblock || req_prim)
|
||||||
{
|
{
|
||||||
if (DBG_LOOKUP && !foundk && !req_prim)
|
if (DBG_LOOKUP && !foundk && !req_prim)
|
||||||
log_debug ("\tno suitable subkeys found - trying primary\n");
|
log_debug ("\tno suitable subkeys found - trying primary\n");
|
||||||
@ -3300,10 +3303,12 @@ finish_lookup (getkey_ctx_t ctx, kbnode_t keyblock, unsigned int *r_flags)
|
|||||||
{
|
{
|
||||||
if (DBG_LOOKUP)
|
if (DBG_LOOKUP)
|
||||||
log_debug ("\tno suitable key found - giving up\n");
|
log_debug ("\tno suitable key found - giving up\n");
|
||||||
|
if (r_flags)
|
||||||
|
*r_flags |= LOOKUP_NOT_SELECTED;
|
||||||
return NULL; /* Not found. */
|
return NULL; /* Not found. */
|
||||||
}
|
}
|
||||||
|
|
||||||
found:
|
found:
|
||||||
if (DBG_LOOKUP)
|
if (DBG_LOOKUP)
|
||||||
log_debug ("\tusing key %08lX\n",
|
log_debug ("\tusing key %08lX\n",
|
||||||
(ulong) keyid_from_pk (latest_key->pkt->pkt.public_key, NULL));
|
(ulong) keyid_from_pk (latest_key->pkt->pkt.public_key, NULL));
|
||||||
@ -3408,12 +3413,10 @@ lookup (getkey_ctx_t ctx, kbnode_t *ret_keyblock, kbnode_t *ret_found_key,
|
|||||||
goto skip; /* No secret key available. */
|
goto skip; /* No secret key available. */
|
||||||
|
|
||||||
/* Warning: node flag bits 0 and 1 should be preserved by
|
/* Warning: node flag bits 0 and 1 should be preserved by
|
||||||
* merge_selfsigs. For secret keys, premerge transferred the
|
* merge_selfsigs. */
|
||||||
* keys to the keyblock. */
|
|
||||||
merge_selfsigs (keyblock);
|
merge_selfsigs (keyblock);
|
||||||
found_key = finish_lookup (ctx, keyblock, &infoflags);
|
found_key = finish_lookup (keyblock, ctx->req_usage, ctx->exact,
|
||||||
if (!found_key)
|
&infoflags);
|
||||||
infoflags |= LOOKUP_NOT_SELECTED;
|
|
||||||
print_status_key_considered (keyblock, infoflags);
|
print_status_key_considered (keyblock, infoflags);
|
||||||
if (found_key)
|
if (found_key)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user