GPG is too much trouble for the access file
This commit is contained in:
@@ -16,21 +16,26 @@ void printUsage()
|
||||
fprintf(stderr, "\t-h \t Show this help message\n");
|
||||
fprintf(stderr, "\t-s \t Use SSL (requires -c option)\n");
|
||||
fprintf(stderr, "\t-c \t SSL certificate path encoded as pkcs12\n");
|
||||
fprintf(stderr, "\t-a \t Optional GPG encrypted access control file\n");
|
||||
fprintf(stderr, "\t-a \t Optional access control file\n");
|
||||
}
|
||||
|
||||
BOOL acquireCredentials(const char *accessFile, NSString **out_username, NSString **out_password)
|
||||
BOOL acquireCredentials(bool encrypted, const char *accessFile, NSString **out_username, NSString **out_password)
|
||||
{
|
||||
BOOL success = NO;
|
||||
NSString *asString = nil;
|
||||
NSError *launchError = nil;
|
||||
|
||||
NSString *accessFilePath = [NSString stringWithUTF8String:accessFile];
|
||||
if (encrypted) {
|
||||
NSPipe *stdoutPipe = [NSPipe pipe];
|
||||
NSPipe *stderrPipe = [NSPipe pipe];
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
task.launchPath = @"/usr/local/bin/gpg";
|
||||
task.arguments = @[ @"-q", @"-d", [NSString stringWithUTF8String:accessFile] ];
|
||||
task.arguments = @[ @"-q", @"-d", accessFilePath ];
|
||||
task.standardOutput = stdoutPipe;
|
||||
task.standardError = stderrPipe;
|
||||
|
||||
NSError *launchError = nil;
|
||||
BOOL success = [task launchAndReturnError:&launchError];
|
||||
success = [task launchAndReturnError:&launchError];
|
||||
[task waitUntilExit];
|
||||
|
||||
if (success) {
|
||||
@@ -44,7 +49,22 @@ BOOL acquireCredentials(const char *accessFile, NSString **out_username, NSStrin
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSString *asString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
asString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
} else {
|
||||
NSError *fileReadError = nil;
|
||||
asString = [NSString stringWithContentsOfFile:accessFilePath
|
||||
encoding:NSASCIIStringEncoding
|
||||
error:&fileReadError];
|
||||
if (fileReadError != nil) {
|
||||
MBIMLogFatal(@"File open error when opening access file: %@", fileReadError.localizedDescription);
|
||||
return NO;
|
||||
}
|
||||
|
||||
success = (asString.length > 0);
|
||||
}
|
||||
|
||||
if (success) {
|
||||
NSScanner *scanner = [NSScanner scannerWithString:asString];
|
||||
|
||||
BOOL scannerSuccess = NO;
|
||||
@@ -133,7 +153,7 @@ int main(int argc, char *const argv[]) {
|
||||
NSString *username = nil;
|
||||
NSString *password = nil;
|
||||
|
||||
BOOL success = acquireCredentials(accessFilePath, &username, &password);
|
||||
BOOL success = acquireCredentials(false, accessFilePath, &username, &password);
|
||||
if (!success) {
|
||||
MBIMLogInfo(
|
||||
@"Access file must be a GPG encrypted file (encrypted with your private key, to your pub key) "
|
||||
|
||||
Reference in New Issue
Block a user