From: "cron2 (Code Review)" Date: Sat, 4 Apr 2026 15:05:50 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="pIUcYXeb35I="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Add unit test for printing various details of certificates List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --pIUcYXeb35I= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#4) to the change originally created by= plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1598?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by flichtenheld Change subject: Add unit test for printing various details of certificates ...................................................................... Add unit test for printing various details of certificates These unit tests will ensure that refactoring of these methods does not change the output. Change-Id: Iacbd8195cdedc7226bddc686ca8dccf9f25f8842 Signed-off-by: Arne Schwabe Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1598 Message-Id: <20260331173403.3082-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36= 389.html Signed-off-by: Gert Doering --- M tests/unit_tests/openvpn/test_ssl.c 1 file changed, 82 insertions(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/98/1598/4 diff --git a/tests/unit_tests/openvpn/test_ssl.c b/tests/unit_tests/openvpn= /test_ssl.c index 2b73ee7..0e9cecf 100644 --- a/tests/unit_tests/openvpn/test_ssl.c +++ b/tests/unit_tests/openvpn/test_ssl.c @@ -46,7 +46,9 @@ #include "test_common.h" #include "ssl.h" #include "buffer.h" +#include "cert_data.h" #include "packet_id.h" +#include "ssl_verify.h" /* Mock function to be allowed to include win32.c which is required for * getting the temp directory */ @@ -750,6 +752,83 @@ test_data_channel_known_vectors_run(false); } +#if defined(ENABLE_CRYPTO_MBEDTLS) +static openvpn_x509_cert_t * +get_certificate(const char *cert_str) +{ + mbedtls_x509_crt *cert; + ALLOC_OBJ_CLEAR(cert, mbedtls_x509_crt); + int ret =3D mbedtls_x509_crt_parse(cert, (const unsigned char *)cert_s= tr, + strlen(cert_str) + 1); + + assert_int_equal(ret, 0); + return cert; +} + +static void +free_certificate(openvpn_x509_cert_t *cert) +{ + mbedtls_x509_crt_free(cert); + free(cert); +} +#else +static openvpn_x509_cert_t * +get_certificate(const char *cert_str) +{ + BIO *in =3D BIO_new_mem_buf((char *)cert1, -1); + assert_non_null(in); + X509 *cert =3D PEM_read_bio_X509(in, NULL, NULL, NULL); + assert_non_null(cert); + BIO_free(in); + return cert; +} + +static void +free_certificate(openvpn_x509_cert_t *cert) +{ + X509_free(cert); +} +#endif + +void +crypto_test_print_cert_details(void **state) +{ + openvpn_x509_cert_t *cert =3D get_certificate(cert1); + struct gc_arena gc =3D gc_new(); + + const char *fp =3D backend_x509_get_serial_hex(cert, &gc); + + /* we messed this up between TLS libraries. But let's at least notice = in + * the future ...*/ +#if defined(ENABLE_CRYPTO_MBEDTLS) + assert_string_equal(fp, "82:6B:DD:CC:BD:E5:5E:B7:08:F1:2D:68:00:3C:24:= DE"); +#else + assert_string_equal(fp, "82:6b:dd:cc:bd:e5:5e:b7:08:f1:2d:68:00:3c:24:= de"); +#endif + + const char *sn =3D backend_x509_get_serial(cert, &gc); + assert_string_equal(sn, "173359713849739808110610111821055272158"); + + char username[TLS_USERNAME_LEN + 1] =3D { 0 }; /* null-terminated */ + + int ret =3D backend_x509_get_username(username, sizeof(username), "CN", + cert); + + assert_string_equal(username, "ovpn-test-ec1"); + assert_int_equal(ret, SUCCESS); + +#ifndef ENABLE_CRYPTO_MBEDTLS + /* mbed TLS does not implement this */ + ret =3D backend_x509_get_username(username, sizeof(username), "serialN= umber", + cert); + assert_int_equal(ret, SUCCESS); + assert_string_equal(username, "0x826BDDCCBDE55EB708F12D68003C24DE"); +#endif + + gc_free(&gc); + free_certificate(cert); +} + int main(void) @@ -773,7 +852,9 @@ cmocka_unit_test(test_data_channel_roundtrip_aes_256_cbc), cmocka_unit_test(test_data_channel_roundtrip_bf_cbc), cmocka_unit_test(test_data_channel_known_vectors_epoch), - cmocka_unit_test(test_data_channel_known_vectors_shortpktid) + cmocka_unit_test(test_data_channel_known_vectors_shortpktid), + cmocka_unit_test(crypto_test_print_cert_details) + }; #if defined(ENABLE_CRYPTO_OPENSSL) -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1598?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Iacbd8195cdedc7226bddc686ca8dccf9f25f8842 Gerrit-Change-Number: 1598 Gerrit-PatchSet: 4 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel --pIUcYXeb35I= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #4 to the change originally created by plaisthos.<= /p>

Vi= ew Change

The following approvals got outdated and were removed: Code-Review+2 by flichtenheld

Add unit test for printing v=
arious details of certificates

These unit tests will ensure that ref= actoring of these methods does not
change the output.

