diff options
-rwxr-xr-x | mailcert.sh | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/mailcert.sh b/mailcert.sh index 7767be6..167e571 100755 --- a/mailcert.sh +++ b/mailcert.sh @@ -50,11 +50,13 @@ if ! [ "$USEREMAIL" ]; then # address from cmdline fi fi +echo "" echo CACERT is assumed to be: "$CACERT" echo USERCERT is assumed to be: "$USERCERT" echo USEREMAIL is assumed to be: "$USEREMAIL" -echo Press Ctrl-C if any of this looks incorrect. -sleep 5 +echo "" +echo Press Ctrl-C if any of this looks incorrect, otherwise hit enter. +read [[ $(openssl x509 -in omgca/ca/omgca.crt -noout -subject) =~ .+CN=(.+) ]] CACN="${BASH_REMATCH[1]}" @@ -62,12 +64,42 @@ if [[ "$CACN" =~ (.+)/emailAddress.+ ]]; then CACN=${BASH_REMATCH[1]} fi -# FIXME: implement /usr/lib/sendmail input, including attachment syntax -# /usr/lib/sendmail -t << EOF -cat << EOF -To: "$USEREMAIL" -From: "$E" -Subject: Certificate from "$CACN" -MIME-Version: 1.0 -Content-Type: +export BOUNDARY="$(dd if=/dev/urandom bs=16 count=1 status=noxfer 2>/dev/null | base64)" +export USERCERTNAME=$(basename "$USERCERT") +export CACERTNAME=$(basename "$CACERT") +( + echo "To: $USEREMAIL" + echo "From: $E" + echo "Subject: Certificate from $CACN" + echo "User-Agent: cash mailcert.sh" + echo "MIME-Version: 1.0" + echo "Content-Type: multipart/mixed; boundary=\"$BOUNDARY\"" + echo "" + echo "This is a multipart message in MIME format." + echo "" + echo "--$BOUNDARY" + echo "Content-Type: text/plain" + echo "Content-Disposition: inline" + echo "" + echo "You'll want both of these." + echo "" + echo "$USERCERTNAME is your user certificate." + echo "" + echo "$CACERTNAME is the certificate authority certificate." + echo "--$BOUNDARY" + echo "Content-Type: application/x-x509-ca-cert" + echo "Content-Disposition: attachment; filename=\"$USERCERTNAME\"" + echo "" + cat "$CACERT" + echo "" + echo "--$BOUNDARY" + echo "Content-Type: application/x-x509-ca-cert" + echo "Content-Disposition: attachment; filename=\"$CACERTNAME\"" + echo "" + cat "$USERCERT" + echo "" + echo "--$BOUNDARY--" +) | /usr/lib/sendmail -t + +echo "Sent!" |