Last active
August 29, 2015 13:57
-
-
Save cgrushko/1aea22fca9cbae703489 to your computer and use it in GitHub Desktop.
Given two OS X keychains, create two 2-column files. First column is last modification date of an entry, the second column is the name of the entry.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [ "$#" -ne 2 ]; then | |
echo "Usage: compare-keychains.sh first.keychain second.keychain" | |
exit 1 | |
fi | |
# Takes a keychain ($1), and generates a file that has a column of last-modifed dates, | |
# and a column of the names of items in the keychain. | |
# Result is written into a temp file whose name is stored in "$2". | |
extract() { | |
local BASE=`basename "$1"` | |
local NAMES_FILENAME=`mktemp -t $BASE.names` | |
local DATES_FILENAME=`mktemp -t $BASE.dates` | |
local MERGED_FILENAME=`mktemp -t $BASE` | |
security dump-keychain "$1" | grep 0x00000007 | cut -c23- > "$NAMES_FILENAME" | |
security dump-keychain "$1" | grep '"mdat"' | cut -c59-72 > "$DATES_FILENAME" | |
pr -m -t "$DATES_FILENAME" "$NAMES_FILENAME" | sort > "$MERGED_FILENAME" | |
rm "$DATES_FILENAME" "$NAMES_FILENAME" | |
eval "$2=$MERGED_FILENAME" | |
} | |
extract $1 MERGED1 | |
extract $2 MERGED2 | |
meld "$MERGED1" "$MERGED2" | |
rm "$MERGED1" "$MERGED2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
E.g.,
20130701020437 "bla"
20130701020437 "bla"
20130701020437 "bla"