69
--smtp-pass <str> * Password for SMTP-AUTH; not necessary.
70
--smtp-encryption <str> * tls or ssl; anything else disables.
71
--smtp-ssl * Deprecated. Use '--smtp-encryption ssl'.
72
+ --smtp-ssl-cert-path <str> * Path to ca-certificates (either directory or file).
73
+ Pass an empty string to disable certificate
74
+ verification.
75
--smtp-domain <str> * The domain name sent to HELO/EHLO handshake
76
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
77
197
my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc);
198
my ($to_cmd, $cc_cmd);
199
my ($smtp_server, $smtp_server_port, @smtp_server_options);
197
-my ($smtp_authuser, $smtp_encryption);
200
+my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);
201
my ($identity, $aliasfiletype, @alias_files, $smtp_domain);
202
my ($validate, $confirm);
203
my (@suppress_cc);
225
"smtpserveroption" => \@smtp_server_options,
226
"smtpuser" => \$smtp_authuser,
227
"smtppass" => \$smtp_authpass,
228
+ "smtpsslcertpath" => \$smtp_ssl_cert_path,
229
"smtpdomain" => \$smtp_domain,
230
"to" => \@initial_to,
231
"tocmd" => \$to_cmd,
306
"smtp-pass:s" => \$smtp_authpass,
307
"smtp-ssl" => sub { $smtp_encryption = 'ssl' },
308
"smtp-encryption=s" => \$smtp_encryption,
309
+ "smtp-ssl-cert-path" => \$smtp_ssl_cert_path,
310
"smtp-debug:i" => \$debug_net_smtp,
311
"smtp-domain:s" => \$smtp_domain,
312
"identity=s" => \$identity,
1094
return $auth;
1095
}
1096
1097
+sub ssl_verify_params {
1098
+ eval {
1099
+ require IO::Socket::SSL;
1100
+ IO::Socket::SSL->import(qw/SSL_VERIFY_PEER SSL_VERIFY_NONE/);
1101
+ };
1102
+ if ($@) {
1103
+ print STDERR "Not using SSL_VERIFY_PEER due to out-of-date IO::Socket::SSL.\n";
1104
+ return;
1105
+ }
1106
+
1107
+ if (!defined $smtp_ssl_cert_path) {
1108
+ $smtp_ssl_cert_path = "/etc/ssl/certs";
1109
+ }
1110
+
1111
+ if ($smtp_ssl_cert_path eq "") {
1112
+ return (SSL_verify_mode => SSL_VERIFY_NONE());
1113
+ } elsif (-d $smtp_ssl_cert_path) {
1114
+ return (SSL_verify_mode => SSL_VERIFY_PEER(),
1115
+ SSL_ca_path => $smtp_ssl_cert_path);
1116
+ } elsif (-f $smtp_ssl_cert_path) {
1117
+ return (SSL_verify_mode => SSL_VERIFY_PEER(),
1118
+ SSL_ca_file => $smtp_ssl_cert_path);
1119
+ } else {
1120
+ print STDERR "Not using SSL_VERIFY_PEER because the CA path does not exist.\n";
1121
+ return (SSL_verify_mode => SSL_VERIFY_NONE());
1122
+ }
1123
+}
1124
+
1125
# Returns 1 if the message was sent, and 0 otherwise.
1126
# In actuality, the whole program dies when there
1127
# is an error sending a message.
1227
$smtp_domain ||= maildomain();
1228
$smtp ||= Net::SMTP::SSL->new($smtp_server,
1229
Hello => $smtp_domain,
1197
- Port => $smtp_server_port);
1230
+ Port => $smtp_server_port,
1231
+ ssl_verify_params());
1232
}
1233
else {
1234
require Net::SMTP;
1241
$smtp->command('STARTTLS');
1242
$smtp->response();
1243
if ($smtp->code == 220) {
1210
- $smtp = Net::SMTP::SSL->start_SSL($smtp)
1244
+ $smtp = Net::SMTP::SSL->start_SSL($smtp,
1245
+ ssl_verify_params())
1246
or die "STARTTLS failed! ".$smtp->message;
1247
$smtp_encryption = '';
1248
# Send EHLO again to receive fresh