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/CoreFoundation.h> 48 #include <CoreFoundation/CFPriv.h> 49 50 #include <Security/SecureObjectSync/SOSCloudCircle.h> 51 #include <Security/SecureObjectSync/SOSCloudCircleInternal.h> 52 #include <Security/SecureObjectSync/SOSPeerInfo.h> 53 #include "keychain/SecureObjectSync/SOSPeerInfoPriv.h" 54 #include "keychain/SecureObjectSync/SOSPeerInfoV2.h" 55 #include "keychain/SecureObjectSync/SOSUserKeygen.h" 56 #include "keychain/SecureObjectSync/SOSKVSKeys.h" 57 #include "keychain/securityd/SOSCloudCircleServer.h" 58 #include <Security/SecOTRSession.h> 59 #include "keychain/SecureObjectSync/CKBridge/SOSCloudKeychainClient.h" 60 61 #include <utilities/SecCFWrappers.h> 62 #include <utilities/debugging.h> 63 64 #include "SecurityTool/sharedTool/readline.h" 65 #include <notify.h> 66 67 #include "keychain_log.h" 68 #include "secToolFileIO.h" 69 #include "secViewDisplay.h" 70 #include "accountCirclesViewsPrint.h" 71 #include <utilities/debugging.h> 72 73 74 #include <Security/SecPasswordGenerate.h> 75 76 #define MAXKVSKEYTYPE kUnknownKey 77 #define DATE_LENGTH 18 78 79 static bool logmark(const char *optarg) { 80 if(!optarg) return false; 81 secnotice("mark", "%s", optarg); 82 return true; 83 } 84 85 86 // enable, disable, accept, reject, status, Reset, Clear 87 int 88 keychain_log(int argc, char * const *argv) 89 { 90 /* 91 "Keychain Logging" 92 " -i info (current status)" 93 " -D [itemName] dump contents of KVS" 94 " -L list all known view and their status" 95 " -M string place a mark in the syslog - category \"mark\"" 96 97 */ 98 SOSLogSetOutputTo(NULL, NULL); 99 100 int ch, result = 0; 101 CFErrorRef error = NULL; 102 bool hadError = false; 103 104 while ((ch = getopt(argc, argv, "DiLM:")) != -1) 105 switch (ch) { 106 107 case 'i': 108 SOSCCDumpCircleInformation(); 109 SOSCCDumpEngineInformation(); 110 break; 111 112 113 case 'D': 114 (void)SOSCCDumpCircleKVSInformation(optarg); 115 break; 116 117 case 'L': 118 hadError = !listviewcmd(&error); 119 break; 120 121 case 'M': 122 hadError = !logmark(optarg); 123 break; 124 125 case '?': 126 default: 127 return SHOW_USAGE_MESSAGE; 128 } 129 130 if (hadError) 131 printerr(CFSTR("Error: %@\n"), error); 132 133 return result; 134 }