From 5cfc89296e29af1456e828acd27b593fef6f3553 Mon Sep 17 00:00:00 2001 From: Dan Keder Date: Fri, 16 Oct 2009 15:01:36 +0200 Subject: [PATCH] Moved things about SSL certificate paths to Net/Server/Coro.pm --- perl/Net/IMAP/Server.pm | 21 +------------------ perl/Net/Server/Coro.pm | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 20 deletions(-) diff --git a/perl/Net/IMAP/Server.pm b/perl/Net/IMAP/Server.pm index 80450c8..85075dd 100644 --- a/perl/Net/IMAP/Server.pm +++ b/perl/Net/IMAP/Server.pm @@ -38,7 +38,7 @@ Note that, following RFC suggestions, login is not allowed except under a either SSL or TLS. Thus, you are required to have a F directory under the current working directory, containing files F and C. Failure to do so will cause -the server to fail to start. Note that if the default paths suit your +the server to fail to start. Note that if the default paths don't suit your needs, you can specify different ones. =head1 INTERFACE @@ -62,7 +62,6 @@ __PACKAGE__->mk_accessors( user group poll_every unauth_idle auth_idle unauth_commands - server_cert server_key / ); @@ -134,16 +133,6 @@ How long, in seconds, to wait before disconnecting authenticated connections. By RFC specification, this B be longer than 30 minutes. The default is an hour; set to zero to disable. -=item server_cert - -Path to the SSL certificate that the server should use. This can be -either relative or absolute path. - -=item server_key - -Path to the SSL certificate key that the server should use. This can be -either relative or absolute path. - =back =cut @@ -162,19 +151,11 @@ sub new { unauth_idle => 5*60, auth_idle => 60*60, unauth_commands => 10, - server_cert => "certs/server-cert.pem", - server_key => "certs/server-key.pem", @_, command_class => {}, connection => {}, } ); - unless ( -r $self->server_key and -r $self->server_cert ) { - my $server_cert = $self->server_cert; - my $server_key = $self->server_key; - die - "Can't read certificates ($server_cert and $server_key)\n"; - } UNIVERSAL::require( $self->auth_class ) or die "Can't require auth class: $@\n"; diff --git a/perl/Net/Server/Coro.pm b/perl/Net/Server/Coro.pm index 204849c..2203376 100644 --- a/perl/Net/Server/Coro.pm +++ b/perl/Net/Server/Coro.pm @@ -42,6 +42,40 @@ usage details. =cut +=head2 new + +Create new Net::Server::Coro object. It accepts these parameters (in +addition to Net::Server parameters): + +=item server_cert + +Path to the SSL certificate that the server should use. This can be +either relative or absolute path. + +=item server_key + +Path to the SSL certificate key that the server should use. This can be +either relative or absolute path. + +=cut + +sub new { + my $class = shift; + my %args = @_; + my $self = $class->SUPER::new(@_); + + # Check certificates + my $server_cert = $args{'server_cert'} || "certs/server-cert.pem"; + my $server_key = $args{'server_key'} || "certs/server-key.pem"; + if (not (-r $server_key and -r $server_cert)) { + die "Can't read certificates ($server_cert and $server_key)\n"; + } + $self->server_cert($server_cert); + $self->server_key($server_key); + + return $self; +} + sub post_bind_hook { my $self = shift; my $prop = $self->{server}; @@ -150,6 +184,22 @@ sub loop { schedule; } +sub server_cert { + my ($self, $cert) = @_; + if (defined $cert) { + $self->{'server_cert'} = $cert; + } + return $self->{'server_cert'}; +} + +sub server_key { + my ($self, $key) = @_; + if (defined $key) { + $self->{'server_key'} = $key; + } + return $self->{'server_key'}; +} + =head1 DEPENDENCIES L, L, L -- 1.5.3.3