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
85 echo class
=${class},sync
=${sync},tomb
=${tomb}: >> $OUTPUT/keychain
-state.log
86 ${secexec} item
-q class
=${class},sync
=${sync},tomb
=${tomb} | grep '^acct'|wc -l 2>&1 >> $OUTPUT/keychain
-state.log
91 if (( ! $SHORT )); then
92 syslog
-k Sender Seq syncdefaults
> $OUTPUT/syslog_syncdefaults.log
93 syslog
-k Sender Seq
$secd > $OUTPUT/syslog_secd.log
94 syslog
-k Sender Seq CloudKeychain
> $OUTPUT/syslog_cloudkeychain.log
97 (( $SHORT )) || (sbdtool status
> $OUTPUT/sbdtool_status.log
2>&1)
98 (( $SHORT )) || plutil
-p $HOME/Library
/SyncedPreferences
/com.apple.sbd.plist
> $OUTPUT/sbd_kvs.txt
100 $syd status
> $OUTPUT/syd_status.txt
2>&1
101 $syd lastrequest
> $OUTPUT/syd_lastrequest.txt
2>&1
102 $syd serverlimits
> $OUTPUT/syd_serverlimits.txt
2>&1
104 # Compare kvsutil and sync -D state, shows if store diverged from on-device state.
105 if (( ! $SHORT )); then
106 if [ -f $OUTPUT/kvsutil_show.txt
]; then
107 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
108 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
109 diff -u $OUTPUT/kvs_keys.txt
$OUTPUT/syncD_keys.txt
> $OUTPUT/kvs_syncD_diff.txt
113 if [ "$PROD" = "IOS" ]; then
114 cp /private
/var
/preferences
/com.apple.security.cloudkeychainproxy3.keysToRegister.plist
$OUTPUT/
115 cp /var
/mobile
/Library
/SyncedPreferences
/com.apple.security.cloudkeychainproxy3.plist
$OUTPUT/
117 cp ~
/Library
/Preferences
/com.apple.security.cloudkeychainproxy3.keysToRegister.plist
$OUTPUT/
118 cp ~
/Library
/SyncedPreferences
/com.apple.security.cloudkeychainproxy3.plist
$OUTPUT/
121 if (( ! $SHORT )); then
122 cp $SECLOGPATH/security.log
* $OUTPUT/
124 cp $CRASHDIR/*${secd}* $OUTPUT/
125 cp $CRASHDIR/*syncdefaults
* $OUTPUT/
126 cp $CRASHDIR/*CloudKeychain
* $OUTPUT/
128 (cd $CSDIR && for x
in *_
*.asl
; do syslog
-f "$x" > "$OUTPUT/${x%%.asl}.log"; done)
130 (cd $SECLOGPATH; gzcat
-c -f security.log
*) > $OUTPUT/security
-complete.log
133 (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
134 (cd $SECLOGPATH; gzcat
-c security.log.
*.gz
; cat security.log.
*Z
) | cut
-d ' ' -f 6- | sort |uniq -c | sort -n > $OUTPUT/security
-sorted.log
137 ) > $OUTPUT/ckcdiagnose.log
2>&1
139 tar czf
$OUTPUT.tgz
-C $OUTPUTPARENT $OUTPUTBASE
143 if (( ! $SHORT )); then
145 echo "The file containing the diagnostic information is "
147 echo 'Please attach it to a Radar in "Security / iCloud Keychain"'
150 [ "$PROD" = "OSX" ] && open
$OUTPUTPARENT