I was writing an instant messaging client for fun, which would encrypt messages with gpg before sending them across the network using netcat (there are likely better ways of doing this than netcat, but it's the one I'm used to). However, when I try to encrypt my message, I get the response:
wrong response from gnupg (expected SHM_INFO): at ./pchat line (I marked the line below)
It's my understanding that the GPG module expects filenames as arguments for the messages to encrypt, and where to save the result, and it returns SHM_INFO upon file-not-found errors. I thought I could use local variables as if they were files by passing them in like \$varname, but this appears not to be working correctly.
Any help would be greatly appreciated. Thanks!
#!/usr/bin/env perl use warnings; use strict; use Term::ReadKey; # For the noecho use GnuPG qw( :algo ); # From the GnuPG CPAN page if( $ARGV != 2 ) { die "Usage: pchat <host> <port>"; } client( $ARGV[0], $ARGV[1] ); sub client { my $target = shift; my $port = shift; print "Who do I encrypt to: "; my $keyname = <STDIN>; chomp( $keyname ); ReadMode('noecho'); print "PGP Key passphrase (not echoed): "; my $passphrase = <STDIN>; chomp $passphrase; print "\n"; # The user's return key won't be echoed ReadMode(0); # Reset term status open (my $net, "|-", "nc $target $port") or die "Can't open ne +tcat!"; while( 0 == 0 ) { my $message = encrypt( $keyname, $passphrase ); last if $message eq "exit"; print $message . "\n"; # Here's where I'm _going_ to send the message via net +cat. # I haven't done it yet, I want to just get the encryp +tion working first. } close $net; print "Connection Terminated.\n"; } sub encrypt { my $gpg = new GnuPG() or die "Cannot open gpg!"; my $keyname = shift; my $passphrase = shift; print "Message: "; my $message = <STDIN>; chomp( $message ); return "exit" if( length($message) == 0 ); # Quit if blank mes +sage $message . "\n" . chr(04); # Tack on a return and EOF, so this + looks like a file to GPG my $encrypted_message = ""; $gpg->encrypt( recipient => $keyname, plaintext => \$message, +output => \$encrypted_message, sign => 1, passphrase => $passphrase, +armor => 1 ) or die "Error encrypting: $!"; # The above is the line I'm getting errors on. return $encrypted_message; }
In reply to Perl GPG Chat by riven
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |