Skip to content

Instantly share code, notes, and snippets.

@cgrushko
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgrushko/1aea22fca9cbae703489 to your computer and use it in GitHub Desktop.
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.
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"
@cgrushko
Copy link
Author

cgrushko commented Apr 1, 2014

E.g.,
20130701020437 "bla"
20130701020437 "bla"
20130701020437 "bla"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment