@@ -69,6 +69,9 @@ sub usage {
69
69
--smtp-pass <str> * Password for SMTP-AUTH; not necessary.
70
70
--smtp-encryption <str> * tls or ssl; anything else disables.
71
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.
72
75
--smtp-domain <str> * The domain name sent to HELO/EHLO handshake
73
76
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
74
77
@@ -194,7 +197,7 @@ sub do_edit {
194
197
my ($thread , $chain_reply_to , $suppress_from , $signed_off_by_cc );
195
198
my ($to_cmd , $cc_cmd );
196
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 );
198
201
my ($identity , $aliasfiletype , @alias_files , $smtp_domain );
199
202
my ($validate , $confirm );
200
203
my (@suppress_cc );
@@ -220,6 +223,7 @@ sub do_edit {
220
223
" smtpserveroption" => \@smtp_server_options ,
221
224
" smtpuser" => \$smtp_authuser ,
222
225
" smtppass" => \$smtp_authpass ,
226
+ " smtpsslcertpath" => \$smtp_ssl_cert_path ,
223
227
" smtpdomain" => \$smtp_domain ,
224
228
" to" => \@initial_to ,
225
229
" tocmd" => \$to_cmd ,
@@ -287,6 +291,7 @@ sub signal_handler {
287
291
" smtp-pass:s" => \$smtp_authpass ,
288
292
" smtp-ssl" => sub { $smtp_encryption = ' ssl' },
289
293
" smtp-encryption=s" => \$smtp_encryption ,
294
+ " smtp-ssl-cert-path" => \$smtp_ssl_cert_path ,
290
295
" smtp-debug:i" => \$debug_net_smtp ,
291
296
" smtp-domain:s" => \$smtp_domain ,
292
297
" identity=s" => \$identity ,
@@ -1079,6 +1084,34 @@ sub smtp_auth_maybe {
1079
1084
return $auth ;
1080
1085
}
1081
1086
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
+
1082
1115
# Returns 1 if the message was sent, and 0 otherwise.
1083
1116
# In actuality, the whole program dies when there
1084
1117
# is an error sending a message.
@@ -1183,7 +1216,8 @@ sub send_message {
1183
1216
$smtp_domain ||= maildomain();
1184
1217
$smtp ||= Net::SMTP::SSL-> new($smtp_server ,
1185
1218
Hello => $smtp_domain ,
1186
- Port => $smtp_server_port );
1219
+ Port => $smtp_server_port ,
1220
+ ssl_verify_params());
1187
1221
}
1188
1222
else {
1189
1223
require Net::SMTP;
@@ -1198,7 +1232,8 @@ sub send_message {
1198
1232
$smtp -> command(' STARTTLS' );
1199
1233
$smtp -> response();
1200
1234
if ($smtp -> code == 220) {
1201
- $smtp = Net::SMTP::SSL-> start_SSL($smtp )
1235
+ $smtp = Net::SMTP::SSL-> start_SSL($smtp ,
1236
+ ssl_verify_params())
1202
1237
or die " STARTTLS failed! " .$smtp -> message;
1203
1238
$smtp_encryption = ' ' ;
1204
1239
# Send EHLO again to receive fresh
0 commit comments