Change-Id: = Iacbd8195cdedc7226bddc686ca8dccf9f25f8842
Signed-off-by: Arne Schwabe &l= t;arne@...1227...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+= /1598
Message-Id: <20260331173403.3082-1-gert@...1296...>
URL: = https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36389.h= tml
Signed-off-by: Gert Doering <gert@...1296...>
---
M test= s/unit_tests/openvpn/test_ssl.c
1 file changed, 82 insertions(+), 1 dele= tion(-)

git pull ssh://gerrit.openvpn.net:29418/=
openvpn refs/changes/98/1598/4
diff --git a/tests/unit_tests/openvp=
n/test_ssl.c b/tests/unit_tests/openvpn/test_ssl.c
index 2b= 73ee7..0e9cecf 100644
--- a/tests/unit_tests/openvpn/test_s= sl.c
+++ b/tests/unit_tests/openvpn/test_ssl.c
@@ -46,7 +46,9 @@
#include "test_common.h"
#include "ssl.h"
#include "= buffer.h"
+#incl= ude "cert_data.h"
#include "packet_id.h&quo= t;
+#include "ss= l_verify.h"

/* Mock function to be = allowed to include win32.c which is required for
* gettin= g the temp directory */
@@ -750,6 +752,83 @@
test_data_channel_known_vectors_run(false);

}

+#if def= ined(ENABLE_CRYPTO_MBEDTLS)
+static openvpn_x509_cert_t *
+get_certificate(const char *cert_str)
+{
+ mbedtls_x509_crt *cert;
+ ALLOC_OBJ_CLEAR(cert, mbedtls_x509_crt);
+ int ret =3D mbedtls_x= 509_crt_parse(cert, (const unsigned char *)cert_str,
+ strl= en(cert_str) + 1);
+<= /span>
+ assert_int_equal= (ret, 0);
+ return= cert;
+}
<= span style=3D"color: hsl(120, 100%, 40%);">+

+static void
+free_certificate(openvpn_x509_cert_t *cert)
+{

+ mbedtls_x509_crt_free(cert);
+ free(cert);
+}
+#else
+static openvpn_x509_cert_t *
+get_certificate(const char *cert_str)
+{
+ BIO *in =3D BIO_new_mem_buf((char *)cert1, -1);
+ assert_non_null(in);
<= br>+ X509 *cert =3D PEM_read= _bio_X509(in, NULL, NULL, NULL);
+ assert_non_null(cert);
+ BIO_free(in);
+ return cert;
+}
+

+static void
= +free_certificate(openvpn_x509_= cert_t *cert)
+{
+ X509_free(cert);
+}
+#endif
+
+void
+crypto_test_p= rint_cert_details(void **state)
+{
+ op= envpn_x509_cert_t *cert =3D get_certificate(cert1);
+ struct gc_arena gc =3D gc_new();
+
+ const char *fp =3D backend_x509_get_s= erial_hex(cert, &gc);
+
+ /* we mes= sed this up between TLS libraries. But let's at least notice in<= br>+ * the future ...*/
+#if defined(ENABLE_CRYP= TO_MBEDTLS)
+ asse= rt_string_equal(fp, "82:6B:DD:CC:BD:E5:5E:B7:08:F1:2D:68:00:3C:24:DE&q= uot;);
+#else<= br>+ assert_string_equal(fp,= "82:6b:dd:cc:bd:e5:5e:b7:08:f1:2d:68:00:3c:24:de");
+#endif

+
+ const char *sn =3D backend_x509_get_serial(cert, &gc);
+ assert_string_equ= al(sn, "173359713849739808110610111821055272158");
+

+ char username[TLS_USERNAME_LEN + 1] =3D { 0 }; /*= null-terminated */
+=
+ int ret =3D bac= kend_x509_get_username(username, sizeof(username), "CN",+ = cert);
+<= /span>
+ assert_string_eq= ual(username, "ovpn-test-ec1");
+ assert_int_equal(ret, SUCCESS);
+
+#ifndef ENABLE_CRYPTO_MBEDTLS
+ /* mbed TLS does not implement this */
+ ret =3D backend_x50= 9_get_username(username, sizeof(username), "serialNumber",=
+ = cert);
+ = assert_int_equal(ret, SUCCESS);
+ assert_string_equal(username, "0x826BDDCCBDE55EB708F1= 2D68003C24DE");
= +#endif
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ gc_free(&gc);
+ free_certificate(cert);
+}
+

int=
main(void)
@@ -773,7 +852,9 @@
= cmocka_unit_test(test_data_channel_roundtrip_aes_256_cbc),
cmocka_unit_test(test_data_channel_roundtrip_bf_cbc= ),
cmocka_unit_test(test_data_channel_known_vector= s_epoch),
- cmoc= ka_unit_test(test_data_channel_known_vectors_shortpktid)
+ cmocka_unit_test(test_data_cha= nnel_known_vectors_shortpktid),
+ cmocka_unit_test(crypto_test_print_cert_details)=
+
};

#if defined(ENABLE_CRYPTO_OPENSSL)=

To view, visit change 1598. To unsubscribe, or fo= r help writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iacbd8195cdedc7226bddc686ca8= dccf9f25f8842
Gerrit-Change-Number: 1598
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --pIUcYXeb35I=--