]> snippets.scripts.mit.edu Git - Scripts/git/.git/blame - barnowl/zcrypt.pl
barnowl/zcrypt.pl: Fix a syntax error.
[Scripts/git/.git] / barnowl / zcrypt.pl
CommitLineData
cb96a5e1
GT
1# BarnOwls older than late September 2008 will segfault on short zcrypt messages.
2# Besides, the code is sketchy and doesn't belong in core. This perl module
3# will add :zcrypt and :decrypt commands that use outland's zcrypt binary via
4# Perl, so a bug in zcrypt can't possibly affect BarnOwl proper. The :zcrypt
5# command replaces the built-in one.
6#
7# To use this code, type
e51766d3 8# :perl do '/mit/snippets/barnowl/zcrypt.pl'
cb96a5e1
GT
9#
10# This first line will disable BarnOwl's own zcrypt code, so messages are
11# encrypted onscreen. Use :decrypt to display them. (Security bugs were later
12# found in the decryption code, although these probably affect locker zcrypt
13# too.)
14
15BarnOwl::command("unset zcrypt");
16
17use IPC::Open2;
18BarnOwl::new_command(decrypt => sub {
19 my $msg = BarnOwl::getcurmsg();
20 my $cmd = shift;
21 my @args = @_;
22 if (scalar @args == 0) {
23 @args = ('-c', $msg->class, '-i', $msg->instance);
24 }
25 my ($zo, $zi);
26 my $pid = open2($zo, $zi, '/mit/outland/bin/zcrypt', '-D', @args) or die "Couldn't launch zcrypt\n";
27 my $decrypted;
d58b13ca 28 print $zi @{$msg->fields}[1] . "\n";
cb96a5e1
GT
29 close $zi;
30 while (<$zo>) {
31 chomp;
32 last if $_ eq "**END**";
33 $decrypted .= "$_\n";
34 }
35 BarnOwl::popless_ztext($decrypted);
36 waitpid $pid, 0;
37 },
38 {summary => "Decrypt a zcrypted message once",
39 usage => "decrypt [args]",
40 description => "Invokes /mit/outland/bin/zcrypt on the current message,\n
41using the class and instance to find the crypt key, and pops up the\n
42decrypted output. If args are specified, they are passed to zcrypt and the\n
43class and instance are ignored.\n\n
44SEE ALSO: zcrypt(1)"});
45
46BarnOwl::new_command(zcrypt => sub {
47 my $cmd = shift;
48 my @args = @_;
49 my $argstring = join ' ', @args;
50 BarnOwl::start_edit_win("/mit/outland/bin/zcrypt $argstring", sub {
51 my $msg = shift;
52 my ($zo, $zi);
53 my $pid = open2($zo, $zi, '/mit/outland/bin/zcrypt', @args);
54 print $zi "$msg\n";
55 close $zi;
56 local $/;
57 BarnOwl::message(<$zo>);
58 waitpid $pid, 0;
59 });
60 },
61 {summary => "Run /mit/outland/bin/zcrypt",
62 usage => "zcrypt -c [class] -i [instance]",
63 description => "Calls /mit/outland/bin/zcrypt on a message you type in.\n\n
64SEE ALSO: zcrypt(1)"});