3 # Poor man's option parsing.
4 # Replace with shift/case once more options come along.
6 if [ "$1" == "-s" ]; then
10 PRODUCT_NAME
=$(sw_vers -productName)
11 PRODUCT_VERSION
=$(sw_vers -buildVersion)
12 HOSTNAME
=$(hostname -s)
13 NOW
=$(date "+%Y%m%d%H%M%S")
21 CRASHDIR
=/Library
/Logs
/DiagnosticReports
22 CSDIR
=$HOME/Library
/Logs
/CloudServices
23 SECLOGPATH
=/var
/log
/module
/com.apple.securityd
24 syd
=/System
/Library
/PrivateFrameworks
/SyncedDefaults.framework
/Support
/syncdefaultsd
25 kvsutil
=/AppleInternal
/Applications
/kvsutil
31 OUTPUTPARENT
=/Library
/Logs
/CrashReporter
32 CRASHDIR
=/var
/mobile
/Library
/Logs
/CrashReporter
33 CSDIR
=$CRASHDIR/DiagnosticLogs
/CloudServices
34 SECLOGPATH
=/var
/mobile
/Library
/Logs
/CrashReporter
/DiagnosticLogs
35 syd
=/System
/Library
/PrivateFrameworks
/SyncedDefaults.framework
/Support
/syncdefaultsd
36 kvsutil
=/usr
/local
/bin
/kvsutil
40 if (( ! $SHORT )); then
41 OUTPUTBASE
=ckcdiagnose_
${HOSTNAME}_
${PRODUCT_VERSION}_
${NOW}
43 OUTPUTBASE
=ckcdiagnose_snapshot_
${HOSTNAME}_
${PRODUCT_VERSION}_
${NOW}
45 OUTPUT
=$OUTPUTPARENT/$OUTPUTBASE
49 if [ "$PROD" = "IOS" ]; then
50 while !(/usr
/local
/bin
/profilectl cpstate
| grep -Eq 'Unlocked|Disabled'); do
51 echo Please ensure that your device is unlocked and press Enter.
>&2
57 echo Outputting to
$OUTPUT
60 sw_vers
> $OUTPUT/sw_vers.log
62 $secexec sync
-D > $OUTPUT/syncD.log
63 $secexec sync
-i > $OUTPUT/synci.log
64 $secexec sync
-L > $OUTPUT/syncL.log
66 (( $SHORT )) || ([ -x $kvsutil ] && $kvsutil show com.apple.security.cloudkeychainproxy3
> $OUTPUT/kvsutil_show.txt
2>&1)
68 if [ "$PROD" == "OSX" ]; then
69 $secexec item
-g class
=genp
,nleg
=1,svce
="iCloud Keychain Account Meta-data" > $OUTPUT/ickcmetadata.log
70 $secexec item
-g class
=genp
,nleg
=1,acct
=engine
-state > $OUTPUT/engine
-state.log
71 elif [ "$PROD" == "IOS" ]; then
72 $secexec item
-g class
=genp
,svce
="iCloud Keychain Account Meta-data" > $OUTPUT/ickcmetadata.log
73 $secexec item
-g class
=genp
,acct
=engine
-state > $OUTPUT/engine
-state.log
76 # In preparation, before getting any of the logs, query all classes,
77 # just in order to excercise the decryption and corruption
78 # verification for all items. This will log errors and simulated crashes
79 # if any of the items should turn out corrupted.
80 # The items are NOT saved in the diagnostic log, because they potentially
81 # contain very private items.
82 for class
in genp inet cert keys
; do
86 echo class
=${class},sync
=${sync},tomb
=${tomb},u_AuthUI
=u_AuthUIS
: >> $OUTPUT/keychain
-state.log
87 ${secexec} item
-q class
=${class},sync
=${sync},tomb
=${tomb},u_AuthUI
=u_AuthUIS
| grep '^acct'|wc -l 2>&1 >> $OUTPUT/keychain
-state.log
92 if (( ! $SHORT )); then
93 syslog
-k Sender Seq syncdefaults
> $OUTPUT/syslog_syncdefaults.log
94 syslog
-k Sender Seq
$secd > $OUTPUT/syslog_secd.log
95 syslog
-k Sender Seq CloudKeychain
> $OUTPUT/syslog_cloudkeychain.log
98 (( $SHORT )) || (sbdtool status
> $OUTPUT/sbdtool_status.log
2>&1)
100 if [ "$PROD" == "OSX" ]; then
101 (( $SHORT )) || plutil
-p $HOME/Library
/SyncedPreferences
/com.apple.sbd.plist
> $OUTPUT/sbd_kvs.txt
102 elif [ "$PROD" == "IOS" ]; then
103 (( $SHORT )) || plutil
-p /var
/mobile
/Library
/SyncedPreferences
/com.apple.sbd.plist
> $OUTPUT/sbd_kvs.txt
106 $syd status
> $OUTPUT/syd_status.txt
2>&1
107 $syd lastrequest
> $OUTPUT/syd_lastrequest.txt
2>&1
108 $syd serverlimits
> $OUTPUT/syd_serverlimits.txt
2>&1
110 # Compare kvsutil and sync -D state, shows if store diverged from on-device state.
111 if (( ! $SHORT )); then
112 if [ -f $OUTPUT/kvsutil_show.txt
]; then
113 cat $OUTPUT/kvsutil_show.txt
| grep -E '^ "?[o-]?ak.* = ' | sed -E 's/^ "?([^"]*)"? = \<.* (.*) (.*)\>.*$/\1 \2\3/g;s/^(.*) [0-9a-f]*([0-9a-f]{8})/\1 \2/g' | sort > $OUTPUT/kvs_keys.txt
114 cat $OUTPUT/syncD.log
| grep -E 'contents = "?[o-]?ak' | sed -E 's/^.*contents = "?([^"]*)"?\} = .*bytes = .* ... [0-9a-f]+([0-9a-f]{8})\}/\1 \2/g' | sort > $OUTPUT/syncD_keys.txt
115 diff -u $OUTPUT/kvs_keys.txt
$OUTPUT/syncD_keys.txt
> $OUTPUT/kvs_syncD_diff.txt
119 if [ "$PROD" = "IOS" ]; then
120 cp /private
/var
/preferences
/com.apple.security.cloudkeychainproxy3.keysToRegister.plist
$OUTPUT/
121 cp /var
/mobile
/Library
/SyncedPreferences
/com.apple.security.cloudkeychainproxy3.plist
$OUTPUT/
123 cp ~
/Library
/Preferences
/com.apple.security.cloudkeychainproxy3.keysToRegister.plist
$OUTPUT/
124 cp ~
/Library
/SyncedPreferences
/com.apple.security.cloudkeychainproxy3.plist
$OUTPUT/
127 if (( ! $SHORT )); then
128 cp $SECLOGPATH/security.log
* $OUTPUT/
130 cp $CRASHDIR/*${secd}* $OUTPUT/
131 cp $CRASHDIR/*syncdefaults
* $OUTPUT/
132 cp $CRASHDIR/*CloudKeychain
* $OUTPUT/
134 (cd $CSDIR && for x
in *_
*.asl
; do syslog
-f "$x" > "$OUTPUT/${x%%.asl}.log"; done)
136 (cd $SECLOGPATH; gzcat
-c -f security.log
*) > $OUTPUT/security
-complete.log
139 (cd $SECLOGPATH; gzcat
-c security.log.
*.gz
; cat security.log.
*Z
) | grep -E -- 'Invalid date.|-26275|[cC]orrupt|[cC]rash|Public Key not available' > $OUTPUT/problems.log
140 (cd $SECLOGPATH; gzcat
-c security.log.
*.gz
; cat security.log.
*Z
) | cut
-d ' ' -f 6- | sort |uniq -c | sort -n > $OUTPUT/security
-sorted.log
143 ) > $OUTPUT/ckcdiagnose.log
2>&1
145 tar czf
$OUTPUT.tgz
-C $OUTPUTPARENT $OUTPUTBASE
149 if (( ! $SHORT )); then
151 echo "The file containing the diagnostic information is "
153 echo 'Please attach it to a Radar in "Security / iCloud Keychain"'
156 [ "$PROD" = "OSX" ] && open
$OUTPUTPARENT