gpgme_get_sig_key() problems
Gordon Worley
redbird at rbisland.cx
Thu Aug 8 18:08:02 CEST 2002
On Thursday, August 8, 2002, at 03:28 AM, Marcus Brinkmann wrote:
> On Tue, Aug 06, 2002 at 12:09:48PM -0400, Gordon Worley wrote:
>> Hi. I'm having problems with getting the keys that correspond to
>> signatures when there are multiple signatures. I have, in my example
>> file, three signatures (my main key, my Mac GPG key, and a test key
>> that
>> I created) on the data. When I call gpgme_get_sig_key(), it sometimes
>> does not return a key when the index is valid (it will report index out
>> of bounds). After a few seconds, though, it will work. This only
>> happens sometimes, though.
>
> This is strange. Seems to me like there is a timing problem in the
> code,
> although I can not see it. Can you provide us witha test program that
> shows
> the problem on your machine? Maybe I can also get more input by
> letting you
> run a modified version of GPGME that prints out some debugging output
> if we
> can not reproduce it here.
Well, I don't have enough experience working with GPGME itself (I use
our Objective C wrapper) to write a test program, but here are the
relevant bits of code that I call in the process of trying to get the
signatures' keys.
//In my end-user program
NSMutableArray *keys = [NSMutableArray array];
for (i = 0; i < [signatures count]; i++) {
[keys addObject: [(GPGSignature *)[signatures objectAtIndex: i]
key]];
}
////////////////////////////////////////
//in GPGME.framework
//this is a GPGSignature method
- (GPGKey *) key
{
//NSLog(@"%d", _index);
return [_context keyOfSignatureAtIndex:_index];
}
////////////////////////////////////////
//Also in GPGME.framework
//This is a GPGContext method (that's what the _context above is)
- (GPGKey *) keyOfSignatureAtIndex:(int)index
{
GpgmeKey aGpgmeKey;
GpgmeError anError = gpgme_get_sig_key(_context, index, &aGpgmeKey);
GPGKey *key;
//NSLog(@"keyOfSignatureAtIndex: %d", index);
if(anError == GPGME_EOF)
return nil;
if(anError != GPGME_No_Error)
[[NSException exceptionWithGPGError:anError userInfo:nil] raise];
NSAssert(aGpgmeKey != NULL, @"### No gpgmeKey but no error?!");
key = [[GPGKey alloc] initWithInternalRepresentation:aGpgmeKey];
// Key returned by gpgme_get_sig_key() has one reference;
// Wrapper also takes a reference on it,
// thus we can remove one reference, safely.
gpgme_key_unref(aGpgmeKey);
return [key autorelease];
}
/////////////////////////////////////////
Sorry, that's probably not much help, but maybe it will give some
indication of what's happening.
From my own debugging, I thought that maybe a truly invalid index was
being passed, but checking the index through the call chain shows that
it is always correct and there isn't a one off error or something like
then when I ask for the key.
As you suggest, my guess is a timing error of some sort, since it only
sometimes happens. We recently had a problem like this of our own with
passphrases, and it turned out to be an error with Objective C's
autorelease pool. If you are using some kind of similar garbage
collection method (if any at all), maybe that could be causing problems?
If you need me to run GPGME with extra debugging code, just point me to
the right sources.
--
Gordon Worley - Mac GPG Project
http://macgpg.sourceforge.net/ ``Doveriai no proveriai.''
redbird at rbisland.cx --Russian proverb
PGP: 0xBBD3B003
More information about the Gnupg-devel
mailing list