Skip to content

Commit 629ac65

Browse files
committed
Merge branch 'jv/send-email-selective-smtp-auth'
"git send-email" learned a new option --smtp-auth to limit the SMTP AUTH mechanisms to be used to a subset of what the system library supports. * jv/send-email-selective-smtp-auth: send-email: provide whitelist of SMTP AUTH mechanisms
2 parents ed070a4 + 0f2e68b commit 629ac65

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

Documentation/git-send-email.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,19 @@ Sending
171171
to determine your FQDN automatically. Default is the value of
172172
'sendemail.smtpDomain'.
173173

174+
--smtp-auth=<mechanisms>::
175+
Whitespace-separated list of allowed SMTP-AUTH mechanisms. This setting
176+
forces using only the listed mechanisms. Example:
177+
+
178+
------
179+
$ git send-email --smtp-auth="PLAIN LOGIN GSSAPI" ...
180+
------
181+
+
182+
If at least one of the specified mechanisms matches the ones advertised by the
183+
SMTP server and if it is supported by the utilized SASL library, the mechanism
184+
is used for authentication. If neither 'sendemail.smtpAuth' nor '--smtp-auth'
185+
is specified, all mechanisms supported by the SASL library can be used.
186+
174187
--smtp-pass[=<password>]::
175188
Password for SMTP-AUTH. The argument is optional: If no
176189
argument is specified, then the empty string is used as

git-send-email.perl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ sub usage {
7575
Pass an empty string to disable certificate
7676
verification.
7777
--smtp-domain <str> * The domain name sent to HELO/EHLO handshake
78+
--smtp-auth <str> * Space-separated list of allowed AUTH mechanisms.
79+
This setting forces to use one of the listed mechanisms.
7880
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
7981
8082
Automating:
@@ -208,7 +210,7 @@ sub do_edit {
208210
my ($to_cmd, $cc_cmd);
209211
my ($smtp_server, $smtp_server_port, @smtp_server_options);
210212
my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);
211-
my ($identity, $aliasfiletype, @alias_files, $smtp_domain);
213+
my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);
212214
my ($validate, $confirm);
213215
my (@suppress_cc);
214216
my ($auto_8bit_encoding);
@@ -239,6 +241,7 @@ sub do_edit {
239241
"smtppass" => \$smtp_authpass,
240242
"smtpsslcertpath" => \$smtp_ssl_cert_path,
241243
"smtpdomain" => \$smtp_domain,
244+
"smtpauth" => \$smtp_auth,
242245
"to" => \@initial_to,
243246
"tocmd" => \$to_cmd,
244247
"cc" => \@initial_cc,
@@ -310,6 +313,7 @@ sub signal_handler {
310313
"smtp-ssl-cert-path=s" => \$smtp_ssl_cert_path,
311314
"smtp-debug:i" => \$debug_net_smtp,
312315
"smtp-domain:s" => \$smtp_domain,
316+
"smtp-auth=s" => \$smtp_auth,
313317
"identity=s" => \$identity,
314318
"annotate!" => \$annotate,
315319
"no-annotate" => sub {$annotate = 0},
@@ -1130,6 +1134,12 @@ sub smtp_auth_maybe {
11301134
Authen::SASL->import(qw(Perl));
11311135
};
11321136

1137+
# Check mechanism naming as defined in:
1138+
# https://tools.ietf.org/html/rfc4422#page-8
1139+
if ($smtp_auth !~ /^(\b[A-Z0-9-_]{1,20}\s*)*$/) {
1140+
die "invalid smtp auth: '${smtp_auth}'";
1141+
}
1142+
11331143
# TODO: Authentication may fail not because credentials were
11341144
# invalid but due to other reasons, in which we should not
11351145
# reject credentials.
@@ -1142,6 +1152,20 @@ sub smtp_auth_maybe {
11421152
'password' => $smtp_authpass
11431153
}, sub {
11441154
my $cred = shift;
1155+
1156+
if ($smtp_auth) {
1157+
my $sasl = Authen::SASL->new(
1158+
mechanism => $smtp_auth,
1159+
callback => {
1160+
user => $cred->{'username'},
1161+
pass => $cred->{'password'},
1162+
authname => $cred->{'username'},
1163+
}
1164+
);
1165+
1166+
return !!$smtp->auth($sasl);
1167+
}
1168+
11451169
return !!$smtp->auth($cred->{'username'}, $cred->{'password'});
11461170
});
11471171

0 commit comments

Comments
 (0)