From 27d0f32f77fbef59ddf7c6d79b5b4adee6b2e6ac Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 15 Mar 2013 15:46:03 +0100 Subject: [PATCH] gpg: Distinguish between missing and cleared key flags. * include/cipher.h (PUBKEY_USAGE_NONE): New. * g10/getkey.c (parse_key_usage): Set new flag. -- We do not want to use the default capabilities (derived from the algorithm) if any key flags are given in a signature. Thus if key flags are used in any way, the default key capabilities are never used. This allows to create a key with key flags set to all zero so it can't be used. This better reflects common sense. (cherry picked from commit 4bde12206c5bf199dc6e12a74af8da4558ba41bf) (cherry picked from commit 0a805ed1604ef3e9b27f3e22a936a2d439300e9f) Resolved conflicts: include/cipher.h --- g10/getkey.c | 8 +++++++- include/cipher.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/g10/getkey.c b/g10/getkey.c index 5440c29d7..3c953d61e 100644 --- a/g10/getkey.c +++ b/g10/getkey.c @@ -1494,13 +1494,19 @@ parse_key_usage(PKT_signature *sig) if(flags) key_usage |= PUBKEY_USAGE_UNKNOWN; + + if (!key_usage) + key_usage |= PUBKEY_USAGE_NONE; } + else if (p) /* Key flags of length zero. */ + key_usage |= PUBKEY_USAGE_NONE; /* We set PUBKEY_USAGE_UNKNOWN to indicate that this key has a capability that we do not handle. This serves to distinguish between a zero key usage which we handle as the default capabilities for that algorithm, and a usage that we do not - handle. */ + handle. Likewise we use PUBKEY_USAGE_NONE to indicate that + key_flags have been given but they do not specify any usage. */ return key_usage; } diff --git a/include/cipher.h b/include/cipher.h index a69c6b38d..dcc304521 100644 --- a/include/cipher.h +++ b/include/cipher.h @@ -58,6 +58,7 @@ #define PUBKEY_USAGE_CERT 4 /* key is also good to certify other keys*/ #define PUBKEY_USAGE_AUTH 8 /* key is good for authentication */ #define PUBKEY_USAGE_UNKNOWN 128 /* key has an unknown usage bit */ +#define PUBKEY_USAGE_NONE 256 /* No usage given. */ #define DIGEST_ALGO_MD5 1 #define DIGEST_ALGO_SHA1 2