diff options
author | Werner Koch <[email protected]> | 2018-08-29 07:36:09 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2018-08-29 07:36:09 +0000 |
commit | 3da835713fb6220112d988e1953f3d84beabbf6a (patch) | |
tree | e999d83cf2981b60cc527fa5bb727bc588bf4309 /g10/parse-packet.c | |
parent | gpg: Refresh expired keys originating from the WKD. (diff) | |
download | gnupg-3da835713fb6220112d988e1953f3d84beabbf6a.tar.gz gnupg-3da835713fb6220112d988e1953f3d84beabbf6a.zip |
gpg: New option --known-notation.
* g10/gpg.c (oKnownNotation): New const.
(opts): Add option --known-notation.
(main): Set option.
* g10/parse-packet.c (known_notations_list): New local var.
(register_known_notation): New.
(can_handle_critical_notation): Rewrite to handle the new feature.
Also print the name of unknown notations in verbose mode.
--
GnuPG-bug-id: 4060
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'g10/parse-packet.c')
-rw-r--r-- | g10/parse-packet.c | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/g10/parse-packet.c b/g10/parse-packet.c index 0fa8be62c..92c65294a 100644 --- a/g10/parse-packet.c +++ b/g10/parse-packet.c @@ -43,11 +43,15 @@ #define MAX_COMMENT_PACKET_LENGTH ( 64 * 1024) #define MAX_ATTR_PACKET_LENGTH ( 16 * 1024*1024) - static int mpi_print_mode; static int list_mode; static estream_t listfp; +/* A linked list of known notation names. Note that the FLAG is used + * to store the length of the name to speed up the check. */ +static strlist_t known_notations_list; + + static int parse (parse_packet_ctx_t ctx, PACKET *pkt, int onlykeypkts, off_t * retpos, int *skip, IOBUF out, int do_skip #if DEBUG_PARSE_PACKET @@ -189,6 +193,36 @@ mpi_read (iobuf_t inp, unsigned int *ret_nread, int secure) } +/* Register STRING as a known critical notation name. */ +void +register_known_notation (const char *string) +{ + strlist_t sl; + + if (!known_notations_list) + { + sl = add_to_strlist (&known_notations_list, + "[email protected]"); + sl->flags = 32; + sl = add_to_strlist (&known_notations_list, "[email protected]"); + sl->flags = 21; + } + if (!string) + return; /* Only initialized the default known notations. */ + + /* In --set-notation we use an exclamation mark to indicate a + * critical notation. As a convenience skip this here. */ + if (*string == '!') + string++; + + if (!*string || strlist_find (known_notations_list, string)) + return; /* Empty string or already registered. */ + + sl = add_to_strlist (&known_notations_list, string); + sl->flags = strlen (string); +} + + int set_packet_list_mode (int mode) { @@ -1640,14 +1674,24 @@ parse_one_sig_subpkt (const byte * buffer, size_t n, int type) /* Return true if we understand the critical notation. */ static int -can_handle_critical_notation (const byte * name, size_t len) +can_handle_critical_notation (const byte *name, size_t len) { - if (len == 32 && memcmp (name, "[email protected]", 32) == 0) - return 1; - if (len == 21 && memcmp (name, "[email protected]", 21) == 0) - return 1; + strlist_t sl; - return 0; + register_known_notation (NULL); /* Make sure it is initialized. */ + + for (sl = known_notations_list; sl; sl = sl->next) + if (sl->flags == len && !memcmp (sl->d, name, len)) + return 1; /* Known */ + + if (opt.verbose) + { + log_info(_("Unknown critical signature notation: ") ); + print_utf8_buffer (log_get_stream(), name, len); + log_printf ("\n"); + } + + return 0; /* Unknown. */ } |