]> snippets.scripts.mit.edu Git - Scripts/git/.git/blame - barnowl/zcrypt.pl
barnowl/zcrypt.pl: Use zcrypt from the barnowl locker.
[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
3c2ef01d 3# will add :zcrypt and :decrypt commands that use barnowl's zcrypt binary via
cb96a5e1
GT
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);
3c2ef01d 26 my $pid = open2($zo, $zi, 'athrun', 'barnowl', 'zcrypt', '-D', @args) or die "Couldn't launch zcrypt\n";
cb96a5e1 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]",
3c2ef01d 40 description => "Invokes athrun barnowl zcrypt on the current message,\n
cb96a5e1
GT
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;
3c2ef01d 50 BarnOwl::start_edit_win("athrun barnowl zcrypt $argstring", sub {
cb96a5e1
GT
51 my $msg = shift;
52 my ($zo, $zi);
3c2ef01d 53 my $pid = open2($zo, $zi, 'athrun', 'barnowl', 'zcrypt', @args);
cb96a5e1
GT
54 print $zi "$msg\n";
55 close $zi;
56 local $/;
57 BarnOwl::message(<$zo>);
58 waitpid $pid, 0;
59 });
60 },
3c2ef01d 61 {summary => "Run athrun barnowl zcrypt",
cb96a5e1 62 usage => "zcrypt -c [class] -i [instance]",
3c2ef01d 63 description => "Calls athrun barnowl zcrypt on a message you type in.\n\n
cb96a5e1 64SEE ALSO: zcrypt(1)"});