Skip to content

Commit

Permalink
Fixed bug with gpg2 search helpers; added -options; fixed -copyWithZone:
Browse files Browse the repository at this point in the history
git-svn-id: http://macgpg.svn.sourceforge.net/svnroot/macgpg/GPGME/trunk@1842 c19e94ca-3d1d-0410-add0-bf5d5e3bda8e
  • Loading branch information
davelopper committed May 12, 2008
1 parent fda918f commit 6cbde51
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 58 deletions.
87 changes: 51 additions & 36 deletions GPGContext.h
Expand Up @@ -47,6 +47,7 @@ extern "C" {
@class NSMutableSet;
@class GPGData;
@class GPGKey;
@class GPGOptions;


/*!
Expand Down Expand Up @@ -385,15 +386,15 @@ GPG_EXPORT NSString * const GPGNextTrustItemKey;
* @method setUsesArmor:
* @abstract Enables or disables the use of an <i>ASCII armor</i> for all
* output.
* @discussion Default value is NO.
* @param armor YES or NO.
* @discussion Default value is <code>NO</code>.
* @param armor <code>YES</code> or <code>NO</code>.
*/
- (void) setUsesArmor:(BOOL)armor;

/*!
* @method usesArmor
* @abstract Returns whether context uses <i>ASCII armor</i> or not.
* @discussion Default value is NO.
* @discussion Default value is <code>NO</code>.
*/
- (BOOL) usesArmor;

Expand All @@ -412,15 +413,15 @@ GPG_EXPORT NSString * const GPGNextTrustItemKey;
* This option is only relevant to the OpenPGP crypto engine, and
* ignored by all other engines.
*
* Default value is NO.
* @param mode YES or NO.
* Default value is <code>NO</code>.
* @param mode <code>YES</code> or <code>NO</code>.
*/
- (void) setUsesTextMode:(BOOL)mode;

/*!
* @method usesTextMode
* @abstract Returns whether context uses <i>text mode</i> or not.
* @discussion Default value is NO.
* @discussion Default value is <code>NO</code>.
*/
- (BOOL) usesTextMode;

Expand Down Expand Up @@ -863,6 +864,17 @@ GPG_EXPORT NSString * const GPGNextTrustItemKey;
*/
- (GPGEngine *) engine;

/*!
* @method options
* @abstract Convenience method. Returns the options file of currently used
* engine.
* @discussion Will return a new instance on each invocation. If you change the
* engine or its home directory, you need to ask for a new
* <code>@link //macgpg/occ/cl/GPGOptions GPGOptions@/link</code>
* instance.
*/
- (GPGOptions *) options;

@end


Expand All @@ -876,13 +888,14 @@ GPG_EXPORT NSString * const GPGNextTrustItemKey;
/*!
* @method waitOnAnyRequest:
* @abstract Waits for any finished request.
* @discussion Waits for any finished request. When <i>hang</i> is YES the
* method will wait, otherwise it will return immediately when
* @discussion Waits for any finished request. When <i>hang</i> is <code>YES</code>
* the method will wait, otherwise it will return immediately when
* there is no pending finished request.
*
* Returns the context of the finished request or nil if
* <i>hang</i> is NO and no request has finished.
* @param hang NO will return immediately, YES will wait.
* <i>hang</i> is <code>NO</code> and no request has finished.
* @param hang <code>NO</code> will return immediately, <code>YES</code>
* will wait.
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* exception which reflects the termination status of the
* operation (in case of error). The exception's userInfo
Expand All @@ -900,13 +913,15 @@ GPG_EXPORT NSString * const GPGNextTrustItemKey;
* the crypto back-end and watches over the run time status of the
* back-end process.
*
* If <i>hang</i> is YES the method does not return until the
* operation is completed or cancelled. Otherwise the method will
* not block for a long time.
* If <i>hang</i> is <code>YES</code> the method does not return
* until the operation is completed or cancelled. Otherwise the
* method will not block for a long time.
*
* Returns YES if there is a finished request for context or NO if
* <i>hang</i> is NO and no request (for context) has finished.
* @param hang NO will return immediately, YES will wait.
* Returns <code>YES</code> if there is a finished request for
* context or <code>NO</code> if <i>hang</i> is <code>NO</code> and
* no request (for context) has finished.
* @param hang <code>NO</code> will return immediately, <code>YES</code>
* will wait.
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* exception which reflects the termination status of the
* operation (in case of error). The exception's userInfo
Expand Down Expand Up @@ -1133,14 +1148,14 @@ GPG_EXPORT NSString * const GPGNextTrustItemKey;
* and <code>@link //macgpg/occ/cl/GPGKeyGroup GPGKeyGroup@/link</code>
* objects; you can mix them.
*
* If the <i>trustAllKeys</i> parameter is set to YES, then all
* passed keys will be trusted, even if the keys do not have a high
* enough validity in the <i>key ring</i>. This flag should be used
* with care; in general it is not a good idea to use any untrusted
* keys.
* If the <i>trustAllKeys</i> parameter is set to <code>YES</code>,
* then all passed keys will be trusted, even if the keys do not
* have a high enough validity in the <i>key ring</i>. This flag
* should be used with care; in general it is not a good idea to
* use any untrusted keys.
* @param inputData Data to encrypt
* @param recipientKeys Keys and key groups to use for encryption
* @param trustAllKeys Ignore <i>key ring</i> trust validities when YES
* @param trustAllKeys Ignore <i>key ring</i> trust validities when <code>YES</code>
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* exception with error code:<dl>
* <dt><code>@link //macgpg/c/econst/GPGErrorUnusablePublicKey GPGErrorUnusablePublicKey@/link</code></dt>
Expand Down Expand Up @@ -1186,7 +1201,7 @@ GPG_EXPORT NSString * const GPGNextTrustItemKey;
* objects; you can mix them.
* @param inputData Data to sign and encrypt
* @param keys Keys and key groups to use for encryption
* @param trustAllKeys Ignore <i>key ring</i> trust validities when YES
* @param trustAllKeys Ignore <i>key ring</i> trust validities when <code>YES</code>
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* exception with error code:<dl>
* <dt><code>@link //macgpg/c/econst/GPGErrorNoData GPGErrorNoData@/link</code></dt>
Expand Down Expand Up @@ -1388,10 +1403,10 @@ GPG_EXPORT NSString * const GPGNextTrustItemKey;
* @abstract Deletes the given <i>key</i> from the standard <i>key ring</i>
* of the crypto engine used by the context.
* @discussion To delete a secret key along with the public key,
* <i>allowSecret</i> must be YES, else only the public key is
* <i>allowSecret</i> must be <code>YES</code>, else only the public key is
* deleted, if that is supported.
* @param key Key to delete
* @param allowSecret Delete also matching secret key when YES
* @param allowSecret Delete also matching secret key when <code>YES</code>
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* exception with error code:<dl>
* <dt><code>@link //macgpg/c/econst/GPGErrorNoPublicKey GPGErrorNoPublicKey@/link</code></dt>
Expand All @@ -1400,7 +1415,7 @@ GPG_EXPORT NSString * const GPGNextTrustItemKey;
* <dd><i>key</i> was not specified unambiguously.</dd>
* <dt><code>@link //macgpg/c/econst/GPGErrorConflict GPGErrorConflict@/link</code></dt>
* <dd>Secret key for <i>key</i> is available, but
* <i>allowSecret</i> is NO.</dd></dl>
* <i>allowSecret</i> is <code>NO</code>.</dd></dl>
* Other exceptions could be raised too.
*/
- (void) deleteKey:(GPGKey *)key evenIfSecretKey:(BOOL)allowSecret;
Expand All @@ -1413,10 +1428,10 @@ GPG_EXPORT NSString * const GPGNextTrustItemKey;
/*!
* @method keyFromFingerprint:secretKey:
* @abstract Fetches a single key, given its fingerprint (or key ID).
* @discussion If <i>secretKey</i> is YES, returns a secret key, else returns a
* public key. You can set the key list mode if you want to
* retrieve key signatures too. Returns nil if no matching key is
* found.
* @discussion If <i>secretKey</i> is <code>YES</code>, returns a secret key,
* else returns a public key. You can set the key list mode if you
* want to retrieve key signatures too. Returns nil if no matching
* key is found.
* @param fingerprint Fingerprint or key ID
* @param secretKey Searches secret keys only
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
Expand Down Expand Up @@ -1493,8 +1508,8 @@ GPG_EXPORT NSString * const GPGNextTrustItemKey;
* search to a certain common name or user, not to list many
* specific keys at once by listing their fingerprints or key IDs.
*
* If <i>secretKeysOnly</i> is YES, searches only for secret keys,
* else searches only for public keys.
* If <i>secretKeysOnly</i> is <code>YES</code>, searches only for
* secret keys, else searches only for public keys.
*
* This call also resets any pending key listing operation.
*
Expand Down Expand Up @@ -1783,8 +1798,8 @@ GPG_EXPORT NSString * const GPGNextTrustItemKey;

/*!
* @method isPerformingAsyncOperation
* @abstract Returns YES when the context is performing an asynchronous
* operation.
* @abstract Returns <code>YES</code> when the context is performing an
* asynchronous operation.
*/
-(BOOL) isPerformingAsyncOperation;

Expand Down Expand Up @@ -1822,8 +1837,8 @@ GPG_EXPORT NSString * const GPGNextTrustItemKey;
* object to its passphrase delegate when needing a passphrase.
* @discussion <i>key</i> is the secret key for which the user is asked a
* passphrase. <i>key</i> is nil only in case of symmetric
* signature/decryption. <i>again</i> is set to YES if user typed a
* wrong passphrase the previous time(s).
* signature/decryption. <i>again</i> is set to <code>YES</code>
* if user typed a wrong passphrase the previous time(s).
*
* If you return nil, it means that user cancelled passphrase
* request.
Expand Down
45 changes: 23 additions & 22 deletions GPGContext.m
Expand Up @@ -202,7 +202,7 @@ - (id) copyWithZone:(NSZone *)zone
while(anEngineCopy = [engineCopyEnum nextObject]){
if([anEngineCopy engineProtocol] == [anEngine engineProtocol]){
[anEngineCopy setExecutablePath:[anEngine executablePath]];
[anEngineCopy setHomeDirectory:[anEngine homeDirectory]];
[anEngineCopy setCustomHomeDirectory:[anEngine customHomeDirectory]];
break;
}
}
Expand Down Expand Up @@ -772,6 +772,11 @@ - (GPGEngine *) engine
return nil;
}

