gpg: Use the matching key if the search description is exact.
authorNeal H. Walfield <neal@g10code.com>
Wed, 2 Dec 2015 19:51:52 +0000 (20:51 +0100)
committerNeal H. Walfield <neal@g10code.com>
Wed, 2 Dec 2015 23:00:54 +0000 (00:00 +0100)
* g10/gpg.c (check_user_ids): If the search description is for an
exact match (a keyid or fingerprint that ends in '!'), then use the
matching key, not the primary key.
* tests/openpgp/Makefile.am (TESTS): Add use-exact-key.test.
(priv_keys): Add privkeys/00FE67F28A52A8AA08FFAED20AF832DA916D1985.asc,
privkeys/1DF48228FEFF3EC2481B106E0ACA8C465C662CC5.asc,
privkeys/A2832820DC9F40751BDCD375BB0945BA33EC6B4C.asc,
privkeys/ADE710D74409777B7729A7653373D820F67892E0.asc and
privkeys/CEFC51AF91F68A2904FBFF62C4F075A4785B803F.asc.
(sample_keys): Add
samplekeys/E657FB607BB4F21C90BB6651BC067AF28BC90111.asc.
* tests/openpgp/privkeys/00FE67F28A52A8AA08FFAED20AF832DA916D1985.asc:
New file.
* tests/openpgp/privkeys/1DF48228FEFF3EC2481B106E0ACA8C465C662CC5.asc:
New file.
* tests/openpgp/privkeys/A2832820DC9F40751BDCD375BB0945BA33EC6B4C.asc:
New file.
* tests/openpgp/privkeys/ADE710D74409777B7729A7653373D820F67892E0.asc:
New file.
* tests/openpgp/privkeys/CEFC51AF91F68A2904FBFF62C4F075A4785B803F.asc:
New file.
* tests/openpgp/samplekeys/E657FB607BB4F21C90BB6651BC067AF28BC90111.asc:
New file.
* tests/openpgp/use-exact-key.test: New file.
* tests/openpgp/version.test: Install the new private keys.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
Reported-by: Reported-by: Kristian Fiskerstrand
  <kristian.fiskerstrand@sumptuouscapital.com>
Fixes-commit: 10cca02

g10/gpg.c
tests/openpgp/Makefile.am
tests/openpgp/privkeys/00FE67F28A52A8AA08FFAED20AF832DA916D1985.asc [new file with mode: 0644]
tests/openpgp/privkeys/1DF48228FEFF3EC2481B106E0ACA8C465C662CC5.asc [new file with mode: 0644]
tests/openpgp/privkeys/A2832820DC9F40751BDCD375BB0945BA33EC6B4C.asc [new file with mode: 0644]
tests/openpgp/privkeys/ADE710D74409777B7729A7653373D820F67892E0.asc [new file with mode: 0644]
tests/openpgp/privkeys/CEFC51AF91F68A2904FBFF62C4F075A4785B803F.asc [new file with mode: 0644]
tests/openpgp/samplekeys/E657FB607BB4F21C90BB6651BC067AF28BC90111.asc [new file with mode: 0644]
tests/openpgp/samplekeys/README
tests/openpgp/use-exact-key.test [new file with mode: 0755]
tests/openpgp/version.test

index 5aeb94d..7741251 100644 (file)
--- a/g10/gpg.c
+++ b/g10/gpg.c
@@ -2196,19 +2196,46 @@ check_user_ids (strlist_t *sp,
         }
 
       pk = kb->pkt->pkt.public_key;
-      fingerprint_from_pk (pk, fingerprint_bin, &fingerprint_bin_len);
-      assert (fingerprint_bin_len == sizeof (fingerprint_bin));
-      bin2hex (fingerprint_bin, MAX_FINGERPRINT_LEN, fingerprint);
       if ((desc.mode == KEYDB_SEARCH_MODE_SHORT_KID
            || desc.mode == KEYDB_SEARCH_MODE_LONG_KID
            || desc.mode == KEYDB_SEARCH_MODE_FPR16
            || desc.mode == KEYDB_SEARCH_MODE_FPR20)
           && strchr (t->d, '!'))
