From: "cron2 (Code Review)" Date: Wed, 26 Jun 2024 09:18:21 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., gianmarco@...2726..., 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="EPUqMvvqav0="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Http-proxy: fix bug preventing proxy credentials caching List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: its_Giaan , plaisthos , flichtenheld Cc: openvpn-devel --EPUqMvvqav0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#11) to the change originally created b= y its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/523?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: Http-proxy: fix bug preventing proxy credentials caching ...................................................................... Http-proxy: fix bug preventing proxy credentials caching Caching proxy credentials was not working due to the lack of handling already defined creds in get_user_pass(), which prevented the caching from working properly. Fix this issue by getting the value of c->first_time, that indicates if we're at the first iteration of the main loop and use it as second argument of the get_user_pass_http(). Otherwise, on SIGUSR1 or SIGHUP upon instance context restart credentials would be erased every time. The nocache member has been added to the struct http_proxy_options and also a getter method to retrieve that option from ssl has been added, by doing this we're able to erase previous queried user credentials to ensure correct operation. Fixes: Trac #1187 Signed-off-by: Gianmarco De Gregori Acked-by: Gert Doering Change-Id: Ia3e06c0832c4ca0ab868c845279fb71c01a1a78a Acked-by: Frank Lichtenheld Message-Id: <20240623200551.20092-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28= 835.html Signed-off-by: Gert Doering --- M doc/man-sections/generic-options.rst M src/openvpn/init.c M src/openvpn/options.c M src/openvpn/proxy.c M src/openvpn/proxy.h M src/openvpn/ssl.c M src/openvpn/ssl.h 7 files changed, 38 insertions(+), 14 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/23/523/11 diff --git a/doc/man-sections/generic-options.rst b/doc/man-sections/generi= c-options.rst index eb9cf28..ba9376b 100644 --- a/doc/man-sections/generic-options.rst +++ b/doc/man-sections/generic-options.rst @@ -19,9 +19,6 @@ When using ``--auth-nocache`` in combination with a user/password file and ``--chroot`` or ``--daemon``, make sure to use an absolute path. - This directive does not affect the ``--http-proxy`` username/password. - It is always cached. - --cd dir Change directory to ``dir`` prior to reading any files such as configuration files, key files, scripts, etc. ``dir`` should be an diff --git a/src/openvpn/init.c b/src/openvpn/init.c index b081b2f..a49e563 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -691,6 +691,8 @@ if (c->options.ce.http_proxy_options) { + c->options.ce.http_proxy_options->first_time =3D c->first_time; + /* Possible HTTP proxy user/pass input */ c->c1.http_proxy =3D http_proxy_new(c->options.ce.http_proxy_optio= ns); if (c->c1.http_proxy) diff --git a/src/openvpn/options.c b/src/openvpn/options.c index f2c7536..dbe1425 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -1650,6 +1650,7 @@ SHOW_STR(auth_file); SHOW_STR(auth_file_up); SHOW_BOOL(inline_creds); + SHOW_BOOL(nocache); SHOW_STR(http_version); SHOW_STR(user_agent); for (i =3D 0; i < MAX_CUSTOM_HTTP_HEADER && o->custom_headers[i].name= ; i++) @@ -3151,6 +3152,11 @@ ce->flags |=3D CE_DISABLED; } + if (ce->http_proxy_options) + { + ce->http_proxy_options->nocache =3D ssl_get_auth_nocache(); + } + /* our socks code is not fully IPv6 enabled yet (TCP works, UDP not) * so fall back to IPv4-only (trac #1221) */ diff --git a/src/openvpn/proxy.c b/src/openvpn/proxy.c index ba3d87c..5de0da4 100644 --- a/src/openvpn/proxy.c +++ b/src/openvpn/proxy.c @@ -276,7 +276,7 @@ { auth_file =3D p->options.auth_file_up; } - if (p->queried_creds) + if (p->queried_creds && !static_proxy_user_pass.nocache) { flags |=3D GET_USER_PASS_PREVIOUS_CREDS_FAILED; } @@ -288,9 +288,14 @@ auth_file, UP_TYPE_PROXY, flags); - p->queried_creds =3D true; - p->up =3D static_proxy_user_pass; + static_proxy_user_pass.nocache =3D p->options.nocache; } + + /* + * Using cached credentials + */ + p->queried_creds =3D true; + p->up =3D static_proxy_user_pass; } #if 0 @@ -542,7 +547,7 @@ * we know whether we need any. */ if (p->auth_method =3D=3D HTTP_AUTH_BASIC || p->auth_method =3D=3D HTT= P_AUTH_NTLM2) { - get_user_pass_http(p, true); + get_user_pass_http(p, p->options.first_time); } #if !NTLM @@ -656,6 +661,11 @@ || p->auth_method =3D=3D HTTP_AUTH_NTLM2) { get_user_pass_http(p, false); + + if (p->up.nocache) + { + clear_user_pass_http(); + } } /* are we being called again after getting the digest server nonce in = the previous transaction? */ @@ -1036,13 +1046,6 @@ } goto error; } - - /* clear state */ - if (p->options.auth_retry) - { - clear_user_pass_http(); - } - store_proxy_authenticate(p, NULL); } /* check return code, success =3D 200 */ diff --git a/src/openvpn/proxy.h b/src/openvpn/proxy.h index a502c9d..d9e598c 100644 --- a/src/openvpn/proxy.h +++ b/src/openvpn/proxy.h @@ -57,6 +57,8 @@ const char *user_agent; struct http_custom_header custom_headers[MAX_CUSTOM_HTTP_HEADER]; bool inline_creds; /* auth_file_up is inline credentials */ + bool first_time; /* indicates if we need to wipe user creds at the fir= st iteration of the main loop */ + bool nocache; }; struct http_proxy_options_simple { diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 17078c9..e0e9591 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -335,6 +335,15 @@ } /* + * Get the password caching + */ +bool +ssl_get_auth_nocache(void) +{ + return passbuf.nocache; +} + +/* * Set an authentication token */ void diff --git a/src/openvpn/ssl.h b/src/openvpn/ssl.h index 0e2a43f..1a45048 100644 --- a/src/openvpn/ssl.h +++ b/src/openvpn/ssl.h @@ -397,6 +397,11 @@ void ssl_set_auth_nocache(void); /* + * Getter method for retrieving the auth-nocache option. + */ +bool ssl_get_auth_nocache(void); + +/* * Purge any stored authentication information, both for key files and tun= nel * authentication. If PCKS #11 is enabled, purge authentication for that t= oo. * Note that auth_token is not cleared. -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/523?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: Ia3e06c0832c4ca0ab868c845279fb71c01a1a78a Gerrit-Change-Number: 523 Gerrit-PatchSet: 11 Gerrit-Owner: its_Giaan Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --EPUqMvvqav0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #11 to the change originally c= reated by its_Giaan.

