# zcrypt.pl # # To use place the following lines at the beginning of the format sub: # sub owl::format_msg() { # my $zcrypt = zcrypt_recieve(\$owl::msg, $owl::opcode, # $owl::class, $owl::instance); # return $zcrypt if $zcrypt; # Also add this line to the startup sub to load the zcrypt alias: # sub owl::startup { # zcrypt_init(); # load zcrypt functionality # After that you can use zcrypt like you use zwrite. # :zcrypt -c class -i instance # C-x z will start a zcrypt command, be aware that when replying you # still have to call zcrypt manually. # zcrypt.pl works by sending the (not yet encrypted) message to # yourself (with the same class, instance pair you specified) and then # on recieving it, sending out the encrypted version to the class. # This method exposes the key to a greater risk of being cracked since # for each message both encrypted and decrypted versions are # obtainable by sniffing the network. Any bugs, comments, or # suggestions email jdaniel@mit.edu use IPC::Open2; # get the decrypted version of a message sub zcrypt_decode ($$) { my ($emsg, $class) = @_; my $pid = open2(\*RDRFH, \*WTRFH, "zcrypt -D -c $class"); print WTRFH $emsg; close WTRFH; my $dmsg = ""; my $end = "**END**\n"; while () { last if $_ eq $end; $dmsg .= $_; } close RDRFH; return $dmsg; } # get the encrypted version of the message sub zcrypt_encode ($$) { my ($dmsg, $class) = @_; my $pid = open2(\*RDRFH, \*WTRFH, "zcrypt -E -c $class"); print WTRFH $dmsg; close WTRFH; my $emsg = ; return $emsg; } # encrypt and send a message sub zcrypt_send ($$$) { my ($dmsg, $class, $inst) = @_; my $emsg = zcrypt_encode $dmsg, $class; my $command = "zwrite -O crypt -c '$class' -i '$inst'"; owl::send_zwrite($command, $emsg); } # call from owl::format_msg() to encrypt or decrypt a incoming message # or to do nothing depending on the message. The first argument is a # pointer to the message so that it can be replaced with the decrypted # text when appropriate. returns 0 for normal messages and ones it # has decrypted, returns a message otherwise. sub zcrypt_recieve ($$$$) { my ($pmsg, $opcode, $class, $inst) = @_; if ($opcode eq "crypt") { # encrypted message to decode $$pmsg = zcrypt_decode $$pmsg, $class; return 0; } elsif ($opcode eq "encrypt") { # message to decrypt zcrypt_send $$pmsg, $class, $inst; return "Encrypted message sent"; } else { return 0; } } # call from owl::startup() to initialize the command alias for zcrypt # and subscribe to the personal instances of the classes that zcrypt # is to be used for. Uses any classes specified in the arguments in # addition to ones in the user's ~/.crypt_table file sub zcrypt_init (@) { my @classes = @_; owl::command('alias zcrypt zwrite $ENV{USER} -O encrypt'); owl::command('bindkey recv "C-x z" command start-command zcrypt '); open CRYPT_TABLE, "<$ENV{HOME}/.crypt-table"; while () { my ($class) = m/^crypt-(.*?):/; push @classes, $class; } close CRYPT_TABLE; for my $class (@classes) { owl::command("subscribe $class * %me%"); } return "zcrypt inited"; } 1;