Skip to content

Commit

Permalink
Merge pull request #8 from dmayer/master
Browse files Browse the repository at this point in the history
iOS 9 fixes, output coloring fix, and crash fix
  • Loading branch information
NitinJami committed Feb 3, 2016
2 parents 5feb9cf + 4893402 commit 36f32e7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
ARCH_FLAGS=-arch armv7 -marm -march=armv7-a
ARCH_FLAGS=-arch arm64 -arch armv7 -marm -march=armv7-a

keychaineditor: main.m
clang \
-Os -Wall -bind_at_load -fobjc-arc \
$(ARCH_FLAGS) \
-mios-version-min=7.0 \
-isysroot `xcrun --sdk iphoneos8.3 --show-sdk-path` \
-isysroot `xcrun --sdk iphoneos9.2 --show-sdk-path` \
-framework Foundation -framework Security \
-o keychaineditor main.m
ldid -Sentitlements.xml keychaineditor

clean:
rm -f keychaineditor
Binary file modified keychaineditor
Binary file not shown.
44 changes: 23 additions & 21 deletions main.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

void printUsage() {

fprintf(stdout, "\n\e[4;30mUsage:\e[0;31m ./keychaineditor commands \
\n\e[4;30mCommands can be:\e[0;31m\
fprintf(stdout, "\n\e[0;0mUsage:\e[0;31m ./keychaineditor commands \
\n\e[0;0mCommands can be:\e[0;31m\
\n\t--help: Prints the usage.\
\n\t--action: Can be either min-dump, dump, edit, delete.\
\n\t--find: uses 'CONTAINS' to find strings from the dump.\
Expand All @@ -50,13 +50,13 @@ void printUsage() {
\n\e[0;32mNote: If there is no account name, pass a '' string.\
\n\e[0;32mNote: --find is an optional command for dump. It search from\
\n\e[0;32m{Account, Service, EntitlementGroup, Protection}.\
\n\e[4;30mExamples:\e[0;31m\
\n\e[4;0mExamples:\e[0;31m\
\n\t./keychaineditor --action dump --find XXX\
\n\tOr\
\n\t./keychaineditor --action delete --account XXX --service XXX\
\n\tOr\
\n\t./keychaineditor --action edit --account XXX --service XXX --data XXX\
\e[0;30m\n\n");
\e[0;0m\n\n");

return;

Expand All @@ -75,21 +75,21 @@ OSStatus osstatusToHumanReadableString(OSStatus status) {

switch (status) {
case errSecSuccess:
fprintf(stdout, "\e[0;32mOperation successfully completed.\e[0;30m\n");
fprintf(stdout, "\e[0;32mOperation successfully completed.\e[0;0m\n");
break;
case errSecItemNotFound:
fprintf(stderr, "\e[0;31mThe specified item could not be found in the keychain.\e[0;30m\n");
fprintf(stderr, "\e[0;31mThe specified item could not be found in the keychain.\e[0;0m\n");
break;
case errSecAuthFailed:
fprintf(stderr, "\e[0;31mDid you turn off the passcode on device? The item is no longer available.\e[0;30m\n");
fprintf(stderr, "\e[0;31mIf that is not the case, UserPresence is required. Check your device for the prompt.\e[0;30m\n");
fprintf(stderr, "\e[0;31mDid you turn off the passcode on device? The item is no longer available.\e[0;0m\n");
fprintf(stderr, "\e[0;31mIf that is not the case, UserPresence is required. Check your device for the prompt.\e[0;0m\n");
break;
case -34018:
fprintf(stderr, "\e[0;31mError: Client has neither application-identifier nor keychain-access-groups entitlements. Please refer README for further instructions.\e[0;30m\n");
fprintf(stderr, "\e[0;31mError: Client has neither application-identifier nor keychain-access-groups entitlements. Please refer README for further instructions.\e[0;0m\n");
break;

default:
fprintf(stderr, "\e[0;31mUnhandled Error: Please contact developer to report this error. Error code: %d\e[0;30m\n", (int)status);
fprintf(stderr, "\e[0;31mUnhandled Error: Please contact developer to report this error. Error code: %d\e[0;0m\n", (int)status);
break;
}

Expand Down Expand Up @@ -282,9 +282,11 @@ void prepareJsonOutput(NSDictionary *results, NSString *find) {
forKey:@"Creation Time"];

[innerJSON setObject:checkForNoDataValue([eachItemFromResults objectForKey:(__bridge id)kSecValueData]) forKey:@"Data"];

[innerJSON setObject:checkUserPresence((__bridge SecAccessControlRef) \
([eachItemFromResults objectForKey:(__bridge id)(kSecAttrAccessControl)])) forKey:@"UserPresence"];

if([eachItemFromResults objectForKey:(__bridge id)(kSecAttrAccessControl)]) {
[innerJSON setObject: checkUserPresence((__bridge SecAccessControlRef) \
([eachItemFromResults objectForKey:(__bridge id)(kSecAttrAccessControl)])) forKey:@"UserPresence"];
}

[parentJSON setObject:innerJSON forKey:[NSString stringWithFormat:@"%lu", (unsigned long)++index]];
}
Expand Down Expand Up @@ -316,7 +318,7 @@ void prepareJsonOutput(NSDictionary *results, NSString *find) {
fprintf(stdout, "%s\n", [[[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding] UTF8String]);
}
else {
fprintf(stderr, "\n\e[0;31mInternal error when preparing JSON output. Error: %s\e[0;30m\n", [[error localizedDescription] UTF8String]);
fprintf(stderr, "\n\e[0;31mInternal error when preparing JSON output. Error: %s\e[0;0m\n", [[error localizedDescription] UTF8String]);
}
}

Expand All @@ -332,7 +334,7 @@ void prepareMinimumOutput(NSDictionary *results) {
NSString *account = [[NSString alloc] init];
NSString *service = [[NSString alloc] init];

fprintf(stdout, "\e[0;31mWarning: The names are truncated to max width of 35 charaters. Please use this dump as a reference, and use --find to get full details.\n\e[0;30m");
fprintf(stdout, "\e[0;31mWarning: The names are truncated to max width of 35 charaters. Please use this dump as a reference, and use --find to get full details.\n\e[0;0m");

// Prettify the output.
fprintf(stdout, "Account%28s | Service\n", "");
Expand Down Expand Up @@ -555,7 +557,7 @@ int main(int argc, char *argv[]) {
*/

if (![[NSString stringWithFormat:@"%s", argv[1]] isEqualToString:@"--action"]) {
fprintf(stderr, "\e[0;31mInvalid command passed as first argument. Please use --help to get usage information.\e[0;30m");
fprintf(stderr, "\e[0;31mInvalid command passed as first argument. Please use --help to get usage information.\e[0;0m");
return EXIT_FAILURE;
}

Expand Down Expand Up @@ -589,7 +591,7 @@ int main(int argc, char *argv[]) {
*/

if (![@[@"min-dump", @"dump", @"edit", @"delete"] containsObject:action]) {
fprintf(stderr, "\e[0;31mInvalid action passed. Please use --help to get usage information.\n\e[0;30m");
fprintf(stderr, "\e[0;31mInvalid action passed. Please use --help to get usage information.\n\e[0;0m");
return EXIT_FAILURE;
}

Expand All @@ -611,7 +613,7 @@ int main(int argc, char *argv[]) {
*/

if ( (acct == nil) || (srvc == nil) || (data == nil) ) {
fprintf(stderr, "\e[0;31mEdit requires account, service and data. Please use --help to get usage information.\n\e[0;30m");
fprintf(stderr, "\e[0;31mEdit requires account, service and data. Please use --help to get usage information.\n\e[0;0m");
return EXIT_FAILURE;
}

Expand All @@ -627,7 +629,7 @@ int main(int argc, char *argv[]) {
NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:data options:NSDataBase64DecodingIgnoreUnknownCharacters];

if (decodedData == nil) {
fprintf(stderr, "\e[0;31mData only accepts base64 strings. Please use --help to get usage information.\n\e[0;30m");
fprintf(stderr, "\e[0;31mData only accepts base64 strings. Please use --help to get usage information.\n\e[0;0m");
return EXIT_FAILURE;
}

Expand All @@ -642,7 +644,7 @@ int main(int argc, char *argv[]) {
*/

if ( (acct == nil) || (srvc == nil) ) {
fprintf(stderr, "\e[0;31mDelete requires account, service. Please use --help to get usage information.\n\e[0;30m");
fprintf(stderr, "\e[0;31mDelete requires account, service. Please use --help to get usage information.\n\e[0;0m");
return EXIT_FAILURE;
}

Expand All @@ -653,4 +655,4 @@ int main(int argc, char *argv[]) {
}

return EXIT_SUCCESS;
}
}

0 comments on commit 36f32e7

Please sign in to comment.