diff options
author | Iain Lane <iainl@gnome.org> | 2019-01-28 14:38:40 +0000 |
---|---|---|
committer | Iain Lane <iainl@gnome.org> | 2019-02-06 17:34:49 +0000 |
commit | 6f1756ac231ca86494235833fa22aac175309787 (patch) | |
tree | 8b0813030fd0947892ed10e435e64c8d7133a502 /egg | |
parent | f6b7a78dc3be89c9f3dc3e400a45f90fbb49987e (diff) | |
download | gcr-6f1756ac231ca86494235833fa22aac175309787.tar.gz |
egg: Write Proc-Type header before DEK-Info
These headers (at least for OpenSSL) must come in this order. We
shouldn't assume that `g_hash_table_foreach` is going to give a
particular ordering - it's not guaranteed, and has changed with GLib
2.59.
This is a cherry-pick of 23fdfe728a27a01ef50affd849be5188c0cda954 from
gnome-keyring.
Diffstat (limited to 'egg')
-rw-r--r-- | egg/egg-armor.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/egg/egg-armor.c b/egg/egg-armor.c index 7d1355c..3ca8d75 100644 --- a/egg/egg-armor.c +++ b/egg/egg-armor.c @@ -59,6 +59,8 @@ EGG_SECURE_DECLARE (armor); #define ARMOR_PREF_END "-----END " #define ARMOR_PREF_END_L 9 +static const gchar * const ORDERED_HEADERS[] = { "Proc-Type", "DEK-Info", NULL }; + static void parse_header_lines (const gchar *hbeg, const gchar *hend, @@ -336,13 +338,16 @@ egg_armor_parse (GBytes *data, } static void -append_each_header (gpointer key, gpointer value, gpointer user_data) +append_each_header (gconstpointer key, gconstpointer value, gpointer user_data) { GString *string = (GString*)user_data; - g_string_append (string, (gchar*)key); + if (g_strv_contains (ORDERED_HEADERS, (const gchar *) key)) + return; + + g_string_append (string, (const gchar *)key); g_string_append (string, ": "); - g_string_append (string, (gchar*)value); + g_string_append (string, (const gchar *)value); g_string_append_c (string, '\n'); } @@ -357,6 +362,7 @@ egg_armor_write (const guchar *data, gint state, save; gsize i, length; gsize n_prefix, estimate; + gchar *value; g_return_val_if_fail (data || !n_data, NULL); g_return_val_if_fail (type, NULL); @@ -370,9 +376,19 @@ egg_armor_write (const guchar *data, g_string_append_len (string, ARMOR_SUFF, ARMOR_SUFF_L); g_string_append_c (string, '\n'); - /* The headers */ + /* The headers. Some must come in a specific order. */ + for (i = 0; ORDERED_HEADERS[i] != NULL; i++) { + value = g_hash_table_lookup (headers, ORDERED_HEADERS[i]); + if (value != NULL) + g_string_append_printf (string, + "%s: %s\n", + ORDERED_HEADERS[i], + value); + } + + /* And the rest we output in any arbitrary order. */ if (headers && g_hash_table_size (headers) > 0) { - g_hash_table_foreach (headers, append_each_header, string); + g_hash_table_foreach (headers, (GHFunc) append_each_header, string); g_string_append_c (string, '\n'); } |