LCOV - code coverage report
Current view: top level - tests/gpg - t-keylist.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 117 285 41.1 %
Date: 2018-11-15 08:49:49 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* t-keylist.c  - regression test
       2             :    Copyright (C) 2000 Werner Koch (dd9jn)
       3             :    Copyright (C) 2001, 2003, 2004 g10 Code GmbH
       4             : 
       5             :    This file is part of GPGME.
       6             : 
       7             :    GPGME is free software; you can redistribute it and/or modify it
       8             :    under the terms of the GNU Lesser General Public License as
       9             :    published by the Free Software Foundation; either version 2.1 of
      10             :    the License, or (at your option) any later version.
      11             : 
      12             :    GPGME is distributed in the hope that it will be useful, but
      13             :    WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :    Lesser General Public License for more details.
      16             : 
      17             :    You should have received a copy of the GNU Lesser General Public
      18             :    License along with this program; if not, write to the Free Software
      19             :    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
      20             :    02111-1307, USA.  */
      21             : 
      22             : /* We need to include config.h so that we know whether we are building
      23             :    with large file system (LFS) support. */
      24             : #ifdef HAVE_CONFIG_H
      25             : #include <config.h>
      26             : #endif
      27             : 
      28             : #include <stdlib.h>
      29             : #include <stdio.h>
      30             : #include <string.h>
      31             : 
      32             : #include <gpgme.h>
      33             : 
      34             : #include "t-support.h"
      35             : 
      36             : 
      37             : struct key_info_s
      38             : {
      39             :   const char *fpr;
      40             :   const char *sec_keyid;
      41             :   struct
      42             :   {
      43             :     const char *name;
      44             :     const char *comment;
      45             :     const char *email;
      46             :   } uid[3];
      47             :   int n_subkeys;
      48             :   void (*misc_check)(struct key_info_s *keyinfo, gpgme_key_t key);
      49             : };
      50             : 
      51             : 
      52             : static void check_whisky (struct key_info_s *keyinfo, gpgme_key_t key);
      53             : 
      54             : 
      55             : 
      56             : struct key_info_s keys[] =
      57             :   {
      58             :     { "A0FF4590BB6122EDEF6E3C542D727CC768697734", "6AE6D7EE46A871F8",
      59             :       { { "Alfa Test", "demo key", "alfa@example.net" },
      60             :         { "Alpha Test", "demo key", "alpha@example.net" },
      61             :         { "Alice", "demo key", NULL } }, 1 },
      62             :     { "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", "5381EA4EE29BA37F",
      63             :       { { "Bob", "demo key", NULL },
      64             :         { "Bravo Test", "demo key", "bravo@example.net" } }, 1 },
      65             :     { "61EE841A2A27EB983B3B3C26413F4AF31AFDAB6C", "E71E72ACBC43DA60",
      66             :       { { "Charlie Test", "demo key", "charlie@example.net" } }, 1 },
      67             :     { "6560C59C43D031C54D7C588EEBA9F240EB9DC9E6", "06F22880B0C45424",
      68             :       { { "Delta Test", "demo key", "delta@example.net" } }, 1 },
      69             :     { "3531152DE293E26A07F504BC318C1FAEFAEF6D1B", "B5C79E1A7272144D",
      70             :       { { "Echelon", "demo key", NULL },
      71             :         { "Echo Test", "demo key", "echo@example.net" },
      72             :         { "Eve", "demo key", NULL } }, 1 },
      73             :     { "56D33268F7FE693FBB594762D4BF57F37372E243", "0A32EE79EE45198E",
      74             :       { { "Foxtrot Test", "demo key", "foxtrot@example.net" } }, 1 },
      75             :     { "C9C07DCC6621B9FB8D071B1D168410A48FC282E6", "247491CC9DCAD354",
      76             :       { { "Golf Test", "demo key", "golf@example.net" } }, 1 },
      77             :     { "9E91CBB11E4D4135583EF90513DB965534C6E3F1", "76E26537D622AD0A",
      78             :       { { "Hotel Test", "demo key", "hotel@example.net" } }, 1 },
      79             :     { "CD538D6CC9FB3D745ECDA5201FE8FC6F04259677", "C1C8EFDE61F76C73",
      80             :       { { "India Test", "demo key", "india@example.net" } }, 1 },
      81             :     { "F8F1EDC73995AB739AD54B380C820C71D2699313", "BD0B108735F8F136",
      82             :       { { "Juliet Test", "demo key", "juliet@example.net" } }, 1 },
      83             :     { "3FD11083779196C2ECDD9594AD1B0FAD43C2D0C7", "86CBB34A9AF64D02",
      84             :       { { "Kilo Test", "demo key", "kilo@example.net" } }, 1 },
      85             :     { "1DDD28CEF714F5B03B8C246937CAB51FB79103F8", "0363B449FE56350C",
      86             :       { { "Lima Test", "demo key", "lima@example.net" } }, 1 },
      87             :     { "2686AA191A278013992C72EBBE794852BE5CF886", "5F600A834F31EAE8",
      88             :       { { "Mallory", "demo key", NULL },
      89             :         { "Mike Test", "demo key", "mike@example.net" } }, 1 },
      90             :     { "5AB9D6D7BAA1C95B3BAA3D9425B00FD430CEC684", "4C1D63308B70E472",
      91             :       { { "November Test", "demo key", "november@example.net" } }, 1 },
      92             :     { "43929E89F8F79381678CAE515F6356BA6D9732AC", "FF0785712681619F",
      93             :       { { "Oscar Test", "demo key", "oscar@example.net" } }, 1 },
      94             :     { "6FAA9C201E5E26DCBAEC39FD5D15E01D3FF13206", "2764E18263330D9C",
      95             :       { { "Papa test", "demo key", "papa@example.net" } }, 1 },
      96             :     { "A7969DA1C3297AA96D49843F1C67EC133C661C84", "6CDCFC44A029ACF4",
      97             :       { { "Quebec Test", "demo key", "quebec@example.net" } }, 1 },
      98             :     { "38FBE1E4BF6A5E1242C8F6A13BDBEDB1777FBED3", "9FAB805A11D102EA",
      99             :       { { "Romeo Test", "demo key", "romeo@example.net" } }, 1 },
     100             :     { "045B2334ADD69FC221076841A5E67F7FA3AE3EA1", "93B88B0F0F1B50B4",
     101             :       { { "Sierra Test", "demo key", "sierra@example.net" } }, 1 },
     102             :     { "ECAC774F4EEEB0620767044A58CB9A4C85A81F38", "97B60E01101C0402",
     103             :       { { "Tango Test", "demo key", "tango@example.net" } }, 1 },
     104             :     { "0DBCAD3F08843B9557C6C4D4A94C0F75653244D6", "93079B915522BDB9",
     105             :       { { "Uniform Test", "demo key", "uniform@example.net" } }, 1 },
     106             :     { "E8143C489C8D41124DC40D0B47AF4B6961F04784", "04071FB807287134",
     107             :       { { "Victor Test", "demo key", "victor@example.org" } }, 1 },
     108             :     { "E8D6C90B683B0982BD557A99DEF0F7B8EC67DBDE", "D7FBB421FD6E27F6",
     109             :       { { "Whisky Test", "demo key", "whisky@example.net" } }, 3,
     110             :           check_whisky },
     111             :     { "04C1DF62EFA0EBB00519B06A8979A6C5567FB34A", "5CC6F87F41E408BE",
     112             :       { { "XRay Test", "demo key", "xray@example.net" } }, 1 },
     113             :     { "ED9B316F78644A58D042655A9EEF34CD4B11B25F", "5ADFD255F7B080AD",
     114             :       { { "Yankee Test", "demo key", "yankee@example.net" } }, 1 },
     115             :     { "23FD347A419429BACCD5E72D6BC4778054ACD246", "EF9DC276A172C881",
     116             :       { { "Zulu Test", "demo key", "zulu@example.net" } }, 1 },
     117             :     { "ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55", "087DD7E0381701C4",
     118             :       { { "Joe Random Hacker", "test key with passphrase \"abc\"",
     119             :           "joe@example.com" } }, 1 },
     120             :     { NULL }
     121             :   };
     122             : 
     123             : 
     124             : int
     125           1 : main (int argc, char **argv)
     126             : {
     127             :   gpgme_error_t err;
     128             :   gpgme_ctx_t ctx;
     129             :   gpgme_key_t key;
     130             :   gpgme_keylist_result_t result;
     131           1 :   int i = 0;
     132             :   int n;
     133             :   gpgme_subkey_t subkey;
     134             : 
     135             :   (void)argc;
     136             :   (void)argv;
     137             : 
     138           1 :   init_gpgme (GPGME_PROTOCOL_OpenPGP);
     139             : 
     140           1 :   err = gpgme_new (&ctx);
     141           1 :   fail_if_err (err);
     142             : 
     143           1 :   err = gpgme_op_keylist_start (ctx, NULL, 0);
     144           1 :   fail_if_err (err);
     145             : 
     146          29 :   while (!(err = gpgme_op_keylist_next (ctx, &key)))
     147             :     {
     148          27 :       if (!keys[i].fpr)
     149             :         {
     150           0 :           fprintf (stderr, "More keys returned than expected\n");
     151           0 :           exit (1);
     152             :         }
     153             : 
     154             :       /* Global key flags.  */
     155          27 :       if (key->revoked)
     156             :         {
     157           0 :           fprintf (stderr, "Key unexpectedly revoked\n");
     158           0 :           exit (1);
     159             :         }
     160          27 :       if (key->expired)
     161             :         {
     162           0 :           fprintf (stderr, "Key unexpectedly expired\n");
     163           0 :           exit (1);
     164             :         }
     165          27 :       if (key->disabled)
     166             :         {
     167           0 :           fprintf (stderr, "Key unexpectedly disabled\n");
     168           0 :           exit (1);
     169             :         }
     170          27 :       if (key->invalid)
     171             :         {
     172           0 :           fprintf (stderr, "Key unexpectedly invalid\n");
     173           0 :           exit (1);
     174             :         }
     175             : #if 0
     176             :       /* GnuPG 2.1+ have a different subkey for encryption.  */
     177             :       if (!key->can_encrypt)
     178             :         {
     179             :           fprintf (stderr, "Key unexpectedly unusable for encryption\n");
     180             :           exit (1);
     181             :         }
     182             : #endif
     183          27 :       if (!key->can_sign)
     184             :         {
     185           0 :           fprintf (stderr, "Key unexpectedly unusable for signing\n");
     186           0 :           exit (1);
     187             :         }
     188          27 :       if (!key->can_certify)
     189             :         {
     190           0 :           fprintf (stderr, "Key unexpectedly unusable for certifications\n");
     191           0 :           exit (1);
     192             :         }
     193          27 :       if (key->secret)
     194             :         {
     195           0 :           fprintf (stderr, "Key unexpectedly secret\n");
     196           0 :           exit (1);
     197             :         }
     198          27 :       if (key->protocol != GPGME_PROTOCOL_OpenPGP)
     199             :         {
     200           0 :           fprintf (stderr, "Key has unexpected protocol: %s\n",
     201           0 :                    gpgme_get_protocol_name (key->protocol));
     202           0 :           exit (1);
     203             :         }
     204          27 :       if (key->issuer_serial)
     205             :         {
     206           0 :           fprintf (stderr, "Key unexpectedly carries issuer serial: %s\n",
     207           0 :                    key->issuer_serial);
     208           0 :           exit (1);
     209             :         }
     210          27 :       if (key->issuer_name)
     211             :         {
     212           0 :           fprintf (stderr, "Key unexpectedly carries issuer name: %s\n",
     213           0 :                    key->issuer_name);
     214           0 :           exit (1);
     215             :         }
     216          27 :       if (key->chain_id)
     217             :         {
     218           0 :           fprintf (stderr, "Key unexpectedly carries chain ID: %s\n",
     219           0 :                    key->chain_id);
     220           0 :           exit (1);
     221             :         }
     222          27 :       if (key->owner_trust != GPGME_VALIDITY_UNKNOWN)
     223             :         {
     224           0 :           fprintf (stderr, "Key has unexpected owner trust: %i\n",
     225           0 :                    key->owner_trust);
     226           0 :           exit (1);
     227             :         }
     228             : 
     229          83 :       for (n=0, subkey = key->subkeys; subkey; subkey = subkey->next)
     230          56 :         n++;
     231          27 :       if (!n || n-1 != keys[i].n_subkeys)
     232             :         {
     233           0 :           fprintf (stderr, "Key `%s' has unexpected number of subkeys\n",
     234             :                    keys[i].uid[0].name);
     235           0 :           exit (1);
     236             :         }
     237             : 
     238             :       /* Primary key.  */
     239          27 :       if (key->subkeys->revoked)
     240             :         {
     241           0 :           fprintf (stderr, "Primary key unexpectedly revoked\n");
     242           0 :           exit (1);
     243             :         }
     244          27 :       if (key->subkeys->expired)
     245             :         {
     246           0 :           fprintf (stderr, "Primary key unexpectedly expired\n");
     247           0 :           exit (1);
     248             :         }
     249          27 :       if (key->subkeys->disabled)
     250             :         {
     251           0 :           fprintf (stderr, "Primary key unexpectedly disabled\n");
     252           0 :           exit (1);
     253             :         }
     254          27 :       if (key->subkeys->invalid)
     255             :         {
     256           0 :           fprintf (stderr, "Primary key unexpectedly invalid\n");
     257           0 :           exit (1);
     258             :         }
     259          27 :       if (key->subkeys->can_encrypt)
     260             :         {
     261           0 :           fprintf (stderr, "Primary key unexpectedly usable for encryption\n");
     262           0 :           exit (1);
     263             :         }
     264          27 :       if (!key->subkeys->can_sign)
     265             :         {
     266           0 :           fprintf (stderr, "Primary key unexpectedly unusable for signing\n");
     267           0 :           exit (1);
     268             :         }
     269          27 :       if (!key->subkeys->can_certify)
     270             :         {
     271           0 :           fprintf (stderr, "Primary key unexpectedly unusable for certifications\n");
     272           0 :           exit (1);
     273             :         }
     274          27 :       if (key->subkeys->secret)
     275             :         {
     276           0 :           fprintf (stderr, "Primary key unexpectedly secret\n");
     277           0 :           exit (1);
     278             :         }
     279          27 :       if (key->subkeys->is_cardkey)
     280             :         {
     281           0 :           fprintf (stderr, "Public key marked as card key\n");
     282           0 :           exit (1);
     283             :         }
     284          27 :       if (key->subkeys->card_number)
     285             :         {
     286           0 :           fprintf (stderr, "Public key with card number set\n");
     287           0 :           exit (1);
     288             :         }
     289          27 :       if (key->subkeys->pubkey_algo != GPGME_PK_DSA)
     290             :         {
     291           0 :           fprintf (stderr, "Primary key has unexpected public key algo: %s\n",
     292           0 :                    gpgme_pubkey_algo_name (key->subkeys->pubkey_algo));
     293           0 :           exit (1);
     294             :         }
     295          27 :       if (key->subkeys->length != 1024)
     296             :         {
     297           0 :           fprintf (stderr, "Primary key has unexpected length: %i\n",
     298           0 :                    key->subkeys->length);
     299           0 :           exit (1);
     300             :         }
     301          27 :       if (strcmp (key->subkeys->keyid, &keys[i].fpr[40 - 16]))
     302             :         {
     303           0 :           fprintf (stderr, "Primary key `%s' has unexpected key ID: %s\n",
     304           0 :                    keys[i].uid[0].name, key->subkeys->keyid);
     305           0 :           exit (1);
     306             :         }
     307          27 :       if (strcmp (key->subkeys->fpr, keys[i].fpr))
     308             :         {
     309           0 :           fprintf (stderr, "Primary key has unexpected fingerprint: %s\n",
     310           0 :                    key->subkeys->fpr);
     311           0 :           exit (1);
     312             :         }
     313          27 :       if (key->subkeys->expires)
     314             :         {
     315           0 :           fprintf (stderr, "Primary key `%s' unexpectedly expires: %lu\n",
     316           0 :                    keys[i].uid[0].name, key->subkeys->expires);
     317           0 :           exit (1);
     318             :         }
     319             : 
     320             :       /* Secondary key.  */
     321          27 :       if (key->subkeys->next->revoked)
     322             :         {
     323           0 :           fprintf (stderr, "Secondary key unexpectedly revoked\n");
     324           0 :           exit (1);
     325             :         }
     326          27 :       if (key->subkeys->next->expired)
     327             :         {
     328           0 :           fprintf (stderr, "Secondary key unexpectedly expired\n");
     329           0 :           exit (1);
     330             :         }
     331          27 :       if (key->subkeys->next->disabled)
     332             :         {
     333           0 :           fprintf (stderr, "Secondary key unexpectedly disabled\n");
     334           0 :           exit (1);
     335             :         }
     336          27 :       if (key->subkeys->next->invalid)
     337             :         {
     338           0 :           fprintf (stderr, "Secondary key unexpectedly invalid\n");
     339           0 :           exit (1);
     340             :         }
     341          27 :       if (!key->subkeys->next->can_encrypt)
     342             :         {
     343           0 :           fprintf (stderr, "Secondary key unexpectedly unusable for encryption\n");
     344           0 :           exit (1);
     345             :         }
     346          27 :       if (key->subkeys->next->can_sign)
     347             :         {
     348           0 :           fprintf (stderr, "Secondary key unexpectedly usable for signing\n");
     349           0 :           exit (1);
     350             :         }
     351          27 :       if (key->subkeys->next->can_certify)
     352             :         {
     353           0 :           fprintf (stderr, "Secondary key unexpectedly usable for certifications\n");
     354           0 :           exit (1);
     355             :         }
     356          27 :       if (key->subkeys->next->secret)
     357             :         {
     358           0 :           fprintf (stderr, "Secondary key unexpectedly secret\n");
     359           0 :           exit (1);
     360             :         }
     361          27 :       if (key->subkeys->next->is_cardkey)
     362             :         {
     363           0 :           fprintf (stderr, "Secondary public key marked as card key\n");
     364           0 :           exit (1);
     365             :         }
     366          27 :       if (key->subkeys->next->card_number)
     367             :         {
     368           0 :           fprintf (stderr, "Secondary public key with card number set\n");
     369           0 :           exit (1);
     370             :         }
     371          27 :       if (key->subkeys->next->pubkey_algo != GPGME_PK_ELG_E)
     372             :         {
     373           0 :           fprintf (stderr, "Secondary key has unexpected public key algo: %s\n",
     374           0 :                    gpgme_pubkey_algo_name (key->subkeys->next->pubkey_algo));
     375           0 :           exit (1);
     376             :         }
     377          27 :       if (key->subkeys->next->length != 1024)
     378             :         {
     379           0 :           fprintf (stderr, "Secondary key has unexpected length: %i\n",
     380           0 :                    key->subkeys->next->length);
     381           0 :           exit (1);
     382             :         }
     383          27 :       if (strcmp (key->subkeys->next->keyid, keys[i].sec_keyid))
     384             :         {
     385           0 :           fprintf (stderr, "Secondary key `%s' has unexpected key ID: %s/%s\n",
     386             :                    keys[i].uid[0].name,
     387           0 :                    key->subkeys->next->keyid, keys[i].sec_keyid );
     388           0 :           exit (1);
     389             :         }
     390          27 :       if (!key->subkeys->next->fpr)
     391             :         {
     392           0 :           fprintf (stderr, "Secondary key has unexpectedly no fingerprint\n");
     393           0 :           exit (1);
     394             :         }
     395          27 :       if (key->subkeys->next->expires)
     396             :         {
     397           0 :           fprintf (stderr, "Secondary key unexpectedly expires: %lu\n",
     398           0 :                    key->subkeys->next->expires);
     399           0 :           exit (1);
     400             :         }
     401             : 
     402             :       /* FIXME: The below test will crash if we want to check for a
     403             :          name, comment or email that doesn't exist in the key's user
     404             :          IDs.  */
     405          29 :       if (!((!keys[i].uid[0].name && !key->uids)
     406          27 :             || (keys[i].uid[0].name && !keys[i].uid[1].name
     407          23 :                 && key->uids && !key->uids->next)
     408           4 :             || (keys[i].uid[0].name && keys[i].uid[1].name
     409           4 :                 && !keys[i].uid[2].name
     410           2 :                 && key->uids && key->uids->next && !key->uids->next->next)
     411           4 :             || (keys[i].uid[0].name && keys[i].uid[1].name
     412           2 :                 && keys[i].uid[2].name
     413           2 :                 && key->uids && key->uids->next && key->uids->next->next
     414           2 :                 && !key->uids->next->next->next)))
     415             :           {
     416           0 :             fprintf (stderr, "Key has unexpected number of user IDs\n");
     417           0 :             exit (1);
     418             :           }
     419          27 :       if (key->uids && key->uids->revoked)
     420             :         {
     421           0 :           fprintf (stderr, "First user ID unexpectedly revoked\n");
     422           0 :           exit (1);
     423             :         }
     424          27 :       if (key->uids && key->uids->invalid)
     425             :         {
     426           0 :           fprintf (stderr, "First user ID unexpectedly invalid\n");
     427           0 :           exit (1);
     428             :         }
     429          27 :       if (key->uids && key->uids->validity != GPGME_VALIDITY_UNKNOWN)
     430             :         {
     431           0 :           fprintf (stderr, "First user ID has unexpectedly validity: %i\n",
     432           0 :                    key->uids->validity);
     433           0 :           exit (1);
     434             :         }
     435          27 :       if (key->uids && key->uids->signatures)
     436             :         {
     437           0 :           fprintf (stderr, "First user ID unexpectedly signed\n");
     438           0 :           exit (1);
     439             :         }
     440          27 :       if (keys[i].uid[0].name
     441          27 :           && strcmp (keys[i].uid[0].name, key->uids->name))
     442             :         {
     443           0 :           fprintf (stderr, "Unexpected name in first user ID: %s\n",
     444           0 :                    key->uids->name);
     445           0 :           exit (1);
     446             :         }
     447          27 :       if (keys[i].uid[0].comment
     448          27 :           && strcmp (keys[i].uid[0].comment, key->uids->comment))
     449             :         {
     450           0 :           fprintf (stderr, "Unexpected comment in first user ID: %s\n",
     451           0 :                    key->uids->comment);
     452           0 :           exit (1);
     453             :         }
     454          27 :       if (keys[i].uid[0].email
     455          24 :           && strcmp (keys[i].uid[0].email, key->uids->email))
     456             :         {
     457           0 :           fprintf (stderr, "Unexpected email in first user ID: %s\n",
     458           0 :                    key->uids->email);
     459           0 :           exit (1);
     460             :         }
     461          27 :       if (key->uids && key->uids->next && key->uids->next->revoked)
     462             :         {
     463           0 :           fprintf (stderr, "Second user ID unexpectedly revoked\n");
     464           0 :           exit (1);
     465             :         }
     466          27 :       if (key->uids && key->uids->next && key->uids->next->invalid)
     467             :         {
     468           0 :           fprintf (stderr, "Second user ID unexpectedly invalid\n");
     469           0 :           exit (1);
     470             :         }
     471          27 :       if (key->uids && key->uids->next
     472           4 :           && key->uids->next->validity != GPGME_VALIDITY_UNKNOWN)
     473             :         {
     474           0 :           fprintf (stderr, "Second user ID has unexpectedly validity: %i\n",
     475           0 :                    key->uids->next->validity);
     476           0 :           exit (1);
     477             :         }
     478          27 :       if (key->uids && key->uids->next && key->uids->next->signatures)
     479             :         {
     480           0 :           fprintf (stderr, "Second user ID unexpectedly signed\n");
     481           0 :           exit (1);
     482             :         }
     483          27 :       if (keys[i].uid[1].name
     484           4 :           && strcmp (keys[i].uid[1].name, key->uids->next->name))
     485             :         {
     486           0 :           fprintf (stderr, "Unexpected name in second user ID: %s\n",
     487           0 :                    key->uids->next->name);
     488           0 :           exit (1);
     489             :         }
     490          27 :       if (keys[i].uid[1].comment
     491           4 :           && strcmp (keys[i].uid[1].comment, key->uids->next->comment))
     492             :         {
     493           0 :           fprintf (stderr, "Unexpected comment in second user ID: %s\n",
     494           0 :                    key->uids->next->comment);
     495           0 :           exit (1);
     496             :         }
     497          27 :       if (keys[i].uid[1].email
     498           4 :           && strcmp (keys[i].uid[1].email, key->uids->next->email))
     499             :         {
     500           0 :           fprintf (stderr, "Unexpected email in second user ID: %s\n",
     501           0 :                    key->uids->next->email);
     502           0 :           exit (1);
     503             :         }
     504          27 :       if (key->uids && key->uids->next && key->uids->next->next
     505           2 :           && key->uids->next->next->revoked)
     506             :         {
     507           0 :           fprintf (stderr, "Third user ID unexpectedly revoked\n");
     508           0 :           exit (1);
     509             :         }
     510          27 :       if (key->uids && key->uids->next && key->uids->next->next
     511           2 :           && key->uids->next->next->invalid)
     512             :         {
     513           0 :           fprintf (stderr, "Third user ID unexpectedly invalid\n");
     514           0 :           exit (1);
     515             :         }
     516          27 :       if (key->uids && key->uids->next && key->uids->next->next
     517           2 :           && key->uids->next->next->validity != GPGME_VALIDITY_UNKNOWN)
     518             :         {
     519           0 :           fprintf (stderr, "Third user ID has unexpectedly validity: %i\n",
     520           0 :                    key->uids->next->next->validity);
     521           0 :           exit (1);
     522             :         }
     523          27 :       if (key->uids && key->uids->next && key->uids->next->next
     524           2 :           && key->uids->next->next->signatures)
     525             :         {
     526           0 :           fprintf (stderr, "Third user ID unexpectedly signed\n");
     527           0 :           exit (1);
     528             :         }
     529          27 :       if (keys[i].uid[2].name
     530           2 :           && strcmp (keys[i].uid[2].name, key->uids->next->next->name))
     531             :         {
     532           0 :           fprintf (stderr, "Unexpected name in third user ID: %s\n",
     533           0 :                    key->uids->next->next->name);
     534           0 :           exit (1);
     535             :         }
     536          27 :       if (keys[i].uid[2].comment
     537           2 :           && strcmp (keys[i].uid[2].comment, key->uids->next->next->comment))
     538             :         {
     539           0 :           fprintf (stderr, "Unexpected comment in third user ID: %s\n",
     540           0 :                    key->uids->next->next->comment);
     541           0 :           exit (1);
     542             :         }
     543          27 :       if (keys[i].uid[2].email
     544           0 :           && strcmp (keys[i].uid[2].email, key->uids->next->next->email))
     545             :         {
     546           0 :           fprintf (stderr, "Unexpected email in third user ID: %s\n",
     547           0 :                    key->uids->next->next->email);
     548           0 :           exit (1);
     549             :         }
     550             : 
     551          27 :       if (keys[i].misc_check)
     552           1 :         keys[i].misc_check (keys+i, key);
     553             : 
     554          27 :       gpgme_key_unref (key);
     555          27 :       i++;
     556             :     }
     557           1 :   if (gpgme_err_code (err) != GPG_ERR_EOF)
     558           0 :     fail_if_err (err);
     559           1 :   err = gpgme_op_keylist_end (ctx);
     560           1 :   fail_if_err (err);
     561             : 
     562           1 :   result = gpgme_op_keylist_result (ctx);
     563           1 :   if (result->truncated)
     564             :     {
     565           0 :       fprintf (stderr, "Key listing unexpectedly truncated\n");
     566           0 :       exit (1);
     567             :     }
     568             : 
     569           1 :   if (keys[i].fpr)
     570             :     {
     571           0 :       fprintf (stderr, "Less keys (%d) returned than expected (%d)\n",
     572             :                i, (int)(DIM (keys) - 1));
     573           0 :       exit (1);
     574             :     }
     575             : 
     576           1 :   gpgme_release (ctx);
     577           1 :   return 0;
     578             : }
     579             : 
     580             : 
     581             : 
     582             : /* Check expration of keys.  This test assumes three subkeys of which
     583             :    2 are expired; it is used with the "Whisky" test key.  It has
     584             :    already been checked that these 3 subkeys are available. */
     585             : static void
     586           1 : check_whisky (struct key_info_s *keyinfo, gpgme_key_t key)
     587             : {
     588           1 :   const char *name = keyinfo->uid[0].name;
     589             :   gpgme_subkey_t sub1, sub2;
     590             : 
     591           1 :   sub1 = key->subkeys->next->next;
     592           1 :   sub2 = sub1->next;
     593             : 
     594           1 :   if (!sub1->expired || !sub2->expired)
     595             :     {
     596           0 :       fprintf (stderr, "Subkey of `%s' not flagged as expired\n", name);
     597           0 :       exit (1);
     598             :     }
     599           1 :   if (sub1->expires != 1129636886 || sub2->expires != 1129636939)
     600             :     {
     601           0 :       fprintf (stderr, "Subkey of `%s' has wrong expiration date\n", name);
     602           0 :       exit (1);
     603             :     }
     604             : 
     605           1 : }
     606             : 

Generated by: LCOV version 1.13