Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

JSON::RPC::Server with SSL

by mwb613 (Novice)
on Mar 11, 2014 at 05:59 UTC ( #1077792=perlquestion: print w/ replies, xml ) Need Help??
mwb613 has asked for the wisdom of the Perl Monks concerning the following question:

Monks, I supplicate myself before the collective wisdom of the monastery. I have recently been playing around with the JSON::RPC::Server::Daemon module. I have had some luck implementing it w/o SSL but I would like to utilize SSL going forward. I am currently testing on a self-signed certificate via this guide. I set up httpd to use the certificate and it's working as designed (albeit with the unsigned cert warning...). Here is my constructor for the the JSON Daemon:
my $ssl_key_path = '/etc/pki/tls/private/ca.key'; my $ssl_cert_path = '/etc/pki/tls/cert.pem'; my $port = $ARGV[0]; $port = 88888 unless $port; my $server = JSON::RPC::Server::Daemon->new( LocalAddr => '127.0.0.1', LocalPort => $port, SSL_key_file => $ssl_key_path, SSL_cert_file => $ssl_cert_path, SSL_verify_mode => 0 ) || die "failed to listen: $!"; $server->dispatch({'/test' => 'myApp'}); $server->handle();
This code runs w/o error, however, as soon as I try to connect via a simple client the daemon quits (again w/o error -- though I'm unsure where to trap an error w/o overloading the module). Here is the client script:
#!/usr/bin/perl use JSON::RPC::Client; my $client = new JSON::RPC::Client; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; my $port = $ARGV[0]; $port = 88888 unless $port; my $uri = 'https://127.0.0.1:'.$port.'/test'; my $obj = { method => 'get_ticket_info', # or 'MyApp.sum' params => [105195,555435], }; my $res = $client->call( $uri, $obj );
Prior to trying to implement SSL I was having no problems sending requests and responding to them. I based my SSL cert lines in the Daemon constructor on the IO::Socket:SSL documentation. Has anyone been able to get SSL to work with the JSON::RPC::Server::Daemon module? I've noticed there is not much documentation or example code on the web which leads me to think people might be using other alternatives for this type of job. Thanks for your time!

Comment on JSON::RPC::Server with SSL
Select or Download Code
Re: JSON::RPC::Server with SSL
by zentara (Archbishop) on Mar 11, 2014 at 15:39 UTC
    Hi, I was looking thru some code on stackoverflow, and there are ways to try and catch the error message in your client. For example:
    my $res = $client->call( $uri, $obj ); if($res){ if ($res->is_error) { print "Error : ", $res->error_message; } else { print $res->result; } } else { print $client->status_line; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Thanks Zentara! I incorporated that handling code into my client. I am now getting the following error message in my client (with the daemon still failing w/o error):
      No res 500 Can't connect to 127.0.0.1:88888
      I've been trying to extract some info from the server methods shown here but can't seem to get to the HTTPS::Daemon or IO::Socket::SSL error that is occurring.
        88888 is greater than 65535 and is therefore not a valid port number.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1077792]
Approved by Corion
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-08-28 14:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (263 votes), past polls