Give access to key capabilities
This commit is contained in:
parent
10b3a86f83
commit
5b561c2f11
@ -1,3 +1,20 @@
|
|||||||
|
2001-03-15 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
|
* rungpg.c: Included time.h.
|
||||||
|
|
||||||
|
* key.h: New keyflags for capabilities.
|
||||||
|
* keylist.c (set_mainkey_capability, set_subkey_capability): New.
|
||||||
|
(keylist_colon_handler): Parse them.
|
||||||
|
* gpgme.h: New attribute values for capabilties.
|
||||||
|
* key.c (gpgme_key_get_string_attr): Return them.
|
||||||
|
(capabilities_to_string): New.
|
||||||
|
(gpgme_key_get_ulong_attr): Return the global caps.
|
||||||
|
|
||||||
|
2001-03-14 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
|
* w32-io.c (destroy_reader,destroy_writer): Fixed syntax error.
|
||||||
|
Thanks to Jan Oliver Wagner.
|
||||||
|
|
||||||
2001-03-13 Werner Koch <wk@gnupg.org>
|
2001-03-13 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
* context.h: Add invalid and revoke flags to user_id structure.
|
* context.h: Add invalid and revoke flags to user_id structure.
|
||||||
|
@ -133,7 +133,11 @@ typedef enum {
|
|||||||
GPGME_ATTR_KEY_REVOKED = 16,
|
GPGME_ATTR_KEY_REVOKED = 16,
|
||||||
GPGME_ATTR_KEY_INVALID = 17,
|
GPGME_ATTR_KEY_INVALID = 17,
|
||||||
GPGME_ATTR_UID_REVOKED = 18,
|
GPGME_ATTR_UID_REVOKED = 18,
|
||||||
GPGME_ATTR_UID_INVALID = 19
|
GPGME_ATTR_UID_INVALID = 19,
|
||||||
|
GPGME_ATTR_KEY_CAPS = 20,
|
||||||
|
GPGME_ATTR_CAN_ENCRYPT = 21,
|
||||||
|
GPGME_ATTR_CAN_SIGN = 22,
|
||||||
|
GPGME_ATTR_CAN_CERTIFY = 23
|
||||||
} GpgmeAttr;
|
} GpgmeAttr;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
36
gpgme/key.c
36
gpgme/key.c
@ -455,6 +455,24 @@ gpgme_key_get_as_xml ( GpgmeKey key )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
capabilities_to_string (struct subkey_s *k)
|
||||||
|
{
|
||||||
|
static char *strings[8] = {
|
||||||
|
"",
|
||||||
|
"c",
|
||||||
|
"s",
|
||||||
|
"sc",
|
||||||
|
"e",
|
||||||
|
"ec",
|
||||||
|
"es",
|
||||||
|
"esc"
|
||||||
|
};
|
||||||
|
return strings[ (!!k->flags.can_encrypt << 2)
|
||||||
|
| (!!k->flags.can_sign << 1)
|
||||||
|
| (!!k->flags.can_certify ) ];
|
||||||
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
gpgme_key_get_string_attr ( GpgmeKey key, GpgmeAttr what,
|
gpgme_key_get_string_attr ( GpgmeKey key, GpgmeAttr what,
|
||||||
const void *reserved, int idx )
|
const void *reserved, int idx )
|
||||||
@ -536,11 +554,20 @@ gpgme_key_get_string_attr ( GpgmeKey key, GpgmeAttr what,
|
|||||||
case GPGME_ATTR_KEY_INVALID:
|
case GPGME_ATTR_KEY_INVALID:
|
||||||
case GPGME_ATTR_UID_REVOKED:
|
case GPGME_ATTR_UID_REVOKED:
|
||||||
case GPGME_ATTR_UID_INVALID:
|
case GPGME_ATTR_UID_INVALID:
|
||||||
|
case GPGME_ATTR_CAN_ENCRYPT:
|
||||||
|
case GPGME_ATTR_CAN_SIGN:
|
||||||
|
case GPGME_ATTR_CAN_CERTIFY:
|
||||||
break;
|
break;
|
||||||
case GPGME_ATTR_IS_SECRET:
|
case GPGME_ATTR_IS_SECRET:
|
||||||
if (key->secret)
|
if (key->secret)
|
||||||
val = "1";
|
val = "1";
|
||||||
break;
|
break;
|
||||||
|
case GPGME_ATTR_KEY_CAPS:
|
||||||
|
for (k=&key->keys; k && idx; k=k->next, idx-- )
|
||||||
|
;
|
||||||
|
if (k)
|
||||||
|
val = capabilities_to_string (k);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
@ -613,6 +640,15 @@ gpgme_key_get_ulong_attr ( GpgmeKey key, GpgmeAttr what,
|
|||||||
if (u)
|
if (u)
|
||||||
val = u->invalid;
|
val = u->invalid;
|
||||||
break;
|
break;
|
||||||
|
case GPGME_ATTR_CAN_ENCRYPT:
|
||||||
|
val = key->gloflags.can_encrypt;
|
||||||
|
break;
|
||||||
|
case GPGME_ATTR_CAN_SIGN:
|
||||||
|
val = key->gloflags.can_sign;
|
||||||
|
break;
|
||||||
|
case GPGME_ATTR_CAN_CERTIFY:
|
||||||
|
val = key->gloflags.can_encrypt;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,9 @@ struct subkey_s {
|
|||||||
unsigned int expired:1 ;
|
unsigned int expired:1 ;
|
||||||
unsigned int disabled:1 ;
|
unsigned int disabled:1 ;
|
||||||
unsigned int invalid:1 ;
|
unsigned int invalid:1 ;
|
||||||
|
unsigned int can_encrypt:1;
|
||||||
|
unsigned int can_sign:1;
|
||||||
|
unsigned int can_certify:1;
|
||||||
} flags;
|
} flags;
|
||||||
unsigned int key_algo;
|
unsigned int key_algo;
|
||||||
unsigned int key_len;
|
unsigned int key_len;
|
||||||
@ -47,6 +50,9 @@ struct gpgme_key_s {
|
|||||||
unsigned int expired:1 ;
|
unsigned int expired:1 ;
|
||||||
unsigned int disabled:1 ;
|
unsigned int disabled:1 ;
|
||||||
unsigned int invalid:1 ;
|
unsigned int invalid:1 ;
|
||||||
|
unsigned int can_encrypt:1;
|
||||||
|
unsigned int can_sign:1;
|
||||||
|
unsigned int can_certify:1;
|
||||||
} gloflags;
|
} gloflags;
|
||||||
unsigned int ref_count;
|
unsigned int ref_count;
|
||||||
unsigned int secret:1;
|
unsigned int secret:1;
|
||||||
|
@ -135,6 +135,34 @@ set_subkey_trust_info ( struct subkey_s *k, const char *s )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_mainkey_capability ( GpgmeKey key, const char *s )
|
||||||
|
{
|
||||||
|
for (; *s ; s++ ) {
|
||||||
|
switch (*s) {
|
||||||
|
case 'e': key->keys.flags.can_encrypt = 1; break;
|
||||||
|
case 's': key->keys.flags.can_sign = 1; break;
|
||||||
|
case 'c': key->keys.flags.can_certify = 1; break;
|
||||||
|
case 'E': key->gloflags.can_encrypt = 1; break;
|
||||||
|
case 'S': key->gloflags.can_sign = 1; break;
|
||||||
|
case 'C': key->gloflags.can_certify = 1; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_subkey_capability ( struct subkey_s *k, const char *s )
|
||||||
|
{
|
||||||
|
for (; *s; s++ ) {
|
||||||
|
switch (*s) {
|
||||||
|
case 'e': k->flags.can_encrypt = 1; break;
|
||||||
|
case 's': k->flags.can_sign = 1; break;
|
||||||
|
case 'c': k->flags.can_certify = 1; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Note: we are allowed to modify line */
|
/* Note: we are allowed to modify line */
|
||||||
static void
|
static void
|
||||||
@ -245,9 +273,12 @@ keylist_colon_handler ( GpgmeCtx ctx, char *line )
|
|||||||
break;
|
break;
|
||||||
case 10: /* not used due to --fixed-list-mode option */
|
case 10: /* not used due to --fixed-list-mode option */
|
||||||
break;
|
break;
|
||||||
case 11: /* signature class */
|
case 11: /* signature class */
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12: /* capabilities */
|
||||||
|
set_mainkey_capability (key, p );
|
||||||
|
break;
|
||||||
|
case 13:
|
||||||
pend = NULL; /* we can stop here */
|
pend = NULL; /* we can stop here */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -284,7 +315,10 @@ keylist_colon_handler ( GpgmeCtx ctx, char *line )
|
|||||||
break;
|
break;
|
||||||
case 11: /* signature class */
|
case 11: /* signature class */
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12: /* capability */
|
||||||
|
set_subkey_capability ( sk, p );
|
||||||
|
break;
|
||||||
|
case 13:
|
||||||
pend = NULL; /* we can stop here */
|
pend = NULL; /* we can stop here */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,9 @@
|
|||||||
const char *
|
const char *
|
||||||
_gpgme_get_gpg_path (void)
|
_gpgme_get_gpg_path (void)
|
||||||
{
|
{
|
||||||
|
/* #warning Forced to development version
|
||||||
|
return "/home/wk/work/gnupg-stable/g10/gpg";
|
||||||
|
*/
|
||||||
return GPG_PATH;
|
return GPG_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@ -54,10 +54,17 @@ doit ( GpgmeCtx ctx, const char *pattern )
|
|||||||
else
|
else
|
||||||
fputs("<!-- Ooops: gpgme_key_get_as_xml failed -->\n", stdout );
|
fputs("<!-- Ooops: gpgme_key_get_as_xml failed -->\n", stdout );
|
||||||
|
|
||||||
s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, 0 );
|
|
||||||
printf ("<!-- keyid=%s -->\n", s );
|
for (i=0; ; i++ ) {
|
||||||
s = gpgme_key_get_string_attr (key, GPGME_ATTR_ALGO, NULL, 0 );
|
s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, i );
|
||||||
printf ("<!-- algo=%s -->\n", s );
|
if (!s)
|
||||||
|
break;
|
||||||
|
printf ("<!-- keyid.%d=%s -->\n", i, s );
|
||||||
|
s = gpgme_key_get_string_attr (key, GPGME_ATTR_ALGO, NULL, i );
|
||||||
|
printf ("<!-- algo.%d=%s -->\n", i, s );
|
||||||
|
s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEY_CAPS, NULL, i );
|
||||||
|
printf ("<!-- caps.%d=%s -->\n", i, s );
|
||||||
|
}
|
||||||
for (i=0; ; i++ ) {
|
for (i=0; ; i++ ) {
|
||||||
s = gpgme_key_get_string_attr (key, GPGME_ATTR_NAME, NULL, i );
|
s = gpgme_key_get_string_attr (key, GPGME_ATTR_NAME, NULL, i );
|
||||||
if (!s)
|
if (!s)
|
||||||
@ -68,6 +75,15 @@ doit ( GpgmeCtx ctx, const char *pattern )
|
|||||||
s = gpgme_key_get_string_attr (key, GPGME_ATTR_COMMENT, NULL, i );
|
s = gpgme_key_get_string_attr (key, GPGME_ATTR_COMMENT, NULL, i );
|
||||||
printf ("<!-- comment.%d=%s -->\n", i, s );
|
printf ("<!-- comment.%d=%s -->\n", i, s );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fputs ("<!-- usable for:", stdout );
|
||||||
|
if ( gpgme_key_get_ulong_attr (key, GPGME_ATTR_CAN_ENCRYPT, NULL, 0 ))
|
||||||
|
fputs (" encryption", stdout);
|
||||||
|
if ( gpgme_key_get_ulong_attr (key, GPGME_ATTR_CAN_SIGN, NULL, 0 ))
|
||||||
|
fputs (" signing", stdout);
|
||||||
|
if ( gpgme_key_get_ulong_attr (key, GPGME_ATTR_CAN_CERTIFY, NULL, 0 ))
|
||||||
|
fputs (" certification", stdout);
|
||||||
|
fputs (" -->\n", stdout );
|
||||||
|
|
||||||
printf ("<!-- End key object (%p) -->\n", key );
|
printf ("<!-- End key object (%p) -->\n", key );
|
||||||
gpgme_key_release (key);
|
gpgme_key_release (key);
|
||||||
@ -97,6 +113,7 @@ main (int argc, char **argv )
|
|||||||
|
|
||||||
err = gpgme_new (&ctx);
|
err = gpgme_new (&ctx);
|
||||||
fail_if_err (err);
|
fail_if_err (err);
|
||||||
|
gpgme_set_keylist_mode (ctx, 1); /* no validity calculation */
|
||||||
do {
|
do {
|
||||||
fprintf (stderr, "** pattern=`%s'\n", pattern );
|
fprintf (stderr, "** pattern=`%s'\n", pattern );
|
||||||
doit ( ctx, pattern );
|
doit ( ctx, pattern );
|
||||||
|
Loading…
Reference in New Issue
Block a user