2000-11-09 16:35:35 +00:00
|
|
|
/* verify.c - signature verification
|
|
|
|
* Copyright (C) 2000 Werner Koch (dd9jn)
|
2001-04-02 08:40:32 +00:00
|
|
|
* Copyright (C) 2001 g10 Code GmbH
|
2000-11-09 16:35:35 +00:00
|
|
|
*
|
|
|
|
* This file is part of GPGME.
|
|
|
|
*
|
|
|
|
* GPGME is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GPGME is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
#include "context.h"
|
|
|
|
#include "ops.h"
|
2001-05-28 17:35:10 +00:00
|
|
|
#include "key.h"
|
2000-11-09 16:35:35 +00:00
|
|
|
|
2001-11-15 21:32:09 +00:00
|
|
|
struct verify_result_s
|
|
|
|
{
|
|
|
|
struct verify_result_s *next;
|
|
|
|
GpgmeSigStat status;
|
|
|
|
GpgmeData notation; /* We store an XML fragment here. */
|
|
|
|
int collecting; /* Private to finish_sig(). */
|
|
|
|
int notation_in_data; /* Private to add_notation(). */
|
|
|
|
char fpr[41]; /* Fingerprint of a good signature or keyid of
|
|
|
|
a bad one. */
|
|
|
|
ulong timestamp; /* Signature creation time. */
|
2000-11-09 16:35:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2001-11-15 21:32:09 +00:00
|
|
|
_gpgme_release_verify_result (VerifyResult result)
|
2000-11-09 16:35:35 +00:00
|
|
|
{
|
2001-11-15 21:32:09 +00:00
|
|
|
while (result)
|
|
|
|
{
|
|
|
|
VerifyResult next_result = result->next;
|
|
|
|
gpgme_data_release (result->notation);
|
|
|
|
xfree (result);
|
|
|
|
result = next_result;
|
2001-02-12 15:23:29 +00:00
|
|
|
}
|
2000-11-09 16:35:35 +00:00
|
|
|
}
|
|
|
|
|
2001-11-15 21:32:09 +00:00
|
|
|
/* FIXME: Check that we are adding this to the correct signature. */
|
2000-11-15 21:36:48 +00:00
|
|
|
static void
|
|
|
|
add_notation ( GpgmeCtx ctx, GpgStatusCode code, const char *data )
|
|
|
|
{
|
|
|
|
GpgmeData dh = ctx->result.verify->notation;
|
|
|
|
|
|
|
|
if ( !dh ) {
|
2000-11-16 13:15:48 +00:00
|
|
|
if ( gpgme_data_new ( &dh ) ) {
|
2000-11-15 21:36:48 +00:00
|
|
|
ctx->out_of_core = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ctx->result.verify->notation = dh;
|
|
|
|
_gpgme_data_append_string (dh, " <notation>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( code == STATUS_NOTATION_DATA ) {
|
|
|
|
if ( !ctx->result.verify->notation_in_data )
|
|
|
|
_gpgme_data_append_string (dh, " <data>");
|
|
|
|
_gpgme_data_append_percentstring_for_xml (dh, data);
|
|
|
|
ctx->result.verify->notation_in_data = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ctx->result.verify->notation_in_data ) {
|
|
|
|
_gpgme_data_append_string (dh, "</data>\n");
|
|
|
|
ctx->result.verify->notation_in_data = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( code == STATUS_NOTATION_NAME ) {
|
|
|
|
_gpgme_data_append_string (dh, " <name>");
|
|
|
|
_gpgme_data_append_percentstring_for_xml (dh, data);
|
|
|
|
_gpgme_data_append_string (dh, "</name>\n");
|
|
|
|
}
|
|
|
|
else if ( code == STATUS_POLICY_URL ) {
|
|
|
|
_gpgme_data_append_string (dh, " <policy>");
|
|
|
|
_gpgme_data_append_percentstring_for_xml (dh, data);
|
|
|
|
_gpgme_data_append_string (dh, "</policy>\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-12 15:23:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* finish a pending signature info collection and prepare for a new
|
|
|
|
* signature info collection
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
finish_sig (GpgmeCtx ctx, int stop)
|
|
|
|
{
|
|
|
|
if (stop)
|
|
|
|
return; /* nothing to do */
|
|
|
|
|
|
|
|
if (ctx->result.verify->collecting) {
|
|
|
|
VerifyResult res2;
|
|
|
|
|
|
|
|
ctx->result.verify->collecting = 0;
|
|
|
|
/* create a new result structure */
|
|
|
|
res2 = xtrycalloc ( 1, sizeof *res2 );
|
|
|
|
if ( !res2 ) {
|
|
|
|
ctx->out_of_core = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
res2->next = ctx->result.verify;
|
|
|
|
ctx->result.verify = res2;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->result.verify->collecting = 1;
|
|
|
|
}
|
|
|
|
|
2001-11-16 01:37:06 +00:00
|
|
|
void
|
|
|
|
_gpgme_verify_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
|
2000-11-09 16:35:35 +00:00
|
|
|
{
|
2001-02-12 15:23:29 +00:00
|
|
|
char *p;
|
|
|
|
int i;
|
|
|
|
|
2000-11-09 16:35:35 +00:00
|
|
|
if ( ctx->out_of_core )
|
|
|
|
return;
|
2001-11-15 21:32:09 +00:00
|
|
|
if (!ctx->result.verify)
|
|
|
|
{
|
|
|
|
ctx->result.verify = xtrycalloc (1, sizeof *ctx->result.verify);
|
|
|
|
if (!ctx->result.verify)
|
|
|
|
{
|
2000-11-09 16:35:35 +00:00
|
|
|
ctx->out_of_core = 1;
|
|
|
|
return;
|
2001-11-15 21:32:09 +00:00
|
|
|
}
|
|
|
|
}
|
2000-11-09 16:35:35 +00:00
|
|
|
|
2001-02-12 15:23:29 +00:00
|
|
|
if (code == STATUS_GOODSIG
|
|
|
|
|| code == STATUS_BADSIG || code == STATUS_ERRSIG) {
|
|
|
|
finish_sig (ctx,0);
|
|
|
|
if ( ctx->out_of_core )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-11-09 16:35:35 +00:00
|
|
|
switch (code) {
|
2001-09-07 12:47:33 +00:00
|
|
|
case STATUS_NODATA:
|
|
|
|
ctx->result.verify->status = GPGME_SIG_STAT_NOSIG;
|
|
|
|
break;
|
|
|
|
|
2000-11-09 16:35:35 +00:00
|
|
|
case STATUS_GOODSIG:
|
2001-09-07 12:47:33 +00:00
|
|
|
/* We only look at VALIDSIG */
|
2001-02-12 15:23:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUS_VALIDSIG:
|
2000-11-15 21:36:48 +00:00
|
|
|
ctx->result.verify->status = GPGME_SIG_STAT_GOOD;
|
2001-02-12 15:23:29 +00:00
|
|
|
p = ctx->result.verify->fpr;
|
|
|
|
for (i=0; i < DIM(ctx->result.verify->fpr)
|
|
|
|
&& args[i] && args[i] != ' ' ; i++ )
|
|
|
|
*p++ = args[i];
|
|
|
|
*p = 0;
|
|
|
|
/* skip the formatted date */
|
|
|
|
while ( args[i] && args[i] == ' ')
|
|
|
|
i++;
|
|
|
|
while ( args[i] && args[i] != ' ')
|
|
|
|
i++;
|
|
|
|
/* and get the timestamp */
|
|
|
|
ctx->result.verify->timestamp = strtoul (args+i, NULL, 10);
|
2000-11-09 16:35:35 +00:00
|
|
|
break;
|
2001-02-12 15:23:29 +00:00
|
|
|
|
2000-11-09 16:35:35 +00:00
|
|
|
case STATUS_BADSIG:
|
2000-11-15 21:36:48 +00:00
|
|
|
ctx->result.verify->status = GPGME_SIG_STAT_BAD;
|
2001-02-12 15:23:29 +00:00
|
|
|
/* store the keyID in the fpr field */
|
|
|
|
p = ctx->result.verify->fpr;
|
|
|
|
for (i=0; i < DIM(ctx->result.verify->fpr)
|
|
|
|
&& args[i] && args[i] != ' ' ; i++ )
|
|
|
|
*p++ = args[i];
|
|
|
|
*p = 0;
|
2000-11-09 16:35:35 +00:00
|
|
|
break;
|
2001-02-12 15:23:29 +00:00
|
|
|
|
2000-11-09 16:35:35 +00:00
|
|
|
case STATUS_ERRSIG:
|
2000-11-15 21:36:48 +00:00
|
|
|
ctx->result.verify->status = GPGME_SIG_STAT_ERROR;
|
2000-11-09 16:35:35 +00:00
|
|
|
/* FIXME: distinguish between a regular error and a missing key.
|
|
|
|
* this is encoded in the args. */
|
2001-02-12 15:23:29 +00:00
|
|
|
/* store the keyID in the fpr field */
|
|
|
|
p = ctx->result.verify->fpr;
|
|
|
|
for (i=0; i < DIM(ctx->result.verify->fpr)
|
|
|
|
&& args[i] && args[i] != ' ' ; i++ )
|
|
|
|
*p++ = args[i];
|
|
|
|
*p = 0;
|
2000-11-09 16:35:35 +00:00
|
|
|
break;
|
2000-11-15 21:36:48 +00:00
|
|
|
|
|
|
|
case STATUS_NOTATION_NAME:
|
|
|
|
case STATUS_NOTATION_DATA:
|
|
|
|
case STATUS_POLICY_URL:
|
|
|
|
add_notation ( ctx, code, args );
|
|
|
|
break;
|
|
|
|
|
2000-12-12 13:31:25 +00:00
|
|
|
case STATUS_END_STREAM:
|
|
|
|
break;
|
|
|
|
|
2001-02-12 15:23:29 +00:00
|
|
|
case STATUS_EOF:
|
|
|
|
finish_sig(ctx,1);
|
|
|
|
break;
|
|
|
|
|
2000-11-09 16:35:35 +00:00
|
|
|
default:
|
|
|
|
/* ignore all other codes */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GpgmeError
|
2000-11-13 13:25:22 +00:00
|
|
|
gpgme_op_verify_start ( GpgmeCtx c, GpgmeData sig, GpgmeData text )
|
2000-11-09 16:35:35 +00:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
int i;
|
2001-05-28 17:35:10 +00:00
|
|
|
int pipemode = 0; /*!!text; use pipemode for detached sigs */
|
2000-11-09 16:35:35 +00:00
|
|
|
|
|
|
|
fail_on_pending_request( c );
|
|
|
|
c->pending = 1;
|
|
|
|
|
|
|
|
_gpgme_release_result (c);
|
|
|
|
c->out_of_core = 0;
|
2000-12-12 13:31:25 +00:00
|
|
|
|
|
|
|
if ( !pipemode ) {
|
|
|
|
_gpgme_gpg_release ( c->gpg );
|
2000-11-09 16:35:35 +00:00
|
|
|
c->gpg = NULL;
|
|
|
|
}
|
2000-12-12 13:31:25 +00:00
|
|
|
|
|
|
|
if ( !c->gpg )
|
|
|
|
rc = _gpgme_gpg_new ( &c->gpg );
|
2000-11-09 16:35:35 +00:00
|
|
|
if (rc)
|
|
|
|
goto leave;
|
|
|
|
|
2000-12-12 13:31:25 +00:00
|
|
|
if (pipemode)
|
|
|
|
_gpgme_gpg_enable_pipemode ( c->gpg );
|
2001-11-16 01:37:06 +00:00
|
|
|
_gpgme_gpg_set_status_handler (c->gpg, _gpgme_verify_status_handler, c);
|
2000-11-09 16:35:35 +00:00
|
|
|
|
|
|
|
/* build the commandline */
|
2000-12-12 13:31:25 +00:00
|
|
|
_gpgme_gpg_add_arg ( c->gpg, pipemode?"--pipemode" : "--verify" );
|
2000-11-09 16:35:35 +00:00
|
|
|
for ( i=0; i < c->verbosity; i++ )
|
|
|
|
_gpgme_gpg_add_arg ( c->gpg, "--verbose" );
|
|
|
|
|
|
|
|
/* Check the supplied data */
|
2000-11-13 13:25:22 +00:00
|
|
|
if ( gpgme_data_get_type (sig) == GPGME_DATA_TYPE_NONE ) {
|
2000-11-09 16:35:35 +00:00
|
|
|
rc = mk_error (No_Data);
|
|
|
|
goto leave;
|
|
|
|
}
|
2000-11-13 13:25:22 +00:00
|
|
|
if ( text && gpgme_data_get_type (text) == GPGME_DATA_TYPE_NONE ) {
|
2000-11-09 16:35:35 +00:00
|
|
|
rc = mk_error (No_Data);
|
|
|
|
goto leave;
|
|
|
|
}
|
2000-11-13 13:25:22 +00:00
|
|
|
_gpgme_data_set_mode (sig, GPGME_DATA_MODE_OUT );
|
2000-11-09 16:35:35 +00:00
|
|
|
if (text) /* detached signature */
|
2000-11-13 13:25:22 +00:00
|
|
|
_gpgme_data_set_mode (text, GPGME_DATA_MODE_OUT );
|
2000-11-09 16:35:35 +00:00
|
|
|
/* Tell the gpg object about the data */
|
|
|
|
_gpgme_gpg_add_arg ( c->gpg, "--" );
|
2000-12-12 13:31:25 +00:00
|
|
|
if (pipemode) {
|
|
|
|
_gpgme_gpg_add_pm_data ( c->gpg, sig, 0 );
|
|
|
|
_gpgme_gpg_add_pm_data ( c->gpg, text, 1 );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_gpgme_gpg_add_data ( c->gpg, sig, -1 );
|
|
|
|
if (text) {
|
|
|
|
_gpgme_gpg_add_arg ( c->gpg, "-" );
|
|
|
|
_gpgme_gpg_add_data ( c->gpg, text, 0 );
|
|
|
|
}
|
2000-12-06 12:17:10 +00:00
|
|
|
}
|
2000-11-09 16:35:35 +00:00
|
|
|
|
|
|
|
/* and kick off the process */
|
|
|
|
rc = _gpgme_gpg_spawn ( c->gpg, c );
|
|
|
|
|
|
|
|
leave:
|
|
|
|
if (rc) {
|
|
|
|
c->pending = 0;
|
2000-11-13 13:25:22 +00:00
|
|
|
_gpgme_gpg_release ( c->gpg ); c->gpg = NULL;
|
2000-11-09 16:35:35 +00:00
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-12 15:23:29 +00:00
|
|
|
/*
|
|
|
|
* Figure out a common status value for all signatures
|
|
|
|
*/
|
2001-11-16 01:37:06 +00:00
|
|
|
GpgmeSigStat
|
|
|
|
_gpgme_intersect_stati (VerifyResult result)
|
2001-02-12 15:23:29 +00:00
|
|
|
{
|
2001-11-15 21:32:09 +00:00
|
|
|
GpgmeSigStat status = result->status;
|
2001-02-12 15:23:29 +00:00
|
|
|
|
2001-11-15 21:32:09 +00:00
|
|
|
for (result = result->next; result; result = result->next)
|
|
|
|
{
|
|
|
|
if (status != result->status)
|
|
|
|
return GPGME_SIG_STAT_DIFF;
|
2001-02-12 15:23:29 +00:00
|
|
|
}
|
2001-11-15 21:32:09 +00:00
|
|
|
return status;
|
2001-02-12 15:23:29 +00:00
|
|
|
}
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
/**
|
|
|
|
* gpgme_op_verify:
|
|
|
|
* @c: the context
|
|
|
|
* @sig: the signature data
|
|
|
|
* @text: the signed text
|
|
|
|
* @r_stat: returns the status of the signature
|
|
|
|
*
|
|
|
|
* Perform a signature check on the signature given in @sig. Currently it is
|
|
|
|
* assumed that this is a detached signature for the material given in @text.
|
|
|
|
* The result of this operation is returned in @r_stat which can take these
|
|
|
|
* values:
|
|
|
|
* GPGME_SIG_STAT_NONE: No status - should not happen
|
|
|
|
* GPGME_SIG_STAT_GOOD: The signature is valid
|
|
|
|
* GPGME_SIG_STAT_BAD: The signature is not valid
|
|
|
|
* GPGME_SIG_STAT_NOKEY: The signature could not be checked due to a
|
|
|
|
* missing key
|
|
|
|
* GPGME_SIG_STAT_NOSIG: This is not a signature
|
|
|
|
* GPGME_SIG_STAT_ERROR: Due to some other error the check could not be done.
|
2001-02-12 15:23:29 +00:00
|
|
|
* GPGME_SIG_STAT_DIFF: There is more than 1 signature and they have not
|
|
|
|
* the same status.
|
2000-11-22 17:10:48 +00:00
|
|
|
*
|
|
|
|
* Return value: 0 on success or an errorcode if something not related to
|
|
|
|
* the signature itself did go wrong.
|
|
|
|
**/
|
2000-11-09 16:35:35 +00:00
|
|
|
GpgmeError
|
2000-11-15 21:36:48 +00:00
|
|
|
gpgme_op_verify ( GpgmeCtx c, GpgmeData sig, GpgmeData text,
|
|
|
|
GpgmeSigStat *r_stat )
|
2000-11-09 16:35:35 +00:00
|
|
|
{
|
2000-11-15 21:36:48 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if ( !r_stat )
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
|
|
|
gpgme_data_release (c->notation);
|
|
|
|
c->notation = NULL;
|
|
|
|
|
|
|
|
*r_stat = GPGME_SIG_STAT_NONE;
|
|
|
|
rc = gpgme_op_verify_start ( c, sig, text );
|
2000-11-09 16:35:35 +00:00
|
|
|
if ( !rc ) {
|
|
|
|
gpgme_wait (c, 1);
|
2001-11-15 21:32:09 +00:00
|
|
|
if (!c->result.verify)
|
2000-11-09 16:35:35 +00:00
|
|
|
rc = mk_error (General_Error);
|
2001-11-15 21:32:09 +00:00
|
|
|
else if (c->out_of_core)
|
2000-11-09 16:35:35 +00:00
|
|
|
rc = mk_error (Out_Of_Core);
|
|
|
|
else {
|
2001-11-15 21:32:09 +00:00
|
|
|
/* FIXME: Put all notation data into one XML fragment. */
|
2000-11-15 21:36:48 +00:00
|
|
|
if ( c->result.verify->notation ) {
|
|
|
|
GpgmeData dh = c->result.verify->notation;
|
|
|
|
|
|
|
|
if ( c->result.verify->notation_in_data ) {
|
|
|
|
_gpgme_data_append_string (dh, "</data>\n");
|
|
|
|
c->result.verify->notation_in_data = 0;
|
|
|
|
}
|
|
|
|
_gpgme_data_append_string (dh, "</notation>\n");
|
|
|
|
c->notation = dh;
|
|
|
|
c->result.verify->notation = NULL;
|
2000-11-09 16:35:35 +00:00
|
|
|
}
|
2001-11-16 01:37:06 +00:00
|
|
|
*r_stat = _gpgme_intersect_stati (c->result.verify);
|
2000-11-09 16:35:35 +00:00
|
|
|
}
|
|
|
|
c->pending = 0;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-12 15:23:29 +00:00
|
|
|
/**
|
|
|
|
* gpgme_get_sig_status:
|
|
|
|
* @c: Context
|
|
|
|
* @idx: Index of the signature starting at 0
|
|
|
|
* @r_stat: Returns the status
|
|
|
|
* @r_created: Returns the creation timestamp
|
|
|
|
*
|
|
|
|
* Return information about an already verified signatures.
|
|
|
|
*
|
|
|
|
* Return value: The fingerprint or NULL in case of an problem or
|
|
|
|
* when there are no more signatures.
|
|
|
|
**/
|
|
|
|
const char *
|
|
|
|
gpgme_get_sig_status (GpgmeCtx c, int idx,
|
2001-11-15 21:32:09 +00:00
|
|
|
GpgmeSigStat *r_stat, time_t *r_created)
|
2001-02-12 15:23:29 +00:00
|
|
|
{
|
2001-11-15 21:32:09 +00:00
|
|
|
VerifyResult result;
|
|
|
|
|
|
|
|
if (!c || c->pending || !c->result.verify)
|
|
|
|
return NULL; /* No results yet or verification error. */
|
|
|
|
|
|
|
|
for (result = c->result.verify;
|
|
|
|
result && idx > 0; result = result->next, idx--)
|
|
|
|
;
|
|
|
|
if (!result)
|
|
|
|
return NULL; /* No more signatures. */
|
|
|
|
|
|
|
|
if (r_stat)
|
|
|
|
*r_stat = result->status;
|
|
|
|
if (r_created)
|
|
|
|
*r_created = result->timestamp;
|
|
|
|
return result->fpr;
|
2001-02-12 15:23:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gpgme_get_sig_key:
|
|
|
|
* @c: context
|
|
|
|
* @idx: Index of the signature starting at 0
|
|
|
|
* @r_key: Returns the key object
|
|
|
|
*
|
|
|
|
* Return a key object which was used to check the signature.
|
|
|
|
*
|
2001-02-19 17:22:38 +00:00
|
|
|
* Return value: An Errorcode or 0 for success. GPGME_EOF is returned to
|
2001-02-12 15:23:29 +00:00
|
|
|
* indicate that there are no more signatures.
|
|
|
|
**/
|
|
|
|
GpgmeError
|
|
|
|
gpgme_get_sig_key (GpgmeCtx c, int idx, GpgmeKey *r_key)
|
|
|
|
{
|
2001-11-15 21:32:09 +00:00
|
|
|
VerifyResult result;
|
|
|
|
GpgmeError err = 0;
|
|
|
|
|
|
|
|
if (!c || !r_key)
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
if (c->pending || !c->result.verify)
|
|
|
|
return mk_error (Busy);
|
|
|
|
|
|
|
|
for (result = c->result.verify;
|
|
|
|
result && idx > 0; result = result->next, idx--)
|
|
|
|
;
|
|
|
|
if (!result)
|
|
|
|
return mk_error (EOF);
|
|
|
|
|
|
|
|
if (strlen(result->fpr) < 16) /* We have at least a key ID. */
|
|
|
|
return mk_error (Invalid_Key);
|
|
|
|
|
|
|
|
*r_key = _gpgme_key_cache_get (result->fpr);
|
|
|
|
if (!*r_key)
|
|
|
|
{
|
|
|
|
GpgmeCtx listctx;
|
|
|
|
|
|
|
|
/* Fixme: This can be optimized by keeping an internal context
|
|
|
|
used for such key listings. */
|
|
|
|
err = gpgme_new (&listctx);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
gpgme_set_keylist_mode (listctx, c->keylist_mode);
|
|
|
|
err = gpgme_op_keylist_start (listctx, result->fpr, 0);
|
|
|
|
if (!err)
|
|
|
|
err = gpgme_op_keylist_next (listctx, r_key);
|
|
|
|
gpgme_release (listctx);
|
2001-05-28 17:35:10 +00:00
|
|
|
}
|
2001-11-15 21:32:09 +00:00
|
|
|
return err;
|
2001-02-12 15:23:29 +00:00
|
|
|
}
|