]> git.saurik.com Git - apple/security.git/blobdiff - OSX/sec/Security/Tool/keychain_find.c
Security-57740.51.3.tar.gz
[apple/security.git] / OSX / sec / Security / Tool / keychain_find.c
index dc0151f573056984befb1cef24f04c1d65aa7738..0d4f132b9e35fad404f85adb4ec5f6361473054c 100644 (file)
@@ -1,9 +1,27 @@
-//
-//
-//
-//
-
-
+/*
+ * Copyright (c) 2003-2007,2009-2010,2013-2014 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ *
+ * keychain_find.c
+ */
 
 #include <CoreFoundation/CoreFoundation.h>
 
@@ -43,6 +61,20 @@ static void add_key(const void *key, const void *value, void *context) {
     CFArrayAppendValue(context, key);
 }
 
+static bool isPrintableString(CFStringRef theString){
+    bool result = false;
+    CFCharacterSetRef controlSet = CFCharacterSetGetPredefined(kCFCharacterSetControl);
+    CFCharacterSetRef newlineSet = CFCharacterSetGetPredefined(kCFCharacterSetNewline);
+    CFCharacterSetRef illegalSet = CFCharacterSetGetPredefined(kCFCharacterSetIllegal);
+
+    CFMutableCharacterSetRef unacceptable = CFCharacterSetCreateMutableCopy(kCFAllocatorDefault, controlSet);
+    CFCharacterSetUnion(unacceptable, newlineSet);
+    CFCharacterSetUnion(unacceptable, illegalSet);
+    result = CFStringFindCharacterFromSet(theString, unacceptable, CFRangeMake(0, CFStringGetLength(theString)), 0, NULL);
+    CFReleaseNull(unacceptable);
+    return result;
+}
+
 static void display_item(const void *v_item, void *context) {
     CFDictionaryRef item = (CFDictionaryRef)v_item;
     CFIndex dict_count, key_ix, key_count;
@@ -81,12 +113,18 @@ static void display_item(const void *v_item, void *context) {
             CFDataRef v_d = (CFDataRef)value;
             CFStringRef v_s = CFStringCreateFromExternalRepresentation(
                 kCFAllocatorDefault, v_d, kCFStringEncodingUTF8);
+
             if (v_s) {
-                CFStringAppend(line, CFSTR("/"));
-                CFStringAppend(line, v_s);
-                CFStringAppend(line, CFSTR("/ "));
-                CFRelease(v_s);
+                if(!isPrintableString(v_s))
+                    CFStringAppend(line, CFSTR("not printable "));
+                else{
+                    CFStringAppend(line, CFSTR("/"));
+                    CFStringAppend(line, v_s);
+                    CFStringAppend(line, CFSTR("/ "));
+                }
             }
+            CFReleaseNull(v_s);
+
             const uint8_t *bytes = CFDataGetBytePtr(v_d);
             CFIndex len = CFDataGetLength(v_d);
             for (jx = 0; jx < len; ++jx) {
@@ -467,6 +505,8 @@ int keychain_item(int argc, char * const *argv) {
             result = 1;
         }
     } else {
+        if (!do_delete && CFDictionaryGetValue(query, kSecUseAuthenticationUI) == NULL)
+            CFDictionarySetValue(query, kSecUseAuthenticationUI, kSecUseAuthenticationUISkip);
         do_find_or_delete(query, do_delete);
     }