If you want to hack on it, start with one of the tests/t-foo programs.
You need the latest CVS version of GnuPG 1.0, see
-http://www.gnupg.org/cvs-access.html . If you use passphrases for
-your keys, you should get the gpg-agent which comes with the GnuPG
-unstable version (either CVS HEAD or
-ftp.gnupg.org/pub/gcrypt/alpha/gnupg/gnupg-1.1.2.tar.gz) and install
-the agent from the agent subdirectory or use the new
-gpgme_set_passphrase_cb()
+http://www.gnupg.org/cvs-access.html .
+
+You need at least GnuPG 1.0.4d (but don't use a 1.1.x version).
+
To build the W32 version, use
./autogen.sh --build-w32
# AGE, set REVISION to 0.
# 3. Interfaces removed (BAD, breaks upward compatibility): Increment
# CURRENT, set AGE and REVISION to 0.
-AM_INIT_AUTOMAKE(gpgme,0.1.3a)
-LIBGPGME_LT_CURRENT=1
-LIBGPGME_LT_AGE=1
+AM_INIT_AUTOMAKE(gpgme,0.1.4)
+LIBGPGME_LT_CURRENT=2
+LIBGPGME_LT_AGE=2
LIBGPGME_LT_REVISION=0
##############################################
struct user_id_s {
struct user_id_s *next;
- int validity; /* 0 = undefined, 1 = not, 2 = marginal,
- 3 = full, 4 = ultimate */
+ GpgmeValidity validity;
const char *name_part; /* all 3 point into strings behind name */
const char *email_part; /* or to read-only strings */
const char *comment_part;
int okay;
int failed;
void *last_pw_handle;
+ char *userid_hint;
+ char *passphrase_info;
+ int bad_passphrase;
};
void
_gpgme_release_decrypt_result ( DecryptResult res )
{
+ if (!res )
+ return;
+ xfree (res->passphrase_info);
+ xfree (res->userid_hint);
xfree (res);
}
case STATUS_EOF:
break;
+ case STATUS_USERID_HINT:
+ xfree (ctx->result.decrypt->userid_hint);
+ if (!(ctx->result.decrypt->userid_hint = xtrystrdup (args)) )
+ ctx->out_of_core = 1;
+ break;
+
+ case STATUS_BAD_PASSPHRASE:
+ ctx->result.decrypt->bad_passphrase++;
+ break;
+
+ case STATUS_GOOD_PASSPHRASE:
+ ctx->result.decrypt->bad_passphrase = 0;
+ break;
+
case STATUS_NEED_PASSPHRASE:
case STATUS_NEED_PASSPHRASE_SYM:
- fprintf (stderr, "need a passphrase ...\n" );
+ xfree (ctx->result.decrypt->passphrase_info);
+ if (!(ctx->result.decrypt->passphrase_info = xtrystrdup (args)) )
+ ctx->out_of_core = 1;
break;
case STATUS_MISSING_PASSPHRASE:
default:
/* ignore all other codes */
- fprintf (stderr, "decrypt_status: code=%d not handled\n", code );
break;
}
}
+
static const char *
command_handler ( void *opaque, GpgStatusCode code, const char *key )
{
/* We have been called for cleanup */
if ( c->passphrase_cb ) {
/* Fixme: take the key in account */
- c->passphrase_cb (c->passphrase_cb_value, 0,
+ c->passphrase_cb (c->passphrase_cb_value, NULL,
&c->result.decrypt->last_pw_handle );
}
return NULL;
if ( code == STATUS_GET_HIDDEN && !strcmp (key, "passphrase.enter") ) {
- return c->passphrase_cb (c->passphrase_cb_value,
- "Hey, Mr. Hoover wants your passphrase!",
- &c->result.decrypt->last_pw_handle );
+ const char *userid_hint = c->result.decrypt->userid_hint;
+ const char *passphrase_info = c->result.decrypt->passphrase_info;
+ int bad_passphrase = c->result.decrypt->bad_passphrase;
+ char *buf;
+ const char *s;
+
+ c->result.decrypt->bad_passphrase = 0;
+ if (!userid_hint)
+ userid_hint = "[User ID hint missing]";
+ if (!passphrase_info)
+ passphrase_info = "[passphrase info missing]";
+ buf = xtrymalloc ( 20 + strlen (userid_hint)
+ + strlen (passphrase_info) + 3);
+ if (!buf) {
+ c->out_of_core = 1;
+ return NULL;
+ }
+ sprintf (buf, "%s\n%s\n%s",
+ bad_passphrase? "TRY_AGAIN":"ENTER",
+ userid_hint, passphrase_info );
+
+ s = c->passphrase_cb (c->passphrase_cb_value,
+ buf, &c->result.decrypt->last_pw_handle );
+ xfree (buf);
+ return s;
}
return NULL;
_gpgme_gpg_add_arg ( c->gpg, "--armor" );
for ( i=0; i < c->verbosity; i++ )
_gpgme_gpg_add_arg ( c->gpg, "--verbose" );
+ /* If we know that all recipients are valid (full or ultimate trust)
+ * we can pass suppress further checks */
+ if ( _gpgme_recipients_all_valid (recp) )
+ _gpgme_gpg_add_arg ( c->gpg, "--always-trust" );
_gpgme_append_gpg_args_from_recipients ( recp, c->gpg );
return;
_gpgme_gpg_release ( c->gpg );
_gpgme_release_result ( c );
- _gpgme_key_release ( c->tmp_key );
+ gpgme_key_release ( c->tmp_key );
gpgme_data_release ( c->help_data_1 );
gpgme_data_release ( c->notation );
/* fixme: release the key_queue */
* and called whenever gpgme needs a passphrase. DESC will have a nice
* text, to be used to prompt for the passphrase and R_HD is just a parameter
* to be used by the callback it self. Becuase the callback returns a const
- * string, the callback might want to know when it can releae resources
+ * string, the callback might want to know when it can release resources
* assocated with that returned string; gpgme helps here by calling this
* passphrase callback with an DESC of %NULL as soon as it does not need
* the returned string anymore. The callback function might then choose
* let autoconf (using the AM_PATH_GPGME macro) check that this
* header matches the installed library.
* Warning: Do not edit the next line. configure will do that for you! */
-#define GPGME_VERSION "0.1.3a"
+#define GPGME_VERSION "0.1.4"
GPGME_ATTR_TYPE = 14
} GpgmeAttr;
+typedef enum {
+ GPGME_VALIDITY_UNKNOWN = 0,
+ GPGME_VALIDITY_UNDEFINED = 1,
+ GPGME_VALIDITY_NEVER = 2,
+ GPGME_VALIDITY_MARGINAL = 3,
+ GPGME_VALIDITY_FULL = 4,
+ GPGME_VALIDITY_ULTIMATE = 5
+} GpgmeValidity;
+
typedef const char *(*GpgmePassphraseCb)(void*,
const char *desc, void *r_hd);
void gpgme_recipients_release ( GpgmeRecipients rset);
GpgmeError gpgme_recipients_add_name (GpgmeRecipients rset,
const char *name);
+GpgmeError gpgme_recipients_add_name_with_validity (GpgmeRecipients rset,
+ const char *name,
+ GpgmeValidity val );
unsigned int gpgme_recipients_count ( const GpgmeRecipients rset );
GpgmeError gpgme_recipients_enum_open (const GpgmeRecipients rset,void **ctx);
const char *gpgme_recipients_enum_read (const GpgmeRecipients rset,void **ctx);
/* Key and trust functions */
+void gpgme_key_release ( GpgmeKey key );
char *gpgme_key_get_as_xml ( GpgmeKey key );
const char *gpgme_key_get_string_attr ( GpgmeKey key, GpgmeAttr what,
const void *reserved, int idx );
void
-_gpgme_key_release ( GpgmeKey key )
+gpgme_key_release ( GpgmeKey key )
{
struct user_id_s *u, *u2;
struct subkey_s *k, *k2;
val = u? u->comment_part : NULL;
break;
case GPGME_ATTR_VALIDITY:
- val = "[foxme]";
+ for (u=key->uids; u && idx; u=u->next, idx-- )
+ ;
+ if (u) {
+ switch (u->validity) {
+ case GPGME_VALIDITY_UNKNOWN: val = "?"; break;
+ case GPGME_VALIDITY_UNDEFINED: val = "q"; break;
+ case GPGME_VALIDITY_NEVER: val = "n"; break;
+ case GPGME_VALIDITY_MARGINAL: val = "m"; break;
+ case GPGME_VALIDITY_FULL: val = "f"; break;
+ case GPGME_VALIDITY_ULTIMATE: val = "u"; break;
+ }
+ }
break;
case GPGME_ATTR_LEVEL: /* not used here */
case GPGME_ATTR_TYPE:
const void *reserved, int idx )
{
unsigned long val = 0;
+ struct user_id_s *u;
if (!key)
return 0;
case GPGME_ATTR_CREATED:
val = key->keys.timestamp < 0? 0L:(unsigned long)key->keys.timestamp;
break;
+ case GPGME_ATTR_VALIDITY:
+ for (u=key->uids; u && idx; u=u->next, idx-- )
+ ;
+ if (u)
+ val = u->validity;
+ break;
default:
break;
}
q = xtrymalloc ( sizeof *q );
if ( !q ) {
- _gpgme_key_release (key);
+ gpgme_key_release (key);
ctx->out_of_core = 1;
return;
}
_gpgme_gpg_release ( c->gpg );
c->gpg = NULL;
}
- _gpgme_key_release (c->tmp_key);
+ gpgme_key_release (c->tmp_key);
c->tmp_key = NULL;
/* Fixme: release key_queue */
void _gpgme_append_gpg_args_from_recipients (
const GpgmeRecipients rset,
GpgObject gpg );
+int _gpgme_recipients_all_valid ( const GpgmeRecipients rset );
/*-- data.c --*/
/*-- key.c --*/
GpgmeError _gpgme_key_new( GpgmeKey *r_key );
-void _gpgme_key_release ( GpgmeKey key );
/*-- verify.c --*/
GpgmeError
gpgme_recipients_add_name (GpgmeRecipients rset, const char *name )
+{
+ return gpgme_recipients_add_name_with_validity (
+ rset, name, GPGME_VALIDITY_UNKNOWN
+ );
+}
+
+GpgmeError
+gpgme_recipients_add_name_with_validity (GpgmeRecipients rset,
+ const char *name,
+ GpgmeValidity val )
{
struct user_id_s *r;
r = xtrymalloc ( sizeof *r + strlen (name) );
if (!r)
return mk_error (Out_Of_Core);
+ r->validity = val;
r->name_part = "";
r->email_part = "";
r->comment_part = "";
return 0;
}
+
+
unsigned int
gpgme_recipients_count ( const GpgmeRecipients rset )
{
}
}
+int
+_gpgme_recipients_all_valid ( const GpgmeRecipients rset )
+{
+ struct user_id_s *r;
+ assert (rset);
+ for (r=rset->list ; r; r = r->next ) {
+ if (r->validity != GPGME_VALIDITY_FULL
+ && r->validity != GPGME_VALIDITY_ULTIMATE )
+ return 0; /*no*/
+ }
+ return 1; /*yes*/
+}
STATUS_SHM_GET_BOOL ,
STATUS_SHM_GET_HIDDEN ,
STATUS_NEED_PASSPHRASE ,
+ STATUS_USERID_HINT ,
STATUS_VALIDSIG ,
STATUS_SIG_ID ,
STATUS_ENC_TO ,
{ "TRUST_NEVER", STATUS_TRUST_NEVER },
{ "TRUST_ULTIMATE", STATUS_TRUST_ULTIMATE },
{ "TRUST_UNDEFINED", STATUS_TRUST_UNDEFINED },
+ { "USERID_HINT", STATUS_USERID_HINT },
{ "VALIDSIG", STATUS_VALIDSIG },
{NULL, 0}
};
item->val[0] = *p;
item->val[1] = 0;
break;
- case 10: /* user ID */
+ case 9: /* user ID */
item->name = xtrystrdup (p);
if (!item->name)
ctx->out_of_core = 1;
err = gpgme_recipients_new (&rset);
fail_if_err (err);
- err = gpgme_recipients_add_name (rset, "Bob");
+ err = gpgme_recipients_add_name_with_validity (rset, "Bob",
+ GPGME_VALIDITY_FULL);
fail_if_err (err);
- err = gpgme_recipients_add_name (rset, "Alpha");
+ err = gpgme_recipients_add_name_with_validity (rset, "Alpha",
+ GPGME_VALIDITY_FULL);
fail_if_err (err);
printf ("<!-- comment.%d=%s -->\n", i, s );
}
printf ("<!-- End key object (%p) -->\n", key );
+ gpgme_key_release (key);
}
if ( err != GPGME_EOF )
fail_if_err (err);
loop = 1;
argc--; argv++;
}
- pattern = argc? *argv : NULL;
+ pattern = argc? *argv : "alice";
err = gpgme_new (&ctx);
fail_if_err (err);