tests: Add ECC key generation for tests/gpgsm.

* tests/gpgsm/t-genkey.c (check_result): New.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2020-03-27 19:50:24 +09:00
parent 71ef398bfd
commit 3658e2df65
2 changed files with 65 additions and 33 deletions

View File

@ -59,37 +59,9 @@ progress (void *self, const char *what, int type, int current, int total)
} }
int static void
main (void) check_result (gpgme_genkey_result_t result)
{ {
gpgme_ctx_t ctx;
gpgme_error_t err;
const char *parms = "<GnupgKeyParms format=\"internal\">\n"
"Key-Type: RSA\n"
"Key-Length: 1024\n"
"Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester\n"
"Name-Email: joe@foo.bar\n"
"</GnupgKeyParms>\n";
gpgme_genkey_result_t result;
gpgme_data_t certreq;
init_gpgme (GPGME_PROTOCOL_CMS);
err = gpgme_data_new (&certreq);
fail_if_err (err);
err = gpgme_new (&ctx);
fail_if_err (err);
gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
gpgme_set_armor (ctx, 1);
gpgme_set_progress_cb (ctx, progress, NULL);
err = gpgme_op_genkey (ctx, parms, certreq, NULL);
fail_if_err (err);
result = gpgme_op_genkey_result (ctx);
if (!result) if (!result)
{ {
fprintf (stderr, "%s:%d: gpgme_op_genkey_result returns NULL\n", fprintf (stderr, "%s:%d: gpgme_op_genkey_result returns NULL\n",
@ -121,10 +93,66 @@ main (void)
__FILE__, __LINE__); __FILE__, __LINE__);
exit (1); exit (1);
} }
gpgme_release (ctx); }
static const char *parms[] = {
"<GnupgKeyParms format=\"internal\">\n"
"Key-Type: RSA\n"
"Key-Length: 1024\n"
"Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester\n"
"Name-Email: joe@foo.bar\n"
"</GnupgKeyParms>\n",
"<GnupgKeyParms format=\"internal\">\n"
"Key-Type: ECC\n"
"Key-Curve: NIST P-256\n"
"Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester\n"
"Name-Email: joe@foo.bar\n"
"</GnupgKeyParms>\n",
"<GnupgKeyParms format=\"internal\">\n"
"Key-Type: ECC\n"
"Key-Curve: Ed25519\n"
"Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester\n"
"Name-Email: joe@foo.bar\n"
"</GnupgKeyParms>\n",
};
int
main (void)
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_genkey_result_t result;
int i;
init_gpgme (GPGME_PROTOCOL_CMS);
err = gpgme_new (&ctx);
fail_if_err (err);
gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
gpgme_set_armor (ctx, 1);
gpgme_set_progress_cb (ctx, progress, NULL);
for (i = 0; i < DIM(parms); i++)
{
gpgme_data_t certreq;
progress_called = 0;
err = gpgme_data_new (&certreq);
fail_if_err (err);
err = gpgme_op_genkey (ctx, parms[i], certreq, NULL);
fail_if_err (err);
result = gpgme_op_genkey_result (ctx);
check_result (result);
print_data (certreq); print_data (certreq);
gpgme_data_release (certreq); gpgme_data_release (certreq);
}
gpgme_release (ctx);
return 0; return 0;
} }

View File

@ -26,6 +26,10 @@
#include <gpgme.h> #include <gpgme.h>
#ifndef DIM
#define DIM(v) (sizeof(v)/sizeof((v)[0]))
#endif
#define fail_if_err(err) \ #define fail_if_err(err) \
do \ do \
{ \ { \