View Change

The following approvals got outdate= d and were removed: Code-Review+2 by cron2

Http-proxy: fix bug preventing proxy credentials cac=
hing

Caching proxy credentials was not working due to the
lack of= handling already defined creds in get_user_pass(),
which prevented the = caching from working properly.

Fix this issue by getting the value o= f c->first_time,
that indicates if we're at the first iterationof the main loop and use it as second argument of the
get_user_pass_ht= tp(). Otherwise, on SIGUSR1 or SIGHUP
upon instance context restart cred= entials would be erased
every time.

The nocache member has been a= dded to the struct
http_proxy_options and also a getter method to retrie= ve
that option from ssl has been added, by doing this
we're able = to erase previous queried user credentials
to ensure correct operation.<= br>
Fixes: Trac #1187
Signed-off-by: Gianmarco De Gregori <gianmar= co@...2726...>
Acked-by: Gert Doering <gert@...1296...>
Chan= ge-Id: Ia3e06c0832c4ca0ab868c845279fb71c01a1a78a
Acked-by: Frank Lichten= held <frank@...2641...>
Message-Id: <20240623200551.20092-1-ger= t@...1296...>
URL: https://www.mail-archive.com/openvpn-devel@...1096...= ourceforge.net/msg28835.html
Signed-off-by: Gert Doering <gert@...1826...= 6...>
---
M doc/man-sections/generic-options.rst
M src/openvpn/= init.c
M src/openvpn/options.c
M src/openvpn/proxy.c
M src/openvpn= /proxy.h
M src/openvpn/ssl.c
M src/openvpn/ssl.h
7 files changed, = 38 insertions(+), 14 deletions(-)

git pull ssh://gerrit.openvpn.n=
et:29418/openvpn refs/changes/23/523/11
diff --git a/doc/man-sectio=
ns/generic-options.rst b/doc/man-sections/generic-options.rst
index eb9cf28..ba9376b 100644
--- a/doc/man-sections/gen= eric-options.rst
+++ b/doc/man-sections/generic-options.rst=
@@ -19,9 +19,6 @@
When using ``--auth-n= ocache`` in combination with a user/password file
and ``= --chroot`` or ``--daemon``, make sure to use an absolute path.

- This directive= does not affect the ``--http-proxy`` username/password.
- It is always cached.
-
--cd dir
Change directory to ``dir`` prior to reading any files such as
configuration files, key files, scripts, etc. ``dir`` should = be an
diff --git a/src/openvpn/init.c b/src/openvpn/init.c<= /span>
index b081b2f..a49e563 100644
--- a/src/ope= nvpn/init.c
+++ b/src/openvpn/init.c
@@ -69= 1,6 +691,8 @@

