|
|
734417 |
From d3ad0a08dbd9e32a498a5f3335d521d6c38f4f1f Mon Sep 17 00:00:00 2001
|
|
|
734417 |
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
|
|
|
734417 |
Date: Wed, 21 Mar 2018 13:21:42 +0100
|
|
|
734417 |
Subject: [PATCH 1/4] SSL support for Net::SMTP
|
|
|
734417 |
MIME-Version: 1.0
|
|
|
734417 |
Content-Type: text/plain; charset=UTF-8
|
|
|
734417 |
Content-Transfer-Encoding: 8bit
|
|
|
734417 |
|
|
|
734417 |
Ported to Net::SMTP 2.31 as found in Perl 5.16.3 from libnet upstream:
|
|
|
734417 |
|
|
|
734417 |
commit 34436780081aa8793b16f51864bce42a7cdd7e8b
|
|
|
734417 |
Author: Steffen Ullrich <Steffen_Ullrich@genua.de>
|
|
|
734417 |
Date: Fri May 16 21:55:20 2014 +0200
|
|
|
734417 |
|
|
|
734417 |
added tests for Net::SMTP SSL and IPv6, save arguments in Net::SMTP to apply them on starttls
|
|
|
734417 |
|
|
|
734417 |
IPv6 support exluded.
|
|
|
734417 |
|
|
|
734417 |
Check for IO::Socket::SSL version removed because we have default sane
|
|
|
734417 |
default CA list since perl-IO-Socket-SSL-1.94-7.el7. We also set
|
|
|
734417 |
SSL_verify_mode => SSL_VERIFY_PEER by default.
|
|
|
734417 |
|
|
|
734417 |
Signed-off-by: Petr Písař <ppisar@redhat.com>
|
|
|
734417 |
---
|
|
|
734417 |
cpan/libnet/Net/Cmd.pm | 1 -
|
|
|
734417 |
cpan/libnet/Net/SMTP.pm | 72 +++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
734417 |
2 files changed, 72 insertions(+), 1 deletion(-)
|
|
|
734417 |
|
|
|
734417 |
diff --git a/cpan/libnet/Net/Cmd.pm b/cpan/libnet/Net/Cmd.pm
|
|
|
734417 |
index 4f0e444..29eeb14 100644
|
|
|
734417 |
--- a/cpan/libnet/Net/Cmd.pm
|
|
|
734417 |
+++ b/cpan/libnet/Net/Cmd.pm
|
|
|
734417 |
@@ -53,7 +53,6 @@ my %debug = ();
|
|
|
734417 |
|
|
|
734417 |
my $tr = $^O eq 'os390' ? Convert::EBCDIC->new() : undef;
|
|
|
734417 |
|
|
|
734417 |
-
|
|
|
734417 |
sub toebcdic {
|
|
|
734417 |
my $cmd = shift;
|
|
|
734417 |
|
|
|
734417 |
diff --git a/cpan/libnet/Net/SMTP.pm b/cpan/libnet/Net/SMTP.pm
|
|
|
734417 |
index a28496d..6143990 100644
|
|
|
734417 |
--- a/cpan/libnet/Net/SMTP.pm
|
|
|
734417 |
+++ b/cpan/libnet/Net/SMTP.pm
|
|
|
734417 |
@@ -18,6 +18,15 @@ use Net::Config;
|
|
|
734417 |
|
|
|
734417 |
$VERSION = "2.31";
|
|
|
734417 |
|
|
|
734417 |
+# Code for detecting if we can use SSL
|
|
|
734417 |
+my $ssl_class = eval {
|
|
|
734417 |
+ require IO::Socket::SSL;
|
|
|
734417 |
+} && 'IO::Socket::SSL';
|
|
|
734417 |
+my $nossl_warn = !$ssl_class &&
|
|
|
734417 |
+ 'To use SSL please install IO::Socket::SSL';
|
|
|
734417 |
+
|
|
|
734417 |
+sub can_ssl { $ssl_class };
|
|
|
734417 |
+
|
|
|
734417 |
@ISA = qw(Net::Cmd IO::Socket::INET);
|
|
|
734417 |
|
|
|
734417 |
|
|
|
734417 |
@@ -33,6 +42,13 @@ sub new {
|
|
|
734417 |
%arg = @_;
|
|
|
734417 |
$host = delete $arg{Host};
|
|
|
734417 |
}
|
|
|
734417 |
+
|
|
|
734417 |
+ if ($arg{SSL}) {
|
|
|
734417 |
+ # SSL from start
|
|
|
734417 |
+ die $nossl_warn if !$ssl_class;
|
|
|
734417 |
+ $arg{Port} ||= 465;
|
|
|
734417 |
+ }
|
|
|
734417 |
+
|
|
|
734417 |
my $hosts = defined $host ? $host : $NetConfig{smtp_hosts};
|
|
|
734417 |
my $obj;
|
|
|
734417 |
|
|
|
734417 |
@@ -54,6 +70,11 @@ sub new {
|
|
|
734417 |
return undef
|
|
|
734417 |
unless defined $obj;
|
|
|
734417 |
|
|
|
734417 |
+ if ($arg{SSL}) {
|
|
|
734417 |
+ Net::SMTP::_SSLified->start_SSL($obj,SSL_verifycn_name => $host,%arg)
|
|
|
734417 |
+ or return;
|
|
|
734417 |
+ }
|
|
|
734417 |
+
|
|
|
734417 |
$obj->autoflush(1);
|
|
|
734417 |
|
|
|
734417 |
$obj->debug(exists $arg{Debug} ? $arg{Debug} : undef);
|
|
|
734417 |
@@ -185,11 +206,22 @@ sub hello {
|
|
|
734417 |
}
|
|
|
734417 |
|
|
|
734417 |
return undef unless $ok;
|
|
|
734417 |
+ ${*$me}{net_smtp_hello_domain} = $domain;
|
|
|
734417 |
|
|
|
734417 |
$msg[0] =~ /\A\s*(\S+)/;
|
|
|
734417 |
return ($1 || " ");
|
|
|
734417 |
}
|
|
|
734417 |
|
|
|
734417 |
+sub starttls {
|
|
|
734417 |
+ my $self = shift;
|
|
|
734417 |
+ $ssl_class or die $nossl_warn;
|
|
|
734417 |
+ $self->_STARTTLS or return;
|
|
|
734417 |
+ Net::SMTP::_SSLified->start_SSL($self,@_) or return;
|
|
|
734417 |
+
|
|
|
734417 |
+ # another hello after starttls to read new ESMTP capabilities
|
|
|
734417 |
+ return $self->hello(${*$self}{net_smtp_hello_domain});
|
|
|
734417 |
+}
|
|
|
734417 |
+
|
|
|
734417 |
|
|
|
734417 |
sub supports {
|
|
|
734417 |
my $self = shift;
|
|
|
734417 |
@@ -527,6 +559,27 @@ sub _BDAT { shift->command("BDAT", @_) }
|
|
|
734417 |
sub _TURN { shift->unsupported(@_); }
|
|
|
734417 |
sub _ETRN { shift->command("ETRN", @_)->response() == CMD_OK }
|
|
|
734417 |
sub _AUTH { shift->command("AUTH", @_)->response() == CMD_OK }
|
|
|
734417 |
+sub _STARTTLS { shift->command("STARTTLS", @_)->response() == CMD_OK }
|
|
|
734417 |
+
|
|
|
734417 |
+
|
|
|
734417 |
+{
|
|
|
734417 |
+ package Net::SMTP::_SSLified;
|
|
|
734417 |
+ our @ISA = ( $ssl_class ? ($ssl_class):(), 'Net::SMTP' );
|
|
|
734417 |
+ sub starttls { die "SMTP connection is already in SSL mode" }
|
|
|
734417 |
+ sub start_SSL {
|
|
|
734417 |
+ my ($class,$smtp,%arg) = @_;
|
|
|
734417 |
+ delete @arg{ grep { !m{^SSL_} } keys %arg };
|
|
|
734417 |
+ ( $arg{SSL_verifycn_name} ||= $smtp->host )
|
|
|
734417 |
+ =~s{(?
|
|
|
734417 |
+ $arg{SSL_verifycn_scheme} ||= 'smtp';
|
|
|
734417 |
+ $arg{SSL_verify_mode} ||= IO::Socket::SSL::SSL_VERIFY_PEER();
|
|
|
734417 |
+ my $ok = $class->SUPER::start_SSL($smtp,%arg);
|
|
|
734417 |
+ $@ = $ssl_class->errstr if !$ok;
|
|
|
734417 |
+ return $ok;
|
|
|
734417 |
+ }
|
|
|
734417 |
+}
|
|
|
734417 |
+
|
|
|
734417 |
+
|
|
|
734417 |
|
|
|
734417 |
1;
|
|
|
734417 |
|
|
|
734417 |
@@ -613,6 +666,11 @@ the C<PeerAddr> option in L<IO::Socket::INET>, or a reference to
|
|
|
734417 |
an array with hosts to try in turn. The L</host> method will return the value
|
|
|
734417 |
which was used to connect to the host.
|
|
|
734417 |
|
|
|
734417 |
+B<SSL> - If the connection should be done from start with SSL, contrary to later
|
|
|
734417 |
+upgrade with C<starttls>.
|
|
|
734417 |
+You can use SSL arguments as documented in L<IO::Socket::SSL>, but it will
|
|
|
734417 |
+usually use the right arguments already.
|
|
|
734417 |
+
|
|
|
734417 |
B<LocalAddr> and B<LocalPort> - These parameters are passed directly
|
|
|
734417 |
to IO::Socket to allow binding the socket to a local port.
|
|
|
734417 |
|
|
|
734417 |
@@ -643,6 +701,14 @@ Example:
|
|
|
734417 |
Debug => 1,
|
|
|
734417 |
);
|
|
|
734417 |
|
|
|
734417 |
+ # the same with direct SSL
|
|
|
734417 |
+ $smtp = Net::SMTP->new('mailhost',
|
|
|
734417 |
+ Hello => 'my.mail.domain',
|
|
|
734417 |
+ Timeout => 30,
|
|
|
734417 |
+ Debug => 1,
|
|
|
734417 |
+ SSL => 1,
|
|
|
734417 |
+ );
|
|
|
734417 |
+
|
|
|
734417 |
# Connect to the default server from Net::config
|
|
|
734417 |
$smtp = Net::SMTP->new(
|
|
|
734417 |
Hello => 'my.mail.domain',
|
|
|
734417 |
@@ -686,6 +752,12 @@ to connect to the host.
|
|
|
734417 |
|
|
|
734417 |
Request a queue run for the DOMAIN given.
|
|
|
734417 |
|
|
|
734417 |
+=item starttls ( SSLARGS )
|
|
|
734417 |
+
|
|
|
734417 |
+Upgrade existing plain connection to SSL.
|
|
|
734417 |
+You can use SSL arguments as documented in L<IO::Socket::SSL>, but it will
|
|
|
734417 |
+usually use the right arguments already.
|
|
|
734417 |
+
|
|
|
734417 |
=item auth ( USERNAME, PASSWORD )
|
|
|
734417 |
|
|
|
734417 |
Attempt SASL authentication.
|
|
|
734417 |
--
|
|
|
734417 |
2.14.3
|
|
|
734417 |
|