lol

gnupg24: add freepg patches

Add patches to GnuPG 2.4 from FreePG, a common resource for GnuPG
downstream packagers to track, maintain, and apply commonly-used patches
for GnuPG that have been refused by upstream.

The purpose of adding these patches to nixpkgs is to ensure
compatibility with other OpenPGP tools.

https://gitlab.com/freepg/gnupg/

+25 -316
-107
pkgs/tools/security/gnupg/24-allow-import-of-previously-known-keys-even-without-UI.patch
··· 1 - From: Vincent Breitmoser <look@my.amazin.horse> 2 - Date: Thu, 13 Jun 2019 21:27:42 +0200 3 - Subject: gpg: allow import of previously known keys, even without UIDs 4 - 5 - * g10/import.c (import_one): Accept an incoming OpenPGP certificate that 6 - has no user id, as long as we already have a local variant of the cert 7 - that matches the primary key. 8 - 9 - -- 10 - 11 - This fixes two of the three broken tests in import-incomplete.scm. 12 - 13 - GnuPG-Bug-id: 4393 14 - Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net> 15 - --- 16 - g10/import.c | 44 +++++++++++--------------------------------- 17 - 1 file changed, 11 insertions(+), 33 deletions(-) 18 - 19 - 20 - diff --git a/g10/import.c b/g10/import.c 21 - index 9fab46ca6..61896a6bf 100644 22 - --- a/g10/import.c 23 - +++ b/g10/import.c 24 - @@ -1954,7 +1954,6 @@ import_one_real (ctrl_t ctrl, 25 - size_t an; 26 - char pkstrbuf[PUBKEY_STRING_SIZE]; 27 - int merge_keys_done = 0; 28 - - int any_filter = 0; 29 - KEYDB_HANDLE hd = NULL; 30 - 31 - if (r_valid) 32 - @@ -1992,13 +1991,6 @@ import_one_real (ctrl_t ctrl, 33 - } 34 - 35 - 36 - - if (!uidnode) 37 - - { 38 - - if (!silent) 39 - - log_error( _("key %s: no user ID\n"), keystr_from_pk(pk)); 40 - - return 0; 41 - - } 42 - - 43 - if (screener && screener (keyblock, screener_arg)) 44 - { 45 - log_error (_("key %s: %s\n"), keystr_from_pk (pk), 46 - @@ -2078,18 +2070,10 @@ import_one_real (ctrl_t ctrl, 47 - } 48 - } 49 - 50 - - /* Delete invalid parts and bail out if there are no user ids left. */ 51 - - if (!delete_inv_parts (ctrl, keyblock, keyid, options, otherrevsigs)) 52 - - { 53 - - if (!silent) 54 - - { 55 - - log_error ( _("key %s: no valid user IDs\n"), keystr_from_pk(pk)); 56 - - if (!opt.quiet) 57 - - log_info(_("this may be caused by a missing self-signature\n")); 58 - - } 59 - - stats->no_user_id++; 60 - - return 0; 61 - - } 62 - + /* Delete invalid parts, and note if we have any valid ones left. 63 - + * We will later abort import if this key is new but contains 64 - + * no valid uids. */ 65 - + delete_inv_parts (ctrl, keyblock, keyid, options, otherrevsigs); 66 - 67 - /* Get rid of deleted nodes. */ 68 - commit_kbnode (&keyblock); 69 - @@ -2099,24 +2083,11 @@ import_one_real (ctrl_t ctrl, 70 - { 71 - apply_keep_uid_filter (ctrl, keyblock, import_filter.keep_uid); 72 - commit_kbnode (&keyblock); 73 - - any_filter = 1; 74 - } 75 - if (import_filter.drop_sig) 76 - { 77 - apply_drop_sig_filter (ctrl, keyblock, import_filter.drop_sig); 78 - commit_kbnode (&keyblock); 79 - - any_filter = 1; 80 - - } 81 - - 82 - - /* If we ran any filter we need to check that at least one user id 83 - - * is left in the keyring. Note that we do not use log_error in 84 - - * this case. */ 85 - - if (any_filter && !any_uid_left (keyblock)) 86 - - { 87 - - if (!opt.quiet ) 88 - - log_info ( _("key %s: no valid user IDs\n"), keystr_from_pk (pk)); 89 - - stats->no_user_id++; 90 - - return 0; 91 - } 92 - 93 - /* The keyblock is valid and ready for real import. */ 94 - @@ -2174,6 +2145,13 @@ import_one_real (ctrl_t ctrl, 95 - err = 0; 96 - stats->skipped_new_keys++; 97 - } 98 - + else if (err && !any_uid_left (keyblock)) 99 - + { 100 - + if (!silent) 101 - + log_info( _("key %s: new key but contains no user ID - skipped\n"), keystr(keyid)); 102 - + err = 0; 103 - + stats->no_user_id++; 104 - + } 105 - else if (err) /* Insert this key. */ 106 - { 107 - /* Note: ERR can only be NO_PUBKEY or UNUSABLE_PUBKEY. */
-200
pkgs/tools/security/gnupg/24-revert-rfc4880bis-defaults.patch
··· 1 - From 1e4f1550996334d2a631a5d769e937d29ace47bb Mon Sep 17 00:00:00 2001 2 - From: Jakub Jelen <jjelen@redhat.com> 3 - Date: Thu, 9 Feb 2023 16:38:58 +0100 4 - Subject: [PATCH gnupg] Revert the introduction of the RFC4880bis draft into 5 - defaults 6 - 7 - This reverts commit 4583f4fe2 (gpg: Merge --rfc4880bis features into 8 - --gnupg, 2022-10-31). 9 - --- 10 - g10/gpg.c | 35 ++++++++++++++++++++++++++++++++--- 11 - g10/keygen.c | 30 ++++++++++++++++++------------ 12 - 2 files changed, 50 insertions(+), 15 deletions(-) 13 - 14 - diff --git a/g10/gpg.c b/g10/gpg.c 15 - index dcab0a11a..796888013 100644 16 - --- a/g10/gpg.c 17 - +++ b/g10/gpg.c 18 - @@ -247,6 +247,7 @@ enum cmd_and_opt_values 19 - oGnuPG, 20 - oRFC2440, 21 - oRFC4880, 22 - + oRFC4880bis, 23 - oOpenPGP, 24 - oPGP7, 25 - oPGP8, 26 - @@ -636,6 +637,7 @@ static gpgrt_opt_t opts[] = { 27 - ARGPARSE_s_n (oGnuPG, "no-pgp8", "@"), 28 - ARGPARSE_s_n (oRFC2440, "rfc2440", "@"), 29 - ARGPARSE_s_n (oRFC4880, "rfc4880", "@"), 30 - + ARGPARSE_s_n (oRFC4880bis, "rfc4880bis", "@"), 31 - ARGPARSE_s_n (oOpenPGP, "openpgp", N_("use strict OpenPGP behavior")), 32 - ARGPARSE_s_n (oPGP7, "pgp6", "@"), 33 - ARGPARSE_s_n (oPGP7, "pgp7", "@"), 34 - @@ -978,7 +980,6 @@ static gpgrt_opt_t opts[] = { 35 - ARGPARSE_s_n (oNoop, "no-allow-multiple-messages", "@"), 36 - ARGPARSE_s_s (oNoop, "aead-algo", "@"), 37 - ARGPARSE_s_s (oNoop, "personal-aead-preferences","@"), 38 - - ARGPARSE_s_n (oNoop, "rfc4880bis", "@"), 39 - ARGPARSE_s_n (oNoop, "override-compliance-check", "@"), 40 - 41 - 42 - @@ -2227,7 +2228,7 @@ static struct gnupg_compliance_option compliance_options[] = 43 - { 44 - { "gnupg", oGnuPG }, 45 - { "openpgp", oOpenPGP }, 46 - - { "rfc4880bis", oGnuPG }, 47 - + { "rfc4880bis", oRFC4880bis }, 48 - { "rfc4880", oRFC4880 }, 49 - { "rfc2440", oRFC2440 }, 50 - { "pgp6", oPGP7 }, 51 - @@ -2243,8 +2244,28 @@ static struct gnupg_compliance_option compliance_options[] = 52 - static void 53 - set_compliance_option (enum cmd_and_opt_values option) 54 - { 55 - + opt.flags.rfc4880bis = 0; /* Clear because it is initially set. */ 56 - + 57 - switch (option) 58 - { 59 - + case oRFC4880bis: 60 - + opt.flags.rfc4880bis = 1; 61 - + opt.compliance = CO_RFC4880; 62 - + opt.flags.dsa2 = 1; 63 - + opt.flags.require_cross_cert = 1; 64 - + opt.rfc2440_text = 0; 65 - + opt.allow_non_selfsigned_uid = 1; 66 - + opt.allow_freeform_uid = 1; 67 - + opt.escape_from = 1; 68 - + opt.not_dash_escaped = 0; 69 - + opt.def_cipher_algo = 0; 70 - + opt.def_digest_algo = 0; 71 - + opt.cert_digest_algo = 0; 72 - + opt.compress_algo = -1; 73 - + opt.s2k_mode = 3; /* iterated+salted */ 74 - + opt.s2k_digest_algo = DIGEST_ALGO_SHA256; 75 - + opt.s2k_cipher_algo = CIPHER_ALGO_AES256; 76 - + break; 77 - case oOpenPGP: 78 - case oRFC4880: 79 - /* This is effectively the same as RFC2440, but with 80 - @@ -2288,6 +2309,7 @@ set_compliance_option (enum cmd_and_opt_values option) 81 - case oPGP8: opt.compliance = CO_PGP8; break; 82 - case oGnuPG: 83 - opt.compliance = CO_GNUPG; 84 - + opt.flags.rfc4880bis = 1; 85 - break; 86 - 87 - case oDE_VS: 88 - @@ -2491,6 +2513,7 @@ main (int argc, char **argv) 89 - opt.emit_version = 0; 90 - opt.weak_digests = NULL; 91 - opt.compliance = CO_GNUPG; 92 - + opt.flags.rfc4880bis = 1; 93 - 94 - /* Check special options given on the command line. */ 95 - orig_argc = argc; 96 - @@ -3033,6 +3056,7 @@ main (int argc, char **argv) 97 - case oOpenPGP: 98 - case oRFC2440: 99 - case oRFC4880: 100 - + case oRFC4880bis: 101 - case oPGP7: 102 - case oPGP8: 103 - case oGnuPG: 104 - @@ -3862,6 +3886,11 @@ main (int argc, char **argv) 105 - if( may_coredump && !opt.quiet ) 106 - log_info(_("WARNING: program may create a core file!\n")); 107 - 108 - + if (!opt.flags.rfc4880bis) 109 - + { 110 - + opt.mimemode = 0; /* This will use text mode instead. */ 111 - + } 112 - + 113 - if (eyes_only) { 114 - if (opt.set_filename) 115 - log_info(_("WARNING: %s overrides %s\n"), 116 - @@ -4078,7 +4107,7 @@ main (int argc, char **argv) 117 - /* Check our chosen algorithms against the list of legal 118 - algorithms. */ 119 - 120 - - if(!GNUPG) 121 - + if(!GNUPG && !opt.flags.rfc4880bis) 122 - { 123 - const char *badalg=NULL; 124 - preftype_t badtype=PREFTYPE_NONE; 125 - diff --git a/g10/keygen.c b/g10/keygen.c 126 - index a2cfe3ccf..2a1dd1f81 100644 127 - --- a/g10/keygen.c 128 - +++ b/g10/keygen.c 129 - @@ -404,7 +404,7 @@ keygen_set_std_prefs (const char *string,int personal) 130 - strcat(dummy_string,"S7 "); 131 - strcat(dummy_string,"S2 "); /* 3DES */ 132 - 133 - - if (!openpgp_aead_test_algo (AEAD_ALGO_OCB)) 134 - + if (opt.flags.rfc4880bis && !openpgp_aead_test_algo (AEAD_ALGO_OCB)) 135 - strcat(dummy_string,"A2 "); 136 - 137 - if (personal) 138 - @@ -889,7 +889,7 @@ keygen_upd_std_prefs (PKT_signature *sig, void *opaque) 139 - /* Make sure that the MDC feature flag is set if needed. */ 140 - add_feature_mdc (sig,mdc_available); 141 - add_feature_aead (sig, aead_available); 142 - - add_feature_v5 (sig, 1); 143 - + add_feature_v5 (sig, opt.flags.rfc4880bis); 144 - add_keyserver_modify (sig,ks_modify); 145 - keygen_add_keyserver_url(sig,NULL); 146 - 147 - @@ -3382,7 +3382,10 @@ parse_key_parameter_part (ctrl_t ctrl, 148 - } 149 - } 150 - else if (!ascii_strcasecmp (s, "v5")) 151 - - keyversion = 5; 152 - + { 153 - + if (opt.flags.rfc4880bis) 154 - + keyversion = 5; 155 - + } 156 - else if (!ascii_strcasecmp (s, "v4")) 157 - keyversion = 4; 158 - else 159 - @@ -3641,7 +3644,7 @@ parse_key_parameter_part (ctrl_t ctrl, 160 - * ecdsa := Use algorithm ECDSA. 161 - * eddsa := Use algorithm EdDSA. 162 - * ecdh := Use algorithm ECDH. 163 - - * v5 := Create version 5 key 164 - + * v5 := Create version 5 key (requires option --rfc4880bis) 165 - * 166 - * There are several defaults and fallbacks depending on the 167 - * algorithm. PART can be used to select which part of STRING is 168 - @@ -4513,9 +4516,9 @@ read_parameter_file (ctrl_t ctrl, const char *fname ) 169 - } 170 - } 171 - 172 - - if ((keywords[i].key == pVERSION 173 - - || keywords[i].key == pSUBVERSION)) 174 - - ; /* Ignore version. */ 175 - + if (!opt.flags.rfc4880bis && (keywords[i].key == pVERSION 176 - + || keywords[i].key == pSUBVERSION)) 177 - + ; /* Ignore version unless --rfc4880bis is active. */ 178 - else 179 - { 180 - r = xmalloc_clear( sizeof *r + strlen( value ) ); 181 - @@ -4610,11 +4613,14 @@ quickgen_set_para (struct para_data_s *para, int for_subkey, 182 - para = r; 183 - } 184 - 185 - - r = xmalloc_clear (sizeof *r + 20); 186 - - r->key = for_subkey? pSUBVERSION : pVERSION; 187 - - snprintf (r->u.value, 20, "%d", version); 188 - - r->next = para; 189 - - para = r; 190 - + if (opt.flags.rfc4880bis) 191 - + { 192 - + r = xmalloc_clear (sizeof *r + 20); 193 - + r->key = for_subkey? pSUBVERSION : pVERSION; 194 - + snprintf (r->u.value, 20, "%d", version); 195 - + r->next = para; 196 - + para = r; 197 - + } 198 - 199 - if (keytime) 200 - {
+25 -9
pkgs/tools/security/gnupg/24.nix
··· 2 2 lib, 3 3 stdenv, 4 4 fetchurl, 5 + fetchFromGitLab, 5 6 buildPackages, 6 7 pkg-config, 7 8 texinfo, ··· 68 69 ] 69 70 ++ lib.optionals withTpm2Tss [ tpm2-tss ]; 70 71 71 - patches = [ 72 - ./fix-libusb-include-path.patch 73 - ./tests-add-test-cases-for-import-without-uid.patch 74 - ./accept-subkeys-with-a-good-revocation-but-no-self-sig.patch 75 - ./24-allow-import-of-previously-known-keys-even-without-UI.patch 76 - ./24-revert-rfc4880bis-defaults.patch 77 - # Patch for DoS vuln from https://seclists.org/oss-sec/2022/q3/27 78 - ./v3-0001-Disallow-compressed-signatures-and-certificates.patch 79 - ]; 72 + freepgPatches = fetchFromGitLab { 73 + domain = "gitlab.com"; 74 + owner = "freepg"; 75 + repo = "gnupg"; 76 + rev = "541772915dc4ec832c37f85bc629a22051f0e8f7"; 77 + hash = "sha256-QOUY6EfJbTTN242BtzLojDgECGjUwbLfPJgzn/mj5L8="; 78 + }; 79 + 80 + patches = 81 + [ 82 + ./fix-libusb-include-path.patch 83 + ./CVE-2022-3219.patch 84 + ] 85 + ++ lib.map (v: "${freepgPatches}/STABLE-BRANCH-2-4-freepg/" + v) [ 86 + "0002-gpg-accept-subkeys-with-a-good-revocation-but-no-sel.patch" 87 + "0003-gpg-allow-import-of-previously-known-keys-even-witho.patch" 88 + "0004-tests-add-test-cases-for-import-without-uid.patch" 89 + "0005-gpg-drop-import-clean-from-default-keyserver-import-.patch" 90 + "0006-Do-not-use-OCB-mode-even-if-AEAD-OCB-key-preference-.patch" 91 + "0007-Revert-the-introduction-of-the-RFC4880bis-draft-into.patch" 92 + "0008-avoid-systemd-deprecation-warning.patch" 93 + "0009-Add-systemd-support-for-keyboxd.patch" 94 + "0010-doc-Remove-profile-and-systemd-example-files.patch" 95 + ]; 80 96 81 97 postPatch = 82 98 ''
pkgs/tools/security/gnupg/v3-0001-Disallow-compressed-signatures-and-certificates.patch pkgs/tools/security/gnupg/CVE-2022-3219.patch