An script attached, comments in spanish.
Waiting for a program that does it and handles a database certificate.
-- Manuel Mollar Villanueva Prof TEU depto informatica, UJI http://moon.act.uji.es mailto:[EMAIL PROTECTED] telf 964 72 8355
#!/bin/bash PATH=$PATH:/usr/local/ssl/bin:. if ! [ "$1" ]; then echo uso: $0 '[ -v ] destino [ "mensaje" | -m "linea de comando de metasend" ] asunto [ f [ficherocertificadorecepcion]]' echo ejemplo: $0 'mollar -m "-f ~/cs94-13.jpg -e base64 -m image/jpeg -n -f ~/panotiv.htm -e base64 -m text/html" cosas f mollar.crt' exit 1 fi
tmp=$(date +%s)$$
if [ "$1" = -v ]; then
inf=si
shift
fi
to=$1
msg=$2
if [ "$msg" = -m ]; then
shift
if [ "$inf" ]; then
echo -n 'Construyendo el mensaje con metasend ... '
fi
metasend -b -o $tmp.cuerpo $2
if [ "$inf" ]; then
echo $(wc -c <$tmp.cuerpo) bytes
fi
fi
sub=$3
if [ "$4" = f ] ; then
fir=si;
shift
fi
cif=$4
if ! [ "$fir" ];then
if ! [ -f $tmp.cuerpo ]; then # no metasend
echo "$msg" >$tmp.cuerpo
fi
else # firmado
if [ "$inf" ]; then
echo -n 'Generando la firma ... '
fi
if ! [ -f $tmp.cuerpo ]; then # no metasend
cat <<-EOF >$tmp.cuerpo
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: base64
$(echo "$msg" | mimencode)
EOF
fi
bou=mollar$tmp
firma=$(todos <$tmp.cuerpo | p7sign | sed -e "1 d" -e "$ d")
if [ "$inf" ]; then
echo -n 'de '
fi
quien="$(x509 -in server.pem -subject -noout | sed -e "s/.*Email=\([^/]*\)/\1/")"
if [ "$inf" ]; then
echo -ne "$quien\nConstruyendo firmado mime ... "
fi
quien="From: $quien
"
cat - <<-EOF $tmp.cuerpo >$tmp.cuerpo.tmp
Content-Type: multipart/signed; protocol="application/x-pkcs7-signature";
micalg=sha1; boundary="------------$bou"
This is a cryptographically signed message in MIME format.
It has been buided by the SMIME-agent by M. Mollar.
--------------$bou
EOF
cat <<-EOF >>$tmp.cuerpo.tmp
--------------$bou
Content-Type: application/x-pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature
$firma
--------------$bou--
EOF
mv $tmp.cuerpo.tmp $tmp.cuerpo
if [ "$inf" ]; then
echo $(wc -c <$tmp.cuerpo) bytes
fi
fi
if [ "$cif" ]; then
if [ "$inf" ]; then
echo -n 'Cifrando mensaje ... '
fi
mv $tmp.cuerpo $tmp.cuerpo.tmp
cat <<-EOF >$tmp.cuerpo
Content-Type: application/x-pkcs7-mime; name="smime.p7m"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7m"
Content-Description: S/MIME Encrypted Message
EOF
p7enc -k $cif $tmp.cuerpo.tmp | sed -e "1 d" -e "$ d" >>$tmp.cuerpo
rm $tmp.cuerpo.tmp
if [ "$inf" ]; then
echo $(wc -c <$tmp.cuerpo) bytes
fi
fi
if [ "$inf" ]; then
echo "Enviando el emilio"
fi
cat - <<-EOF $tmp.cuerpo | sendmail -t -oi
${quien}Subject: $sub
To: $to
MIME-Version: 1.0
EOF
rm $tmp.cuerpo
