-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathder2spki.sh
More file actions
executable file
·39 lines (34 loc) · 845 Bytes
/
der2spki.sh
File metadata and controls
executable file
·39 lines (34 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# Consumes cert in DER format and prints SPKI
function der2spki () {
openssl x509 -inform der | \
openssl x509 -pubkey -noout | \
openssl pkey -pubin -outform der | \
openssl dgst -sha256 -binary | \
openssl enc -base64
}
# Get SPKIs from installed user certificates
function derFromAdb2spki () {
local CMD='find /data/misc/user/0/cacerts-added/ -type f -exec base64 -w0 {} \; -exec echo \;'
adb shell su <<<"${CMD}" | while read -r; do
base64 -d <<<"${REPLY}" | der2spki
done | tr '\n' ',' | sed 's/,$//g'
echo
}
function main() {
case "${1,,}" in
adb)
derFromAdb2spki
;;
*)
if [ -f "${1}" ]; then
der2spki < "${1}"
return
fi
printf "Usage: %s <adb|der>\n" "${0}"
;;
esac
}
if [[ "${BASH_SOURCE[0]}" = "${0}" ]]; then
main "$@"
fi