+        /* Exact search.  In this case we want to set FINGERPRINT not
+           to the primary key, but the key (primary or sub) that
+           matched the search criteria.  Note: there will always be
+           exactly one match.  */
         {
-          int i = strlen (fingerprint);
+          kbnode_t n = kb;
+          PKT_public_key *match = NULL;
+          int i;
+
+          do
+            {
+              if ((n->flag & 1))
+                /* The matched node.  */
+                {
+                  assert (! match);
+                  match = n->pkt->pkt.public_key;
+                }
+            }
+          while ((n = find_next_kbnode (n, PKT_PUBLIC_SUBKEY)));
+          assert (match);
+
+          fingerprint_from_pk (match, fingerprint_bin, &fingerprint_bin_len);
+          assert (fingerprint_bin_len == sizeof (fingerprint_bin));
+          bin2hex (fingerprint_bin, MAX_FINGERPRINT_LEN, fingerprint);
+
+          i = strlen (fingerprint);
           fingerprint[i] = '!';
           fingerprint[i + 1] = '\0';
         }
+      else
+        {
+          fingerprint_from_pk (pk, fingerprint_bin, &fingerprint_bin_len);
+          assert (fingerprint_bin_len == sizeof (fingerprint_bin));
+          bin2hex (fingerprint_bin, MAX_FINGERPRINT_LEN, fingerprint);
+        }
 
       add_to_strlist (&s2, fingerprint);
       s2->flags = s->flags;
index aa13be9..914de8c 100644 (file)
@@ -46,7 +46,7 @@ TESTS = version.test mds.test \
        multisig.test verify.test armor.test \
        import.test ecc.test 4gb-packet.test \
        $(sqlite3_dependent_tests) \
-       gpgtar.test \
+       gpgtar.test use-exact-key.test \
        finish.test
 
 
@@ -81,7 +81,12 @@ priv_keys = privkeys/50B2D4FA4122C212611048BC5FC31BD44393626E.asc \
            privkeys/C905D0AB6AE9655C5A35975939997BBF3325D6DD.asc \
            privkeys/B2BAA7144303DF19BB6FDE23781DD3FDD97918D4.asc \
            privkeys/CF60965BF51F67CF80DECE853E0D2D343468571D.asc \
-           privkeys/DF00E361D34F80868D06879AC21D7A7D4E4FAD76.asc
+           privkeys/DF00E361D34F80868D06879AC21D7A7D4E4FAD76.asc \
+           privkeys/00FE67F28A52A8AA08FFAED20AF832DA916D1985.asc \
+           privkeys/1DF48228FEFF3EC2481B106E0ACA8C465C662CC5.asc \
+           privkeys/A2832820DC9F40751BDCD375BB0945BA33EC6B4C.asc \
+           privkeys/ADE710D74409777B7729A7653373D820F67892E0.asc \
+           privkeys/CEFC51AF91F68A2904FBFF62C4F075A4785B803F.asc
 
 
 sample_keys = samplekeys/ecc-sample-1-pub.asc \
@@ -96,7 +101,8 @@ sample_keys = samplekeys/ecc-sample-1-pub.asc \
              samplekeys/dda252ebb8ebe1af-2.asc \
              samplekeys/whats-new-in-2.1.asc \
              samplekeys/e2e-p256-1-clr.asc \
-             samplekeys/e2e-p256-1-prt.asc
+             samplekeys/e2e-p256-1-prt.asc \
+             samplekeys/E657FB607BB4F21C90BB6651BC067AF28BC90111.asc
 
 EXTRA_DIST = defs.inc pinentry.sh $(TESTS) $(TEST_FILES) ChangeLog-2011 \
             mkdemodirs signdemokey $(priv_keys) $(sample_keys)
diff --git a/tests/openpgp/privkeys/00FE67F28A52A8AA08FFAED20AF832DA916D1985.asc b/tests/openpgp/privkeys/00FE67F28A52A8AA08FFAED20AF832DA916D1985.asc
new file mode 100644 (file)
index 0000000..71d9eb9
--- /dev/null
@@ -0,0 +1,17 @@
+-----BEGIN PGP ARMORED FILE-----
+Version: GnuPG v2
+Comment: Use "gpg --dearmor" for unpacking
+
+KDExOnByaXZhdGUta2V5KDM6cnNhKDE6bjEyOToAqCYxh+c0mGKVkNRLiSe19rSb
+OgLVJcL6dH1EnawO6klyypIbrDom7DNNTlp7TMlwQ+UsKbmT8jwkU08/awg6W9Wq
+5LCABUStYrVcwJJlf3p4lBru0BSRlaKuIslpk5Powfj2lPXX6o1eRHsnxk9FTD+M
+GcWkhfL9HF+Rq8vPcicpKDE6ZTM6AQABKSgxOmQxMjg6NPUmd199hJrT8TOzgIRl
+vkfedZRLziNM3yBO2nvEjMxKH3uJxKHh/VUg/VLo72On/HIyiQeeDVYcuLJGTm7e
+degk/9C85hT5K4VUF9+LXXDX1Vz/jQdZxq+JwUE/AdlAEC9fkFQzc0ftI832mgjR
+OASwMVphqYUQERz00ve+NDUpKDE6cDY1OgDJoHlM5kAfmQ3HQsykH2QoWnxA6mTa
+aiCn4XIPEsrXCiwObiwWBj3I+w2OTWbodzxWldxBsaYyVCM3bKR6eldFKSgxOnE2
+NToA1X6NuSiiTP6lQcAqnoPC37LE6PUeoohF05hVoRotOm+/sIcve7ZrgVBvELEr
+q6ZU8fUeCUQoMc2ztQEHyC+0eykoMTp1NjQ6HOTajn4vJZPXy/q5sNWhQ7pZDHeJ
+clqSismtIwvuCV3wMAQMIUr+OWTlGHOCYa8FnBn7PbE6TevGdDEE8CQcfCkpKQ==
+=AhP7
+-----END PGP ARMORED FILE-----
diff --git a/tests/openpgp/privkeys/1DF48228FEFF3EC2481B106E0ACA8C465C662CC5.asc b/tests/openpgp/privkeys/1DF48228FEFF3EC2481B106E0ACA8C465C662CC5.asc
new file mode 100644 (file)
index 0000000..688b182
--- /dev/null
@@ -0,0 +1,23 @@
+-----BEGIN PGP ARMORED FILE-----
+Version: GnuPG v2
+Comment: Use "gpg --dearmor" for unpacking
+
+KDIxOnByb3RlY3RlZC1wcml2YXRlLWtleSgzOnJzYSgxOm4xMjk6AOnl30hwc47r
+LL9QH6g0TX1BEPdWMV4Ou6+rQOErIMAr1AOlUzpjwJllvQqf2OHnQWaTr9kbNLn7
+XUEUhjkH3uHDYMHMdyAb7YJrk3ECDqnmr34VV/F/H5BH7D6AiFktl1SpUTczPxBx
+vPNlJ4joPmTm+ahfg+zL+4pVu6tIhM0LKSgxOmUzOgEAASkoOTpwcm90ZWN0ZWQx
+NDpvcGVucGdwLW5hdGl2ZSgxOTpvcGVucGdwLXByaXZhdGUta2V5KDc6dmVyc2lv
+bjE6NCkoNDphbGdvMzpSU0EpKDQ6c2tleTE6XzEyOToA6eXfSHBzjussv1AfqDRN
+fUEQ91YxXg67r6tA4SsgwCvUA6VTOmPAmWW9Cp/Y4edBZpOv2Rs0uftdQRSGOQfe
+4cNgwcx3IBvtgmuTcQIOqeavfhVX8X8fkEfsPoCIWS2XVKlRNzM/EHG882UniOg+
+ZOb5qF+D7Mv7ilW7q0iEzQsxOl8zOgEAATE6XzEyODpfHMTxVhkHswZdPZ3B7pLc
+LktR6NDmaKNVyhP1/G2y95+dY+s2QT4eosp+uYWeR0XHCqNla7TDND41qrzyEAtH
+iAF3OoydMK4lb0lqfKORRI4tr017wgMxRBLs82Gk5ehtI7AwSca7WvaoAJwKZp42
+th4MOeykeGRRMagJI420QTE6XzY1OgDzN2Pz0dRD20hHKF6eiqAZYaZhmA7pKWuW
+jHCVXO9s6zGfn0Ds+kTQJltOxU/AULATN/ffXqTtXSiprxNUvwnbMTpfNjU6APYx
+GOABYcWOpJn35eSoisB04QtOgT5OpAl/dLbeaJ+Yh9KtrY6wLf/mX03FgE+YbkIf
+TmeB6tDf4RYbXCYyKJExOl82NDo5wagaIbek0F5TRtmqdVk1weEk/0XXdyG/mNIA
+4l/qt/LHcduBN46qHYEKnKhyDMCBDwlSRf455FG8Oi1x+JMYKSg0OmNzdW01OjQx
+MDUyKSgxMDpwcm90ZWN0aW9uNDpub25lKSkpKSk=
+=hX0p
+-----END PGP ARMORED FILE-----
diff --git a/tests/openpgp/privkeys/A2832820DC9F40751BDCD375BB0945BA33EC6B4C.asc b/tests/openpgp/privkeys/A2832820DC9F40751BDCD375BB0945BA33EC6B4C.asc
new file mode 100644 (file)
index 0000000..e69c27c
--- /dev/null
@@ -0,0 +1,17 @@
+-----BEGIN PGP ARMORED FILE-----
+Version: GnuPG v2
+Comment: Use "gpg --dearmor" for unpacking
+
+KDExOnByaXZhdGUta2V5KDM6cnNhKDE6bjEyOToAx9HkS9EewRBeMrB/4u8wPapd
+l6spEli/46To7WcmBhmvEZJdG0ZQatYNvgkREqOadsgd49onjYaCkBSJtrJrSUOS
++Mo56Ff/52ejToFyfuZs6Ky0UGm9tvKEJw3aZiGNAZ5Pyvp+Jf+xLDwvj0xHHAj8
+lEEhOSrIrGvq4yx/+nUpKDE6ZTM6AQABKSgxOmQxMjg6DfYRUGbNEko1eq8wUEfM
+BBL6NRWlaf2/coVcLPIvCvASdlTWoog4KC7KiQOTKM07hp8Wz4u3hcDnMG/u60/u
+BPHPHCZThYlpGLVMhQwI46NZtMcRSNBp1rhJ5dt/FEcSFvseJOgce4PD/96bB3+c
+dbnvKcWM7ncRLj0wVfBzKeEpKDE6cDY1OgDanvj9klp9UkAgNwRxswOgiFOlGBsz
+J4dpCZHzWDCjYUd3eGWieynAnfuvctGTaMyB5xT7RwruntbgeRgPpejZKSgxOnE2
+NToA6fv/DFn2WVRAODQVQQGGxsvO2cM847IFJu96BbbxOLaZJ536RE980c2a9q/9
+B4hOYzKV4B4NI03u5/BqoOY8/SkoMTp1NjQ6ZIvWN1fksXhQMypVTLg8R81igqS3
+GXKmQ+KrVEfTIHnXKxH7tyfDeJSS6nfpfARhAe2mP3TIrbjX+9PR+QmkgykpKQ==
+=dUou
+-----END PGP ARMORED FILE-----
diff --git a/tests/openpgp/privkeys/ADE710D74409777B7729A7653373D820F67892E0.asc b/tests/openpgp/privkeys/ADE710D74409777B7729A7653373D820F67892E0.asc
new file mode 100644 (file)
index 0000000..8a4fbf6
--- /dev/null
@@ -0,0 +1,17 @@
+-----BEGIN PGP ARMORED FILE-----
+Version: GnuPG v2
+Comment: Use "gpg --dearmor" for unpacking
+
+KDExOnByaXZhdGUta2V5KDM6cnNhKDE6bjEyOToA5Hj2C3jzD8OGtLaw7+P2gYdA
+fR4s4YS3/AK+kYYtbm5EX4srysyUbylbQDQXUvRzw4FPkjXbboF6KjHw8icNWHCa
+zwSfPTfCDvi0JIildkfNqwBzCmNDRn++X8rvAeDCEJ/BtfcgfgmDTElSJOd+3B4X
+wnmtnBW54KlR42PLobspKDE6ZTM6AQABKSgxOmQxMjg6AkvpIaKimXAwf3G1m1nl
++LEDKdo55gosry8XToQakvdeXyUerCkplTS1uax8smOQUvrIPYvvnQZ7S9wuPli3
+FWH6l/O+2Cgdti99xTSPeJRBeCuf2vv3bAgu/0tyB8MZgRRM9j5NJCeGO7o4DwRg
+UkLWX2+R5p4daI2LRUfmV4EpKDE6cDY1OgDr3h6mXHrLT4qSNexzz8BAvK/PlHMA
+MAJcy76lXSkl92+c4BcpjFDr5Vpaq/VXoLC4L/IlnEEqY967pAycdLH7KSgxOnE2
+NToA9/lAf6hJ4dHQ6ux5BH8DImq2OjW+sK3tIzzf6fpVkPjDuqOYidm+OL2SFCJa
+ymSWdVq2gQYbkcdRXdGKVJWDQSkoMTp1NjQ6NeHBLEuc/VX+h3ifO1jyMlh+9nZs
+HLkQzUyi2HnrXJ224cjvgc312wvtBQMUyLARWuEuMVMAwWofjX+GZXLz0ikpKQ==
+=Rw+Y
+-----END PGP ARMORED FILE-----
diff --git a/tests/openpgp/privkeys/CEFC51AF91F68A2904FBFF62C4F075A4785B803F.asc b/tests/openpgp/privkeys/CEFC51AF91F68A2904FBFF62C4F075A4785B803F.asc
new file mode 100644 (file)
index 0000000..224ce95
--- /dev/null
@@ -0,0 +1,17 @@
+-----BEGIN PGP ARMORED FILE-----
+Version: GnuPG v2
+Comment: Use "gpg --dearmor" for unpacking
+
+KDExOnByaXZhdGUta2V5KDM6cnNhKDE6bjEyOToAvkUCG0xYaTIkZiTwd1wCUF8a
+Q2+YdrBGjSfzCyB8DzbPozYA29eOAayDg9RuesQGISmFQ6YRSINsAogdNfZmKu8j
+VMp/2mRQR6necW4OKkdtdnAI8B6Qaj/clBJt990RahXcrXG13fa0n72TpRbxmUUs
+Y4KRpbCRm44rR9AAWPspKDE6ZTM6AQABKSgxOmQxMjg6IvI/yc3C60dXYh9kvzd6
+AVMGWt5zTVFhE+oDfMaxooW5q0tu6vHzViFeYmcxB4FbctnSbTNiN0RUIT7oxpGE
+AAumKRejGAaMwiKZz3bMV05l0LI0Yn10GzXsLtRx+iKzpUxThZETRU43BJeMqP5/
+rVqdQAu47pClgTwQWn6bXNkpKDE6cDY1OgDXtvl8CYDL/Q+9qZDCyItE5j7X4wRV
+en939fdDepuYAgsLLc7yqnDUOzajXWyx6PxygpnRs5cwmo2zbtZyyWKFKSgxOnE2
+NToA4c2I2FZT8gQLl9E3LF8TkBACZzsGb/t3mBUhYNSNZ7W6R/AkZARLI3IZOto5
+xhBrxfQayRISS2PBk390z3JlfykoMTp1NjQ6TamsumtzX7waNMzurt48kluI5Zy9
+isGpweGpp1T+4L+DiXMMAbhFW60gdqqo4+vzkn2M/M/8BPrKCw1TlDn3TSkpKQ==
+=lYo+
+-----END PGP ARMORED FILE-----
diff --git a/tests/openpgp/samplekeys/E657FB607BB4F21C90BB6651BC067AF28BC90111.asc b/tests/openpgp/samplekeys/E657FB607BB4F21C90BB6651BC067AF28BC90111.asc
new file mode 100644 (file)
index 0000000..a4772d4
--- /dev/null
@@ -0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ZGzS5+11BFIY5B97hw2DBzHcgG+2Ca5NxAg6p5q9+FVfxfx+Q
+R+w+gIhZLZdUqVE3Mz8QcbzzZSeI6D5k5vmoX4Psy/uKVburSITNCwARAQABiQE9
+BBgBCAAJBQJWX26cAhsCAKgJELwGevKLyQERnSAEGQEIAAYFAlZfbpwACgkQvKQ8
+RB6pdHlhowQA2zOO2inuV/Z4Hl5PCDljiChFrKlddXkkdD7vXbdRh2XrQXMttmWW
+9a2NoeYsI4GyRb0T9fT0c7hDgY1NY3k+UHB+ex33xH7X6YADW8mY01q2zJqec9IY
+P2eBAHZrHImlBGStWX+VVHGtZwsDvR/gxkZkYnN1GFPN2ll0z81O0CjjWAP/delj
+0OY6Vc00SxfKJPb1ralpLIEMgRJWOayISHt6J4L1EGVVFs3gs9dqBQQ++65Iw55L
+m4+nieZzExTvSvYVBRbdWBgIJ1mFElHEy2KfeWzMA88pTMBssmH3xIGlkub/guWc
+OZSqAC5pVGPYCcXie7mx1k+5DrnQUgaf11zdvzI=
+=Htgs
+-----END PGP PUBLIC KEY BLOCK-----
index 0d9490a..20d9f51 100644 (file)
@@ -13,3 +13,4 @@ dda252ebb8ebe1af-2.asc rsa4096 key 2 with a long keyid collision.
 whats-new-in-2.1.asc   Collection of sample keys.
 e2e-p256-1-clr.asc     Google End-end-End test key (no protection)
 e2e-p256-1-prt.asc     Ditto, but protected with passphrase "a".
