Skip to contentSkip to conversation

send-email: add client certificate options

PATCH Superseded David Timber 2 participants 10 messages Feb 20 – Mar 4 Documentation

lore
Share & tools
lore
#0 lore raw

cover send-email: add client certificate options

Additional doc touch up on configurations. No code change :)

David Timber (1):
send-mail: add client certificate options

 Documentation/config/sendemail.adoc |  6 ++++
 Documentation/git-send-email.adoc   | 17 ++++++++++
 git-send-email.perl                 | 48 ++++++++++++++++++++++-------
 3 files changed, 60 insertions(+), 11 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/1 send-mail: add client certificate options

For SMTP servers that do "mutual certificate verification", the mail client is required to present its own TLS certificate as well. This patch adds --smtp-ssl-client-cert and --smtp-ssl-client-key for such servers.

---
 Documentation/config/sendemail.adoc |  6 ++++
 Documentation/git-send-email.adoc   | 17 ++++++++++
 git-send-email.perl                 | 48 ++++++++++++++++++++++-------
 3 files changed, 60 insertions(+), 11 deletions(-)
Documentation/config/sendemail.adoc +6 -0
index 90164c734d..3d9925c1e0 100644
@@ -12,6 +12,12 @@ sendemail.smtpSSLCertPath::
 	Path to ca-certificates (either a directory or a single file).
 	Set it to an empty string to disable certificate verification.
 
+sendemail.smtpSSLClientCert::
+	Path to a client certificate file to present to the SMTP server.
+
+sendemail.smtpSSLClientKey::
+	Path to the client private key file.
+
 sendemail.<identity>.*::
 	Identity-specific versions of the `sendemail.*` parameters
 	found below, taking precedence over those when this
Documentation/git-send-email.adoc +17 -0
index ebe8853e9f..51177508c1 100644
@@ -290,6 +290,23 @@ must be used for each option.
 	variable, if set, or the backing SSL library's compiled-in default
 	otherwise (which should be the best choice on most platforms).
 
+--smtp-ssl-client-cert <path>::
+	Path to a client certificate file to present to the SMTP server. This option
+	can be used when the server verifies the certificate from the client. The
+	format could be in either PKCS12 or PEM. In the latter case, the private key
+	can be specified using `--smtp-ssl-client-key` option. More more
+	detail, see
+	https://metacpan.org/pod/IO::Socket::SSL#SSL_cert_file-|-SSL_cert-|-SSL_key_file-|-SSL_key
+	Defaults to the value of the `sendemail.smtpSSLClientCert` configuration
+	variable, if set.
+
+--smtp-ssl-client-key <path>::
+	Optional path to the client private key file. If this is not given and a
+	PKCS12 certificate file is used, the private key from the PKCS12 certificate
+	will be used(see `--smtp-ssl-client-cert`). Defaults to the value of the
+	`sendemail.smtpSSLClientKey` configuration variable, if set.
+
+
 --smtp-user=<user>::
 	Username for SMTP-AUTH. Default is the value of `sendemail.smtpUser`;
 	if a username is not specified (with `--smtp-user` or `sendemail.smtpUser`),
git-send-email.perl +37 -11

87 lines not on this page · raw message

Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH v1 1/1] send-mail: add client certificate options

Documentation/config/sendemail.adoc sendemail.smtpSSLCertPath:: · line 19

Quoted 5 lines · David Timber
Documentation/config/sendemail.adoc +5 -0
+sendemail.smtpSSLClientCert::
+	Path to a client certificate file to present to the SMTP server.
+
+sendemail.smtpSSLClientKey::
+	Path to the client private key file.

Do we want to add "that corresponds to the smtpSSLClientCert" at the end, perhaps?

Documentation/git-send-email.adoc must be used for each option. · line 295

Quoted 11 lines
Documentation/git-send-email.adoc +3 -0
index ebe8853e9f..51177508c1 100644
@@ -290,6 +290,23 @@ must be used for each option.
 	variable, if set, or the backing SSL library's compiled-in default
 	otherwise (which should be the best choice on most platforms).
 
+--smtp-ssl-client-cert <path>::
+	Path to a client certificate file to present to the SMTP server. This option
+	can be used when the server verifies the certificate from the client. The

Shouldn't there be a word "require" somewhere in the above to clarify why a user may want to use this option? A server may optionally verify a certificate only when it is given one, but if it lets us do what we want without such verification, we do not have much incentive to give them a certificate.

