2016-08-06 18:43:08 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# mverify MSG - verify a OpenPGP or SMIME message
|
|
|
|
|
2018-01-06 17:34:16 +00:00
|
|
|
# Needs gpg (for OpenPGP) and openssl (for SMIME).
|
2016-08-06 18:43:08 +00:00
|
|
|
|
|
|
|
[ "$#" -eq 0 ] && set -- .
|
|
|
|
|
2018-01-10 22:50:54 +00:00
|
|
|
mshow -t "$1" | DOS2UNIX='/
$/!s/$/
/' awk -v "msg=$1" '
|
2016-08-06 18:43:08 +00:00
|
|
|
{ match($0, "^ *"); indent = RLENGTH }
|
|
|
|
$2 == "text/plain" { plain++ }
|
2017-08-05 18:13:16 +00:00
|
|
|
$2 == "multipart/signed" { signed = 0+$1; si = indent; next }
|
|
|
|
signed && !content && indent == si+2 { content = 0+$1; next }
|
|
|
|
signed && content && !signature && indent == si+2 { signature = 0+$1; type = $2 }
|
2016-08-06 18:43:08 +00:00
|
|
|
function q(a) { gsub("\\47", "\47\\\47\47", a); return "\47"a"\47" }
|
|
|
|
END {
|
|
|
|
if (type == "" && plain) { // guess plain text armored signature
|
2018-01-06 17:20:15 +00:00
|
|
|
exit(system("mshow -r " q(msg) " | gpg --verify"));
|
2016-08-06 18:43:08 +00:00
|
|
|
} else if (type == "") {
|
|
|
|
print("No signature found.")
|
|
|
|
exit(100)
|
|
|
|
} else if (type == "application/pgp-signature") {
|
2018-01-06 17:34:16 +00:00
|
|
|
exit(system("mshow -r -O " q(msg) " " q(content) \
|
2018-01-10 22:50:54 +00:00
|
|
|
" | sed $DOS2UNIX | " \
|
2018-01-06 17:34:16 +00:00
|
|
|
" { mshow -O " q(msg) " " q(signature) \
|
|
|
|
" | gpg --verify - /dev/fd/3; } 3<&0"))
|
2016-08-06 18:43:08 +00:00
|
|
|
} else if (type == "application/pkcs7-signature") {
|
|
|
|
exit(system("mshow -r -O " q(msg) " " q(signed) \
|
|
|
|
" | openssl smime -verify"))
|
|
|
|
} else {
|
2017-08-05 12:35:18 +00:00
|
|
|
print("Cannot verify signatures of type " type ".")
|
2016-08-06 18:43:08 +00:00
|
|
|
exit(2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'
|