@@ -69,6 +69,9 @@ sub usage {
6969 --smtp-pass <str> * Password for SMTP-AUTH; not necessary.
7070 --smtp-encryption <str> * tls or ssl; anything else disables.
7171 --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.
7275 --smtp-domain <str> * The domain name sent to HELO/EHLO handshake
7376 --smtp-debug <0|1> * Disable, enable Net::SMTP debug.
7477
@@ -194,7 +197,7 @@ sub do_edit {
194197my ($thread , $chain_reply_to , $suppress_from , $signed_off_by_cc );
195198my ($to_cmd , $cc_cmd );
196199my ($smtp_server , $smtp_server_port , @smtp_server_options );
197- my ($smtp_authuser , $smtp_encryption );
200+ my ($smtp_authuser , $smtp_encryption , $smtp_ssl_cert_path );
198201my ($identity , $aliasfiletype , @alias_files , $smtp_domain );
199202my ($validate , $confirm );
200203my (@suppress_cc );
@@ -220,6 +223,7 @@ sub do_edit {
220223 " smtpserveroption" => \@smtp_server_options ,
221224 " smtpuser" => \$smtp_authuser ,
222225 " smtppass" => \$smtp_authpass ,
226+ " smtpsslcertpath" => \$smtp_ssl_cert_path ,
223227 " smtpdomain" => \$smtp_domain ,
224228 " to" => \@initial_to ,
225229 " tocmd" => \$to_cmd ,
@@ -287,6 +291,7 @@ sub signal_handler {
287291 " smtp-pass:s" => \$smtp_authpass ,
288292 " smtp-ssl" => sub { $smtp_encryption = ' ssl' },
289293 " smtp-encryption=s" => \$smtp_encryption ,
294+ " smtp-ssl-cert-path" => \$smtp_ssl_cert_path ,
290295 " smtp-debug:i" => \$debug_net_smtp ,
291296 " smtp-domain:s" => \$smtp_domain ,
292297 " identity=s" => \$identity ,
@@ -1079,6 +1084,34 @@ sub smtp_auth_maybe {
10791084 return $auth ;
10801085}
10811086
1087+ sub ssl_verify_params {
1088+ eval {
1089+ require IO::Socket::SSL;
1090+ IO::Socket::SSL-> import (qw/ SSL_VERIFY_PEER SSL_VERIFY_NONE/ );
1091+ };
1092+ if ($@ ) {
1093+ print STDERR " Not using SSL_VERIFY_PEER due to out-of-date IO::Socket::SSL.\n " ;
1094+ return ;
1095+ }
1096+
1097+ if (!defined $smtp_ssl_cert_path ) {
1098+ $smtp_ssl_cert_path = " /etc/ssl/certs" ;
1099+ }
1100+
1101+ if ($smtp_ssl_cert_path eq " " ) {
1102+ return (SSL_verify_mode => SSL_VERIFY_NONE());
1103+ } elsif (-d $smtp_ssl_cert_path ) {
1104+ return (SSL_verify_mode => SSL_VERIFY_PEER(),
1105+ SSL_ca_path => $smtp_ssl_cert_path );
1106+ } elsif (-f $smtp_ssl_cert_path ) {
1107+ return (SSL_verify_mode => SSL_VERIFY_PEER(),
1108+ SSL_ca_file => $smtp_ssl_cert_path );
1109+ } else {
1110+ print STDERR " Not using SSL_VERIFY_PEER because the CA path does not exist.\n " ;
1111+ return (SSL_verify_mode => SSL_VERIFY_NONE());
1112+ }
1113+ }
1114+
10821115# Returns 1 if the message was sent, and 0 otherwise.
10831116# In actuality, the whole program dies when there
10841117# is an error sending a message.
@@ -1183,7 +1216,8 @@ sub send_message {
11831216 $smtp_domain ||= maildomain();
11841217 $smtp ||= Net::SMTP::SSL-> new($smtp_server ,
11851218 Hello => $smtp_domain ,
1186- Port => $smtp_server_port );
1219+ Port => $smtp_server_port ,
1220+ ssl_verify_params());
11871221 }
11881222 else {
11891223 require Net::SMTP;
@@ -1198,7 +1232,8 @@ sub send_message {
11981232 $smtp -> command(' STARTTLS' );
11991233 $smtp -> response();
12001234 if ($smtp -> code == 220) {
1201- $smtp = Net::SMTP::SSL-> start_SSL($smtp )
1235+ $smtp = Net::SMTP::SSL-> start_SSL($smtp ,
1236+ ssl_verify_params())
12021237 or die " STARTTLS failed! " .$smtp -> message;
12031238 $smtp_encryption = ' ' ;
12041239 # Send EHLO again to receive fresh
0 commit comments