From 2fc0e9c1b8eeac923b2e2d8dbe574993c8417009 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Tue, 21 Aug 2012 13:03:50 -0400 Subject: add ez-pine stuff to dotfiles --- bin/ez-pine-gpg-encrypt | 125 ++++++++++++++++++++++++++++++ bin/ez-pine-gpg-helper-recipient | 112 +++++++++++++++++++++++++++ bin/ez-pine-gpg-helper-sender | 117 ++++++++++++++++++++++++++++ bin/ez-pine-gpg-incoming | 159 +++++++++++++++++++++++++++++++++++++++ bin/ez-pine-gpg-sign | 129 +++++++++++++++++++++++++++++++ bin/ez-pine-gpg-sign-and-encrypt | 134 +++++++++++++++++++++++++++++++++ bin/ez-pine-gpg-symmetric | 86 +++++++++++++++++++++ 7 files changed, 862 insertions(+) create mode 100755 bin/ez-pine-gpg-encrypt create mode 100755 bin/ez-pine-gpg-helper-recipient create mode 100755 bin/ez-pine-gpg-helper-sender create mode 100755 bin/ez-pine-gpg-incoming create mode 100755 bin/ez-pine-gpg-sign create mode 100755 bin/ez-pine-gpg-sign-and-encrypt create mode 100755 bin/ez-pine-gpg-symmetric diff --git a/bin/ez-pine-gpg-encrypt b/bin/ez-pine-gpg-encrypt new file mode 100755 index 0000000..3f544be --- /dev/null +++ b/bin/ez-pine-gpg-encrypt @@ -0,0 +1,125 @@ +#!/bin/sh + +######################################################## +## ez-pine-gpg-encrypt ## +## part of ez-pine-gpg v0.4h // gpg filters for pine ## +## http://Business-PHP.com/opensource/ez-pine-gpg/ ## +## (c) 13 Feb 2004, Atom Emet ## +## (c) 16 Dec 2004, Atom Emet ## +## Atom {at} Business-PHP.com ## +## Distributed under the GNU General Public License ## +## http://www.gnu.org/copyleft/gpl.html ## +## ## +## ################################################ ## +## ## +## This program is free software; you can ## +## redistribute it and/or modify it under the terms ## +## of the GNU General Public License as published by ## +## the Free Software Foundation; either version 2 of ## +## the License, or (at your option) any later ## +## version. ## +## ## +## This program is distributed in the hope that it ## +## will be useful, but WITHOUT ANY WARRANTY; without ## +## even the implied warranty of MERCHANTABILITY or ## +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## +## General Public License for more details. ## +## ## +## You should have received a copy of the GNU ## +## General Public License along with this program; ## +## if not, write to the ## +## Free Software Foundation, Inc., ## +## 59 Temple Place - Suite 330, ## +## Boston, MA 02111-1307, USA. ## +######################################################## + +######################################### +## PATH is configured during installation +PATH=/bin:/usr/bin:/home/bnewbold/bin + +################### +## clear the screen +clear 1>&2 + +############################################################### +## display notices and give the user an opportunity to bail out +## +echo '#########################################################################' 1>&2 +echo '## This message is being processed by ez-pine-gpg v0.4h ##' 1>&2 +echo '## http://Business-PHP.com/opensource/ez-pine-gpg/ ##' 1>&2 +echo '## (c) 13 Feb 2004, Atom Emet ##' 1>&2 +echo '## (c) 16 Dec 2004, Atom Emet ##' 1>&2 +echo '## Distributed under the GNU General Public License ##' 1>&2 +echo '## See source for details ##' 1>&2 +echo '## ##' 1>&2 +echo '## THIS FILTER ENCRYPTS BUT DOES NOT SIGN YOUR MESSAGE! ##' 1>&2 +echo '## ##' 1>&2 +echo '## (May not be safe for BCC recipients -- see documentation) ##' 1>&2 +echo '## ##' 1>&2 +echo '## Are you sure you want to send this message without signing it? ##' 1>&2 +echo '## Press ENTER to continue or ^C to cancel. ##' 1>&2 +echo '#########################################################################' 1>&2 + +#################################################### +## we only need an acknowledgment: hit or ^C +## of course, some loser will type in their passphrase +## so we want it to NOT echo and we want to unset it +## hopefully this will be unset before their +## passphrase is written to disk cache +## the stty commmand also compensates for an un-acknowledged display bug in pine +## +stty -f /dev/tty -echo +read answer 0< /dev/tty +answer= +stty -f /dev/tty echo + +####################################### +## function to gracefully handle errors +## if something goes wrong display an error message +## that includes the recipients +## +gpg_failed () { + echo '#########################################################################' 1>&2 + echo '## Something went wrong #### See above for more info ##' 1>&2 + echo '#########################################################################' 1>&2 + echo "## Tried encrypting to: `printf '\011'`(key ID)" 1>&2 + for each_recipient in ${@} + do + [ "`echo ${each_recipient} | egrep '@'`" ] && echo "## <${each_recipient}>`printf '\011'`(`gpg --with-colons --list-keys ${each_recipient} 2> /dev/null | egrep ^pub | head -n 1 | cut -d : -f 5`)" 1>&2 + done + echo '#########################################################################' 1>&2 + ######################## + ## unset these variables + recipients= ; each_recipient= + ############################################################################# + ## a non-zero exit status will force pine to recognize that the script failed + ## forcing an acknowledgment here will leave diagnostic info visible to user + echo '/////////////////////// Press to continue ///////////////////////' 1>&2 + read dead < /dev/tty + clear 1>&2 + exit 1 +} + +############################################### +## recipients are passed as arguments from pine +## and processed by "ez-pine-gpg-helper-recipient" +## if a key can't be found for an address +## then bail out with an error message +## +recipients=`ez-pine-gpg-helper-recipient ${@}` || gpg_failed ${@} + +#################################################### +## send the message from STDIN through gpg to STDOUT +## if it fails then bail out with an error message +## +gpg -ea ${recipients} || gpg_failed ${recipients} + +######################################## +## unset variables we don't need anymore +## +recipients= ; each_recipient= + +############# +## we're done +## +exit 0 diff --git a/bin/ez-pine-gpg-helper-recipient b/bin/ez-pine-gpg-helper-recipient new file mode 100755 index 0000000..b78a18d --- /dev/null +++ b/bin/ez-pine-gpg-helper-recipient @@ -0,0 +1,112 @@ +#!/bin/sh + +######################################################## +## ez-pine-gpg-helper-recipient ## +## part of ez-pine-gpg v0.4h // gpg filters for pine ## +## http://Business-PHP.com/opensource/ez-pine-gpg/ ## +## (c) 13 Feb 2004, Atom Emet ## +## (c) 16 Dec 2004, Atom Emet ## +## Atom {at} Business-PHP.com ## +## Distributed under the GNU General Public License ## +## http://www.gnu.org/copyleft/gpl.html ## +## ## +## ################################################ ## +## ## +## This program is free software; you can ## +## redistribute it and/or modify it under the terms ## +## of the GNU General Public License as published by ## +## the Free Software Foundation; either version 2 of ## +## the License, or (at your option) any later ## +## version. ## +## ## +## This program is distributed in the hope that it ## +## will be useful, but WITHOUT ANY WARRANTY; without ## +## even the implied warranty of MERCHANTABILITY or ## +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## +## General Public License for more details. ## +## ## +## You should have received a copy of the GNU ## +## General Public License along with this program; ## +## if not, write to the ## +## Free Software Foundation, Inc., ## +## 59 Temple Place - Suite 330, ## +## Boston, MA 02111-1307, USA. ## +######################################################## + +######################################### +## PATH is configured during installation +PATH=/bin:/usr/bin:/home/bnewbold/bin + +######################################################################## +## make sure all specified recipients have a valid key in the keyring ## +######################################################################## + +##################################################### +## clear out variables that might have been inherited +recipient= ; recipient_list= + +######################################### +## this function checks if each recipient +## has a valid key in the keyring +## if a valid key is not found it will try to +## find a reasonable substitute +## +valid_recipient () { + recipient=`echo ${1} | tr -d '\r'` + if gpg --batch --list-public-keys ${recipient} 2>&- 1>&- + then + ## if a valid public key is found that's good + echo "-r ${recipient}" + exit 0 + elif [ "`echo ${recipient} | egrep '.*-.*@'`" ] + then + echo '/////////////////////////////////////////////////////////////////////////' 1>&2 + echo "// No public key found in keyring for <${recipient}>" 1>&2 + recipient=`echo ${recipient} | sed 's/-.*@/@/'` + echo "// Should I try encrypting to a key for <${recipient}>? [Y/n]: " | tr -d '\n' 1>&2 + read answer 0< /dev/tty + echo 1>&2 + if [ "`echo "${answer}" | egrep -i n`" ] + then + ## don't try to substitute the email address + exit 3 + elif gpg --batch --list-public-keys ${recipient} 2>&- 1>&- + then + ## a valid public key is found after modification + echo "-r ${recipient}" + exit 0 + fi + fi + ## unable to find a valid key -- bail out + echo '/////////////////////////////////////////////////////////////////////////' 1>&2 + echo "// No valid public key found in keyring for <${recipient}>" 1>&2 + echo "// Please import a valid key for <${recipient}>" 1>&2 + echo '/////////////////////////////////////////////////////////////////////////' 1>&2 + exit 3 +} + +############################################### +## for each address that's given as an argument +## make sure a valid key exists in the keyring +## +for n in ${@} +do + recipient_list="${recipient_list} `valid_recipient ${1}`" || exit 3 + shift +done + +######################################### +## return a list of addresses that have a +## valid public key in the keyring +## +echo "${recipient_list}" + +######################################## +## unset variables we don't need anymore +## +recipient= ; recipient_list= + +####### +## exit +## +exit 0 diff --git a/bin/ez-pine-gpg-helper-sender b/bin/ez-pine-gpg-helper-sender new file mode 100755 index 0000000..25f3586 --- /dev/null +++ b/bin/ez-pine-gpg-helper-sender @@ -0,0 +1,117 @@ +#!/bin/sh + +######################################################## +## ez-pine-gpg-helper-sender ## +## part of ez-pine-gpg v0.4h // gpg filters for pine ## +## http://Business-PHP.com/opensource/ez-pine-gpg/ ## +## (c) 13 Feb 2004, Atom Emet ## +## (c) 16 Dec 2004, Atom Emet ## +## Atom {at} Business-PHP.com ## +## Distributed under the GNU General Public License ## +## http://www.gnu.org/copyleft/gpl.html ## +## ## +## ################################################ ## +## ## +## This program is free software; you can ## +## redistribute it and/or modify it under the terms ## +## of the GNU General Public License as published by ## +## the Free Software Foundation; either version 2 of ## +## the License, or (at your option) any later ## +## version. ## +## ## +## This program is distributed in the hope that it ## +## will be useful, but WITHOUT ANY WARRANTY; without ## +## even the implied warranty of MERCHANTABILITY or ## +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## +## General Public License for more details. ## +## ## +## You should have received a copy of the GNU ## +## General Public License along with this program; ## +## if not, write to the ## +## Free Software Foundation, Inc., ## +## 59 Temple Place - Suite 330, ## +## Boston, MA 02111-1307, USA. ## +######################################################## + +######################################### +## PATH is configured during installation +PATH=/bin:/usr/bin:/home/bnewbold/bin + +########################################################################## +## make sure the role being used to send has a valid key in the keyring ## +########################################################################## + +##################################################### +## the var "msg" is the full headers and message body +## +msg="`cat`" + +###################################################################################### +## if there is an "OpenPGP" find the "id" field +## use that key for signing: +## OpenPGP: id=0x12345678 +## +if which 822fields >& - 2>& - +then + key_id=`echo "${msg}" | 822fields OpenPGP | sed 's!([^)]*)!!g' | tr ' ;' '\n' | egrep ^id | cut -d= -f2` + if [ "${key_id}" ] + then + echo "Signing with \"OpenPGP\" UID: ${key_id}" 1>&2 + echo "${key_id}" + key_id= ; msg= + exit 0 + fi +fi + +############################################################### +## if there is a header "X-OpenPGP-KeyID" or "X-OpenPGP-Key-ID" +## use that key for signing: +## X-OpenPGP-KeyID: 0x12345678 +## +key_id=`echo "${msg}" | tr -d '\r' | egrep -i '^X-OpenPGP-Key(-)?ID: ' | tr ' ' '\n' | egrep '0x' | head -n 1` +if [ "${key_id}" ] +then + echo "${key_id}" + key_id= ; msg= + exit 0 +fi + +############################################### +## the last token on the "From" line is used as +## gpg's "--local-user" option +## angle brackets (<>) are stripped off +## +from=`echo "${msg}" | egrep '^From: ' | head -n 1 | tr -d '[\n\r]' | sed 's/^.* // ; s/[<>]//g'` + +####################################### +## make sure we've found a valid sender +## +if ! gpg --list-secret-keys ${from} 2>&- 1>&- && [ "`echo ${from} | egrep '.*-.*@'`" ] +then + echo '/////////////////////////////////////////////////////////////////////////' 1>&2 + echo "// No secret key found for <${from}>" 1>&2 + from=`echo ${from} | sed 's/-.*@/@/'` + echo "// Should I try signing with a key for <${from}>? [Y/n]: " | tr -d '\n' 1>&2 + read answer 0< /dev/tty + if [ `echo "${answer}" | egrep -i n` ] + then + msg= ; from= + exit 2 + fi + echo 1>&2 +fi + +######################################################### +## echo the sending address that we have a secret key for +## this returns the address to the calling process +echo "${from}" + +######################################## +## unset variables we don't need anymore +## +msg= ; from= + +############# +## we're done +## +exit 0 diff --git a/bin/ez-pine-gpg-incoming b/bin/ez-pine-gpg-incoming new file mode 100755 index 0000000..2cf8a3b --- /dev/null +++ b/bin/ez-pine-gpg-incoming @@ -0,0 +1,159 @@ +#!/bin/sh + +######################################################## +## ez-pine-gpg-incoming ## +## part of ez-pine-gpg v0.4h // gpg filters for pine ## +## http://Business-PHP.com/opensource/ez-pine-gpg/ ## +## (c) 13 Feb 2004, Atom Emet ## +## (c) 16 Dec 2004, Atom Emet ## +## Atom {at} Business-PHP.com ## +## Distributed under the GNU General Public License ## +## http://www.gnu.org/copyleft/gpl.html ## +## ## +## ################################################ ## +## ## +## This program is free software; you can ## +## redistribute it and/or modify it under the terms ## +## of the GNU General Public License as published by ## +## the Free Software Foundation; either version 2 of ## +## the License, or (at your option) any later ## +## version. ## +## ## +## This program is distributed in the hope that it ## +## will be useful, but WITHOUT ANY WARRANTY; without ## +## even the implied warranty of MERCHANTABILITY or ## +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## +## General Public License for more details. ## +## ## +## You should have received a copy of the GNU ## +## General Public License along with this program; ## +## if not, write to the ## +## Free Software Foundation, Inc., ## +## 59 Temple Place - Suite 330, ## +## Boston, MA 02111-1307, USA. ## +######################################################## + +######################################### +## PATH is configured during installation +PATH=/bin:/usr/bin:/home/bnewbold/bin + +################### +## clear the screen +clear 1>&2 + +echo '#########################################################################' 1>&2 +echo '## This message is being processed by ez-pine-gpg v0.4h ##' 1>&2 +echo '## http://Business-PHP.com/opensource/ez-pine-gpg/ ##' 1>&2 +echo '## (c) 13 Feb 2004, Atom Emet ##' 1>&2 +echo '## (c) 16 Dec 2004, Atom Emet ##' 1>&2 +echo '## Distributed under the GNU General Public License ##' 1>&2 +echo '## See source for details ##' 1>&2 +echo '#########################################################################' 1>&2 + +#################################################### +## if things go wrong, this notice will be displayed +## along with the incoming message +## +gpg_failed () { + echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' + echo '%%%%%%%%%%%% Something went wrong --- See above for more info %%%%%%%%%%%%' + echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' + ############################# + ## if the message is textmode + if [ "${textmode}" = 'yes' ] + then + ############################################################ + ## display the input and un-dash-escape any clearsigned text + echo "${input}" | sed '/^-----BEGIN PGP SIGNED MESSAGE-----/,/^-----BEGIN PGP SIGNATURE-----/ s/^- -/-/' + elif [ "${textmode}" = 'no' ] && [ "${stdout}" ] + then + ####################################### + ## if the message seems to be encrypted + ## and gpg produces STDOUT display the decrypted message + echo "${stdout}" + else + ############################################################################## + ## if we're here then the message was encrypted but not successfully decrypted + ## just display the input + echo "${input}" + fi + ############################################# + ## unset variables that we don't need anymore + input= ; stdout= ; textmode= + ############################################ + ## just because something went wrong doesn't + ## mean that pine needs to know about it. + ## a zero exit status makes pine happy + clear 1>&2 + exit 0 +} + +########################################### +## do the right thing even if ^C is pressed +## +trap 'gpg_failed' 2 + +############################################################ +## create a variable "input" containing STDIN to this script +## +input="`cat`" + +##################################################### +## test if the message in textmode or binary/armored? +if echo "${input}" | gpg --list-only --list-packets 2>&1 | egrep -q '^[[:space:]]+mode t' +then + export textmode=yes +else + export textmode=no +fi + +############################################################## +## echo a message that let's us know ez-pine-gpg is being used +## and display the machine name and current date/time +## +echo '##########################################################################' +echo '## ez-pine-gpg v0.4h ## http://Business-PHP.com/opensource/ez-pine-gpg/' +echo "## `date` ## `uname -n`" +echo '##########################################################################' + +################################################# +## display some information about the the message +## we're only concerned with STDERR +echo "${input}" | gpg --list-only > /dev/null + +############################################### +## the variable "stdout" is the output from gpg +## notices from gpg STDERR are redirected to STDOUT and displayed +## if gpg fails then bail out with an error message +## +{ stdout="`echo "${input}" | gpg --decrypt`" || gpg_failed ; } 2>&1 + +############################################# +## figure out how to best display the message +## +if [ "${textmode}" = 'no' ] +then + ######################################################## + ## if the message is armored display the output from gpg + echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' + echo '%%%%%%%%%%%%%%%%%%%%%%%% OpenPGP ENCODED MESSAGE %%%%%%%%%%%%%%%%%%%%%%%%%' + echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' + echo "${stdout}" +else + ########################################################################################## + ## if the message is clearsigned (or malformed?) display the input and un-dash-escape text + echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' + echo '%%%%%%%%%%%%%%%%%%%%%%%%% OpenPGP SIGNED MESSAGE %%%%%%%%%%%%%%%%%%%%%%%%%' + echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' + echo "${input}" | sed '/^-----BEGIN PGP SIGNED MESSAGE-----/,/^-----BEGIN PGP SIGNATURE-----/ s/^- -/-/' +fi + +########################### +## get rid of the variables +## containing the message +input= ; stdout= ; textmode= + +############# +## we're done +## +exit 0 diff --git a/bin/ez-pine-gpg-sign b/bin/ez-pine-gpg-sign new file mode 100755 index 0000000..fe9a994 --- /dev/null +++ b/bin/ez-pine-gpg-sign @@ -0,0 +1,129 @@ +#!/bin/sh + +######################################################## +## ez-pine-gpg-sign ## +## part of ez-pine-gpg v0.4h // gpg filters for pine ## +## http://Business-PHP.com/opensource/ez-pine-gpg/ ## +## (c) 13 Feb 2004, Atom Emet ## +## (c) 16 Dec 2004, Atom Emet ## +## Atom {at} Business-PHP.com ## +## Distributed under the GNU General Public License ## +## http://www.gnu.org/copyleft/gpl.html ## +## ## +## ################################################ ## +## ## +## This program is free software; you can ## +## redistribute it and/or modify it under the terms ## +## of the GNU General Public License as published by ## +## the Free Software Foundation; either version 2 of ## +## the License, or (at your option) any later ## +## version. ## +## ## +## This program is distributed in the hope that it ## +## will be useful, but WITHOUT ANY WARRANTY; without ## +## even the implied warranty of MERCHANTABILITY or ## +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## +## General Public License for more details. ## +## ## +## You should have received a copy of the GNU ## +## General Public License along with this program; ## +## if not, write to the ## +## Free Software Foundation, Inc., ## +## 59 Temple Place - Suite 330, ## +## Boston, MA 02111-1307, USA. ## +######################################################## + +######################################### +## PATH is configured during installation +PATH=/bin:/usr/bin:/home/bnewbold/bin + +################### +## clear the screen +clear 1>&2 + +###################################################### +## this compensates for an un-acknowledged bug in pine +stty -f /dev/tty echo + +############################################################### +## display notices and give the user an opportunity to bail out +## +echo '#########################################################################' 1>&2 +echo '## This message is being processed by ez-pine-gpg v0.4h ##' 1>&2 +echo '## http://Business-PHP.com/opensource/ez-pine-gpg/ ##' 1>&2 +echo '## (c) 13 Feb 2004, Atom Emet ##' 1>&2 +echo '## (c) 16 Dec 2004, Atom Emet ##' 1>&2 +echo '## Distributed under the GNU General Public License ##' 1>&2 +echo '## See source for details ##' 1>&2 +echo '## ##' 1>&2 +echo '## THIS FILTER SIGNS BUT DOES NOT ENCRYPT YOUR MESSAGE! ##' 1>&2 +echo '## ##' 1>&2 +echo '## Are you sure you want to send this message without encrypting it? ##' 1>&2 +echo '## If you want to cancel sending press ^C ##' 1>&2 +echo '#########################################################################' 1>&2 + +########################################################## +## the variable "msg" is the full headers and message body +## +msg="`cat`" + +######################################################################## +## use "ez-pine-gpg-helper-sender" to find what role is sending the mail +## +from=`echo "${msg}" | ez-pine-gpg-helper-sender` + +################################################### +## we don't need to process any more of the headers +## this assigns the body of the message to the var "body" +## +cr=`printf '\015'` +body=`echo "${msg}" | sed "1,/^${cr}\$/d"` + +########################### +## unset the "msg" variable +## +msg= + +####################################### +## function to gracefully handle errors +## if something goes wrong display an error message +## that includes the sender +## +gpg_failed () { + echo '#########################################################################' 1>&2 + echo '## Something went wrong #### See above for more info ##' 1>&2 + echo '#########################################################################' 1>&2 + echo "## Tried signing message from: ${from}" 1>&2 + echo '#########################################################################' 1>&2 + ######################################## + ## unset variables we don't need anymore + body= ; from= + ############################################################################# + ## a non-zero exit status will force pine to recognize that the script failed + ## forcing an acknowledgment here will leave diagnostic info visible to user + echo '/////////////////////// Press to continue ///////////////////////' 1>&2 + read dead < /dev/tty + clear 1>&2 + exit 1 +} + +########################################### +## do the right thing even if ^C is pressed +## +trap 'gpg_failed' 2 + +####################################################### +## pipe the message body into the gpg clearsign command +## pine will read the signed message from STDOUT +## +{ echo "${body}" ; echo ; } | gpg --local-user "${from}" --clearsign || gpg_failed + +############################################# +## unset variables that we don't need anymore +## +body= ; from= + +############# +## we're done +## +exit 0 diff --git a/bin/ez-pine-gpg-sign-and-encrypt b/bin/ez-pine-gpg-sign-and-encrypt new file mode 100755 index 0000000..9994687 --- /dev/null +++ b/bin/ez-pine-gpg-sign-and-encrypt @@ -0,0 +1,134 @@ +#!/bin/sh + +######################################################## +## ez-pine-gpg-sign-and-encrypt ## +## part of ez-pine-gpg v0.4h // gpg filters for pine ## +## http://Business-PHP.com/opensource/ez-pine-gpg/ ## +## (c) 13 Feb 2004, Atom Emet ## +## (c) 16 Dec 2004, Atom Emet ## +## Atom {at} Business-PHP.com ## +## Distributed under the GNU General Public License ## +## http://www.gnu.org/copyleft/gpl.html ## +## ## +## ################################################ ## +## ## +## This program is free software; you can ## +## redistribute it and/or modify it under the terms ## +## of the GNU General Public License as published by ## +## the Free Software Foundation; either version 2 of ## +## the License, or (at your option) any later ## +## version. ## +## ## +## This program is distributed in the hope that it ## +## will be useful, but WITHOUT ANY WARRANTY; without ## +## even the implied warranty of MERCHANTABILITY or ## +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## +## General Public License for more details. ## +## ## +## You should have received a copy of the GNU ## +## General Public License along with this program; ## +## if not, write to the ## +## Free Software Foundation, Inc., ## +## 59 Temple Place - Suite 330, ## +## Boston, MA 02111-1307, USA. ## +######################################################## + +######################################### +## PATH is configured during installation +PATH=/bin:/usr/bin:/home/bnewbold/bin + +################### +## clear the screen +clear 1>&2 + +###################################################### +## this compensates for an un-acknowledged bug in pine +stty -f /dev/tty echo + +############################################################### +## display notices and give the user an opportunity to bail out +## +echo '#########################################################################' 1>&2 +echo '## This message is being processed by ez-pine-gpg v0.4h ##' 1>&2 +echo '## http://Business-PHP.com/opensource/ez-pine-gpg/ ##' 1>&2 +echo '## (c) 13 Feb 2004, Atom Emet ##' 1>&2 +echo '## (c) 16 Dec 2004, Atom Emet ##' 1>&2 +echo '## Distributed under the GNU General Public License ##' 1>&2 +echo '## See source for details ##' 1>&2 +echo '## ##' 1>&2 +echo '## This filter signs and encrypts your message. ##' 1>&2 +echo '## ##' 1>&2 +echo '## (May not be safe for BCC recipients -- see documentation) ##' 1>&2 +echo '## ##' 1>&2 +echo '## If you want to cancel sending press ^C ##' 1>&2 +echo '#########################################################################' 1>&2 + +####################################### +## function to gracefully handle errors +## if something goes wrong display an error message +## that includes the recipients +## +gpg_failed () { + echo '#########################################################################' 1>&2 + echo '## Something went wrong #### See above for more info ##' 1>&2 + echo '#########################################################################' 1>&2 + echo "## Tried signing message from: ${from}" 1>&2 + echo '#########################################################################' 1>&2 + echo "## Tried encrypting to: `printf '\011'`(key ID)" 1>&2 + for each_recipient in ${@} + do + [ "`echo ${each_recipient} | egrep '@'`" ] && echo "## <${each_recipient}>`printf '\011'`(`gpg --with-colons --list-keys ${each_recipient} 2> /dev/null | egrep ^pub | head -n 1 | cut -d : -f 5`)" 1>&2 + done + echo '#########################################################################' 1>&2 + ######################## + ## unset these variables + recipients= ; each_recipient= ; from= + ############################################################################# + ## a non-zero exit status will force pine to recognize that the script failed + ## forcing an acknowledgment here will leave diagnostic info visible to user + echo '/////////////////////// Press to continue ///////////////////////' 1>&2 + read dead < /dev/tty + clear 1>&2 + exit 1 +} + +########################################### +## do the right thing even if ^C is pressed +## +trap 'echo 1>&2 ; gpg_failed ${@}' 2 + +########################################################## +## the variable "msg" is the full headers and message body +## +msg="`cat`" + +######################################################################## +## use "ez-pine-gpg-helper-sender" to find what role is sending the mail +## +from=`echo "${msg}" | ez-pine-gpg-helper-sender` + +############################################### +## recipients are passed as arguments from pine +## and processed by "ez-pine-gpg-helper-recipient" +## if a key can't be found for an address then +## bail out with an error message +## +recipients=`ez-pine-gpg-helper-recipient ${@}` || gpg_failed ${@} + +################################################################ +## pipe the message body (minus headers) into gpg sign + encrypt +## pine will read the signed message from STDOUT +## +cr=`printf '\015'` +echo "${msg}" | sed "1,/^${cr}\$/d" \ + | gpg --sign --encrypt --local-user "${from}" --armor ${recipients} || gpg_failed ${recipients} + +############################################# +## unset variables that we don't need anymore +## +recipients= ; each_recipient= ; from= ; msg= + +############# +## we're done +## +exit 0 diff --git a/bin/ez-pine-gpg-symmetric b/bin/ez-pine-gpg-symmetric new file mode 100755 index 0000000..0b54d99 --- /dev/null +++ b/bin/ez-pine-gpg-symmetric @@ -0,0 +1,86 @@ +#!/bin/sh + +######################################################## +## ez-pine-gpg-symmetric ## +## part of ez-pine-gpg v0.4h // gpg filters for pine ## +## http://Business-PHP.com/opensource/ez-pine-gpg/ ## +## (c) 13 Feb 2004, Atom Emet ## +## (c) 16 Dec 2004, Atom Emet ## +## Atom {at} Business-PHP.com ## +## Distributed under the GNU General Public License ## +## http://www.gnu.org/copyleft/gpl.html ## +## ## +## ################################################ ## +## ## +## This program is free software; you can ## +## redistribute it and/or modify it under the terms ## +## of the GNU General Public License as published by ## +## the Free Software Foundation; either version 2 of ## +## the License, or (at your option) any later ## +## version. ## +## ## +## This program is distributed in the hope that it ## +## will be useful, but WITHOUT ANY WARRANTY; without ## +## even the implied warranty of MERCHANTABILITY or ## +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## +## General Public License for more details. ## +## ## +## You should have received a copy of the GNU ## +## General Public License along with this program; ## +## if not, write to the ## +## Free Software Foundation, Inc., ## +## 59 Temple Place - Suite 330, ## +## Boston, MA 02111-1307, USA. ## +######################################################## + +######################################### +## PATH is configured during installation +PATH=/bin:/usr/bin:/home/bnewbold/bin + +################### +## clear the screen +clear 1>&2 + +############################################################### +## display notices and give the user an opportunity to bail out +## +echo '#########################################################################' 1>&2 +echo '## This message is being processed by ez-pine-gpg v0.4h ##' 1>&2 +echo '## http://Business-PHP.com/opensource/ez-pine-gpg/ ##' 1>&2 +echo '## (c) 13 Feb 2004, Atom Emet ##' 1>&2 +echo '## (c) 16 Dec 2004, Atom Emet ##' 1>&2 +echo '## Distributed under the GNU General Public License ##' 1>&2 +echo '## See source for details ##' 1>&2 +echo '## ##' 1>&2 +echo '## THIS FILTER SYMMETRICALLY ENCRYPTS YOUR MESSAGE ##' 1>&2 +echo '## ##' 1>&2 +echo '#########################################################################' 1>&2 + +####################################### +## function to gracefully handle errors +## if something goes wrong display an error message +## that includes the recipients +## +gpg_failed () { + echo '#########################################################################' 1>&2 + echo '## Something went wrong #### See above for more info ##' 1>&2 + echo '#########################################################################' 1>&2 + ############################################################################# + ## a non-zero exit status will force pine to recognize that the script failed + ## forcing an acknowledgment here will leave diagnostic info visible to user + echo '/////////////////////// Press to continue ///////////////////////' 1>&2 + read dead < /dev/tty + clear 1>&2 + exit 1 +} + +#################################################### +## send the message from STDIN through gpg to STDOUT +## if it fails then bail out with an error message +## +gpg -ac || gpg_failed + +############# +## we're done +## +exit 0 -- cgit v1.2.3