Browse Source

Add scripts from mblaze/contrib

Directly from tag v6.0, e0733f187b.
master
Lucas 3 months ago
parent
commit
eb605487e5
5 changed files with 111 additions and 2 deletions
  1. +4
    -2
      mblaze/Makefile
  2. +28
    -0
      mblaze/contrib/mencrypt
  3. +20
    -0
      mblaze/contrib/mgpg
  4. +25
    -0
      mblaze/contrib/msign
  5. +34
    -0
      mblaze/contrib/mverify

+ 4
- 2
mblaze/Makefile View File

@@ -15,20 +15,22 @@
PREFIX = ${HOME}/.mblaze

BIN = m mless
CONTRIB = contrib/mencrypt contrib/mgpg contrib/msign contrib/mverify

all: ${BIN}

clean:
rm -f ${BIN}

install: all env mlesskey mless-key-handler
install: all env mlesskey mless-key-handler ${CONTRIB}
mkdir -pm 700 ${PREFIX}
lesskey -o ${PREFIX}/mless mlesskey
cp -f env mless-key-handler ${PREFIX}
mkdir -p ${PREFIX}/bin
cp -f ${BIN} ${PREFIX}/bin
cp -f ${CONTRIB} ${PREFIX}/bin
cd ${PREFIX}/bin && chmod 555 ${BIN}

uninstall:
cd ${PREFIX}/bin && rm -f ${BIN}
cd ${PREFIX}/bin && rm -f ${BIN} ${CONTRIB}
rm -f ${PREFIX}/env ${PREFIX}/mless ${PREFIX}/mless-key-handler

+ 28
- 0
mblaze/contrib/mencrypt View File

@@ -0,0 +1,28 @@
#!/bin/sh
# mencrypt PLAINMSG - generate a PGP/MIME signed and encrypted message

[ -f "$1" ] || exit 1

IFS='
'
FLAGS=$(maddr -a -h from:to:cc:bcc: "$1" |sort -u |sed 's/^/--recipient=/')

FROM=$(maddr -a -h from "$1" | sed 1q)
[ "$FROM" ] && key="--default-key=$FROM"

TMPD=$(mktemp -d -t mencrypt.XXXXXX)
trap "rm -rf '$TMPD'" INT TERM EXIT

awk '/^$/,0' "$1" |
mmime |
gpg2 "$key" --armor --encrypt --sign $FLAGS -o "$TMPD/msg.asc" ||
exit $?

printf 'Version: 1\n' >"$TMPD/version"

{
sed '/^$/q' "$1"
printf '#application/pgp-encrypted %s/version\n' "$TMPD"
printf '#application/octet-stream %s/msg.asc\n' "$TMPD"
} |
mmime -t 'multipart/encrypted; protocol="application/pgp-encrypted"'

+ 20
- 0
mblaze/contrib/mgpg View File

@@ -0,0 +1,20 @@
#!/bin/sh -e

tmp=$(mktemp -t mgpg.XXXXXX)
trap "rm -f '$tmp'" INT TERM EXIT

{
echo "Content-Type: $PIPE_CONTENTTYPE"
echo
cat
} > "$tmp"

n=$(mshow -t "$tmp" | awk -F: '
/: application\/pgp-encrypted/ {supported = 1}
/: application\/octet-stream/ {if (supported) print $1}')

if [ "$n" ]; then
mshow -O "$tmp" "$n" | gpg2 -d 2>&1 || exit 0
exit 64
fi
exit 63

+ 25
- 0
mblaze/contrib/msign View File

@@ -0,0 +1,25 @@
#!/bin/sh
# msign PLAINMSG - generate a PGP/MIME signed message

[ -f "$1" ] || exit 1

IFS='
'

TMPD=$(mktemp -d -t msign.XXXXXX)
trap "rm -rf '$TMPD'" INT TERM EXIT

FROM=$(maddr -a -h from "$1" | sed 1q)
[ "$FROM" ] && key="--default-key=$FROM"

awk '/^$/,0' "$1" | mmime | sed 's/$/ /' >"$TMPD"/content
gpg2 $key --armor --detach-sign -o "$TMPD"/signature.asc "$TMPD"/content ||
exit $?

{
sed '/^$/q' "$1"
printf '#mblaze/raw %s/content\n' "$TMPD"
printf '#application/pgp-signature %s/signature.asc\n' "$TMPD"
} |
mmime -t 'multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"'


+ 34
- 0
mblaze/contrib/mverify View File

@@ -0,0 +1,34 @@
#!/bin/sh
# mverify MSG - verify a OpenPGP or SMIME message

# Needs gpg2 (for OpenPGP) and openssl (for SMIME).

[ "$#" -eq 0 ] && set -- .

mshow -t "$1" | DOS2UNIX='/ $/!s/$/ /' awk -v "msg=$1" '
{ match($0, "^ *"); indent = RLENGTH }
$2 == "text/plain" { plain++ }
$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 }
function q(a) { gsub("\\47", "\47\\\47\47", a); return "\47"a"\47" }
END {
if (type == "" && plain) { // guess plain text armored signature
exit(system("mshow -r " q(msg) " | gpg2 --verify"));
} else if (type == "") {
print("No signature found.")
exit(100)
} else if (type == "application/pgp-signature") {
exit(system("mshow -r -O " q(msg) " " q(content) \
" | sed $DOS2UNIX | " \
" { mshow -O " q(msg) " " q(signature) \
" | gpg2 --verify - /dev/fd/3; } 3<&0"))
} else if (type == "application/pkcs7-signature") {
exit(system("mshow -r -O " q(msg) " " q(signed) \
" | openssl smime -verify"))
} else {
print("Cannot verify signatures of type " type ".")
exit(2)
}
}
'

Loading…
Cancel
Save