+E657FB607BB4F21C90BB6651BC067AF28BC90111.asc Key with subkeys (no protection)
diff --git a/tests/openpgp/use-exact-key.test b/tests/openpgp/use-exact-key.test
new file mode 100755 (executable)
index 0000000..cbbd009
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+. $srcdir/defs.inc || exit 3
+
+# set -x
+
+# Make sure $srcdir is set.
+if test "x$srcdir" = x
+then
+    echo srcdir environment variable not set!
+    exit 1
+fi
+
+# Import the sample key
+#
+# pub   1024R/8BC90111 2015-12-02
+#       Key fingerprint = E657 FB60 7BB4 F21C 90BB  6651 BC06 7AF2 8BC9 0111
+# uid       [ultimate] Barrett Brown <barrett@example.org>
+# sub   1024R/3E880CFF 2015-12-02 (encryption)
+# sub   1024R/F5F77B83 2015-12-02 (signing)
+# sub   1024R/45117079 2015-12-02 (encryption)
+# sub   1024R/1EA97479 2015-12-02 (signing)
+info "Importing public key."
+if $GPG --import $srcdir/samplekeys/E657FB607BB4F21C90BB6651BC067AF28BC90111.asc
+then
+    :
+else
+    error "$k: import failed"
+fi
+
+# By default, the most recent, valid signing subkey (1EA97479).
+for x in 8BC90111 3E880CFF F5F77B83 45117079 1EA97479
+do
+    if ! echo | $GPG -s -u "$x" | $GPG --verify --status-fd=1 \
+            | grep -q 'VALIDSIG 5FBA84ACE02DCB17DA3DFF6BBCA43C441EA97479'
+    then
+        echo | $GPG -s -u "$x" | $GPG --verify --status-fd=2
+        error "Unexpected key used for signing (not the signing subkey, specified \"$x\")."
+        exit 1
+    fi
+done
+
+# But, if we request a particular signing key, we should get it.
+for x in 8BC90111 F5F77B83 1EA97479
+do
+    if ! echo | $GPG -s -u "$x!" | $GPG --verify --status-fd=1 \
+            | grep -q "VALIDSIG [0-9A-F]*$x "
+    then
+        echo | $GPG -s -u "$x!" | $GPG --verify --status-fd=2
+        error "Unexpected key used for signing (specified: \"$x!\")."
+        exit 1
+    fi
+done
+
+exit 0
index 057bcf0..cb3ffa8 100755 (executable)
@@ -74,7 +74,12 @@ for i in 50B2D4FA4122C212611048BC5FC31BD44393626E \
          0D6F6AD4C4C803B25470F9104E9F4E6A4CA64255 \
          FD692BD59D6640A84C8422573D469F84F3B98E53 \
          76F7E2B35832976B50A27A282D9B87E44577EB66 \
-         A0747D5F9425E6664F4FFBEED20FBCA79FDED2BD ; do
+         A0747D5F9425E6664F4FFBEED20FBCA79FDED2BD \
+         00FE67F28A52A8AA08FFAED20AF832DA916D1985 \
+         1DF48228FEFF3EC2481B106E0ACA8C465C662CC5 \
+         A2832820DC9F40751BDCD375BB0945BA33EC6B4C \
+         ADE710D74409777B7729A7653373D820F67892E0 \
+         CEFC51AF91F68A2904FBFF62C4F075A4785B803F; do
    $GPG --dearmor < $srcdir/privkeys/$i.asc > private-keys-v1.d/$i.key
 done