From: "its_Giaan (Code Review)" Date: Thu, 15 Feb 2024 10:01:31 +0000 References: Reply-To: gianmarco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <10eb2954e1a1f458c3f7b920ca2b395e0dccddbd-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="aVCySFP9XWc="; 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: plaisthos , flichtenheld Cc: openvpn-devel --aVCySFP9XWc= 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/+/523?usp=3Demail to review the following change. Change subject: Http-proxy: Fix bug preventing proxy credentials caching. ...................................................................... Http-proxy: Fix bug preventing proxy credentials caching. Previously, the caching of proxy credentials was not working due to the missing of handling already defined creds in get_user_pass_http(), which prevented the caching from working correctly. This issue has been solved by rewriting the get_user_pass_http(). This method now sets the appropriate flags based on whether credentials are defined, have been queried before, or are inline. It then calls the get_user_pass() to retrieve the credentials and store them in a static variable, 'static_proxy_user_pass', which will be used for subsequent requests. If credentials were not previously defined, or caching is not allowed, creds are queried again. Fixes: Trac #1187 Change-Id: Ia3e06c0832c4ca0ab868c845279fb71c01a1a78a Signed-off-by: Gianmarco De Gregori --- M src/openvpn/options.c M src/openvpn/proxy.c M src/openvpn/proxy.h 3 files changed, 31 insertions(+), 27 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/23/523/1 diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 2c79a1e..3f5301f 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -1858,6 +1858,7 @@ SHOW_BOOL(persist_local_ip); SHOW_BOOL(persist_remote_ip); SHOW_BOOL(persist_key); + SHOW_BOOL(ce.http_proxy_options->nocache); #if PASSTOS_CAPABILITY SHOW_BOOL(passtos); @@ -8978,6 +8979,7 @@ { VERIFY_PERMISSION(OPT_P_GENERAL); ssl_set_auth_nocache(); + options->ce.http_proxy_options->nocache =3D true; } else if (streq(p[0], "auth-token") && p[1] && !p[2]) { diff --git a/src/openvpn/proxy.c b/src/openvpn/proxy.c index eeb3989..a4af720 100644 --- a/src/openvpn/proxy.c +++ b/src/openvpn/proxy.c @@ -257,40 +257,41 @@ } static void -get_user_pass_http(struct http_proxy_info *p, const bool force) +get_user_pass_http(struct http_proxy_info *p) { - /* - * in case of forced (re)load, make sure the static storage is set as - * undefined, otherwise get_user_pass() won't try to load any credenti= al - */ - if (force) + static bool is_first_time =3D true; + unsigned int flags =3D GET_USER_PASS_MANAGEMENT; + + if (p->queried_creds && !p->options.nocache) { - clear_user_pass_http(); + flags |=3D GET_USER_PASS_PREVIOUS_CREDS_FAILED; } - if (!static_proxy_user_pass.defined) + if (p->options.inline_creds) { - unsigned int flags =3D GET_USER_PASS_MANAGEMENT; - const char *auth_file =3D p->options.auth_file; - if (p->options.auth_file_up) - { - auth_file =3D p->options.auth_file_up; - } - if (p->queried_creds) - { - flags |=3D GET_USER_PASS_PREVIOUS_CREDS_FAILED; - } - if (p->options.inline_creds) - { - flags |=3D GET_USER_PASS_INLINE_CREDS; - } + flags |=3D GET_USER_PASS_INLINE_CREDS; + } + + if (!static_proxy_user_pass.defined || (is_first_time && !p->options.n= ocache) ) + { get_user_pass(&static_proxy_user_pass, - auth_file, + p->options.auth_file, UP_TYPE_PROXY, flags); - p->queried_creds =3D true; - p->up =3D static_proxy_user_pass; + is_first_time =3D false; } + + else + { + get_user_pass(&static_proxy_user_pass, + p->options.auth_file, + UP_TYPE_PROXY, + flags); + static_proxy_user_pass.defined =3D !p->options.nocache; + } + + p->queried_creds =3D true; + p->up =3D static_proxy_user_pass; } #if 0 @@ -542,7 +543,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); } #if !NTLM @@ -655,7 +656,7 @@ || p->auth_method =3D=3D HTTP_AUTH_DIGEST || p->auth_method =3D=3D HTTP_AUTH_NTLM2) { - get_user_pass_http(p, false); + get_user_pass_http(p); } /* are we being called again after getting the digest server nonce in = the previous transaction? */ diff --git a/src/openvpn/proxy.h b/src/openvpn/proxy.h index 4e78772..b8b4ca9 100644 --- a/src/openvpn/proxy.h +++ b/src/openvpn/proxy.h @@ -57,6 +57,7 @@ const char *user_agent; struct http_custom_header custom_headers[MAX_CUSTOM_HTTP_HEADER]; bool inline_creds; /* auth_file_up is inline credentials */ + bool nocache; }; struct http_proxy_options_simple { -- 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: 1 Gerrit-Owner: its_Giaan Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --aVCySFP9XWc= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

its_Giaan would like plaisthos and flichtenheld to review this change.

Vi= ew Change

Http-proxy: Fix bug preventing proxy credentials caching.
=
Previously, the caching of proxy credentials was not working
due to = the missing of handling already defined creds in
get_user_pass_http(), w= hich prevented the caching from working correctly.

