enhance tls-verify possibility
PATCH 1/1 enhance tls-verify possibility
From: Mathieu GIANNECCHINI <mat.giann at>
It should be nice to enhance tls-verify check possibilities against peer cert during a pending TLS connection like :
- OCSP verification
- check any X509 extensions of the peer certificate
- delta CRL verification
- ...
This patch add a new "tls-export-cert" option which allow to get peer certificate in PEM format and to store it in an openvpn temporary file. Peer certificate is stored before tls-script execution and deleted after. The name of the related temporary file is available under tls-verify script by an environment variable "peer_cert".
The patch was made from OpenVPN svn Beta21 branches.
Here is a very simple exemple of Tls-verify script which provide OCSP support to OpenVPN (with tls-export-cert option) without any OpenVPN "core" modification :
X509=$2
openssl ocsp \
-issuer /etc/openvpn/ssl.crt/RootCA.pem \
-CAfile /etc/openvpn/ssl.capath/OpenVPNServeur-cafile.pem \
-cert $peer_cert \
-url http://your-ocsp-url
if [ $? -ne 0 ]
then
echo "error : OCSP check failed for ${X509}" | logger -t"tls-verify"
exit 1
fi
This has been discussed here:
<http://thread.gmane.org/gmane.network.openvpn.devel/2492>
--- init.c | 1 + options.c | 10 ++++++++++ options.h | 1 + ssl.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ssl.h | 1 + 5 files changed, 73 insertions(+), 0 deletions(-)
init.c +1 -0
@@ -1805,6 +1805,7 @@ do_init_crypto_tls (struct context *c, const unsigned int flags)#endif to.verify_command = options->tls_verify; + to.verify_export_cert = options->tls_export_cert; to.verify_x509name = options->tls_remote; to.crl_file = options->crl_file; to.ns_cert_type = options->ns_cert_type;
options.c +10 -0
@@ -529,6 +529,9 @@ static const char usage_message[] =" tests of certification. cmd should return 0 to allow\n" " TLS handshake to proceed, or 1 to fail. (cmd is\n" " executed as 'cmd certificate_depth X509_NAME_oneline')\n" +"--tls-export-cert [directory] : Get peer cert in PEM format and store it \n" +" in an openvpn temporary file in [directory]. Peer cert is \n" +" stored before tls-verify script execution and deleted after.\n" "--tls-remote x509name: Accept connections only from a host with X509 name\n" " x509name. The remote host must also pass all other tests\n" " of verification.\n"
@@ -1325,6 +1328,7 @@ show_settings (const struct options *o)#endif SHOW_STR (cipher_list);SHOW_STR (tls_verify); +SHOW_STR (tls_export_cert);SHOW_STR (tls_remote);SHOW_STR (crl_file);SHOW_INT (ns_cert_type);
@@ -1914,6 +1918,7 @@ options_postprocess_verify_ce (const struct options *options, const struct conneMUST_BE_UNDEF (pkcs12_file);MUST_BE_UNDEF (cipher_list);MUST_BE_UNDEF (tls_verify); +MUST_BE_UNDEF (tls_export_cert);MUST_BE_UNDEF (tls_remote);MUST_BE_UNDEF (tls_timeout);MUST_BE_UNDEF (renegotiate_bytes);
@@ -5525,6 +5530,11 @@ add_option (struct options *options, goto err; options->tls_verify =string_substitute (p[1 ],',' ,' ' , &options->gc); } +else if (streq (p[0 ],"tls-export-cert" ) && p[1 ]) + { +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->tls_export_cert = p[1 ]; + }else if (streq (p[0 ],"tls-remote" ) && p[1 ]) {VERIFY_PERMISSION (OPT_P_GENERAL );
options.h +1 -0
@@ -440,6 +440,7 @@ struct optionsconst char *pkcs12_file;const char *cipher_list;const char *tls_verify; +const char *tls_export_cert;const char *tls_remote;const char *crl_file;
ssl.c +60 -0
82 lines not on this page · raw message
ssl.h +1 -0
@@ -441,6 +441,7 @@ struct tls_options/* cert verification parms */ const char *verify_command; +const char *verify_export_cert;const char *verify_x509name;const char *crl_file;int ns_cert_type;
Signature · 1 line
1.6.6.1
options.c static const char usage_message[] = · line 534
Quoted 8 lines · David Sommerseth
+++
b/options.coptions.c +3
-0@@ -529,6 +529,9 @@ static const char usage_message[] =" tests of certification. cmd should return 0 to allow\n" " TLS handshake to proceed, or 1 to fail. (cmd is\n" " executed as 'cmd certificate_depth X509_NAME_oneline')\n" +"--tls-export-cert [directory] : Get peer cert in PEM format and store it \n" +" in an openvpn temporary file in [directory]. Peer cert is \n" +" stored before tls-verify script execution and deleted after.\n"
Please update the man page too.
//Peter
Quoted 9 lines · Peter Stuge
Review static const char usage_message[] = · line 529
Quoted 3 lines · David Sommerseth
+++
b/options.c(quoted diff) +0
-0@@ -529,6 +529,9 @@ static const char usage_message[] = " tests of certification. cmd should return 0to allow\n"
Review static const char usage_message[] = · line 530
Quoted 1 line
(quoted diff) +0
-0" TLS handshake to proceed, or 1 to fail. (cmdis\n"
Review static const char usage_message[] = · line 531
Quoted 1 line
(quoted diff) +0
-0" executed as 'cmd certificate_depthX509_NAME_oneline')\n"
Quoted 8 lines
Review static const char usage_message[] = · line 532
Quoted 1 line
(quoted diff) +1
-0+ "--tls-export-cert [directory] : Get peer cert in PEM format andstore it \n"
Review static const char usage_message[] = · line 533
Quoted 1 line
(quoted diff) +1
-0+ " in an openvpn temporary file in [directory].Peer cert is \n"
Review static const char usage_message[] = · line 534
Quoted 1 line
(quoted diff) +1
-0+ " stored before tls-verify script execution anddeleted after.\n"
Please update the man page too
There is no man page. It's in sample-scripts/.
However, the openvpn(8) --tls-verify section of the man page is poor. I just sent another patch that clarifies it. Perhaps this is what you're looking for? If not then just ignore my man page patch.
Karl <[email protected]...>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein
Quoted 3 lines · Karl O. Pinc
Quoted 1 line
Quoted 1 line
+ "--tls-export-cert [directory] : Get peer cert in PEM format and
There is no man page. It's in sample-scripts/.
It's a new option, right?
//Peter
Quoted 7 lines · Peter Stuge
Quoted 1 line · Karl O. Pinc
Quoted 1 line
Quoted 1 line
+ "--tls-export-cert [directory] : Get peer cert in PEM format
and
Quoted 2 lines
There is no man page. It's in sample-scripts/.
It's a new option, right?
The sample script has a new option, yes. But the
--tls-verify option/config file directive used
to invoke the script is unchanged.
The sample script has never had a man page.
Karl <[email protected]...>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein
Quoted 11 lines · Karl O. Pinc
Quoted 2 lines · Peter Stuge
Quoted 1 line · Karl O. Pinc
Quoted 1 line
Quoted 1 line
+ "--tls-export-cert [directory] : Get peer cert in PEM
format
Quoted 5 lines
and
Quoted 2 lines
There is no man page. It's in sample-scripts/.
It's a new option, right?
The sample script has a new option, yes.
Come to think of it, this is wrong. I changed
the meaning of an existing (positional) argument.
Karl <[email protected]...>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein
Quoted 4 lines · Karl O. Pinc
However, the openvpn(8) --tls-verify section of the man page is poor. I just sent another patch that clarifies it. Perhaps this is what you're looking for? If not then just ignore my man page patch.
I just sent another man page patch to be applied on top of the last one. My git-foo is not strong enough to be able to figure out how to send both changes in one patch. (Without re-checking out the whole tree anyway.)
Karl <[email protected]...>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 17 lines · Karl O. Pinc
Quoted 16 lines · Peter Stuge
Review static const char usage_message[] = · line 529
Quoted 3 lines · David Sommerseth
+++
b/options.c(quoted diff) +0
-0@@ -529,6 +529,9 @@ static const char usage_message[] = " tests of certification. cmd should return 0to allow\n"
Review static const char usage_message[] = · line 530
Quoted 1 line
(quoted diff) +0
-0" TLS handshake to proceed, or 1 to fail. (cmdis\n"
Review static const char usage_message[] = · line 531
Quoted 1 line
(quoted diff) +0
-0" executed as 'cmd certificate_depthX509_NAME_oneline')\n"
Review static const char usage_message[] = · line 532
Quoted 1 line
(quoted diff) +1
-0+ "--tls-export-cert [directory] : Get peer cert in PEM format andstore it \n"
Review static const char usage_message[] = · line 533
Quoted 1 line
(quoted diff) +1
-0+ " in an openvpn temporary file in [directory].Peer cert is \n"
Review static const char usage_message[] = · line 534
Quoted 1 line
(quoted diff) +1
-0+ " stored before tls-verify script execution anddeleted after.\n"
Quoted 8 lines
Quoted 1 line
Please update the man page too
There is no man page. It's in sample-scripts/.
However, the openvpn(8) --tls-verify section of the man page is poor. I just sent another patch that clarifies it. Perhaps this is what you're looking for? If not then just ignore my man page patch.
I don't mean to be harsh ... but this patch updates options.c and introduces a new argument to OpenVPN. So I agree, Peter, a man page update is needed!
kind regards,
David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iEYEARECAAYFAkuLlUwACgkQDC186MBRfrpiUQCgrCwtf8ptYVxsktB2dLq83T1U ic8Amwf5tLcVlwlrBKU+sAedeutTZK5H
=vzdA
-----END PGP SIGNATURE-----
Quoted 27 lines · David Sommerseth
Quoted 5 lines · Karl O. Pinc
Quoted 4 lines · Peter Stuge
Review static const char usage_message[] = · line 529
Quoted 3 lines · David Sommerseth
+++
b/options.c(quoted diff) +0
-0@@ -529,6 +529,9 @@ static const char usage_message[] = " tests of certification. cmd should return0
Quoted 2 lines
Quoted 2 lines
to allow\n"
Quoted 1 line
(quoted diff) +0
-0" TLS handshake to proceed, or 1 to fail.(cmd
Quoted 4 lines
Quoted 4 lines
is\n"
Review static const char usage_message[] = · line 531
Quoted 1 line
(quoted diff) +0
-0" executed as 'cmd certificate_depthX509_NAME_oneline')\n"
Quoted 1 line
(quoted diff) +1
-0+ "--tls-export-cert [directory] : Get peer cert in PEM formatand
Quoted 2 lines
Quoted 2 lines
store it \n"
Quoted 1 line
(quoted diff) +1
-0+ " in an openvpn temporary file in[directory].
Quoted 2 lines
Quoted 2 lines
Peer cert is \n"
Quoted 1 line
(quoted diff) +1
-0+ " stored before tls-verify script executionand
Quoted 6 lines
Quoted 3 lines
deleted after.\n"
Please update the man page too
There is no man page. It's in sample-scripts/.
Quoted 8 lines
Quoted 4 lines
However, the openvpn(8) --tls-verify section of the man page is poor. I just sent another patch that clarifies it. Perhaps this is what you're looking for? If not then just ignore my man page patch.
I don't mean to be harsh ... but this patch updates
options.cand introduces a new argument to OpenVPN. So I agree, Peter, a man page update is needed!
Whoops. I was thinking of an entirely different patch and have been sending multiple responses that are entirely off-topic. *facepalm*
I agree. Man page update is needed.
Anyhow, having written a patch to the --tls-verify man page patch(s) someone might want to look at it and see if the wording is better.
Karl <[email protected]...>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein
Hi,
Quoted 6 lines · David Sommerseth
It should be nice to enhance tls-verify check possibilities against peer cert during a pending TLS connection like :
- OCSP verification
- check any X509 extensions of the peer certificate
- delta CRL verification
- ...
semi-ACK.
In general, I think this is useful.
Most of the code is fine, but I spotted a potential issue:
ssl.c verify_callback (int preverify_ok, X509_STORE_CTX * ctx) · line 961
Quoted 13 lines
ssl.c +6
-0@@ -896,6 +950,12 @@ verify_callback (int preverify_ok, X509_STORE_CTX * ctx)argv_msg_prefix (D_TLS_DEBUG , &argv,"TLS: executing verify command" ); ret =openvpn_execve (&argv, opt->es,S_SCRIPT ); +if (opt->verify_export_cert) + { +delete_file (tmp_file); +gc_free (&gc); + } +if (system_ok (ret)) { msg (D_HANDSHAKE, "VERIFY SCRIPT OK: depth=%d, %s",
tmp_file *could* be NULL here (unlikely, but possible).
So maybe this should read:
ssl.c verify_callback (int preverify_ok, X509_STORE_CTX * ctx) · line 961
Quoted 13 lines
ssl.c +6
-0@@ -896,6 +950,12 @@ verify_callback (int preverify_ok, X509_STORE_CTX * ctx)argv_msg_prefix (D_TLS_DEBUG , &argv,"TLS: executing verify command" ); ret =openvpn_execve (&argv, opt->es,S_SCRIPT ); +if (opt->verify_export_cert) + { +if (tmp_file !=NULL )delete_file (tmp_file); +gc_free (&gc); + } +if (system_ok (ret)) { msg (D_HANDSHAKE, "VERIFY SCRIPT OK: depth=%d, %s",
... instead. "delete_file()" is one of the few functions that do not check their argument for "is not NULL", so it's passed unchanged to unlink(), which might cause issues on some platforms.
(Don't put the tmp_file condition into the surrounding if(), as it would then skip the call to gc_free() as well).
With that change, and a manpage documentation of the new option, ACK.
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...