From: "its_Giaan (Code Review)"
Date: Mon, 26 Feb 2024 18:28:29 +0000
In-Reply-To:
References:
Reply-To: gianmarco@...2726..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net, frank@...2641...
Message-ID: <6bf7e0bedc10a71f08679f2e3664a0b6b5eb6d64-EmailReplacePatchSet-HTML@...2715...>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="JzbXgCjUJ/A="; charset=UTF-8
Subject: [Openvpn-devel] [S] 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
--JzbXgCjUJ/A=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/523?usp=3Demail
to look at the new patch set (#2).
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(), which prevented the caching from working
properly.
This issue has been solved by getting the c->first_time
parameter 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 at
the restart of the context instance credentials would be erase.
The nocache option 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
Change-Id: Ia3e06c0832c4ca0ab868c845279fb71c01a1a78a
---
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
6 files changed, 39 insertions(+), 2 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/23/523/2
diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index 52b4308..dc1ee8d 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -697,6 +697,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 2c79a1e..0d22df9 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -3123,6 +3123,10 @@
if (ce->proto =3D=3D PROTO_TCP)
{
ce->proto =3D PROTO_TCP_CLIENT;
+ if (ce->http_proxy_options)
+ {
+ ce->http_proxy_options->nocache =3D ssl_get_auth_nocache();
+ }
}
}
diff --git a/src/openvpn/proxy.c b/src/openvpn/proxy.c
index eeb3989..ff50539 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,6 +288,16 @@
auth_file,
UP_TYPE_PROXY,
flags);
+ static_proxy_user_pass.nocache =3D p->options.nocache;
+ p->queried_creds =3D true;
+ p->up =3D static_proxy_user_pass;
+ }
+
+ /*
+ * Using cached credentials
+ */
+ else if (!static_proxy_user_pass.nocache)
+ {
p->queried_creds =3D true;
p->up =3D static_proxy_user_pass;
}
@@ -542,7 +552,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
@@ -553,6 +563,7 @@
#endif
p->defined =3D true;
+ p->options.nocache =3D o->nocache;
return p;
}
@@ -656,6 +667,10 @@
|| 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? */
diff --git a/src/openvpn/proxy.h b/src/openvpn/proxy.h
index 4e78772..474cfc9 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 33c8670..d174dad 100644
--- a/src/openvpn/ssl.c
+++ b/src/openvpn/ssl.c
@@ -335,6 +335,15 @@
}
/*
+ * Get the password caching
+ */
+bool
+ssl_get_auth_nocache()
+{
+ return passbuf.nocache;
+}
+
+/*
* Set an authentication token
*/
void
diff --git a/src/openvpn/ssl.h b/src/openvpn/ssl.h
index 71b99db..dd6538c 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();
+
+/*
* 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: 2
Gerrit-Owner: its_Giaan
Gerrit-Reviewer: flichtenheld
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-Attention: plaisthos
Gerrit-Attention: its_Giaan
Gerrit-MessageType: newpatchset
--JzbXgCjUJ/A=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: its_Giaan, plaisthos.
its_Giaan uploaded patch set #2 to this change.
<=
a href=3D"http://gerrit.openvpn.net/c/openvpn/+/523?usp=3Demail">View Chang=
e
Http-proxy: fix bug preventing proxy credentials caching
Previ=
ously, the caching of proxy credentials was not working
due to the missi=
ng of handling already defined creds in
get_user_pass(), which prevented=
the caching from working
properly.
This issue has been solved by=
getting the c->first_time
parameter that indicates if we're at t=
he first iteration
of the main loop and use it as second argument of the=
get_user_pass_http() otherwise on SIGUSR1 or SIGHUP at
the restart o=
f the context instance credentials would be erase.
The nocache optio=
n has been added to the struct
http_proxy_options and also a getter meth=
od to retrieve
that option from ssl has been added, by doing this
we&=
#39;re able to erase previous queried user credentials
to ensure correct=
operation.
Fixes: Trac #1187
Signed-off-by: Gianmarco De Gregori=
<gianmarco@...2726...>
Change-Id: Ia3e06c0832c4ca0ab868c845279fb7=
1c01a1a78a
---
M src/openvpn/init.c
M src/openvpn/options.c
M s=
rc/openvpn/proxy.c
M src/openvpn/proxy.h
M src/openvpn/ssl.c
M src=
/openvpn/ssl.h
6 files changed, 39 insertions(+), 2 deletions(-)
=
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/23/523/2
=
diff --git a/src/openvpn/init.c b/src/openvpn/init.c
=
index 52b4308..dc1ee8d 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -697,6 +697,8 @@
if (c->options.ce.http_proxy_option=
s)
{
+ c->options.ce.http_proxy_options->first_time =3D c->=
first_time;
+<=
br> /* Possible HTTP proxy user/pass input */
c->c1.http_proxy =3D http_proxy_new(c->options.ce.http_prox=
y_options);
if (c->c1.http_proxy)
diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 2c79a1e..0d22df9 100644
--- a/src/openvpn/options.=
c
+++ b/src/openvpn/options.c
@@ -3123,6 +3=
123,10 @@
if (ce->proto =3D=3D PROTO_TCP)
{
ce->proto =3D PROTO_T=
CP_CLIENT;
+ =
if (ce->http_proxy_options)
+ {
+ ce->http_proxy_options->nocache =3D ssl_get_a=
uth_nocache();
+ =
}
}
}
=
diff --git a/src/openvpn/proxy.c b/src/openvpn/proxy.c
index eeb3989..ff50539 100644
--- a/src/openv=
pn/proxy.c
+++ b/src/openvpn/proxy.c
@@ -27=
6,7 +276,7 @@
{
auth_=
file =3D p->options.auth_file_up;
}
<=
span style=3D"color: hsl(0, 100%, 40%);">- if (p->queried_creds)<=
/span>
+ if (p->qu=
eried_creds && !static_proxy_user_pass.nocache)
=
{
flags |=3D GET_USER_PASS_PREVIOUS_CRED=
S_FAILED;
}
@@ -288,6 +288,16 @@=
span>
auth_file,
=
UP_TYPE_PROXY,
flags);<=
/span>
+ static_proxy=
_user_pass.nocache =3D p->options.nocache;
+ p->queried_creds =3D true;
<=
span style=3D"color: hsl(120, 100%, 40%);">+ p->up =3D static_pro=
xy_user_pass;
+ }<=
/span>
+
+ /*
+ * Using cached credentials
+ */
+ else if (!static_proxy_user_pass.nocache)=
+ {
=
p->queried_creds =3D true;
p->up =3D st=
atic_proxy_user_pass;
}
@@ -542,7 +552=
,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-&=
gt;options.first_time);
}
=
#if !NTLM
@@ -553,6 +563,7 @@
#endi=
f
p->defined =3D true;
=
+ p->options.nocache =3D =
o->nocache;
return p;
}
=
@@ -656,6 +667,10 @@
|| 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 get=
ting the digest server nonce in the previous transaction? */
diff --git a/src/openvpn/proxy.h b/src/openvpn/proxy.h
in=
dex 4e78772..474cfc9 100644
--- a/src/openvpn/proxy.h
+++ b/src/openvpn/proxy.h
@@ -57,6 +57,8 @@
const char *user_agent;
struct http_c=
ustom_header custom_headers[MAX_CUSTOM_HTTP_HEADER];
b=
ool 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 nocache;=
};
struct http_proxy_options_=
simple {
diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c=
index 33c8670..d174dad 100644
--- a/src/op=
envpn/ssl.c
+++ b/src/openvpn/ssl.c
@@ -335=
,6 +335,15 @@
}
/*
+ * Get the password cach=
ing
+ */
+bool
+ssl_get_auth_nocache()
+{
+ return passbuf.nocache;
+}
+
+/*
* Set an authentication token
*/
vo=
id
diff --git a/src/openvpn/ssl.h b/src/openvpn/ssl.h
index 71b99db..dd6538c 100644
--- a/src/openvpn/=
ssl.h
+++ b/src/openvpn/ssl.h
@@ -397,6 +39=
7,11 @@
void ssl_set_auth_nocache(void);
=
/*
=
+ * Getter method for retrieving the auth-nocache option.
+ */
+bool ssl_get_auth_nocache();
+
+/*
* Purge any stored authentication informat=
ion, both for key files and tunnel
* authentication. If P=
CKS #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 writing mail filters, visit=
settings.
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia3e06c0832c4ca0ab868c845279=
fb71c01a1a78a
Gerrit-Change-Number: 523
Gerrit-PatchSet: 2
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: its_Giaan <gianmarco@...1665...=
726...>
Gerrit-MessageType: newpatchset
--JzbXgCjUJ/A=--