From: "selvanair (Code Review)" Date: Mon, 19 Aug 2024 19:28:49 +0000 References: Reply-To: selva.nair@...277..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <332ae535c38386d882f4a5d5556305eb7cdfe933-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="gVo4ksGTtBM="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Add a test for loading certificate and key using file: URI List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --gVo4ksGTtBM= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/730?usp=3Demail to review the following change. Change subject: Add a test for loading certificate and key using file: URI ...................................................................... Add a test for loading certificate and key using file: URI We do not load any providers, so only file: URI internally supported by OpenSSL 3+ is tested. On non-OpenSSL 3 builds the test prints "SKIPPED". Change-Id: I7615116b5251319aa1f13d671bab7013f3a043ea Signed-off-by: Selva Nair --- M tests/unit_tests/openvpn/test_ssl.c 1 file changed, 43 insertions(+), 0 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/30/730/1 diff --git a/tests/unit_tests/openvpn/test_ssl.c b/tests/unit_tests/openvpn= /test_ssl.c index 651f302..260a7ba 100644 --- a/tests/unit_tests/openvpn/test_ssl.c +++ b/tests/unit_tests/openvpn/test_ssl.c @@ -66,6 +66,10 @@ } #endif +#if defined(ENABLE_CRYPTO_OPENSSL) && (OPENSSL_VERSION_NUMBER > 0x30000000= L) +#define HAVE_OPENSSL_STORE +#endif + /* stubs for some unused functions instead of pulling in too many dependen= cies */ bool get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *= prefix, @@ -234,6 +238,44 @@ tls_ctx_free(&ctx); } +/* test loading cert and key using file:/path URI */ +static void +test_load_certificate_and_key_uri(void **state) +{ + (void) state; + +#if !defined(HAVE_OPENSSL_STORE) + skip(); +#endif /* HAVE_OPENSSL_STORE */ + + struct tls_root_ctx ctx =3D { 0 }; + const char *certfile =3D global_state.certfile; + const char *keyfile =3D global_state.keyfile; + struct gc_arena *gc =3D &global_state.gc; + + struct buffer certuri =3D alloc_buf_gc(6 + strlen(certfile) + 1, gc); = /* 6 bytes for "file:/" */ + struct buffer keyuri =3D alloc_buf_gc(6 + strlen(keyfile) + 1, gc); = /* 6 bytes for "file:/" */ + + /* Windows temp file path starts with drive letter -- add a leading sl= ash for URI */ + const char *lead =3D ""; +#ifdef _WIN32 + lead =3D "/"; +#endif /* _WIN32 */ + assert_true(buf_printf(&certuri, "file:%s%s", lead, certfile)); + assert_true(buf_printf(&keyuri, "file:%s%s", lead, keyfile)); + + /* On Windows replace any '\' in path by '/' required for URI */ +#ifdef _WIN32 + string_mod(BSTR(&certuri), CC_ANY, CC_BACKSLASH, '/'); + string_mod(BSTR(&keyuri), CC_ANY, CC_BACKSLASH, '/'); +#endif /* _WIN32 */ + + tls_ctx_client_new(&ctx); + tls_ctx_load_cert_file(&ctx, BSTR(&certuri), false); + assert_int_equal(tls_ctx_load_priv_file(&ctx, BSTR(&keyuri), false), 0= ); + tls_ctx_free(&ctx); +} + static void init_implicit_iv(struct crypto_options *co) { @@ -452,6 +494,7 @@ const struct CMUnitTest tests[] =3D { cmocka_unit_test(crypto_pem_encode_certificate), cmocka_unit_test(test_load_certificate_and_key), + cmocka_unit_test(test_load_certificate_and_key_uri), cmocka_unit_test(test_data_channel_roundtrip_aes_128_gcm), cmocka_unit_test(test_data_channel_roundtrip_aes_192_gcm), cmocka_unit_test(test_data_channel_roundtrip_aes_256_gcm), -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/730?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I7615116b5251319aa1f13d671bab7013f3a043ea Gerrit-Change-Number: 730 Gerrit-PatchSet: 1 Gerrit-Owner: selvanair Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --gVo4ksGTtBM= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

selvanair would like plaisthos and flichtenheld to review this change.

Vi= ew Change

