diff --git a/MANIFEST b/MANIFEST index d5890ba..1143743 100644 --- a/MANIFEST +++ b/MANIFEST @@ -28,6 +28,7 @@ lib/Lim/RPC/Protocol/XMLRPC.pm lib/Lim/RPC/Protocols.pm lib/Lim/RPC/Server.pm lib/Lim/RPC/TLS.pm +lib/Lim/RPC/TLS/Client.pm lib/Lim/RPC/Transport.pm lib/Lim/RPC/Transport/HTTP.pm lib/Lim/RPC/Transport/HTTPS.pm diff --git a/debian/liblim-common-perl.install b/debian/liblim-common-perl.install index a35ee43..89f5542 100644 --- a/debian/liblim-common-perl.install +++ b/debian/liblim-common-perl.install @@ -1,6 +1,7 @@ usr/share/man/man3/Lim::Component.3pm usr/share/man/man3/Lim::RPC::Value::Collection.3pm usr/share/man/man3/Lim::RPC::TLS.3pm +usr/share/man/man3/Lim::RPC::TLS::Client.3pm usr/share/man/man3/Lim::RPC::Call.3pm usr/share/man/man3/Lim::RPC::Value.3pm usr/share/man/man3/Lim::Plugins.3pm @@ -25,6 +26,7 @@ usr/share/perl5/Lim/RPC/Transport/Clients.pm usr/share/perl5/Lim/RPC/Protocol.pm usr/share/perl5/Lim/RPC/Protocols.pm usr/share/perl5/Lim/RPC/TLS.pm +usr/share/perl5/Lim/RPC/TLS/Client.pm usr/share/perl5/Lim/RPC/Value/Collection.pm usr/share/perl5/Lim/RPC/Call.pm usr/share/perl5/Lim/RPC/Value.pm diff --git a/epel/perl-Lim.spec b/epel/perl-Lim.spec index d94f625..c55b90c 100644 --- a/epel/perl-Lim.spec +++ b/epel/perl-Lim.spec @@ -251,6 +251,7 @@ rm -rf $RPM_BUILD_ROOT %{_mandir}/man3/Lim::Component.3* %{_mandir}/man3/Lim::RPC::Value::Collection.3* %{_mandir}/man3/Lim::RPC::TLS.3* +%{_mandir}/man3/Lim::RPC::TLS::Client.3* %{_mandir}/man3/Lim::RPC::Call.3* %{_mandir}/man3/Lim::RPC::Value.3* %{_mandir}/man3/Lim::Plugins.3* @@ -275,6 +276,7 @@ rm -rf $RPM_BUILD_ROOT %{perl_vendorlib}/Lim/RPC/Protocol.pm %{perl_vendorlib}/Lim/RPC/Protocols.pm %{perl_vendorlib}/Lim/RPC/TLS.pm +%{perl_vendorlib}/Lim/RPC/TLS/Client.pm %{perl_vendorlib}/Lim/RPC/Value/Collection.pm %{perl_vendorlib}/Lim/RPC/Call.pm %{perl_vendorlib}/Lim/RPC/Value.pm diff --git a/lib/Lim/RPC/TLS/Client.pm b/lib/Lim/RPC/TLS/Client.pm new file mode 100644 index 0000000..617632f --- /dev/null +++ b/lib/Lim/RPC/TLS/Client.pm @@ -0,0 +1,124 @@ +package Lim::RPC::TLS::Client; + +use common::sense; +use Carp; + +use Log::Log4perl (); +use Scalar::Util qw(weaken); + +use AnyEvent::TLS (); +use Net::SSLeay (); + +use Lim (); + +=encoding utf8 + +=head1 NAME + +... + +=head1 VERSION + +See L for version. + +=cut + +our $VERSION = $Lim::VERSION; +our $INSTANCE; + +=head1 SYNOPSIS + +... + +=head1 SUBROUTINES/METHODS + +=head2 new + +=cut + +sub new { + my $this = shift; + my $class = ref($this) || $this; + my $self = { + logger => Log::Log4perl->get_logger($class), + }; + bless $self, $class; + weaken($self->{logger}); + + eval { + $self->{tls_ctx} = AnyEvent::TLS->new(%{Lim::Config->{rpc}->{tls}}); + }; + if ($@) { + Lim::OBJ_DEBUG and $self->{logger}->debug('Unable to initialize TLS context, will not use TLS/SSL: ', $@); + $self->{tls_ctx} = undef; + } + + Lim::OBJ_DEBUG and $self->{logger}->debug('new ', __PACKAGE__, ' ', $self); + $self; +} + +sub DESTROY { + my ($self) = @_; + Lim::OBJ_DEBUG and $self->{logger}->debug('destroy ', __PACKAGE__, ' ', $self); +} + +END { + undef($INSTANCE); +} + +=head2 instance + +=cut + +sub instance { + $INSTANCE ||= Lim::RPC::TLS::Client->new; +} + +=head2 tls_ctx + +=cut + +sub tls_ctx { + $_[0]->{tls_ctx}; +} + +=head1 AUTHOR + +Jerry Lundström, C<< >> + +=head1 BUGS + +Please report any bugs or feature requests to L. + +=head1 SUPPORT + +You can find documentation for this module with the perldoc command. + +perldoc Lim + +You can also look for information at: + +=over 4 + +=item * Lim issue tracker (report bugs here) + +L + +=back + +=head1 ACKNOWLEDGEMENTS + +=head1 LICENSE AND COPYRIGHT + +Copyright 2012-2013 Jerry Lundström. + +This program is free software; you can redistribute it and/or modify it +under the terms of either: the GNU General Public License as published +by the Free Software Foundation; or the Artistic License. + +See http://dev.perl.org/licenses/ for more information. + + +=cut + +1; # End of Lim::RPC::TLS::Client diff --git a/lib/Lim/RPC/Transport/Client/HTTP.pm b/lib/Lim/RPC/Transport/Client/HTTP.pm index 65c466b..bf5224f 100644 --- a/lib/Lim/RPC/Transport/Client/HTTP.pm +++ b/lib/Lim/RPC/Transport/Client/HTTP.pm @@ -16,7 +16,7 @@ use HTTP::Status qw(:constants); use Lim (); use Lim::Error (); -use Lim::RPC::TLS (); +use Lim::RPC::TLS::Client (); use Lim::Util (); use base qw(Lim::RPC::Transport::Client); @@ -56,7 +56,7 @@ sub MAX_RESPONSE_LEN (){ 8 * 1024 * 1024 } sub Init { my ($self) = @_; - if ($self->isa('Lim::RPC::Transport::Client::HTTPS') and !defined Lim::RPC::TLS->instance->tls_ctx) { + if ($self->isa('Lim::RPC::Transport::Client::HTTPS') and !defined Lim::RPC::TLS::Client->instance->tls_ctx) { confess 'using HTTPS but can not create TLS context'; } } @@ -97,6 +97,7 @@ sub request { } $self->{request} = $args{request}; $self->{request}->protocol('HTTP/1.1'); + $self->{request}->header( 'Host' => $self->{host} ); Lim::Util::resolve_host $self->{host}, $self->{port}, sub { my ($host, $port) = @_;