Event-RPC
view release on metacpan or search on metacpan
lib/Event/RPC/Server.pm view on Meta::CPAN
server.crt
server.key
server.csr
Event::RPC needs the first two of them to operate with SSL encryption.
To enable SSL encryption you need to pass the following options
to the constructor:
=over 4
=item B<ssl>
The ssl option needs to be set to 1.
=item B<ssl_key_file>
This is the filename of the server.key you generated with
the openssl command.
=item B<ssl_cert_file>
This is the filename of the server.crt file you generated with
the openssl command.
=item B<ssl_passwd_cb>
Your server key is encrypted with a password you entered during the
key creation process described above. This callback must return
it. Depending on how critical your application is you probably must
request the password from the user during server startup or place it
into a more or less secured file. For testing purposes you
can specify a simple anonymous sub here, which just returns the
password, e.g.
ssl_passwd_cb => sub { return "topsecret" }
But note: having the password in plaintext in your program code is
insecure!
=item B<ssl_opts>
This optional parameter takes a hash reference of options
passed to IO::Socket::SSL->new(...) to have more control
over the server SSL listener.
=back
=head2 AUTHENTICATION OPTIONS
SSL encryption is fine, now it's really hard for an attacker to
listen or modify your network communication. But without any further
configuration any user on your network is able to connect to your
server. To prevent this users resp. connections to your server
needs to be authenticated somehow.
Since version 0.87 Event::RPC has an API to delegate authentication
tasks to a module, which can be implemented outside Event::RPC.
To be compatible with prior releases it ships the module
Event::RPC::AuthPasswdHash which implements the old behaviour
transparently.
This default implementation is a simple user/password based model. For now
this controls just the right to connect to your server, so knowing
one valid user/password pair is enough to access all exported methods
of your server. Probably a more differentiated model will be added later
which allows granting access to a subset of exported methods only
for each user who is allowed to connect.
The following options control the authentication:
=over 4
=item B<auth_required>
Set this to 1 to enable authentication and nobody can connect your server
until he passes a valid user/password pair.
=item B<auth_passwd_href>
If you like to use the builtin Event::RPC::AuthPasswdHash module
simply set this attribute. If you decide to use B<auth_module>
(explained beyound) it's not necessary.
B<auth_passwd_href> is a hash of valid user/password pairs. The password
stored here needs to be encrypted using Perl's crypt() function, using
the username as the salt.
Event::RPC has a convenience function for generating such a crypted
password, although it's currently just a 1:1 wrapper around Perl's
builtin crypt() function, but probably this changes someday, so better
use this method:
$crypted_pass = Event::RPC->crypt($user, $pass);
This is a simple example of setting up a proper B<auth_passwd_href> with
two users:
auth_passwd_href => {
fred => Event::RPC->crypt("fred", $freds_password),
nick => Event::RPC->crypt("nick", $nicks_password),
},
=item B<auth_module>
If you like to implement a more complex authentication method yourself
you may set the B<auth_module> attribute to an instance of your class.
For now your implementation just needs to have this method:
$auth_module->check_credentials($user, $pass)
Aware that $pass is encrypted as explained above, so your original
password needs to by crypted using Event::RPC->crypt as well, at
least for the comparison itself.
=back
B<Note:> you can use the authentication module without SSL but aware that
an attacker listening to the network connection will be able to grab
the encrypted password token and authenticate himself with it to the
server (replay attack). Probably a more sophisticated challenge/response
( run in 0.844 second using v1.01-cache-2.11-cpan-524268b4103 )