Documentation/git-send-email.adoc must be used for each option. · line 297

Quoted 2 lines
Documentation/git-send-email.adoc +2 -0
+	format could be in either PKCS12 or PEM. In the latter case, the private key
+	can be specified using `--smtp-ssl-client-key` option. More more

Is that "can be specified" or "should be specified"? "More more" -> "For more".

Documentation/git-send-email.adoc must be used for each option. · line 308

Quoted 11 lines
Documentation/git-send-email.adoc +11 -0
+	detail, see
+	https://metacpan.org/pod/IO::Socket::SSL#SSL_cert_file-|-SSL_cert-|-SSL_key_file-|-SSL_key
+	Defaults to the value of the `sendemail.smtpSSLClientCert` configuration
+	variable, if set.
+
+--smtp-ssl-client-key <path>::
+	Optional path to the client private key file. If this is not given and a
+	PKCS12 certificate file is used, the private key from the PKCS12 certificate
+	will be used(see `--smtp-ssl-client-cert`). Defaults to the value of the
+	`sendemail.smtpSSLClientKey` configuration variable, if set.
+

"will be used(see" -> "will be used (see".

This makes me wonder what the use case is for giving separate key file with a certificate file with its own private key in it. The documentation above clearly describes what happens (i.e., the separate key file makes the key embedded in the certificate file ignored), but I cannot quite think of a reason why anybody would want to do so. The key in the separate file is still something that corresponds to the public part in the certificate, no? The certificate can say "The subject of the certificate may use a private key that corresponds to any of these three public keys", and the certificate file may only have one or two but not all of these three public keys, or something?

Documentation/git-send-email.adoc must be used for each option. · line 310

Quoted 2 lines
Documentation/git-send-email.adoc +2 -0
+	if (defined $smtp_ssl_client_cert) {
+		# The cert could be in PKCS12 format, which can store both cert and key

The comment confused me initially. Yes, the cert could be PKCS12 with key. But the mention of the fact supports what design decision? Not requiring $smtp_ssl_client_key here (unlike the next if block that requires cert when key is used)? If so, perhaps we would want to spell that out?

# We do not check and die when client_key is not # given, as a separate key file is unneeded for # PKCS12 certs.

or something?

Documentation/git-send-email.adoc must be used for each option.

Quoted 7 lines
Documentation/git-send-email.adoc +6 -0
+		$ret{SSL_cert_file} = $smtp_ssl_client_cert;
+		$ret{SSL_use_cert} = 1;
 	}