- (GPGOptions *) options
{
return [[[GPGOptions alloc] initWithPath:[[self engine] optionsFilename]] autorelease];
}

@end


Expand Down Expand Up @@ -1491,11 +1496,6 @@ - (void) stopTrustItemEnumeration
@end


@interface GPGOptions(GPGContext_Revealed)
- (NSArray *) _subOptionsForName:(NSString *)optionName;
@end


enum {
_GPGContextHelperSearchCommand,
_GPGContextHelperGetCommand,
Expand Down Expand Up @@ -1556,11 +1556,12 @@ + (void) performCommand:(int)theCommand forContext:(GPGContext *)theContext argu
NSNumber *formatVersionNumber = nil;
int urlSchemeSeparatorLength = 3; // Length of ://
BOOL passHostArgument = YES;
int engineMajorVersion;

if(executableVersions == nil)
executableVersions = [[NSMutableDictionary alloc] initWithCapacity:5];

gpgOptions = [[GPGOptions alloc] init];
gpgOptions = [[theContext options] retain];
aHostName = [thePassedOptions objectForKey:@"keyserver"];
if(aHostName == nil){
NSArray *optionValues = [gpgOptions activeOptionValuesForName:@"keyserver"];
Expand All @@ -1587,37 +1588,38 @@ + (void) performCommand:(int)theCommand forContext:(GPGContext *)theContext argu
aRange = [aHostName rangeOfString:@"://"];
}
}
engineMajorVersion = [[[theContext engine] version] characterAtIndex:0] - '0';
aString = [aHostName lowercaseString];
if([aString hasPrefix:@"ldap://"]){
launchPath = @"gpgkeys_ldap"; // Hardcoded
launchPath = (engineMajorVersion == 2 ? @"gpg2keys_ldap" : @"gpgkeys_ldap"); // Hardcoded
aProtocol = @"ldap";
}
else if([aString hasPrefix:@"x-hkp://"]){
launchPath = @"gpgkeys_hkp"; // Hardcoded
launchPath = (engineMajorVersion == 2 ? @"gpg2keys_hkp" : @"gpgkeys_hkp"); // Hardcoded
aProtocol = @"x-hkp";
}
else if([aString hasPrefix:@"hkp://"]){
launchPath = @"gpgkeys_hkp"; // Hardcoded
launchPath = (engineMajorVersion == 2 ? @"gpg2keys_hkp" : @"gpgkeys_hkp"); // Hardcoded
aProtocol = @"hkp";
}
else if([aString hasPrefix:@"http://"]){
launchPath = @"gpgkeys_curl"; // Hardcoded
launchPath = (engineMajorVersion == 2 ? @"gpg2keys_curl" : @"gpgkeys_curl"); // Hardcoded
aProtocol = @"http";
}
else if([aString hasPrefix:@"https://"]){
launchPath = @"gpgkeys_curl"; // Hardcoded
launchPath = (engineMajorVersion == 2 ? @"gpg2keys_curl" : @"gpgkeys_curl"); // Hardcoded
aProtocol = @"https";
}
else if([aString hasPrefix:@"ftp://"]){
launchPath = @"gpgkeys_curl"; // Hardcoded
launchPath = (engineMajorVersion == 2 ? @"gpg2keys_curl" : @"gpgkeys_curl"); // Hardcoded
aProtocol = @"ftp";
}
else if([aString hasPrefix:@"ftps://"]){
launchPath = @"gpgkeys_curl"; // Hardcoded
launchPath = (engineMajorVersion == 2 ? @"gpg2keys_curl" : @"gpgkeys_curl"); // Hardcoded
aProtocol = @"ftps";
}
else if([aString hasPrefix:@"finger:"]){
launchPath = @"gpgkeys_finger"; // Hardcoded
launchPath = (engineMajorVersion == 2 ? @"gpg2keys_finger" : @"gpgkeys_finger"); // Hardcoded
aProtocol = @"finger";
}
else{
Expand All @@ -1626,10 +1628,11 @@ + (void) performCommand:(int)theCommand forContext:(GPGContext *)theContext argu
}
aHostName = [aHostName substringFromIndex:aRange.location + urlSchemeSeparatorLength];

if([[[theContext engine] version] characterAtIndex:0] == '1')
if(engineMajorVersion == 1)
aString = [[[[[theContext engine] executablePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"libexec/gnupg"]; // E.g. from /usr/local/bin/gpg to /usr/local/libexec/gnupg
else
aString = [[[[[theContext engine] executablePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"libexec"]; // E.g. from /usr/local/bin/gpg to /usr/local/libexec
else{
aString = [[[[[theContext engine] executablePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"libexec"]; // E.g. from /usr/local/bin/gpg2 to /usr/local/libexec
}
aString = [aString stringByAppendingPathComponent:launchPath];
if(![[NSFileManager defaultManager] fileExistsAtPath:aString]){
aString = [[[[[theContext engine] executablePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"lib/gnupg"]; // E.g. from /sw/bin/gpg to /sw/lib/gnupg (needed for Fink installations!)
Expand All @@ -1638,7 +1641,7 @@ + (void) performCommand:(int)theCommand forContext:(GPGContext *)theContext argu
BOOL tryEmbeddedOnes = YES;

if([aProtocol isEqualToString:@"http"]){
launchPath = @"gpgkeys_http"; // Hardcoded
launchPath = (engineMajorVersion == 2 ? @"gpg2keys_http" : @"gpgkeys_http"); // Hardcoded
aString = [[aString stringByDeletingLastPathComponent] stringByAppendingPathComponent:launchPath];
tryEmbeddedOnes = ![[NSFileManager defaultManager] fileExistsAtPath:aString];
}
Expand Down Expand Up @@ -2288,7 +2291,7 @@ @implementation GPGContext(GPGKeyGroups)

- (NSArray *) keyGroups
{
GPGOptions *options = [[GPGOptions alloc] init];
GPGOptions *options = [self options];
NSArray *groupOptionValues = [options activeOptionValuesForName:@"group"];
NSEnumerator *groupDefEnum = [groupOptionValues objectEnumerator];
NSMutableDictionary *groupsPerName = [NSMutableDictionary dictionaryWithCapacity:[groupOptionValues count]];
Expand Down Expand Up @@ -2322,8 +2325,6 @@ - (NSArray *) keyGroups
[newGroup release];
}

[options release];

return [groupsPerName allValues];
}

Expand Down

0 comments on commit 6cbde51

Please sign in to comment.