problem with signature verify

d_well@isuisse.com d_well@isuisse.com
Fri Oct 11 17:01:02 2002


It doesn't work. This time i have the error message
"GpgmeError No Data" with values (ctx, NULL,
signed_text, &status ).=20

my code :





#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <gpgme.h>

static const char test_text1[] =3D "Hello\n";
static const char test_sig1[] =3D

/*"-----BEGIN PGP SIGNED MESSAGE-----\n"
"Hash: SHA1\n"
"\n"
"Hello\n"
"-----BEGIN PGP SIGNATURE-----\n"
"Version: GnuPG v1.0.6 (GNU/Linux)\n"
"\n"
"iEYEARECAAYFAj2m2YEACgkQLXJ8x2hpdzR50wCeO7Luf+azOEo/
N9SwiXX1cT43\n"
"ngEAnR/o4HhUtINhERN0fpu5yhN3EYXO\n"
"=3DOq6V\n"
"-----END PGP SIGNATURE-----\n";

*/
"-----BEGIN PGP SIGNATURE-----\n"
"Version: GnuPG v1.0.6 (GNU/Linux)\n"
"\n"
"iEYEARECAAYFAj2mjY4ACgkQLXJ8x2hpdzTQOQCeJ+mok17WBu1e
un+E1Xh+UdC6\n"
"tY0AoIfp83caXGQfKGFzlrSs/QlbkvZH\n"
"=3Dv37E\n"
"-----END PGP SIGNATURE-----\n";





#define fail_if_err(a) do { if(a) {                 =20
                    \
                               fprintf (stderr,
"%s:%d: GpgmeError %s\n", \
                                __FILE__, __LINE__,
gpgme_strerror(a));   \
                                exit (1); }         =20
                    \
                             } while(0)


static const char *
status_string (GpgmeSigStat status)
{
    const char *s =3D "?";

    switch ( status ) {
      case GPGME_SIG_STAT_NONE:
        s =3D "None";
        break;
      case GPGME_SIG_STAT_NOSIG:
        s =3D "No Signature";
        break;
      case GPGME_SIG_STAT_GOOD:
        s =3D "Good";
        break;
      case GPGME_SIG_STAT_BAD:
        s =3D "Bad";
        break;
      case GPGME_SIG_STAT_NOKEY:
        s =3D "No Key";
        break;
      case GPGME_SIG_STAT_ERROR:
        s =3D "Error";
        break;
      case GPGME_SIG_STAT_DIFF:
        s =3D "More than one signature";
        break;
    }
    return s;
}

static void
print_sig_stat ( GpgmeCtx ctx, GpgmeSigStat status )
{
    const char *s;
    time_t created;
    int idx;
    GpgmeKey key;

    printf ("Verification Status: %s\n",
status_string (status));

    for(idx=3D0; (s=3Dgpgme_get_sig_status (ctx, idx,
&status, &created)); idx++ ) {
        printf ("sig %d: created: %lu status: %s\n",
idx, (unsigned long)created,
                status_string(status) );
        printf ("sig %d: fpr/keyid=3D`%s'\n", idx, s );
        if ( !gpgme_get_sig_key (ctx, idx, &key) ) {
            char *p =3D gpgme_key_get_as_xml ( key );
            printf ("sig %d: key object:\n%s\n", idx,
p );
            free (p);
            gpgme_key_release (key);
        }
    }
}


int
main (int argc, char **argv )
{
    GpgmeCtx ctx;
    GpgmeError err;
    GpgmeData sig, text;
    GpgmeSigStat status;
    char *nota;
    int n =3D 0;
    int i, j;

    err =3D gpgme_new (&ctx);
    fail_if_err (err);

  do {
    err =3D gpgme_data_new_from_mem ( &text,
                                    test_text1,
strlen (test_text1), 0 );
    fail_if_err (err);

    err =3D gpgme_data_new_from_mem ( &sig,
                                    test_sig1, strlen
(test_sig1), 0 );
    fail_if_err (err);

    err =3D gpgme_op_verify (ctx, NULL, sig, &status );
    fail_if_err (err);

    print_sig_stat (ctx, status);
    if (status !=3D GPGME_SIG_STAT_GOOD)
      {
 fprintf (stderr, "%s:%d: Wrong sig stat\n",
__FILE__, __LINE__);
 exit (1);
      }
    if ( (nota=3Dgpgme_get_notation (ctx)) )
        printf ("---Begin Notation---\n%s---End
Notation---\n", nota );

    puts ("checking a normal signature:");
    gpgme_data_release (sig);
    gpgme_data_release (text);


} while ( argc > 1 && !strcmp( argv[1], "--loop" ) &&
++n < 20 );
      gpgme_release (ctx);

    return 0;
}