Log cert serial no if it is revoked
Hi.
Author: Boris Lytochkin <[email protected]...>
Sponsored-by: Yandex LLC
Log serial number of revoked certificate
In most of situations admin of OpenVPN server needs to know which particular certificate is used by client.
In the case when certificate is OK, environment variable can be used for that but once it is revoked no user scripts are invoked so there is no way to get serial number: only subject is printed in logs. Patch attached addresses this issue logging certificate directly on the line with certificate subject.
Tested with OpenSSL but PolarSSL should be good too.
Signed-off-by Boris Lytochkin <[email protected]...>
Signature · 3 lines
Boris Lytochkin Yandex NOC +7 (495) 739 70 00 ext. 7671
src/openvpn/ssl_verify_openssl.c +3 -1
@@ -585,6 +585,7 @@ x509_verify_crl(const char *crl_file, X509 *peer_cert, const char *subject)BIO *in=NULL ;int n,i;result_t retval =FAILURE ; +struct gc_arena gc =gc_new (); in =BIO_new_file (crl_file,"r" );
@@ -609,7 +610,7 @@ x509_verify_crl(const char *crl_file, X509 *peer_cert, const char *subject)for (i =0 ; i < n; i++) { revoked = (X509_REVOKED *)sk_X509_REVOKED_value (X509_CRL_get_REVOKED (crl), i);if (ASN1_INTEGER_cmp (revoked->serialNumber,X509_get_serialNumber (peer_cert)) ==0 ) { -msg (D_HANDSHAKE ,"CRL CHECK FAILED: %s is REVOKED" ,subject); +msg (D_HANDSHAKE ,"CRL CHECK FAILED: %s (serial %s) is REVOKED" , subject,backend_x509_get_serial_hex (peer_cert, &gc)); goto end; } }
@@ -618,6 +619,7 @@ x509_verify_crl(const char *crl_file, X509 *peer_cert, const char *subject)msg (D_HANDSHAKE ,"CRL CHECK OK: %s" ,subject); end: +gc_free (&gc);BIO_free (in);if (crl)X509_CRL_free (crl);
src/openvpn/ssl_verify_polarssl.c +3 -1
@@ -373,6 +373,7 @@ x509_verify_crl(const char *crl_file, x509_crt *cert, const char *subject) {result_t retval =FAILURE ;x509_crl crl = {0 }; +struct gc_arena gc =gc_new ();int polar_retval =x509_crl_parse_file (&crl, crl_file);if (polar_retval !=0 )
@@ -394,7 +395,7 @@ x509_verify_crl(const char *crl_file, x509_crt *cert, const char *subject)if (0 !=x509_crt_revoked (cert, &crl)) { -msg (D_HANDSHAKE ,"CRL CHECK FAILED: %s is REVOKED" , subject); +msg (D_HANDSHAKE ,"CRL CHECK FAILED: %s (serial %s) is REVOKED" , subject,backend_x509_get_serial_hex (cert, &gc)); goto end; }
@@ -402,6 +403,7 @@ x509_verify_crl(const char *crl_file, x509_crt *cert, const char *subject)msg (D_HANDSHAKE ,"CRL CHECK OK: %s" ,subject); end: +gc_free (&gc);x509_crl_free (&crl);return retval; }
Quoted 3 lines · Boris Lytochkin
Log serial number of revoked certificate
In most of situations admin of OpenVPN server needs to know which particular certificate is used by client.
Cert serial numbers found in the wild are hardly unique (witness the Mozilla CA bundle), thus no one with a sane mind refers to them as identifiers, nor do libraries/apps use them for things like cert pinning, nor should people be encouraged to think they are unique (even though there may now be some spec for that, but history precedes). The only place they'd have meaning is as text string for the local issuer, but it's really just duplication of work.
The sha1 (or better) fingerprint of the cert should be used instead.
Hi.
I disagree.
And openssl crl disagrees with you too. There are no sha1 (or other) fingerprints there, serial numbers are stored there :)
As far as I understand in most of the cases where X509 is used for OpenVPN, single (mostly probable self-signed) CA is used for authentication so serial number should be sane enough to understand which is which. Anyway, feel free to add sha1 (you name it) fingerprint additionally to my patch - more information on the cause of denial of connection the better.
Quoted 19 lines · grarpamp
Quoted 3 lines · Boris Lytochkin
Log serial number of revoked certificate
In most of situations admin of OpenVPN server needs to know which particular certificate is used by client.Cert serial numbers found in the wild are hardly unique (witness the Mozilla CA bundle), thus no one with a sane mind refers to them as identifiers, nor do libraries/apps use them for things like cert pinning, nor should people be encouraged to think they are unique (even though there may now be some spec for that, but history precedes). The only place they'd have meaning is as text string for the local issuer, but it's really just duplication of work.
The sha1 (or better) fingerprint of the cert should be used instead.------------------------------------------------------------------------------
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Signature · 3 lines
Boris Lytochkin Yandex NOC +7 (495) 739 70 00 ext. 7671
Hi,
Quoted 1 line · grarpamp
Cert serial numbers found in the wild are hardly unique (witness
They are not "in the wild" in this context, as the issueing CA in OpenVPN contexts is typically in-house - and serial numbers for certs issued by a single CA(!) *are* unique.
If the cert cannot be verified at all (not revoked, but "issued by another CA" or "not signed at all"), I agree, the serial number does not carry meaningful information - but this is not the case this patch is about.
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]...Quoted 15 lines · Boris Lytochkin
Hi.
Author: Boris Lytochkin <[email protected]...>
Sponsored-by: Yandex LLCLog serial number of revoked certificate
In most of situations admin of OpenVPN server needs to know which particular certificate is used by client.
In the case when certificate is OK, environment variable can be used for that but once it is revoked no user scripts are invoked so there is no way to get serial number: only subject is printed in logs. Patch attached addresses this issue logging certificate directly on the line with certificate subject.
Quoted 3 lines
Tested with OpenSSL but PolarSSL should be good too.
Signed-off-by Boris Lytochkin <[email protected]...>
Feature-wise, this makes a lot of sense. And as Gert has said, the serial numbers are unique to the CA being used, which fits OpenVPN use cases well. The vast majority of OpenVPN installations with PKI uses an internal CA which the admins have full control over.
I have only done a code review and a quick compile with 'make check'.
Hi.
Any news on importing this patch into codebase?
Quoted 34 lines · David Sommerseth
Quoted 15 lines · Boris Lytochkin
Hi.
Author: Boris Lytochkin <[email protected]...>
Sponsored-by: Yandex LLCLog serial number of revoked certificate
In most of situations admin of OpenVPN server needs to know which particular certificate is used by client.
In the case when certificate is OK, environment variable can be used for that but once it is revoked no user scripts are invoked so there is no way to get serial number: only subject is printed in logs. Patch attached addresses this issue logging certificate directly on the line with certificate subject.Quoted 3 lines
Tested with OpenSSL but PolarSSL should be good too.
Signed-off-by Boris Lytochkin <[email protected]...>
Feature-wise, this makes a lot of sense. And as Gert has said, the serial numbers are unique to the CA being used, which fits OpenVPN use cases well. The vast majority of OpenVPN installations with PKI uses an internal CA which the admins have full control over.
I have only done a code review and a quick compile with 'make check'.
From that perspective, I can give it an ACK on the code side. It looks
correct as far as I can understand. It would be good if Steffan could give especially the PolarSSL side an extra check, but even that looks good to me.I have *not* tested this against a CRL file yet. I hope I don't jinx it when I say I think the behaviour in that case will be very predictable.
Signature · 3 lines
Boris Lytochkin Yandex NOC +7 (495) 739 70 00 ext. 7671
Hi,
I agree that the functionality makes, but need to look at the code. I'm currently on a long holiday and haven't had enough spare cycles to spend on openvpn. After I get back (next week), this will be part of my backlog :)
-Steffan
Quoted 53 lines · Boris Lytochkin
Hi.
Any news on importing this patch into codebase?
Quoted 24 lines · David Sommerseth
Quoted 15 lines · Boris Lytochkin
Hi.
Author: Boris Lytochkin <[email protected]...>
Sponsored-by: Yandex LLCLog serial number of revoked certificate
In most of situations admin of OpenVPN server needs to know which particular certificate is used by client.
In the case when certificate is OK, environment variable can be used for that but once it is revoked no user scripts are invoked so there is no way to get serial number: only subject is printed in logs. Patch attached addresses this issue logging certificate directly on the line with certificate subject.Quoted 3 lines
Tested with OpenSSL but PolarSSL should be good too.
Signed-off-by Boris Lytochkin <[email protected]...>
Feature-wise, this makes a lot of sense. And as Gert has said, the serial numbers are unique to the CA being used, which fits OpenVPN use cases well. The vast majority of OpenVPN installations with PKI uses an internal CA which the admins have full control over.
Quoted 10 lines
I have only done a code review and a quick compile with 'make check'.
From that perspective, I can give it an ACK on the code side. It looks
correct as far as I can understand. It would be good if Steffan could give especially the PolarSSL side an extra check, but even that looks good to me.I have *not* tested this against a CRL file yet. I hope I don't jinx it when I say I think the behaviour in that case will be very predictable.
--
Boris Lytochkin
Yandex NOC
+7 (495) 739 70 00 ext. 7671------------------------------------------------------------------------------
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Quoted 3 lines · Steffan Karger
I agree that the functionality makes, but need to look at the code. I'm currently on a long holiday and haven't had enough spare cycles to spend on openvpn. After I get back (next week), this will be part of my backlog :)
I looked at the code this morning, and tested with both OpenSSL and PolarSSL. The functionality makes sense. The serial formatting is a bit confusing ("serial 12" is actually serial 0x12, or 18 in dec), but this matches 'openssl crl -text' output, and putting 0x in front will make the longer AA:BB:CC formatting look weird... So I guess I'm fine with this.
Regarding
@@ -609,7 +610,7 @@ x509_verify_crl(const char *crl_file, X509 *peer_cert, const char *subject)
for (i = 0; i < n; i++) {
revoked = (X509_REVOKED
*)sk_X509_REVOKED_value(X509_CRL_get_REVOKED(crl), i);
if (ASN1_INTEGER_cmp(revoked->serialNumber,
X509_get_serialNumber(peer_cert)) == 0) {
- msg (D_HANDSHAKE, "CRL CHECK FAILED: %s is REVOKED",subject);
+ msg (D_HANDSHAKE, "CRL CHECK FAILED: %s (serial %s) is REVOKED", subject, backend_x509_get_serial_hex(peer_cert, &gc));
goto end;
}}
and
@@ -394,7 +395,7 @@ x509_verify_crl(const char *crl_file, x509_crt *cert, const char *subject)
if (0 != x509_crt_revoked(cert, &crl))
{
- msg (D_HANDSHAKE, "CRL CHECK FAILED: %s is REVOKED", subject);
+ msg (D_HANDSHAKE, "CRL CHECK FAILED: %s (serial %s) is REVOKED", subject, backend_x509_get_serial_hex(cert, &gc));
goto end;
}backend_x509_get_serial_hex() may return NULL, and passing NULL as a string format specifier to printf() results in undefined behaviour. So please add a NULL check before passing the string to msg().
Finally, when you send a v2 of this patch, could you use 'git format-patch' to create a patch file with a clear commit message explaining why this change is useful? (Your original email probably suffices).
-Steffan
Hi.
v2 patch is attached.
Thanks for comments!
Quoted 15 lines · Steffan Karger
Quoted 3 lines · Steffan Karger
I agree that the functionality makes, but need to look at the code. I'm currently on a long holiday and haven't had enough spare cycles to spend on openvpn. After I get back (next week), this will be part of my backlog :)
I looked at the code this morning, and tested with both OpenSSL and PolarSSL. The functionality makes sense. The serial formatting is a bit confusing ("serial 12" is actually serial
0x12, or 18 in dec), but this matches 'openssl crl -text' output, and putting 0x in front will make the longer AA:BB:CC formatting look weird... So I guess I'm fine with this.Regarding
<cut>backend_x509_get_serial_hex()may return NULL, and passing NULL as a string format specifier toprintf()results in undefined behaviour. So please add a NULL check before passing the string tomsg().Finally, when you send a v2 of this patch, could you use 'git format-patch' to create a patch file with a clear commit message explaining why this change is useful? (Your original email probably suffices).
-Steffan
Signature · 3 lines
Boris Lytochkin Yandex NOC +7 (495) 739 70 00 ext. 7671
From e8368ef1b7d18e188dc66c017dc81c7f15f66ab0 Mon Sep 17 00:00:00 2001
From: Boris Lytochkin <[email protected]>
Date: Sun, 20 Sep 2015 17:05:22 +0300
Subject: [PATCH] Log serial number of revoked certificate
In most of situations admin of OpenVPN server needs to know which particular certificate is used by client. In the case when certificate is OK, environment variable can be used for that but once it is revoked no user scripts are invoked so there is no way to get serial number: only subject is printed in logs.
So we log certificate serial in case it is revoked.
Sponsored-by: Yandex LLC
--- src/openvpn/ssl_verify_openssl.c | 6 +++++- src/openvpn/ssl_verify_polarssl.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-)
src/openvpn/ssl_verify_openssl.c +5 -1
@@ -585,6 +585,8 @@ x509_verify_crl(const char *crl_file, X509 *peer_cert, const char *subject)BIO *in=NULL ;int n,i;result_t retval =FAILURE ; +struct gc_arena gc =gc_new (); +char *serial; in =BIO_new_file (crl_file,"r" );
@@ -609,7 +611,8 @@ x509_verify_crl(const char *crl_file, X509 *peer_cert, const char *subject)for (i =0 ; i < n; i++) { revoked = (X509_REVOKED *)sk_X509_REVOKED_value (X509_CRL_get_REVOKED (crl), i);if (ASN1_INTEGER_cmp (revoked->serialNumber,X509_get_serialNumber (peer_cert)) ==0 ) { -msg (D_HANDSHAKE ,"CRL CHECK FAILED: %s is REVOKED" ,subject); + serial =backend_x509_get_serial_hex (peer_cert, &gc); +msg (D_HANDSHAKE ,"CRL CHECK FAILED: %s (serial %s) is REVOKED" , subject, (serial ? serial :"NOT AVAILABLE" )); goto end; } }
@@ -618,6 +621,7 @@ x509_verify_crl(const char *crl_file, X509 *peer_cert, const char *subject)msg (D_HANDSHAKE ,"CRL CHECK OK: %s" ,subject); end: +gc_free (&gc);BIO_free (in);if (crl)X509_CRL_free (crl);
src/openvpn/ssl_verify_polarssl.c +5 -1
@@ -373,6 +373,8 @@ x509_verify_crl(const char *crl_file, x509_crt *cert, const char *subject) {result_t retval =FAILURE ;x509_crl crl = {0 }; +struct gc_arena gc =gc_new (); +char *serial;int polar_retval =x509_crl_parse_file (&crl, crl_file);if (polar_retval !=0 )
@@ -394,7 +396,8 @@ x509_verify_crl(const char *crl_file, x509_crt *cert, const char *subject)if (0 !=x509_crt_revoked (cert, &crl)) { -msg (D_HANDSHAKE ,"CRL CHECK FAILED: %s is REVOKED" , subject); + serial =backend_x509_get_serial_hex (cert, &gc); +msg (D_HANDSHAKE ,"CRL CHECK FAILED: %s (serial %s) is REVOKED" , subject, (serial ? serial :"NOT AVAILABLE" )); goto end; }
@@ -402,6 +405,7 @@ x509_verify_crl(const char *crl_file, x509_crt *cert, const char *subject)msg (D_HANDSHAKE ,"CRL CHECK OK: %s" ,subject); end: +gc_free (&gc);x509_crl_free (&crl);return retval; }
Signature · 1 line
2.1.2
Quoted 3 lines · Boris Lytochkin
v2 patch is attached.
Thanks for comments!
ACK to v2.
Thanks the patch, and quick response!
-Steffan
[Openvpn-devel] [PATCH applied] Re: Log serial number of revoked certificate
In reply to Boris LytochkinYour patch has been applied to the master and release/2.3 branch.
commit 767e4c56becbfeea525e4695a810593f373883cd (master) commit 1e4a3ba3e751017e29db37676e7d3b78d46a97a2 (release/2.3)
Author: Boris Lytochkin Date: Sun Sep 20 17:05:22 2015 +0300
Log serial number of revoked certificate
Signed-off-by: Boris Lytochkin <[email protected]...>
Acked-by: Steffan Karger <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/10154
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering