]> git.saurik.com Git - apple/security.git/blob - OSX/sec/SOSCircle/Tool/keychain_log.m
Security-58286.31.2.tar.gz
[apple/security.git] / OSX / sec / SOSCircle / Tool / keychain_log.m
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_accountKeyIsTrusted = 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_accountKeyIsTrusted = SOSCCValidateUserPublic(&error);
161 if(is_accountKeyIsTrusted)
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
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 default:
395 printmsg(CFSTR("%@: %@\n"), key, value);
396 break;
397 }
398 }
399
400 static void decodeAllTheValues(CFTypeRef objects){
401 SOSKVSKeyType keyType = 0;
402 __block bool didPrint = false;
403
404 for (keyType = 0; keyType <= MAXKVSKEYTYPE; keyType++){
405 CFDictionaryForEach(objects, ^(const void *key, const void *value) {
406 if(SOSKVSKeyGetKeyType(key) == keyType){
407 decodeForKeyType(key, value, keyType);
408 didPrint = true;
409 }
410 });
411 if(didPrint)
412 printmsg(CFSTR("%@\n"), CFSTR(""));
413 didPrint = false;
414 }
415 }
416 static bool dumpKVS(char *itemName, CFErrorRef *err)
417 {
418 CFArrayRef keysToGet = NULL;
419 if (itemName)
420 {
421 CFStringRef itemStr = CFStringCreateWithCString(kCFAllocatorDefault, itemName, kCFStringEncodingUTF8);
422 fprintf(outFile, "Retrieving %s from KVS\n", itemName);
423 keysToGet = CFArrayCreateForCFTypes(kCFAllocatorDefault, itemStr, NULL);
424 CFReleaseSafe(itemStr);
425 }
426 dispatch_queue_t generalq = dispatch_queue_create("general", DISPATCH_QUEUE_SERIAL);
427 dispatch_group_t work_group = dispatch_group_create();
428 CFTypeRef objects = getObjectsFromCloud(keysToGet, generalq, work_group);
429 CFReleaseSafe(keysToGet);
430 if (objects)
431 {
432 fprintf(outFile, "All keys and values straight from KVS\n");
433 printEverything(objects);
434 fprintf(outFile, "\nAll values in decoded form...\n");
435 decodeAllTheValues(objects);
436 }
437 fprintf(outFile, "\n");
438 return true;
439 }
440
441
442
443 #define USE_NEW_SPI 1
444 #if ! USE_NEW_SPI
445
446 static char *createDateStrNow() {
447 char *retval = NULL;
448 time_t clock;
449
450 struct tm *tmstruct;
451
452 time(&clock);
453 tmstruct = localtime(&clock);
454
455 retval = malloc(15);
456 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);
457 return retval;
458 }
459
460 // #include <CoreFoundation/CFPriv.h>
461
462 CF_EXPORT CFDictionaryRef _CFCopySystemVersionDictionary(void);
463 CF_EXPORT const CFStringRef _kCFSystemVersionProductNameKey;
464 CF_EXPORT const CFStringRef _kCFSystemVersionProductVersionKey;
465 CF_EXPORT const CFStringRef _kCFSystemVersionBuildVersionKey;
466
467 static char *CFDictionaryCopyCString(CFDictionaryRef dict, const void *key) {
468 CFStringRef val = CFDictionaryGetValue(dict, key);
469 char *retval = CFStringToCString(val);
470 return retval;
471 }
472
473 #include <pwd.h>
474
475 static void sysdiagnose_dump() {
476 char *outputBase = NULL;
477 char *outputParent = NULL;
478 char *outputDir = NULL;
479 char hostname[80];
480 char *productName = "NA";
481 char *productVersion = "NA";
482 char *buildVersion = "NA";
483 char *keysToRegister = NULL;
484 char *cloudkeychainproxy3 = NULL;
485 char *now = createDateStrNow();
486 size_t length = 0;
487 int status = 0;
488 CFDictionaryRef sysfdef = _CFCopySystemVersionDictionary();
489
490 if(gethostname(hostname, 80)) {
491 strcpy(hostname, "unknownhost");
492 }
493
494 if(sysfdef) {
495 productName = CFDictionaryCopyCString(sysfdef, _kCFSystemVersionProductNameKey);
496 productVersion = CFDictionaryCopyCString(sysfdef, _kCFSystemVersionProductVersionKey);
497 buildVersion = CFDictionaryCopyCString(sysfdef, _kCFSystemVersionBuildVersionKey);
498 }
499
500 // OUTPUTBASE=ckcdiagnose_snapshot_${HOSTNAME}_${PRODUCT_VERSION}_${NOW}
501 length = strlen("ckcdiagnose_snapshot___") + strlen(hostname) + strlen(productVersion) + strlen(now) + 1;
502 outputBase = malloc(length);
503 status = snprintf(outputBase, length, "ckcdiagnose_snapshot_%s_%s_%s", hostname, productVersion, now);
504 if(status < 0) outputBase = "";
505
506 #if TARGET_OS_EMBEDDED
507 outputParent = "/Library/Logs/CrashReporter";
508 keysToRegister = "/private/var/preferences/com.apple.security.cloudkeychainproxy3.keysToRegister.plist";
509 cloudkeychainproxy3 = "/var/mobile/Library/SyncedPreferences/com.apple.security.cloudkeychainproxy3.plist";
510 #else
511 outputParent = "/var/tmp";
512 {
513 char *homeDir = "";
514 struct passwd* pwd = getpwuid(getuid());
515 if (pwd) homeDir = pwd->pw_dir;
516
517 char *k2regfmt = "%s/Library/Preferences/com.apple.security.cloudkeychainproxy3.keysToRegister.plist";
518 char *ckp3fmt = "%s/Library/SyncedPreferences/com.apple.security.cloudkeychainproxy3.plist";
519 size_t k2rlen = strlen(homeDir) + strlen(k2regfmt) + 2;
520 size_t ckp3len = strlen(homeDir) + strlen(ckp3fmt) + 2;
521 keysToRegister = malloc(k2rlen);
522 cloudkeychainproxy3 = malloc(ckp3len);
523 snprintf(keysToRegister, k2rlen, k2regfmt, homeDir);
524 snprintf(cloudkeychainproxy3, ckp3len, ckp3fmt, homeDir);
525 }
526 #endif
527
528 length = strlen(outputParent) + strlen(outputBase) + 2;
529 outputDir = malloc(length);
530 status = snprintf(outputDir, length, "%s/%s", outputParent, outputBase);
531 if(status < 0) return;
532
533 mkdir(outputDir, 0700);
534
535 SOSLogSetOutputTo(outputDir, "sw_vers.log");
536 // report uname stuff + hostname
537 fprintf(outFile, "HostName: %s\n", hostname);
538 fprintf(outFile, "ProductName: %s\n", productName);
539 fprintf(outFile, "ProductVersion: %s\n", productVersion);
540 fprintf(outFile, "BuildVersion: %s\n", buildVersion);
541 closeOutput();
542
543 SOSLogSetOutputTo(outputDir, "syncD.log");
544 // do sync -D
545 dumpKVS(optarg, NULL);
546 closeOutput();
547
548 SOSLogSetOutputTo(outputDir, "synci.log");
549 // do sync -i
550 dumpCircleInfo();
551 closeOutput();
552
553 SOSLogSetOutputTo(outputDir, "syncL.log");
554 // do sync -L
555 listviewcmd(NULL);
556 closeOutput();
557
558 copyFileToOutputDir(outputDir, keysToRegister);
559 copyFileToOutputDir(outputDir, cloudkeychainproxy3);
560
561 free(now);
562 CFReleaseNull(sysfdef);
563 #if ! TARGET_OS_EMBEDDED
564 free(keysToRegister);
565 free(cloudkeychainproxy3);
566 #endif
567
568 }
569 #else
570 static void sysdiagnose_dump() {
571 SOSCCSysdiagnose(NULL);
572 }
573
574 #endif /* USE_NEW_SPI */
575
576 static bool logmark(const char *optarg) {
577 if(!optarg) return false;
578 secnotice("mark", "%s", optarg);
579 return true;
580 }
581
582
583 // enable, disable, accept, reject, status, Reset, Clear
584 int
585 keychain_log(int argc, char * const *argv)
586 {
587 /*
588 "Keychain Logging"
589 " -i info (current status)"
590 " -D [itemName] dump contents of KVS"
591 " -L list all known view and their status"
592 " -s sysdiagnose log dumps"
593 " -M string place a mark in the syslog - category \"mark\""
594
595 */
596 SOSLogSetOutputTo(NULL, NULL);
597
598 int ch, result = 0;
599 CFErrorRef error = NULL;
600 bool hadError = false;
601
602 while ((ch = getopt(argc, argv, "DiLM:s")) != -1)
603 switch (ch) {
604
605 case 'i':
606 dumpCircleInfo();
607 break;
608
609
610 case 's':
611 sysdiagnose_dump();
612 break;
613
614 case 'D':
615 hadError = !dumpKVS(optarg, &error);
616 break;
617
618 case 'L':
619 hadError = !listviewcmd(&error);
620 break;
621
622 case 'M':
623 hadError = !logmark(optarg);
624 break;
625
626 case '?':
627 default:
628 return 2; /* Return 2 triggers usage message. */
629 }
630
631 if (hadError)
632 printerr(CFSTR("Error: %@\n"), error);
633
634 return result;
635 }