Private
Public Access
1
0

GPG is too much trouble for the access file

This commit is contained in:
James Magahern
2021-06-12 17:44:31 -07:00
parent bb169c3e1c
commit 3c99b647d2

View File

@@ -16,21 +16,26 @@ void printUsage()
fprintf(stderr, "\t-h \t Show this help message\n"); fprintf(stderr, "\t-h \t Show this help message\n");
fprintf(stderr, "\t-s \t Use SSL (requires -c option)\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-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 *stdoutPipe = [NSPipe pipe];
NSPipe *stderrPipe = [NSPipe pipe]; NSPipe *stderrPipe = [NSPipe pipe];
NSTask *task = [[NSTask alloc] init]; NSTask *task = [[NSTask alloc] init];
task.launchPath = @"/usr/local/bin/gpg"; task.launchPath = @"/usr/local/bin/gpg";
task.arguments = @[ @"-q", @"-d", [NSString stringWithUTF8String:accessFile] ]; task.arguments = @[ @"-q", @"-d", accessFilePath ];
task.standardOutput = stdoutPipe; task.standardOutput = stdoutPipe;
task.standardError = stderrPipe; task.standardError = stderrPipe;
NSError *launchError = nil; success = [task launchAndReturnError:&launchError];
BOOL success = [task launchAndReturnError:&launchError];
[task waitUntilExit]; [task waitUntilExit];
if (success) { if (success) {
@@ -44,7 +49,22 @@ BOOL acquireCredentials(const char *accessFile, NSString **out_username, NSStrin
return NO; 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]; NSScanner *scanner = [NSScanner scannerWithString:asString];
BOOL scannerSuccess = NO; BOOL scannerSuccess = NO;
@@ -133,7 +153,7 @@ int main(int argc, char *const argv[]) {
NSString *username = nil; NSString *username = nil;
NSString *password = nil; NSString *password = nil;
BOOL success = acquireCredentials(accessFilePath, &username, &password); BOOL success = acquireCredentials(false, accessFilePath, &username, &password);
if (!success) { if (!success) {
MBIMLogInfo( MBIMLogInfo(
@"Access file must be a GPG encrypted file (encrypted with your private key, to your pub key) " @"Access file must be a GPG encrypted file (encrypted with your private key, to your pub key) "