[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PGP signing tools for Elm/Pine/nn



-----BEGIN PGP SIGNED MESSAGE-----


Recent comments re the signing controvery give me the impression that
a repeat of this information might be useful. I apologize if this 
seems like a waste of bandwidth. I can't seem to find a copy of a
tool to make .shar's (or whatever one calls them) so I've 
separated files with ===== markers. I have also uploaded a gzip'ed
.tar of these files, plus a gzip'ed copy of the mkpgp.txt.uu
document referenced below, to cypherpunks/incoming on
ftp.csua.berkeley.edu.

These scripts + a copy of PGP interface nicely with Pine or Elm and
NN to sign/encrypt outgoing messages, and decrypt or signature-
verify incoming mail. The four files below came with the PGP 2.3 
distribution (under contrib/elm_nn); they were not included in the
laster distributions. I don't know why. They still seem to work
fine with the newer MIT-PGP stuff. 

The "mkpgp" script referenced in Michael Handler's message seems to
work fine from inside Pine; but I mostly stick with Elm and nn, so
haven't used it much. 

Again, sorry to use list bandwidth for this; I thought that these were
already in the hands of most of the folks on the list but the last
few days' messages make me feel uncertain about that.

(And no, for the zillionth time, it's not great policy to use PGP
on a machine where you're not root. Use a small key marked "unsecure"
and get on with life. It won't protect you from root but it will
protect you from Detweiler and other small-time annoyances.)

===== Michael Handler's message =====

From: Michael Handler <[email protected]>
Subject: Interfacing PGP with Pine (Script pointer)
Date: 25 Nov 1994 07:03:03 -0800
Message-ID: <[email protected]>


	For a well written script to interface PGP with Pine:

	finger [email protected] | pgp -f > mkpgp.txt.uu

	If you don't have finger access, mail me privately, and I'll send 
the file to you.

Mike, who is only as elegant as his actions let him be
- --
Michael Handler <[email protected]>
Philadelphia, PA                    Civil Liberty Through Complex Mathematics
VoicePGP Development Team       soc.support.youth.gay-lesbian-bi co-moderator

===== readme =====

To integrate PGP 2.1 with Elm and NN:

0) Make sure the path of Perl in the first line of each of the three
files reflects the full path of this utility for your system. Also,
make sure that the EDITOR and PAGER environment variables reflect your
editor and pager of choice (vi and less will be used by default).

1) Put the files morepgp, mailpgp, and postpgp in one of the
directories on your PATH.

2) Modify your ~/.elm/elmrc file to contain the following lines:

	editor	=	mailpgp
	pager	=	morepgp

3) Modify your ~/.nn/init file to contain the following lines:

	set editor	postpgp

That's all folks! Now, each time you post a message or reply to a
message with nn, after you exit your editor, you will be asked whether
you want to sign your message. Each time you compose a private message
with elm, or reply to a message, and leave the editor, you'll be asked
whether you want to sign and/or encrypt the message. When you browse a
message, if it contains any PGP blocks, those will be properly
interpreted. When you reply to a message containing PGP blocks, you'll
have them properly decrypted and quoted in your editor.

BUGS

1) You cannot encrypt messages that you mail from nn. You can only
sign them.

2) When you reply to a PGP-encryted message, the encrypted message is
temporarily kept on the disk, which is a security hole.

3) The temporary files are not wiped out, they are just deleted.

4) The scripts are ugly, reflecting my lack of knowledge of Perl. In
fact, I don't know Perl at all; I hacked somebody else's scripts. If
you know Perl better then me, please feel free to improve the scripts
and don't forget to mail me a copy of the improved version.

I can be contacted as Vesselin Bontchev at
[email protected]

===== mailpgp =====

#!/usr/bin/perl

