]> git.saurik.com Git - apple/security.git/blob - OSX/sec/SOSCircle/Tool/keychain_log.c
89af2f74bbb6ab1b7b6b9d1e18848fa5cd80cda0
[apple/security.git] / OSX / sec / SOSCircle / Tool / keychain_log.c
1 //
2 // keychain_log.c
3 // sec
4 //
5 // Created by Richard Murphy on 1/26/16.
6 //
7 //
8
9 #include "keychain_log.h"
10
11 /*
12 * Copyright (c) 2003-2007,2009-2010,2013-2014 Apple Inc. All Rights Reserved.
13 *
14 * @APPLE_LICENSE_HEADER_START@
15 *
16 * This file contains Original Code and/or Modifications of Original Code
17 * as defined in and that are subject to the Apple Public Source License
18 * Version 2.0 (the 'License'). You may not use this file except in
19 * compliance with the License. Please obtain a copy of the License at
20 * http://www.opensource.apple.com/apsl/ and read it before using this
21 * file.
22 *
23 * The Original Code and all software distributed under the License are
24 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
25 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
26 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
28 * Please see the License for the specific language governing rights and
29 * limitations under the License.
30 *
31 * @APPLE_LICENSE_HEADER_END@
32 *
33 * keychain_add.c
34 */
35
36
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <unistd.h>
41 #include <sys/utsname.h>
42 #include <sys/stat.h>
43 #include <time.h>
44
45 #include <Security/SecItem.h>
46
47 #include <CoreFoundation/CFNumber.h>
48 #include <CoreFoundation/CFString.h>
49
50 #include <Security/SecureObjectSync/SOSCloudCircle.h>
51 #include <Security/SecureObjectSync/SOSCloudCircleInternal.h>
52 #include <Security/SecureObjectSync/SOSPeerInfo.h>
53 #include <Security/SecureObjectSync/SOSPeerInfoPriv.h>
54 #include <Security/SecureObjectSync/SOSPeerInfoV2.h>
55 #include <Security/SecureObjectSync/SOSUserKeygen.h>
56 #include <Security/SecureObjectSync/SOSKVSKeys.h>
57 #include <securityd/SOSCloudCircleServer.h>
58 #include <Security/SecOTRSession.h>
59 #include <SOSCircle/CKBridge/SOSCloudKeychainClient.h>
60
61 #include <utilities/SecCFWrappers.h>
62 #include <utilities/debugging.h>
63
64 #include <SecurityTool/readline.h>
65 #include <notify.h>
66
67 #include "keychain_log.h"
68 #include "secToolFileIO.h"
69 #include "secViewDisplay.h"
70 #include <utilities/debugging.h>
71
72
73 #include <Security/SecPasswordGenerate.h>
74
75 #define MAXKVSKEYTYPE kUnknownKey
76 #define DATE_LENGTH 18
77
78
79 static const char *getSOSCCStatusDescription(SOSCCStatus ccstatus)
80 {
81 switch (ccstatus)
82 {
83 case kSOSCCInCircle: return "In Circle";
84 case kSOSCCNotInCircle: return "Not in Circle";
85 case kSOSCCRequestPending: return "Request pending";
86 case kSOSCCCircleAbsent: return "Circle absent";
87 case kSOSCCError: return "Circle error";
88
89 default:
90 return "<unknown ccstatus>";
91 break;
92 }
93 }
94
95 static void printPeerInfos(char *label, CFArrayRef (^getArray)(CFErrorRef *error)) {
96 CFErrorRef error = NULL;
97 CFArrayRef ppi = getArray(&error);
98 SOSPeerInfoRef me = SOSCCCopyMyPeerInfo(NULL);
99 CFStringRef mypeerID = SOSPeerInfoGetPeerID(me);
100
101 if(ppi) {
102 printmsg(CFSTR("%s count: %ld\n"), label, (long)CFArrayGetCount(ppi));
103 CFArrayForEach(ppi, ^(const void *value) {
104 char buf[160];
105 SOSPeerInfoRef peer = (SOSPeerInfoRef)value;
106 CFIndex version = SOSPeerInfoGetVersion(peer);
107 CFStringRef peerName = SOSPeerInfoGetPeerName(peer);
108 CFStringRef devtype = SOSPeerInfoGetPeerDeviceType(peer);
109 CFStringRef peerID = SOSPeerInfoGetPeerID(peer);
110 CFStringRef transportType = CFSTR("KVS");
111 CFStringRef deviceID = CFSTR("");
112 CFDictionaryRef gestalt = SOSPeerInfoCopyPeerGestalt(peer);
113 CFStringRef osVersion = CFDictionaryGetValue(gestalt, CFSTR("OSVersion"));
114 CFReleaseNull(gestalt);
115
116
117 if(version >= 2){
118 CFDictionaryRef v2Dictionary = peer->v2Dictionary;
119 transportType = CFDictionaryGetValue(v2Dictionary, sTransportType);
120 deviceID = CFDictionaryGetValue(v2Dictionary, sDeviceID);
121 }
122 char *pname = CFStringToCString(peerName);
123 char *dname = CFStringToCString(devtype);
124 char *tname = CFStringToCString(transportType);
125 char *iname = CFStringToCString(deviceID);
126 char *osname = CFStringToCString(osVersion);
127 const char *me = CFEqualSafe(mypeerID, peerID) ? "me>" : " ";
128
129
130 snprintf(buf, 160, "%s %s: %-16s %-16s %-16s %-16s", me, label, pname, dname, tname, iname);
131
132 free(pname);
133 free(dname);
134 CFStringRef pid = SOSPeerInfoGetPeerID(peer);
135 CFIndex vers = SOSPeerInfoGetVersion(peer);
136 printmsg(CFSTR("%s %@ V%d OS:%s\n"), buf, pid, vers, osname);
137 free(osname);
138 });
139 } else {
140 printmsg(CFSTR("No %s, error: %@\n"), label, error);
141 }
142 CFReleaseNull(ppi);
143 CFReleaseNull(error);
144 }
145
146 static void dumpCircleInfo()
147 {
148 CFErrorRef error = NULL;
149 CFArrayRef generations = NULL;
150 bool is_user_public_trusted = false;
151 __block int count = 0;
152
153 SOSCCStatus ccstatus = SOSCCThisDeviceIsInCircle(&error);
154 if(ccstatus == kSOSCCError) {
155 printmsg(CFSTR("End of Dump - unable to proceed due to ccstatus (%s) error: %@\n"), getSOSCCStatusDescription(ccstatus), error);
156 return;
157 }
158 printmsg(CFSTR("ccstatus: %s (%d)\n"), getSOSCCStatusDescription(ccstatus), ccstatus, error);
159
160 is_user_public_trusted = SOSCCValidateUserPublic(&error);
161 if(is_user_public_trusted)
162 printmsg(CFSTR("Account user public is trusted%@"),CFSTR("\n"));
163 else
164 printmsg(CFSTR("Account user public is not trusted error:(%@)\n"), error);
165 CFReleaseNull(error);
166
167 generations = SOSCCCopyGenerationPeerInfo(&error);
168 if(generations) {
169 CFArrayForEach(generations, ^(const void *value) {
170 count++;
171 if(count%2 == 0)
172 printmsg(CFSTR("Circle name: %@, "),value);
173
174 if(count%2 != 0) {
175 CFStringRef genDesc = SOSGenerationCountCopyDescription(value);
176 printmsg(CFSTR("Generation Count: %@"), genDesc);
177 CFReleaseNull(genDesc);
178 }
179 printmsg(CFSTR("%s\n"), "");
180 });
181 } else {
182 printmsg(CFSTR("No generation count: %@\n"), error);
183 }
184 CFReleaseNull(generations);
185 CFReleaseNull(error);
186
187 printPeerInfos(" Peers", ^(CFErrorRef *error) { return SOSCCCopyValidPeerPeerInfo(error); });
188 printPeerInfos(" Invalid", ^(CFErrorRef *error) { return SOSCCCopyNotValidPeerPeerInfo(error); });
189 printPeerInfos(" Retired", ^(CFErrorRef *error) { return SOSCCCopyRetirementPeerInfo(error); });
190 printPeerInfos(" Concur", ^(CFErrorRef *error) { return SOSCCCopyConcurringPeerPeerInfo(error); });
191 printPeerInfos("Applicants", ^(CFErrorRef *error) { return SOSCCCopyApplicantPeerInfo(error); });
192
193 if (!SOSCCForEachEngineStateAsString(&error, ^(CFStringRef oneStateString) {
194 printmsg(CFSTR("%@\n"), oneStateString);
195 })) {
196 printmsg(CFSTR("No engine peers: %@\n"), error);
197 }
198
199 CFReleaseNull(error);
200 }
201
202 static CFTypeRef getObjectsFromCloud(CFArrayRef keysToGet, dispatch_queue_t processQueue, dispatch_group_t dgroup)
203 {
204 __block CFTypeRef object = NULL;
205
206 const uint64_t maxTimeToWaitInSeconds = 30ull * NSEC_PER_SEC;
207 dispatch_semaphore_t waitSemaphore = dispatch_semaphore_create(0);
208 dispatch_time_t finishTime = dispatch_time(DISPATCH_TIME_NOW, maxTimeToWaitInSeconds);
209
210 dispatch_group_enter(dgroup);
211
212 CloudKeychainReplyBlock replyBlock =
213 ^ (CFDictionaryRef returnedValues, CFErrorRef error)
214 {
215 secinfo("sync", "SOSCloudKeychainGetObjectsFromCloud returned: %@", returnedValues);
216 object = returnedValues;
217 if (object)
218 CFRetain(object);
219 if (error)
220 {
221 secerror("SOSCloudKeychainGetObjectsFromCloud returned error: %@", error);
222 }
223 dispatch_group_leave(dgroup);
224 secinfo("sync", "SOSCloudKeychainGetObjectsFromCloud block exit: %@", object);
225 dispatch_semaphore_signal(waitSemaphore);
226 };
227
228 if (!keysToGet)
229 SOSCloudKeychainGetAllObjectsFromCloud(processQueue, replyBlock);
230 else
231 SOSCloudKeychainGetObjectsFromCloud(keysToGet, processQueue, replyBlock);
232
233 dispatch_semaphore_wait(waitSemaphore, finishTime);
234 dispatch_release(waitSemaphore);
235 if (object && (CFGetTypeID(object) == CFNullGetTypeID())) // return a NULL instead of a CFNull
236 {
237 CFRelease(object);
238 object = NULL;
239 }
240 secerror("returned: %@", object);
241 return object;
242 }
243
244 static CFStringRef printFullDataString(CFDataRef data){
245 __block CFStringRef fullData = NULL;
246
247 BufferPerformWithHexString(CFDataGetBytePtr(data), CFDataGetLength(data), ^(CFStringRef dataHex) {
248 fullData = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@"), dataHex);
249 });
250
251 return fullData;
252 }
253
254 static void displayLastKeyParameters(CFTypeRef key, CFTypeRef value)
255 {
256 CFDataRef valueAsData = asData(value, NULL);
257 if(valueAsData){
258 CFDataRef dateData = CFDataCreateCopyFromRange(kCFAllocatorDefault, valueAsData, CFRangeMake(0, DATE_LENGTH));
259 CFDataRef keyParameterData = CFDataCreateCopyFromPositions(kCFAllocatorDefault, valueAsData, DATE_LENGTH, CFDataGetLength(valueAsData));
260 CFStringRef dateString = CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, dateData, kCFStringEncodingUTF8);
261 CFStringRef keyParameterDescription = UserParametersDescription(keyParameterData);
262 if(keyParameterDescription)
263 printmsg(CFSTR("%@: %@: %@\n"), key, dateString, keyParameterDescription);
264 else
265 printmsg(CFSTR("%@: %@\n"), key, printFullDataString(value));
266 CFReleaseNull(dateString);
267 CFReleaseNull(keyParameterData);
268 CFReleaseNull(dateData);
269 CFReleaseNull(keyParameterDescription);
270 }
271 else{
272 printmsg(CFSTR("%@: %@\n"), key, value);
273 }
274 }
275
276 static void displayKeyParameters(CFTypeRef key, CFTypeRef value)
277 {
278 if(isData(value)){
279 CFStringRef keyParameterDescription = UserParametersDescription((CFDataRef)value);
280
281 if(keyParameterDescription)
282 printmsg(CFSTR("%@: %@\n"), key, keyParameterDescription);
283 else
284 printmsg(CFSTR("%@: %@\n"), key, value);
285
286 CFReleaseNull(keyParameterDescription);
287 }
288 else{
289 printmsg(CFSTR("%@: %@\n"), key, value);
290 }
291 }
292
293 static void displayLastCircle(CFTypeRef key, CFTypeRef value)
294 {
295 CFDataRef valueAsData = asData(value, NULL);
296 if(valueAsData){
297 CFErrorRef localError = NULL;
298
299 CFDataRef dateData = CFDataCreateCopyFromRange(kCFAllocatorDefault, valueAsData, CFRangeMake(0, DATE_LENGTH));
300 CFDataRef circleData = CFDataCreateCopyFromPositions(kCFAllocatorDefault, valueAsData, DATE_LENGTH, CFDataGetLength(valueAsData));
301 CFStringRef dateString = CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, dateData, kCFStringEncodingUTF8);
302 SOSCircleRef circle = SOSCircleCreateFromData(NULL, (CFDataRef) circleData, &localError);
303
304 if(circle){
305 CFIndex size = 5;
306 CFNumberRef idLength = CFNumberCreate(kCFAllocatorDefault, kCFNumberCFIndexType, &size);
307 CFDictionaryRef format = CFDictionaryCreateForCFTypes(kCFAllocatorDefault, CFSTR("SyncD"), CFSTR("SyncD"), CFSTR("idLength"), idLength, NULL);
308 printmsgWithFormatOptions(format, CFSTR("%@: %@: %@\n"), key, dateString, circle);
309 CFReleaseNull(idLength);
310 CFReleaseNull(format);
311
312 }
313 else
314 printmsg(CFSTR("%@: %@\n"), key, printFullDataString(circleData));
315
316 CFReleaseNull(dateString);
317 CFReleaseNull(circleData);
318 CFReleaseSafe(circle);
319 CFReleaseNull(dateData);
320 CFReleaseNull(localError);
321 }
322 else{
323 printmsg(CFSTR("%@: %@\n"), key, value);
324 }
325 }
326
327 static void displayCircle(CFTypeRef key, CFTypeRef value)
328 {
329 CFDataRef circleData = (CFDataRef)value;
330
331 CFErrorRef localError = NULL;
332 if (isData(circleData))
333 {
334 CFIndex size = 5;
335 CFNumberRef idLength = CFNumberCreate(kCFAllocatorDefault, kCFNumberCFIndexType, &size);
336 CFDictionaryRef format = CFDictionaryCreateForCFTypes(kCFAllocatorDefault, CFSTR("SyncD"), CFSTR("SyncD"), CFSTR("idLength"), idLength, NULL);
337 SOSCircleRef circle = SOSCircleCreateFromData(NULL, circleData, &localError);
338 printmsgWithFormatOptions(format, CFSTR("%@: %@\n"), key, circle);
339 CFReleaseSafe(circle);
340 CFReleaseNull(idLength);
341 CFReleaseNull(format);
342
343 }
344 else
345 printmsg(CFSTR("%@: %@\n"), key, value);
346 }
347
348 static void displayMessage(CFTypeRef key, CFTypeRef value)
349 {
350 CFDataRef message = (CFDataRef)value;
351 if(isData(message)){
352 const char* messageType = SecOTRPacketTypeString(message);
353 printmsg(CFSTR("%@: %s: %ld\n"), key, messageType, CFDataGetLength(message));
354 }
355 else
356 printmsg(CFSTR("%@: %@\n"), key, value);
357 }
358
359 static void printEverything(CFTypeRef objects)
360 {
361 CFDictionaryForEach(objects, ^(const void *key, const void *value) {
362 if (isData(value))
363 {
364 printmsg(CFSTR("%@: %@\n\n"), key, printFullDataString(value));
365 }
366 else
367 printmsg(CFSTR("%@: %@\n"), key, value);
368 });
369
370 }
371
372 static void decodeForKeyType(CFTypeRef key, CFTypeRef value, SOSKVSKeyType type){
373 switch (type) {
374 case kCircleKey:
375 displayCircle(key, value);
376 break;
377 case kRetirementKey:
378 case kMessageKey:
379 displayMessage(key, value);
380 break;
381 case kParametersKey:
382 displayKeyParameters(key, value);
383 break;
384 case kLastKeyParameterKey:
385 displayLastKeyParameters(key, value);
386 break;
387 case kLastCircleKey:
388 displayLastCircle(key, value);
389 break;
390 case kInitialSyncKey:
391 case kAccountChangedKey:
392 case kDebugInfoKey:
393 case kRingKey:
394 case kPeerInfoKey:
395 default:
396 printmsg(CFSTR("%@: %@\n"), key, value);
397 break;
398 }
399 }
400
401 static void decodeAllTheValues(CFTypeRef objects){
402 SOSKVSKeyType keyType = 0;
403 __block bool didPrint = false;
404
405 for (keyType = 0; keyType <= MAXKVSKEYTYPE; keyType++){
406 CFDictionaryForEach(objects, ^(const void *key, const void *value) {
407 if(SOSKVSKeyGetKeyType(key) == keyType){
408 decodeForKeyType(key, value, keyType);
409 didPrint = true;
410 }
411 });
412 if(didPrint)
413 printmsg(CFSTR("%@\n"), CFSTR(""));
414 didPrint = false;
415 }
416 }
417 static bool dumpKVS(char *itemName, CFErrorRef *err)
418 {
419 CFArrayRef keysToGet = NULL;
420 if (itemName)
421 {
422 CFStringRef itemStr = CFStringCreateWithCString(kCFAllocatorDefault, itemName, kCFStringEncodingUTF8);
423 fprintf(outFile, "Retrieving %s from KVS\n", itemName);
424 keysToGet = CFArrayCreateForCFTypes(kCFAllocatorDefault, itemStr, NULL);
425 CFReleaseSafe(itemStr);
426 }
427 dispatch_queue_t generalq = dispatch_queue_create("general", DISPATCH_QUEUE_SERIAL);
428 dispatch_group_t work_group = dispatch_group_create();
429 CFTypeRef objects = getObjectsFromCloud(keysToGet, generalq, work_group);
430 CFReleaseSafe(keysToGet);
431 if (objects)
432 {
433 fprintf(outFile, "All keys and values straight from KVS\n");
434 printEverything(objects);
435 fprintf(outFile, "\nAll values in decoded form...\n");
436 decodeAllTheValues(objects);
437 }
438 fprintf(outFile, "\n");
439 return true;
440 }
441
442
443
444 #define USE_NEW_SPI 1
445 #if ! USE_NEW_SPI
446
447 static char *createDateStrNow() {
448 char *retval = NULL;
449 time_t clock;
450
451 struct tm *tmstruct;
452
453 time(&clock);
454 tmstruct = localtime(&clock);
455
456 retval = malloc(15);
457 sprintf(retval, "%04d%02d%02d%02d%02d%02d", tmstruct->tm_year+1900, tmstruct->tm_mon+1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
458 return retval;
459 }
460
461 // #include <CoreFoundation/CFPriv.h>
462
463 CF_EXPORT CFDictionaryRef _CFCopySystemVersionDictionary(void);
464 CF_EXPORT const CFStringRef _kCFSystemVersionProductNameKey;
465 CF_EXPORT const CFStringRef _kCFSystemVersionProductVersionKey;
466 CF_EXPORT const CFStringRef _kCFSystemVersionBuildVersionKey;
467
468 static char *CFDictionaryCopyCString(CFDictionaryRef dict, const void *key) {
469 CFStringRef val = CFDictionaryGetValue(dict, key);
470 char *retval = CFStringToCString(val);
471 return retval;
472 }
473
474 #include <pwd.h>
475
476 static void sysdiagnose_dump() {
477 char *outputBase = NULL;
478 char *outputParent = NULL;
479 char *outputDir = NULL;
480 char hostname[80];
481 char *productName = "NA";
482 char *productVersion = "NA";
483 char *buildVersion = "NA";
484 char *keysToRegister = NULL;
485 char *cloudkeychainproxy3 = NULL;
486 char *now = createDateStrNow();
487 size_t length = 0;
488 int status = 0;
489 CFDictionaryRef sysfdef = _CFCopySystemVersionDictionary();
490
491 if(gethostname(hostname, 80)) {
492 strcpy(hostname, "unknownhost");
493 }
494
495 if(sysfdef) {
496 productName = CFDictionaryCopyCString(sysfdef, _kCFSystemVersionProductNameKey);
497 productVersion = CFDictionaryCopyCString(sysfdef, _kCFSystemVersionProductVersionKey);
498 buildVersion = CFDictionaryCopyCString(sysfdef, _kCFSystemVersionBuildVersionKey);
499 }
500
501 // OUTPUTBASE=ckcdiagnose_snapshot_${HOSTNAME}_${PRODUCT_VERSION}_${NOW}
502 length = strlen("ckcdiagnose_snapshot___") + strlen(hostname) + strlen(productVersion) + strlen(now) + 1;
503 outputBase = malloc(length);
504 status = snprintf(outputBase, length, "ckcdiagnose_snapshot_%s_%s_%s", hostname, productVersion, now);
505 if(status < 0) outputBase = "";
506
507 #if TARGET_OS_EMBEDDED
508 outputParent = "/Library/Logs/CrashReporter";
509 keysToRegister = "/private/var/preferences/com.apple.security.cloudkeychainproxy3.keysToRegister.plist";
510 cloudkeychainproxy3 = "/var/mobile/Library/SyncedPreferences/com.apple.security.cloudkeychainproxy3.plist";
511 #else
512 outputParent = "/var/tmp";
513 {
514 char *homeDir = "";
515 struct passwd* pwd = getpwuid(getuid());
516 if (pwd) homeDir = pwd->pw_dir;
517
518 char *k2regfmt = "%s/Library/Preferences/com.apple.security.cloudkeychainproxy3.keysToRegister.plist";
519 char *ckp3fmt = "%s/Library/SyncedPreferences/com.apple.security.cloudkeychainproxy3.plist";
520 size_t k2rlen = strlen(homeDir) + strlen(k2regfmt) + 2;
521 size_t ckp3len = strlen(homeDir) + strlen(ckp3fmt) + 2;
522 keysToRegister = malloc(k2rlen);
523 cloudkeychainproxy3 = malloc(ckp3len);
524 snprintf(keysToRegister, k2rlen, k2regfmt, homeDir);
525 snprintf(cloudkeychainproxy3, ckp3len, ckp3fmt, homeDir);
526 }
527 #endif
528
529 length = strlen(outputParent) + strlen(outputBase) + 2;
530 outputDir = malloc(length);
531 status = snprintf(outputDir, length, "%s/%s", outputParent, outputBase);
532 if(status < 0) return;
533
534 mkdir(outputDir, 0700);
535
536 SOSLogSetOutputTo(outputDir, "sw_vers.log");
537 // report uname stuff + hostname
538 fprintf(outFile, "HostName: %s\n", hostname);
539 fprintf(outFile, "ProductName: %s\n", productName);
540 fprintf(outFile, "ProductVersion: %s\n", productVersion);
541 fprintf(outFile, "BuildVersion: %s\n", buildVersion);
542 closeOutput();
543
544 SOSLogSetOutputTo(outputDir, "syncD.log");
545 // do sync -D
546 dumpKVS(optarg, NULL);
547 closeOutput();
548
549 SOSLogSetOutputTo(outputDir, "synci.log");
550 // do sync -i
551 dumpCircleInfo();
552 closeOutput();
553
554 SOSLogSetOutputTo(outputDir, "syncL.log");
555 // do sync -L
556 listviewcmd(NULL);
557 closeOutput();
558
559 copyFileToOutputDir(outputDir, keysToRegister);
560 copyFileToOutputDir(outputDir, cloudkeychainproxy3);
561
562 free(now);
563 CFReleaseNull(sysfdef);
564 #if ! TARGET_OS_EMBEDDED
565 free(keysToRegister);
566 free(cloudkeychainproxy3);
567 #endif
568
569 }
570 #else
571 static void sysdiagnose_dump() {
572 SOSCCSysdiagnose(NULL);
573 }
574
575 #endif /* USE_NEW_SPI */
576
577 static bool logmark(const char *optarg) {
578 if(!optarg) return false;
579 secnotice("mark", "%s", optarg);
580 return true;
581 }
582
583
584 // enable, disable, accept, reject, status, Reset, Clear
585 int
586 keychain_log(int argc, char * const *argv)
587 {
588 /*
589 "Keychain Logging"
590 " -i info (current status)"
591 " -D [itemName] dump contents of KVS"
592 " -L list all known view and their status"
593 " -s sysdiagnose log dumps"
594 " -M string place a mark in the syslog - category \"mark\""
595
596 */
597 SOSLogSetOutputTo(NULL, NULL);
598
599 int ch, result = 0;
600 CFErrorRef error = NULL;
601 bool hadError = false;
602
603 while ((ch = getopt(argc, argv, "DiLM:s")) != -1)
604 switch (ch) {
605
606 case 'i':
607 dumpCircleInfo();
608 break;
609
610
611 case 's':
612 sysdiagnose_dump();
613 break;
614
615 case 'D':
616 hadError = !dumpKVS(optarg, &error);
617 break;
618
619 case 'L':
620 hadError = !listviewcmd(&error);
621 break;
622
623 case 'M':
624 hadError = !logmark(optarg);
625 break;
626
627 case '?':
628 default:
629 return 2; /* Return 2 triggers usage message. */
630 }
631
632 if (hadError)
633 printerr(CFSTR("Error: %@\n"), error);
634
635 return result;
636 }