Subject: | When passing in Authen::SASL, mechanism should not be overwritten |
distribution Net::SMTPS-0.04
perl v5.16.3
operating system CentOS Linux release 7.3.1611 (Core)
I try to connect to an Amazon SMTP server running STARTTLS with login username and password.
I create my own Authen::SASL object which has the mechanism 'PLAIN' and pass it in when calling Net::SMTPS auth() method.
It overwrites the mechanism setting inside the sasl object with the string returned by doing an AUTH query.
E.g. "PLAIN LOGIN\cM".
Then when calling
my $client = $sasl->client_new('smtp', ${*$self}{'net_smtp_host'}, 0);
It does not understand the above AUTH string, and so
$client->mechanism returns empty string.
my @cmd = ("AUTH", $client->mechanism);
Means the command sent is "AUTH " instead of "AUTH PLAIN".
This causes an error and login fails.
The following diff makes it work by not overwriting sasl mechanism if already set.
sub auth()
162c162
< $sasl->mechanism($mechanisms) unless $sasl->mechanism;
---
Show quoted text
> $sasl->mechanism($mechanisms);
From test code:
use strict;
use warnings;
use Net::SMTPS;
use Authen::SASL;
my $server = 'email-smtp.eu-west-1.amazonaws.com';
my $server_port = 587;
my $mail_sasl_type = 'starttls';
my $mail_sasl_username = 'test';
my $mail_sasl_password = 'test';
my $smtp = Net::SMTPS->new( $server, Port => $server_port, Debug => 1, doSSL => $mail_sasl_type, SSL_verify_mode => 'SSL_VERIFY_NONE' )
|| die "cannot connect to server ${server}";
my $sasl = Authen::SASL->new(
'mechanism' => 'PLAIN', # PLAIN LOGIN Digest-MD5
'callback' => { 'user' => $mail_sasl_username, 'pass' => $mail_sasl_password, 'authname' => $mail_sasl_username },
);
$smtp->auth( $sasl )
|| die "cannot do mail auth";
Actual output:
Net::SMTPS>>> Net::SMTPS(0.04)
Net::SMTPS>>> IO::Socket::INET(1.33)
Net::SMTPS>>> IO::Socket(1.34)
Net::SMTPS>>> IO::Handle(1.33)
Net::SMTPS>>> Exporter(5.68)
Net::SMTPS>>> Net::SMTP(2.31)
Net::SMTPS>>> Net::Cmd(2.29)
Net::SMTPS=GLOB(0x1a92098)<<< 220 email-smtp.amazonaws.com ESMTP SimpleEmailService-1868680137 lG7mtzBOyrl9LL0nmaKw
Net::SMTPS=GLOB(0x1a92098)>>> EHLO localhost.localdomain
Net::SMTPS=GLOB(0x1a92098)<<< 250-email-smtp.amazonaws.com
Net::SMTPS=GLOB(0x1a92098)<<< 250-8BITMIME
Net::SMTPS=GLOB(0x1a92098)<<< 250-SIZE 10485760
Net::SMTPS=GLOB(0x1a92098)<<< 250-STARTTLS
Net::SMTPS=GLOB(0x1a92098)<<< 250-AUTH PLAIN LOGIN
Net::SMTPS=GLOB(0x1a92098)<<< 250 Ok
Net::SMTPS=GLOB(0x1a92098)>>> STARTTLS
Net::SMTPS=GLOB(0x1a92098)<<< 220 Ready to start TLS
Net::SMTPS=GLOB(0x1a92098)>>> EHLO localhost.localdomain
Net::SMTPS=GLOB(0x1a92098)<<< 250-email-smtp.amazonaws.com
Net::SMTPS=GLOB(0x1a92098)<<< 250-8BITMIME
Net::SMTPS=GLOB(0x1a92098)<<< 250-SIZE 10485760
Net::SMTPS=GLOB(0x1a92098)<<< 250-STARTTLS
Net::SMTPS=GLOB(0x1a92098)<<< 250-AUTH PLAIN LOGIN
Net::SMTPS=GLOB(0x1a92098)<<< 250 Ok
Net::SMTPS=GLOB(0x1a92098)>>> AUTH
Net::SMTPS=GLOB(0x1a92098)<<< 501 Syntax: AUTH mechanism [initial-response]
Expected output:
...
Beacon_Net_SMTPS=GLOB(0x1e78cf0)<<< 250-AUTH PLAIN LOGIN
Beacon_Net_SMTPS=GLOB(0x1e78cf0)<<< 250 Ok
Beacon_Net_SMTPS=GLOB(0x1e78cf0)>>> AUTH PLAIN QUtJ...
Beacon_Net_SMTPS=GLOB(0x1e78cf0)<<< 235 Authentication successful.