($visual = $ENV{'VISUAL'}) || ($visual = '/usr/ucb/vi');
$topgp = 0;
$blanks = 0;
$paragraphs = 1;
$blankcompress = 1;
$name=@ARGV[$#ARGV];
umask (077);
open (INPUT, "<$name");
open (OUTPUT, ">${name}.rply") || die "Cannot open ${name}.rply for output.\n";
while (<INPUT>) {
	if (!$topgp && !m/^> -----BEGIN PGP .*-----/) {
		if (m/^> *$/) {
			if ($paragraphs) {
				if ($blankcompress) {
					if ($blanks == 0) {
						print OUTPUT "\n";
						$blanks = 1;
					}
				} else {
					print OUTPUT "\n";
				}
			} else {
				print OUTPUT;
			}
		} elsif (m/^ *$/) {
			if ($blankcompress) {
				if ($blanks == 0) {
					print OUTPUT "\n";
					$blanks = 1;
				}
			} else {
				print OUTPUT;
			}
		} else {
			print OUTPUT;
			if ($. == 1 && !m/^> /) {
				print OUTPUT "\n";
				$blanks = 1;
			} else {
				$blanks = 0;
			}
		}
	}
	if (!$topgp && m/^> -----BEGIN PGP .*-----/) {
		$topgp = 1;
		$tmpfile = "${name}.pgp",
		unlink ($tmpfile);
		open (TMPFILE, ">$tmpfile") || die "Cannot open $tmpfile for output.\n";
	}
	if ($topgp) {
		$_ =~ s/^> //;
		print TMPFILE $_;
		if (m/^-----END PGP .*-----/) {
			$topgp = 0;
			close TMPFILE;
			$clrfile = "${name}.clr";
			`pgp $tmpfile -o $clrfile`;
			open (CLEAR, "<$clrfile") || die "Cannot open $clrfile for input.\n";
			print OUTPUT "-----BEGIN OF PGP DECRYPTED TEXT-----\n\n";
			while (<CLEAR>) {
				if (m/^$/) {
					print OUTPUT "\n";
				} else {
					print OUTPUT "> ";
					print OUTPUT;
				}
			}
			close CLEAR;
			unlink ($clrfile);
			unlink ($tmpfile);
			print OUTPUT "\n-----END OF PGP DECRYPTED TEXT-----\n\n";
		}
	}
}
close OUTPUT;
close INPUT;
unlink ($name);
rename ("${name}.rply", "$name");

system ($visual,@ARGV);

while (!$q) {
	print "Sign this message? [Y]: ";
	$q = <STDIN>;
	$q =~ s/[ \t\n]//g;
	$q = substr ($q, 0, 1);
	if (($q eq 'Y') || ($q eq 'y') || ($q eq '')) {
		push(@opts,'-st','+clearsig=on');
		$q = "y";
	} elsif (($q ne 'N') && ($q ne 'n')) {
		$q = '';
	}
}
$q='';
while (!$q) {
	print "Encrypt this message? [Y]: ";
	$q = <STDIN>;
	$q =~ s/[ \t\n]//g;
	$q = substr ($q, 0, 1);
	if (($q eq 'Y') || ($q eq 'y') || ($q eq '')) {
		push(@opts,'-e');
		$q = "y";
	} elsif (($q ne 'N') && ($q ne 'n')) {
		$q = '';
	}
}
if (@opts) {
	system ('pgp','-a',@opts,$name);
	if ($? == 0) {
		unlink ${name};
		rename ("${name}.asc", "$name");
	}
}

===== morepgp ===== 

#!/usr/bin/perl

# written by jason steiner, [email protected], Jan 1993
#
# if you use or make improvements to this program i would appreciate
# copies of your modifications & your PGP public key.

$|=1;
$topgp=0;
$logname = $ENV{'LOGNAME'};
$pager='/usr/local/bin/less -i -n -s -S -c -M';
$pager = $ENV{'PAGER'} if ($ENV{'PAGER'});
umask 077;
open (PAGER, "|$pager") || die "Cannot open pipe to $pager.\n";
print PAGER "\n";
while (<>) {
	if (!$topgp && m/^-----BEGIN PGP .*-----/) {
		$topgp = 1;
		$tmpfile = "/tmp/.pgp.$logname.$$";
		unlink($tmpfile);
		open (TMPFILE, ">$tmpfile") || die "Cannot open $tmpfile for output.\n";
	}
	if (!$topgp) {
		print PAGER;
	} else {
		print TMPFILE $_;
		if (m/^-----END PGP .*-----/) {
			$topgp = 0;
			close TMPFILE;
			open (CLEAR, "pgp -f < $tmpfile |") || die "Cannot open pipe to PGP.\n";
			print PAGER "-----BEGIN PGP DECRYPTED BLOCK-----\n";
			while (<CLEAR>) {
				print PAGER;
			}
			close CLEAR;
			unlink($tmpfile);
			print PAGER "-----END PGP DECRYPTED BLOCK-----\n";
		}
	}
}
close PAGER;

===== postpgp =====

#!/usr/bin/perl

# written by jason steiner, [email protected], Jan 1993
#
# if you use or make improvements to this program i would appreciate
# copies of your modifications & your PGP public key.

($visual = $ENV{'VISUAL'}) || ($visual = '/usr/ucb/vi');
system($visual,@ARGV);
while (!$q) {
        print "Sign this message? [Y]: ";
        $q = <STDIN>;
	$q =~ s/[ \t\n]//g;
	$q = substr ($q, 0, 1);
        if (($q eq 'Y') || ($q eq 'y') || ($q eq '')) {
                push(@opts,'-st','+clearsig=on');
                $q = "y";
        } elsif (($q ne 'N') && ($q ne 'n')) {
                $q = '';
        }
}
if (@opts) {
        $name = $ARGV[$#ARGV];
	umask(077);
        open(INPUT,$name);
        open(HEAD,">${name}.head");
        open(BODY,">${name}.body");
        while (<INPUT>) {
                if (1 .. /^$/) {
                        print HEAD;
			if (m/^From: / || m/^To: / || m/^Date: /) {
				print BODY;
			}
                } else {
                        print BODY;
                }
        }
        close(HEAD);
        close(BODY);
        system('pgp','-a',@opts,"${name}.body");
	if ($? == 0) {
        	unlink($name);
        	system "cat ${name}.head ${name}.body.asc > $name";
	}
        unlink("${name}.head");
        unlink("${name}.body");
        unlink("${name}.body.asc");
}


-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQCVAwUBLt5gen3YhjZY3fMNAQF1QwP+OETB9ibDTWxLJ3BWQsgG5tAIeSHgeWs7
cOasOVidSoHJ10LPbOjwfCP9mluUTpsWNzIXC3GRSh5QO0esOPubu5CsFUaouEo8
DwvAik5kxIUcztqry8ImktFY14UmLZDjHshN+2WU7yLNG0BBM4C2mfwqkKDN9ESX
ZK2bJj2LVF0=
=2toZ
-----END PGP SIGNATURE-----