This issue has be= en solved by rewriting the get_user_pass_http().
This method now sets th= e appropriate flags based on whether
credentials are defined, have been = queried before, or are inline.
It then calls the get_user_pass() to retr= ieve the credentials
and store them in a static variable, 'static_pr= oxy_user_pass',
which will be used for subsequent requests. If crede= ntials
were not previously defined, or caching is not allowed, creds
= are queried again.

Fixes: Trac #1187
Change-Id: Ia3e06c0832c4ca0a= b868c845279fb71c01a1a78a
Signed-off-by: Gianmarco De Gregori <gianmar= co@...2726...>
---
M src/openvpn/options.c
M src/openvpn/proxy.= c
M src/openvpn/proxy.h
3 files changed, 31 insertions(+), 27 deletio= ns(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/change=
s/23/523/1
diff --git a/src/openvpn/options.c b/src/openvpn/options=
.c
index 2c79a1e..3f5301f 100644
--- a/src/= openvpn/options.c
+++ b/src/openvpn/options.c
@@ -1858,6 +1858,7 @@
SHOW_BOOL(persist_local_ip);<= /span>
SHOW_BOOL(persist_remote_ip);
SHO= W_BOOL(persist_key);
= + SHOW_BOOL(ce.http_proxy_options->nocache);
=
#if PASSTOS_CAPABILITY
SHOW_BOOL(passtos);<= /span>
@@ -8978,6 +8979,7 @@
{
VERIFY_PERMISSION(OPT_P_GENERAL);

ssl_s= et_auth_nocache();
+ = options->ce.http_proxy_options->nocache =3D true;
}

else if (streq(p[0], "auth-token"= ) && p[1] && !p[2])
{
= diff --git a/src/openvpn/proxy.c b/src/openvpn/proxy.c
inde= x eeb3989..a4af720 100644
--- a/src/openvpn/proxy.c<= br>+++ b/src/openvpn/proxy.c
@@ -257,40 +257,41 @@
}

static void
<= span style=3D"color: hsl(0, 100%, 40%);">-get_user_pass_http(struct http_pr= oxy_info *p, const bool force)

+get_user_pass_http(struct http_proxy_info *p)
{=
- /*
- * in case of forced (re)load, m= ake sure the static storage is set as
- * undefined, otherwise get_user_pass() won't try t= o load any credential
-= */
- if (force)=
+ static bool is_= first_time =3D true;
= + unsigned int flags =3D GET_USER_PASS_MANAGEMENT;
+
+ if (p->queried_creds && !p->options.nocach= e)
{
- clear_user_pass_http();
+ flags |=3D GET_USER_PASS_PREVIOUS_CREDS_FAILED;

}

- if (!static_proxy_user_pass.defined)
+ if (p->options.inline_creds)
{
- = unsigned int flags =3D GET_USER_PASS_MANAGEMENT;
- const char *auth_file =3D p->o= ptions.auth_file;
- = if (p->options.auth_file_up)
- {
- auth_file =3D p->options.auth_file_up;
- }
- if (p->queried_creds)
- {
- flags |=3D GET_USER_PASS_PREVIOUS_CREDS_FA= ILED;
- }=
- if (p->options.in= line_creds)
- {<= /span>
- flags |=3D= GET_USER_PASS_INLINE_CREDS;
- }
+ = flags |=3D GET_USER_PASS_INLINE_CREDS;
+ }
+
+ if (!= static_proxy_user_pass.defined || (is_first_time && !p->options.= nocache) )
+ {
get_user_pass(&static_proxy_user_pass,
= - auth_file,=
+ = p->options.auth_file,
UP_TYPE_= PROXY,
flags);
- p->queried_creds =3D true;
- p->up =3D static= _proxy_user_pass;
+ = is_first_time =3D false;
}
+
+ else
+ {
+ ge= t_user_pass(&static_proxy_user_pass,
+ p->options.auth_file,<= br>+ UP_TY= PE_PROXY,
+ = flags);
+= static_proxy_user_pass.defined =3D !p->options.nocache;+ }
+
+ p->queried_creds =3D true;
+ p->up =3D static_proxy_user_pass;
}

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

#if !NTLM<= /span>
@@ -655,7 +656,7 @@
|| p->auth_= method =3D=3D HTTP_AUTH_DIGEST
|| p->auth_metho= d =3D=3D HTTP_AUTH_NTLM2)
{
- get_user_pass_http(p, false);
= + get_user_pass_http(p);=
}

/* are we be= ing called again after getting the digest server nonce in the previous tran= saction? */
diff --git a/src/openvpn/proxy.h b/src/openvpn/= proxy.h
index 4e78772..b8b4ca9 100644
--- a= /src/openvpn/proxy.h
+++ b/src/openvpn/proxy.h
@@ -57,6 +57,7 @@

const char *user_agent; struct http_custom_header custom_headers[MAX_CUSTOM_HTTP_HEADE= R];
bool inline_creds; /* auth_file_up is inline crede= ntials */
+ bool n= ocache;
};

struct http_= proxy_options_simple {

To view, visit <= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/523?usp=3Demail">change 523= . To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia3e06c0832c4ca0ab868c845279= fb71c01a1a78a
Gerrit-Change-Number: 523
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <gianmarco@...2786...= ..>
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
--aVCySFP9XWc=--