Devel-Scooby
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
open TMP_FILE, ">$tmp_filename"
or die "Scooby: could not write to temporary encryption file: $!.\n";
my $line_count = 0;
# Write the agent's source code one line at a time to the temporary file.
while ( my $line2send = <RELOCATE_FILE> )
{
++$line_count;
print TMP_FILE $line2send;
# Check to see if we need to insert the "lexical init" code.
if ( $line_count == ($linenum_mem-1) )
{
print TMP_FILE $stringified if defined( $stringified );
}
}
close RELOCATE_FILE;
close TMP_FILE;
# The agent source code (which has mutated) is now in "$tmp_filename".
open TOENCRYPT_FILE, "$tmp_filename"
or die "Scooby: temporary encryption file could not be opened: $!.\n";
my @entire_toencrypt = <TOENCRYPT_FILE>;
close TOENCRYPT_FILE;
# We are now done with the temporary file, so we can remove it from
# the local storage.
unlink $tmp_filename;
my $message = "@entire_toencrypt\n";
my $public_key_filename = "$remote.$remote_port.public";
my $public_key = new Crypt::RSA::Key::Public(
Filename => $public_key_filename
);
my $rsa = new Crypt::RSA;
# Encrypt the mutated agent using the PK+ of the next Location.
my $cyphertext = $rsa->encrypt(
Message => $message,
Key => $public_key,
Armour => $TRUE
) or die $rsa->errstr, "\n";
# Use the PK- of this Mobile::Executive invocation to
# sign the encrypted mobile agent.
my $cypher_signature = $rsa->sign(
Message => $cyphertext,
Key => $Mobile::Executive::private_key,
Armour => $TRUE
) or die $rsa->errstr, "\n";
# Networking code to send agent to the server starts here.
my $trans_serv = getprotobyname( 'tcp' );
my $remote_host = gethostbyname( $remote ) or inet_aton( $remote );
my $destination = sockaddr_in( $remote_port, $remote_host );
socket( TCP_SOCK, PF_INET, SOCK_STREAM, $trans_serv )
or die "Scooby: socket creation failed: $!.\n";
connect( TCP_SOCK, $destination )
or die "Scooby: connect to remote system failed: $!.\n";
# Turn on auto-flushing.
my $previous = select TCP_SOCK;
$| = 1;
select $previous;
# Send the filename of the agent to the remote Location.
print TCP_SOCK $filename_mem . "\n";
# Send the line# for the next executable line to the Location.
print TCP_SOCK $linenum_mem . "\n";
# We need to work out the port that this client is using "locally".
# The Location will use this protocol port number to query the
# keyserver for the just-about-to-be-sent public key.
my ( $local_pport, $local_ip ) = sockaddr_in( getsockname( TCP_SOCK ) );
# Prior to sending the signature and cyphertext to the next
# Location, we need to update the keyserver with the appropriate
# PK+ so that the next Location can verify the signature. We
# write the PK+ to a disk-file, then read it back in, as this is
# the format that the keyserver expects to receive it in.
$Mobile::Executive::public_key->write(
Filename => "$0.$$.$local_pport.public"
);
open LOCAL_KEYFILE, "$0.$$.$local_pport.public"
or die "Scooby: the local public key file does not exist: $!.\n";
my @entire_local_file = <LOCAL_KEYFILE>;
close LOCAL_KEYFILE;
# We have no further need for the public key file, so remove it.
unlink "$0.$$.$local_pport.public";
# Send the "local" protocol port number and PK+ to the keyserver.
my $keysock_obj = IO::Socket::INET->new( PeerAddr => $key_server,
PeerPort => $REGISTER_PPORT,
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.356 second using v1.00-cache-2.02-grep-82fe00e-cpan-2cc899e4a130 )