Daiki Ueno <[email protected]> writes:

> BTW, I'm wondering if there is any reason why the validity field (Field
> 2 of --with-colons output) is not used for secret keys.  It might be
> useful for the libraries which call gpg internally (epg.el I mean :) to
> check if a key is usable.

Actually, it looks that GPGME ignores the validity when listing keys
with SECRET_ONLY flag.  Here is a sample program:

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <gpgme.h>

static gpgme_error_t
list_key_validity (const char *pattern)
{
  gpgme_ctx_t ctx;
  gpgme_key_t key;
  gpgme_error_t err = gpgme_new (&ctx);
  int secret_only;

  if (err)
    goto out;

  for (secret_only = 0; secret_only < 2; secret_only++)
    {
      err = gpgme_op_keylist_start (ctx, pattern, secret_only);
      if (err)
        goto out;

      while (!err)
        {
          err = gpgme_op_keylist_next (ctx, &key);
          if (err)
            break;
          printf ("%s (%s) revoked = %d, expired = %d\n",
                  key->subkeys->keyid,
                  (secret_only ? "sec" : "pub"),
                  key->subkeys->revoked,
                  key->subkeys->expired);
          gpgme_key_release (key);
        }
      gpgme_op_keylist_end (ctx);
    }

 out:
  gpgme_release (ctx);
  return err;
}

int
main (int argc, char **argv)
{
  int i;

  if (argc < 2)
    {
      fprintf (stderr, "Usage: %s pattern...\n", argv[0]);
      exit (1);
    }

  setlocale (LC_ALL, "");
  gpgme_check_version (NULL);
  gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
#ifdef LC_MESSAGES
  gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
#endif

  for (i = 0; i < argc; i++)
    list_key_validity (argv[i]);

  return 0;
}

/*
 * Local variables:
 * compile-command: "gcc -o list-key-validity list-key-validity.c `gpgme-config 
--cflags --libs`"
 * End:
 */
I get:

$ ./list-key-validity A6CC6651 D1458906
084B0E86A6CC6651 (pub) revoked = 0, expired = 1
892F1451D1458906 (pub) revoked = 1, expired = 0
892F1451D1458906 (sec) revoked = 0, expired = 0

Maybe I'm missing some points of the OpenPGP concept.

Regards,
-- 
Daiki Ueno
_______________________________________________
Gnupg-users mailing list
[email protected]
http://lists.gnupg.org/mailman/listinfo/gnupg-users

Reply via email to