if (c->options.ce.h= ttp_proxy_options)
{
+ c->options.ce.http_proxy_options->first= _time =3D c->first_time;
+
/* Possible HTTP proxy user/pass input */=
c->c1.http_proxy =3D http_proxy_new(c->opti= ons.ce.http_proxy_options);
if (c->c1.http_prox= y)
diff --git a/src/openvpn/options.c b/src/openvpn/options= .c
index f2c7536..dbe1425 100644
--- a/src/= openvpn/options.c
+++ b/src/openvpn/options.c
@@ -1650,6 +1650,7 @@

SHOW_STR(auth_file); SHOW_STR(auth_file_up);
SHOW_BOOL(inline_= creds);
+ SHOW_BOO= L(nocache);
SHOW_STR(http_version);
= SHOW_STR(user_agent);
for (i =3D 0; i < MAX_CUS= TOM_HTTP_HEADER && o->custom_headers[i].name; i++)
@@ -3151,6 +3152,11 @@
ce->flags |=3D CE_DIS= ABLED;
}

+ if (ce->http_proxy_options)
+ {
+ ce->http_proxy_options->nocache = =3D ssl_get_auth_nocache();
+ }
+
/* our socks code is not fully IPv6 enabled yet (TCP works,= UDP not)
* so fall back to IPv4-only (trac #1221)

*/
diff --git a/src/openvpn/proxy.c b/s= rc/openvpn/proxy.c
index ba3d87c..5de0da4 100644
= --- a/src/openvpn/proxy.c
+++ b/src/openvpn/proxy.c
@@ -276,7 +276,7 @@
{
auth_file =3D p->options.auth_file_up;

= }
- if (= p->queried_creds)
= + if (p->queried_creds && !static_proxy_user_pass.nocache= )
{
flags |=3D GET_US= ER_PASS_PREVIOUS_CREDS_FAILED;
}
@= @ -288,9 +288,14 @@
auth_file,
UP_TYPE_PROXY,
= flags);
- = p->queried_creds =3D true;
- p->up =3D static_proxy_user_pass;
+ static_proxy_user_pass.noca= che =3D p->options.nocache;

}
+
+ /*
+ * Using cached credentials
+ */
+ p->queried_creds =3D true;
+ p->up =3D static_proxy_user_pass;
}=

#if 0
@@ -542,7 +547,7 = @@
* we know whether we need any. */
= if (p->auth_method =3D=3D HTTP_AUTH_BASIC || p->auth_method =3D= =3D HTTP_AUTH_NTLM2)
{
- get_user_pass_http(p, true);
+ get_user_pass_http(p, p->= options.first_time);
}

#if !NTLM
@@ -656,6 +661,11 @@
= || p->auth_method =3D=3D HTTP_AUTH_NTLM2)
{=
get_user_pass_http(p, false);
+
+ if (p->up.nocache)
+ {
+ clear_user_pass_http();
+ }
}
=
/* are we being called again after getting the diges= t server nonce in the previous transaction? */
@@ -1036,13 = +1046,6 @@
}
goto= error;
}
-
- = /* clear state */
- = if (p->options.auth_retry)
- {
-= clear_user_pass_http();
- }
- store_proxy_authenticate(p, NULL);
}<= br>
/* check return code, success =3D 200 */

diff --git a/src/openvpn/proxy.h b/src/openvpn/proxy.h=
index a502c9d..d9e598c 100644
--- a/src/openvpn/p= roxy.h
+++ b/src/openvpn/proxy.h
@@ -57,6 += 57,8 @@
const char *user_agent;
s= truct http_custom_header custom_headers[MAX_CUSTOM_HTTP_HEADER];
= bool inline_creds; /* auth_file_up is inline credentials */
+ bool first_time; /* = indicates if we need to wipe user creds at the first iteration of the main = loop */
+ bool noc= ache;
};

struct http_pr= oxy_options_simple {
diff --git a/src/openvpn/ssl.c b/src/o= penvpn/ssl.c
index 17078c9..e0e9591 100644
= --- a/src/openvpn/ssl.c
+++ b/src/openvpn/ssl.c
<= span>@@ -335,6 +335,15 @@

}

/*
+ * Get the p= assword caching
+ */<= /span>
+bool
+ssl_get_auth_nocache(void)
+{
+ return passbuf.nocache;
+}
+
+= /*
* Set an authentication token
*/

void
diff --git a/src/openvpn/ssl.h b/src/ope= nvpn/ssl.h
index 0e2a43f..1a45048 100644
--= - a/src/openvpn/ssl.h
+++ b/src/openvpn/ssl.h
@@ -397,6 +397,11 @@
void ssl_set_auth_nocache(void);

/*
+ * Getter method for retrieving the auth-nocache option.
+ */
+bool ssl_get_auth_nocache(void);
+
+/*
* Purge any stored a= uthentication information, both for key files and tunnel
= * authentication. If PCKS #11 is enabled, purge authentication for that too= .
* Note that auth_token is not cleared.
=

To view, visit change 523. To unsubscribe, or for help writi= ng mail filters, visit setti= ngs.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia3e06c0832c4ca0ab868c845279= fb71c01a1a78a
Gerrit-Change-Number: 523
Gerrit-PatchSet: 11
Gerrit-Owner: its_Giaan <gianmarco@...2786...= ..>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--EPUqMvvqav0=--