+	if (defined $smtp_ssl_client_key) {
+		if (!defined $smtp_ssl_client_cert) {
+			# doesn't make sense to use a client key only
+			die sprintf(__("Only client key \"%s\" specified"), $smtp_ssl_client_key);

Can you wrap this overly long line?

			die sprintf(__("Only client key \"%s\" specified"),
					$smtp_ssl_client_key);

Thanks.

#3 lore raw

Re: [PATCH v1 1/1] send-mail: add client certificate options

Quoted 6 lines · Junio C Hamano

This makes me wonder what the use case is for giving separate key file with a certificate file with its own private key in it. The documentation above clearly describes what happens (i.e., the separate key file makes the key embedded in the certificate file ignored), but I cannot quite think of a reason why anybody would want to do so.

I know. The design of the Perl SSL interface is not top notch.

https://metacpan.org/dist/IO-Socket-SSL/view/lib/IO/Socket/SSL.pod

Quoted 10 lines

For each certificate a key is need, which can either be given as a file with SSL_key_file or as an internal representation of an EVP_PKEY* object with SSL_key (like you get from Net::SSLeay or IO::Socket::SSL::Utils::PEM_xxx2key). If a key was already given within the PKCS#12 file specified by SSL_cert_file it will ignore any SSL_key or SSL_key_file. If no SSL_key or SSL_key_file was given it will try to use the PEM file given with SSL_cert_file again, maybe it contains the key too.

To summarise:

* PKCS12: the key in the cert always takes the precedence
* PEM: if the key file is not given, it will "try" to read one from the cert PEM file

I don't know why anyone would want to put the cert and the key in the same file, not even openssl impose that, but somehow, somewhere, there are people who do and Perl had to cater for the kind as it seems.

Quoted 6 lines

The key in the separate file is still something that corresponds to the public part in the certificate, no? The certificate can say "The subject of the certificate may use a private key that corresponds to any of these three public keys", and the certificate file may only have one or two but not all of these three public keys, or something?

I think this is why they made the logic that way (at least for PKCS12) to prevent the exact madness you were describing. Still, I'd agree that the asymmetry is horrendous.

I'm just trying to expose what's possible with the Perl SSL interface to the user as much as possible. Paranoid people(like me who would want to set up mtual vertification to deter bot attacks) would want both PEM and PKCS12 because major implementations including Thunderbird and K-9 only accept PKCS#12(imposed by the application and imposed by the operating system - Android, respectively) while the openssl x509 stack is more suited for PEM(separate cert and key).

It's a niche, I know. But something tells me that you'd want to push this feature forward. Thank you for the rest of the comments. Will come back with the revised patch that I hope may unconfuse you. Good to know the project is in good hands.

#4 lore raw

Re: [PATCH v1 1/1] send-mail: add client certificate options

Quoted 8 lines · David Timber

I'm just trying to expose what's possible with the Perl SSL interface to the user as much as possible. Paranoid people(like me who would want to set up mtual vertification to deter bot attacks) would want both PEM and PKCS12 because major implementations including Thunderbird and K-9 only accept PKCS#12(imposed by the application and imposed by the operating system - Android, respectively) while the openssl x509 stack is more suited for PEM(separate cert and key).

Quoted 4 lines

It's a niche, I know. But something tells me that you'd want to push this feature forward. Thank you for the rest of the comments. Will come back with the revised patch that I hope may unconfuse you. Good to know the project is in good hands.

OK, please incorporate what you explained here in the commit log message and/or in-code comment, in order to help future readers of "git log -p". I'd prefer to see it done before the topic goes out of my short-term memory ;-)

Thanks.

#5 lore raw

v2 cover send-email: add client certificate options

I'm sorry that I missed last week's submission deadline.

Quoted 5 lines · Junio C Hamano

Shouldn't there be a word "require" somewhere in the above to clarify why a user may want to use this option? A server may optionally verify a certificate only when it is given one, but if it lets us do what we want without such verification, we do not have much incentive to give them a certificate.

RFC 8446 section 4.3.2:

Quoted 3 lines

The client MUST send a Certificate message if and only if the server has requested client authentication via a CertificateRequest message (Section 4.3.2).

In other words, the client won't send its cert to the server unless requested by the server. So, the client presenting its cert to the server in the client hello from the get-go is in violation of this requirement. I reflected that in the reroll.

Also, removed the $ret{SSL_use_cert} = 1; line in the code to be in line with the requirement. That line was confusing and unnecessary in the first place. Whether to use a client cert or not should be up to the underlying implementation to decide.

Removed the whole PKCS#12 vs PEM debacle in the change as I reckon it's a behaviour that could change overnight without a warning. Feels kind of defensive, but a reasonable change all things considered. Users affected by such library behaviour change can always refer to the manual.

David Timber (1):
send-email: add client certificate options

 Documentation/config/sendemail.adoc | 16 ++++++++++
 Documentation/git-send-email.adoc   | 19 ++++++++++++
 git-send-email.perl                 | 47 ++++++++++++++++++++++-------
 3 files changed, 71 insertions(+), 11 deletions(-)
Signature · 1 line
2.53.0.1.ga224b40d3f.dirty
#6 lore raw

PATCH v2 1/1 send-email: add client certificate options

For SMTP servers that do "mutual certificate verification", the mail client is required to present its own TLS certificate as well. This patch adds --smtp-ssl-client-cert and --smtp-ssl-client-key for such servers.

The problem of which private key for the certificate is chosen arises when there are private keys in both the certificate and private key file. According to the documentation of IO::Socket::SSL(link supplied), the behaviour(the private key chosen) depends on the format of the certificate. In a nutshell,

- PKCS12: the key in the cert always takes the precedence
- PEM: if the key file is not given, it will "try" to read one from the cert PEM file

Many users may find this discrepancy unintuitive.

In terms of client certificate, git-send-email is implemented in a way that what's possible with perl's SSL library is exposed to the user as much as possible. In this instance, the user may choose to use a PEM file that contains both certificate and private key should be at their discretion despite the implications.

---
 Documentation/config/sendemail.adoc | 16 ++++++++++
 Documentation/git-send-email.adoc   | 19 ++++++++++++
 git-send-email.perl                 | 47 ++++++++++++++++++++++-------
 3 files changed, 71 insertions(+), 11 deletions(-)
Documentation/config/sendemail.adoc +16 -0
index 90164c734d..6560ecc5ab 100644
@@ -12,6 +12,22 @@ sendemail.smtpSSLCertPath::
 	Path to ca-certificates (either a directory or a single file).
 	Set it to an empty string to disable certificate verification.
 
+sendemail.smtpSSLClientCert::
+	Path to the client certificate file to present if requested by the
+	server. This is required when the server is set up to verify client
+	certificates. If the corresponding private key is not included in the
+	file, it must be supplied using `sendemail.smtpSSLClientKey` or the
+	`--smtp-ssl-client-key` option.
+
+sendemail.smtpSSLClientKey::
+	Path to the client private key file that corresponds to the client
+	certificate. To avoid misconfiguration, this configuration must be used
+	in conjunction with `sendemail.smtpSSLClientKey` or the
+	`--smtp-ssl-client-cert` option. If the client key is included in the
+	client certificate, the choice of private key depends on the format of
+	the certificate. Visit https://metacpan.org/pod/IO::Socket::SSL for more
+	details.
+
 sendemail.<identity>.*::
 	Identity-specific versions of the `sendemail.*` parameters
 	found below, taking precedence over those when this
Documentation/git-send-email.adoc +19 -0
index ebe8853e9f..ed9a0d3053 100644
@@ -290,6 +290,25 @@ must be used for each option.
 	variable, if set, or the backing SSL library's compiled-in default
 	otherwise (which should be the best choice on most platforms).
 
+--smtp-ssl-client-cert <path>::
+	Path to the client certificate file to present if requested by the
+	server. This option is required when the server is set up to verify
+	client certificates. If the corresponding private key is not included in
+	the file, it must be supplied using the `sendemail.smtpSSLClientKey`
+	configuration variable or the `--smtp-ssl-client-key` option. Defaults
+	to the value of the `sendemail.smtpSSLClientCert` configuration
+	variable, if set.
+
+--smtp-ssl-client-key <path>::
+	Path to the client private key file that corresponds to the client
+	certificate. To avoid misconfiguration, this option must be used in
+	conjunction with the `sendemail.smtpSSLClientKey` configuration variable
+	or the `--smtp-ssl-client-cert` option. If the client key is included in
+	the client certificate, the choice of private key depends on the format
+	of the certificate. Visit https://metacpan.org/pod/IO::Socket::SSL for
+	more details. Defaults to the value of the `sendemail.smtpSSLClientKey`
+	configuration variable, if set.
+
 --smtp-user=<user>::
 	Username for SMTP-AUTH. Default is the value of `sendemail.smtpUser`;
 	if a username is not specified (with `--smtp-user` or `sendemail.smtpUser`),
git-send-email.perl +36 -11

86 lines not on this page · raw message

Signature · 1 line
2.53.0.1.ga224b40d3f.dirty
#7 lore raw
Quoted 26 lines · David Timber

For SMTP servers that do "mutual certificate verification", the mail client is required to present its own TLS certificate as well. This patch adds --smtp-ssl-client-cert and --smtp-ssl-client-key for such servers.

The problem of which private key for the certificate is chosen arises when there are private keys in both the certificate and private key file. According to the documentation of IO::Socket::SSL(link supplied), the behaviour(the private key chosen) depends on the format of the certificate. In a nutshell,

- PKCS12: the key in the cert always takes the precedence
- PEM: if the key file is not given, it will "try" to read one from the cert PEM file

Many users may find this discrepancy unintuitive.

In terms of client certificate, git-send-email is implemented in a way that what's possible with perl's SSL library is exposed to the user as much as possible. In this instance, the user may choose to use a PEM file that contains both certificate and private key should be at their discretion despite the implications.

Quoted 6 lines
---
 Documentation/config/sendemail.adoc | 16 ++++++++++
 Documentation/git-send-email.adoc   | 19 ++++++++++++
 git-send-email.perl                 | 47 ++++++++++++++++++++++-------
 3 files changed, 71 insertions(+), 11 deletions(-)

It's a lot of text but quite informative. Will replace.

Shall we declare victory and mark the topic for 'next' now?

Thanks.

#8 lore raw
Quoted 1 line · Junio C Hamano

Shall we declare victory and mark the topic for 'next' now?

By all means! Keep up the good work!