Skip to content

Commit 07b83b5

Browse files
committed
Merge branch 'rr/send-email-ssl-verify'
Newer Net::SMTP::SSL module does not want the user programs to use the default behaviour to let server certificate go without verification, so by default enable the verification with a mechanism to turn it off if needed. * rr/send-email-ssl-verify: send-email: be explicit with SSL certificate verification
2 parents e683889 + 35035bb commit 07b83b5

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,10 @@ sendemail.smtpencryption::
20732073
sendemail.smtpssl::
20742074
Deprecated alias for 'sendemail.smtpencryption = ssl'.
20752075

2076+
sendemail.smtpsslcertpath::
2077+
Path to ca-certificates (either a directory or a single file).
2078+
Set it to an empty string to disable certificate verification.
2079+
20762080
sendemail.<identity>.*::
20772081
Identity-specific versions of the 'sendemail.*' parameters
20782082
found below, taking precedence over those when the this

Documentation/git-send-email.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ must be used for each option.
198198
--smtp-ssl::
199199
Legacy alias for '--smtp-encryption ssl'.
200200

201+
--smtp-ssl-cert-path::
202+
Path to ca-certificates (either a directory or a single file).
203+
Set it to an empty string to disable certificate verification.
204+
Defaults to the value set to the 'sendemail.smtpsslcertpath'
205+
configuration variable, if set, or `/etc/ssl/certs` otherwise.
206+
201207
--smtp-user=<user>::
202208
Username for SMTP-AUTH. Default is the value of 'sendemail.smtpuser';
203209
if a username is not specified (with '--smtp-user' or 'sendemail.smtpuser'),

git-send-email.perl

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
194197
my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc);
195198
my ($to_cmd, $cc_cmd);
196199
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);
198201
my ($identity, $aliasfiletype, @alias_files, $smtp_domain);
199202
my ($validate, $confirm);
200203
my (@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

Comments
 (0)