Skip to content

Instantly share code, notes, and snippets.

@pellaeon
Last active July 16, 2020 23:11
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 pellaeon/66a6acc2ea8752bba74103bbb81fdf65 to your computer and use it in GitHub Desktop.
Save pellaeon/66a6acc2ea8752bba74103bbb81fdf65 to your computer and use it in GitHub Desktop.
Shell script that takes android /data/system/packages.xml as input and print the containing certificates
#!/bin/bash
input="$1"
while IFS= read -r line
do
line1=`echo "$line" | egrep 'cert index="[0-9]+" key="[0-9a-z]+"'`
if [ $? -eq 0 ]
then
index=`echo $line1 | grep -oP 'index="\K\d+'`
hex=`echo $line1 | grep -oP 'key="\K[0-9a-z]+'`
sslinfo=`echo $hex | xxd -p -r | openssl x509 -inform DER -in /dev/stdin -text`
email=`echo "$sslinfo" | grep emailAddress`
pubkeycert=`echo $hex | xxd -p -r | openssl x509 -inform DER -in /dev/stdin -pubkey`
pubkey=`echo "$pubkeycert" | pcregrep -M -- '-----BEGIN PUBLIC KEY-----(\n|.)*-----END PUBLIC KEY-----'`
pubkey=`echo "$pubkey" | tr -d '\n'`
if [ -n "$email" ]
then
echo "$index : $email"
echo "$pubkey"
fi
fi
done < "$input"
#!/bin/bash
for f in /tmp/*.pem
do
echo "===============$f=============="
openssl x509 -inform PEM -in $f -pubkey
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment