summaryrefslogtreecommitdiff
path: root/mailcert.sh
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk@omgwallhack.org>2011-03-29 12:49:10 -0700
committerJoe Rayhawk <jrayhawk@omgwallhack.org>2011-03-29 12:49:10 -0700
commit9684c8d5fbff056ad55902ecdf733ef08e848fd1 (patch)
tree3f0680244b1d2b7b472d5635ef91f929a7c92555 /mailcert.sh
parent54f3c980df8d4f05ac0ff5013870578961d14574 (diff)
downloadcash-9684c8d5fbff056ad55902ecdf733ef08e848fd1.tar.gz
cash-9684c8d5fbff056ad55902ecdf733ef08e848fd1.zip
Making mailcert.sh actually mail certs
Diffstat (limited to 'mailcert.sh')
-rwxr-xr-xmailcert.sh52
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!"