Add a test for loading certificate and key using file: URI
We do not load any providers, so only file: URI internally supported b= y
OpenSSL 3+ is tested. On non-OpenSSL 3 builds the test prints "SK= IPPED".

Change-Id: I7615116b5251319aa1f13d671bab7013f3a043eaSigned-off-by: Selva Nair <selva.nair@...277...>
---
M tests/u= nit_tests/openvpn/test_ssl.c
1 file changed, 43 insertions(+), 0 deletio= ns(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/change=
s/30/730/1
diff --git a/tests/unit_tests/openvpn/test_ssl.c b/tests=
/unit_tests/openvpn/test_ssl.c
index 651f302..260a7ba 10064= 4
--- a/tests/unit_tests/openvpn/test_ssl.c
+++ b/tests/unit_tests/openvpn/test_ssl.c
@@ -66,6 +66,10 = @@
}
#endif

<= span style=3D"color: hsl(120, 100%, 40%);">+#if defined(ENABLE_CRYPTO_OPENS= SL) && (OPENSSL_VERSION_NUMBER > 0x30000000L)
+#define HAVE_OPENSSL_STORE
<= span style=3D"color: hsl(120, 100%, 40%);">+#endif
+
/* stubs for some unused f= unctions instead of pulling in too many dependencies */
bo= ol
get_user_pass_cr(struct user_pass *up, const char *auth= _file, const char *prefix,
@@ -234,6 +238,44 @@
<= span> tls_ctx_free(&ctx);
}

+/* test loading cert and= key using file:/path URI */
+static void
= +test_load_certificate_and_key_uri(void **state)
+{
+ (void) state;
+
+#if !defin= ed(HAVE_OPENSSL_STORE)
+#endi= f /* HAVE_OPENSSL_STORE */
+
+ struct t= ls_root_ctx ctx =3D { 0 };
+ const char *certfile =3D global_state.certfile;
+ const char *keyfile =3D global_s= tate.keyfile;
+ st= ruct gc_arena *gc =3D &global_state.gc;
+
+ struct buffer certuri =3D alloc_buf_gc(6 + strlen(certfile) + 1, g= c); /* 6 bytes for "file:/" */
+ struct buffer keyuri =3D alloc_buf_gc(6 + strlen(k= eyfile) + 1, gc); /* 6 bytes for "file:/" */
+
+ /* Windows temp file path starts with drive letter --= add a leading slash for URI */
+ const char *lead =3D "";
+#ifdef _WIN32
+ lead =3D "/";
+#endif /* _WIN32 */
+ assert_true(buf_printf(&certuri, = "file:%s%s", lead, certfile));
+ assert_true(buf_printf(&keyuri, "file:%s%= s", lead, keyfile));
+
+ /* On Win= dows replace any '\' in path by '/' required for URI */
+#ifdef _WIN32+ string_mod(BSTR(&cert= uri), CC_ANY, CC_BACKSLASH, '/');
+ string_mod(BSTR(&keyuri), CC_ANY, CC_BACKSLAS= H, '/');
+#en= dif /* _WIN32 */
+
+ tls_ctx_client_new= (&ctx);
+ tls_= ctx_load_cert_file(&ctx, BSTR(&certuri), false);
+ assert_int_equal(tls_ctx_load_priv= _file(&ctx, BSTR(&keyuri), false), 0);
+ tls_ctx_free(&ctx);
+}
+
static void
init_implic= it_iv(struct crypto_options *co)
{
@@ -452= ,6 +494,7 @@
const struct CMUnitTest tests[] =3D {
cmocka_unit_test(crypto_pem_encode_certificate),
cmocka_unit_test(test_load_certificate_and_key),

+ cmocka_unit_test(= test_load_certificate_and_key_uri),
cmocka_unit_te= st(test_data_channel_roundtrip_aes_128_gcm),
cmock= a_unit_test(test_data_channel_roundtrip_aes_192_gcm),
= cmocka_unit_test(test_data_channel_roundtrip_aes_256_gcm),

To view, visit change 730. To unsubscribe, or for help w= riting mail filters, visit s= ettings.

=
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7615116b5251319aa1f13d671ba= b7013f3a043ea
Gerrit-Change-Number: 730
Gerrit-PatchSet: 1
Gerrit-Owner: selvanair <selva.nair@...1354...= ..>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--gVo4ksGTtBM=--