From: "cron2 (Code Review)" Date: Mon, 9 Sep 2024 06:56:26 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., selva.nair@...277..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <193504180e05c2d9a10354a0766edda07506cb48-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="+8/v/l3pXWg="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Static-challenge concatenation option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: selvanair , plaisthos , flichtenheld Cc: openvpn-devel --+8/v/l3pXWg= 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= selvanair. ( http://gerrit.openvpn.net/c/openvpn/+/665?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by flichtenheld Change subject: Static-challenge concatenation option ...................................................................... Static-challenge concatenation option Extend "--static-challenge" option to take a third argument (=3D scrv1 or concat) to specify that the password and response should be concatenated instead of using the SCRV1 protocol. If unspecified, it defaults to "scrv1" meaning that the SCRV1 protocol should be used. v2: use scrv1|concat instead of 0|1 as option argument fix typos v3: improve and correct documentation in management-notes.txt Change-Id: I59a90446bfe73d8856516025a58a6f62cc98ab0d Signed-off-by: Selva Nair Acked-by: Frank Lichtenheld Message-Id: <20240719131407.75746-1-frank@...2641...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28= 943.html Signed-off-by: Gert Doering --- M doc/man-sections/client-options.rst M doc/management-notes.txt M src/openvpn/manage.c M src/openvpn/misc.c M src/openvpn/misc.h M src/openvpn/options.c M src/openvpn/ssl.c 7 files changed, 70 insertions(+), 20 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/65/665/4 diff --git a/doc/man-sections/client-options.rst b/doc/man-sections/client-= options.rst index b75fe5b..a06948e 100644 --- a/doc/man-sections/client-options.rst +++ b/doc/man-sections/client-options.rst @@ -541,12 +541,15 @@ Valid syntax: :: - static-challenge text echo + static-challenge text echo [format] The ``text`` challenge text is presented to the user which describes what information is requested. The ``echo`` flag indicates if the user's input should be echoed on the screen. Valid ``echo`` values are - :code:`0` or :code:`1`. + :code:`0` or :code:`1`. The optional ``format`` indicates whether + the password and response should be combined using the SCRV1 protocol + (``format`` =3D :code:`scrv1`) or simply concatenated (``format`` =3D :c= ode:`concat`). + :code:`scrv1` is the default. See management-notes.txt in the OpenVPN distribution for a description of the OpenVPN challenge/response protocol. diff --git a/doc/management-notes.txt b/doc/management-notes.txt index b9947fa..b55135a 100644 --- a/doc/management-notes.txt +++ b/doc/management-notes.txt @@ -1320,14 +1320,20 @@ OpenVPN's --static-challenge option is used to provide the challenge text to OpenVPN and indicate whether or not the response -should be echoed. +should be echoed and how the response should be combined with the +password. When credentials are needed and the --static-challenge option is used, the management interface will send: - >PASSWORD:Need 'Auth' username/password SC:, + >PASSWORD:Need 'Auth' username/password SC:, - ECHO: "1" if response should be echoed, "0" to not echo + flag: an integer whose least significant bit is the ECHO flag and + the next significant bit is the FORMAT flag. + ECHO =3D (flag & 0x1) is 1 if response should be echoed, 0 to not = echo + FORMAT =3D (flag & 0x2) is 1 if response should be concatenated wi= th + password as plain text, 0 if response and password should be encod= ed + as described below. Thus flag could take values 0, 1, 2, or 3. TEXT: challenge text that should be shown to the user to facilitate their response @@ -1342,8 +1348,9 @@ The management interface client in this case should add the static challenge text to the auth dialog followed by a field for the user to -enter a response. Then the management interface client should pack the -password and response together into an encoded password and send: +enter a response. If flag =3D 0 or 1 (i.e., FORMAT=3D0), the management +interface client should pack the password and response together into +an encoded password and send: username "Auth" password "Auth" "SCRV1::" @@ -1354,6 +1361,12 @@ the user. The and/or the can be empty strings. +If flag =3D 2 or 3 (i.e., FORMAT=3D1), the client should simply concatenate +password and response with no separator and send: + + username "Auth" + password "Auth" "" + (As in all username/password responses described in the "COMMAND -- password and username" section above, the username can be in quotes, and special characters such as double quotes or backslashes must be @@ -1361,10 +1374,15 @@ For example, if user "foo" entered "bar" as the password and 8675309 as the PIN, the following management interface commands should be -issued: +issued if flag =3D 0 or 1 (i.e., FORMAT =3D 0): username "Auth" foo password "Auth" "SCRV1:YmFy:ODY3NTMwOQ=3D=3D" ("YmFy" is the base 64 encoding of "bar" and "ODY3NTMwOQ=3D=3D" is the base 64 encoding of "8675309".) + +or, if flag =3D 2 or 3 (i.e., FORMAT =3D 1): + + username "Auth" foo + password "Auth" "bar8675309" diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index 24f3121..05b5a1a 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -3544,7 +3544,8 @@ if (sc) { buf_printf(&alert_msg, " SC:%d,%s", - BOOL_CAST(flags & GET_USER_PASS_STATIC_CHALLENGE_EC= HO), + BOOL_CAST(flags & GET_USER_PASS_STATIC_CHALLENGE_EC= HO) + |(BOOL_CAST(flags & GET_USER_PASS_STATIC_CHALLENGE_= CONCAT) << 1), sc); } diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c index ef4ab69..70ba5e4 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -439,17 +439,28 @@ { msg(M_FATAL, "ERROR: could not retrieve static cha= llenge response"); } - if (openvpn_base64_encode(up->password, strlen(up->pas= sword), &pw64) =3D=3D -1 - || openvpn_base64_encode(response, strlen(response= ), &resp64) =3D=3D -1) + if (!(flags & GET_USER_PASS_STATIC_CHALLENGE_CONCAT)) { - msg(M_FATAL, "ERROR: could not base64-encode passw= ord/static_response"); + if (openvpn_base64_encode(up->password, strlen(up-= >password), &pw64) =3D=3D -1 + || openvpn_base64_encode(response, strlen(resp= onse), &resp64) =3D=3D -1) + { + msg(M_FATAL, "ERROR: could not base64-encode p= assword/static_response"); + } + buf_set_write(&packed_resp, (uint8_t *)up->passwor= d, USER_PASS_LEN); + buf_printf(&packed_resp, "SCRV1:%s:%s", pw64, resp= 64); + string_clear(pw64); + free(pw64); + string_clear(resp64); + free(resp64); } - buf_set_write(&packed_resp, (uint8_t *)up->password, U= SER_PASS_LEN); - buf_printf(&packed_resp, "SCRV1:%s:%s", pw64, resp64); - string_clear(pw64); - free(pw64); - string_clear(resp64); - free(resp64); + else + { + if (strlen(up->password) + strlen(response) >=3D U= SER_PASS_LEN) + { + msg(M_FATAL, "ERROR: could not concatenate pas= sword/static_response: string too long"); + } + strncat(up->password, response, USER_PASS_LEN - st= rlen(up->password) - 1); + } } #endif /* ifdef ENABLE_MANAGEMENT */ } diff --git a/src/openvpn/misc.h b/src/openvpn/misc.h index a967ec8..cdfb0de 100644 --- a/src/openvpn/misc.h +++ b/src/openvpn/misc.h @@ -92,6 +92,7 @@ */ struct static_challenge_info { #define SC_ECHO (1<<0) /* echo response when typed by user */ +#define SC_CONCAT (1<<1) /* concatenate password and response and do no= t base64 encode */ unsigned int flags; const char *challenge_text; @@ -118,6 +119,7 @@ #define GET_USER_PASS_STATIC_CHALLENGE_ECHO (1<<9) /* SCRV1 protocol -- e= cho response */ #define GET_USER_PASS_INLINE_CREDS (1<<10) /* indicates that auth_file is= actually inline creds */ +#define GET_USER_PASS_STATIC_CHALLENGE_CONCAT (1<<11) /* indicates passwo= rd and response should be concatenated */ /** * Retrieves the user credentials from various sources depending on the fl= ags. diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 36105ce..649f48b 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -518,8 +518,10 @@ " Add domains to DNS domain search list\n" "--auth-retry t : How to handle auth failures. Set t to\n" " none (default), interact, or nointeract.\n" - "--static-challenge t e : Enable static challenge/response protocol us= ing\n" + "--static-challenge t e []: Enable static challenge/resp= onse protocol using\n" " challenge text t, with e indicating echo flag (0|1)= \n" + " and optional argument scrv1 or concat to use SCRV1 = protocol or" + " concatenate response with password. Default is scrv= 1.\n" "--connect-timeout n : when polling possible remote servers to connect= to\n" " in a round-robin fashion, spend no more than n seco= nds\n" " waiting for a response before trying the next serve= r.\n" @@ -7948,7 +7950,7 @@ auth_retry_set(msglevel, p[1]); } #ifdef ENABLE_MANAGEMENT - else if (streq(p[0], "static-challenge") && p[1] && p[2] && !p[3]) + else if (streq(p[0], "static-challenge") && p[1] && p[2] && !p[4]) { VERIFY_PERMISSION(OPT_P_GENERAL); options->sc_info.challenge_text =3D p[1]; @@ -7956,6 +7958,15 @@ { options->sc_info.flags |=3D SC_ECHO; } + if (p[3] && streq(p[3], "concat")) + { + options->sc_info.flags |=3D SC_CONCAT; + } + else if (p[3] && !streq(p[3], "scrv1")) + { + msg(msglevel, "--static-challenge: unknown format indicator '%= s'", p[3]); + goto err; + } } #endif else if (streq(p[0], "msg-channel") && p[1]) diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index c2c9c29..8c72d0b 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -315,6 +315,10 @@ { flags |=3D GET_USER_PASS_STATIC_CHALLENGE_ECHO; } + if (sci->flags & SC_CONCAT) + { + flags |=3D GET_USER_PASS_STATIC_CHALLENGE_CONCAT; + } get_user_pass_cr(&auth_user_pass, auth_file, UP_TYPE_AUTH, -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/665?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: I59a90446bfe73d8856516025a58a6f62cc98ab0d Gerrit-Change-Number: 665 Gerrit-PatchSet: 4 Gerrit-Owner: selvanair Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: cron2 Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --+8/v/l3pXWg= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #4 to the change originally cr= eated by selvanair.

View Change

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

Static-challenge concatenation option

= Extend "--static-challenge" option to take a third
argument (= =3D scrv1 or concat) to specify that the password and
response should be= concatenated instead of using the
SCRV1 protocol. If unspecified, it de= faults to "scrv1"
meaning that the SCRV1 protocol should be us= ed.

v2: use scrv1|concat instead of 0|1 as option argument
fi= x typos
v3: improve and correct documentation in management-notes.txt
Change-Id: I59a90446bfe73d8856516025a58a6f62cc98ab0d
Signed-off-by:= Selva Nair <selva.nair@...277...>
Acked-by: Frank Lichtenheld <= ;frank@...2641...>
Message-Id: <20240719131407.75746-1-frank@...2375...= 41...>
URL: https://www.mail-archive.com/openvpn-devel@...1357...= rge.net/msg28943.html
Signed-off-by: Gert Doering <gert@...1296...>= ;
---
M doc/man-sections/client-options.rst
M doc/management-notes= .txt
M src/openvpn/manage.c
M src/openvpn/misc.c
M src/openvpn/mis= c.h
M src/openvpn/options.c
M src/openvpn/ssl.c
7 files changed, 7= 0 insertions(+), 20 deletions(-)

git pull ssh://gerrit.openvpn.ne=
t:29418/openvpn refs/changes/65/665/4
diff --git a/doc/man-sections=
/client-options.rst b/doc/man-sections/client-options.rst
i= ndex b75fe5b..a06948e 100644
--- a/doc/man-sections/client-= options.rst
+++ b/doc/man-sections/client-options.rst
@@ -541,12 +541,15 @@
Valid syntax: ::

- static-challenge text echo
+ static-challenge text echo [format]

The ``text`` challenge text is presented to the use= r which describes what
information is requested. The ``= echo`` flag indicates if the user's
input should be = echoed on the screen. Valid ``echo`` values are
- :code:`0` or :code:`1`.
+ :code:`0` or :code:`1`. The optional ``= format`` indicates whether
+ the password and response should be combined using the SCRV1 proto= col
+ (``format`` = =3D :code:`scrv1`) or simply concatenated (``format`` =3D :code:`concat`).<= /span>
+ :code:`scrv1` is t= he default.

See management-notes.txt i= n the OpenVPN distribution for a description of
the Open= VPN challenge/response protocol.
diff --git a/doc/managemen= t-notes.txt b/doc/management-notes.txt
index b9947fa..b5513= 5a 100644
--- a/doc/management-notes.txt
++= + b/doc/management-notes.txt
@@ -1320,14 +1320,20 @@=

OpenVPN's --static-challenge option is use= d to provide the
challenge text to OpenVPN and indicate wh= ether or not the response
-should be echoed.
+should be echoed and how the response should be combined with the<= br>+password.
=
When credentials are needed and the --static-challenge op= tion is
used, the management interface will send:
- >PASSWO= RD:Need 'Auth' username/password SC:<ECHO>,<TEXT>
+ >PASSWORD:Need '= Auth' username/password SC:<flag>,<TEXT>
<= /span>
- ECHO: "1" = if response should be echoed, "0" to not echo
+ flag: an integer whose least signific= ant bit is the ECHO flag and
+ the next significant bit is the FORMAT flag.
+ ECHO =3D (flag & 0x1)= is 1 if response should be echoed, 0 to not echo

+ FORMAT =3D (flag & 0x2) is 1 if r= esponse should be concatenated with
+ password as plain text, 0 if response and password = should be encoded
+ = as described below. Thus flag could take values 0, 1, 2, or 3.=
TEXT: challenge text that should be shown to the user to
facilitate their response

@@ -1342,8 +1348,9 @@


The management = interface client in this case should add the static
challe= nge text to the auth dialog followed by a field for the user to
<= span style=3D"color: hsl(0, 100%, 40%);">-enter a response. Then the manag= ement interface client should pack the

-password and response together into an encoded password an= d send:
+enter a resp= onse. If flag =3D 0 or 1 (i.e., FORMAT=3D0), the management
+interface client should pack the pa= ssword and response together into

+an encoded password and send:

username "Auth" <username>
passwor= d "Auth" "SCRV1:<password_base64>:<response_base64&= gt;"
@@ -1354,6 +1361,12 @@
the user.= The <password_base64> and/or the <response_base64> can be
empty strings.

+If flag =3D 2 or 3 (i.e., FORMAT=3D1), the client= should simply concatenate
+password and response with no separator and send:
+
+ username "Auth" <username>
+ password "Auth" &quo= t;<password><response>"

+
(As in all username/password respons= es described in the "COMMAND --
password and username= " section above, the username can be in quotes,
and s= pecial characters such as double quotes or backslashes must be
@@ -1361,10 +1374,15 @@

For example,= if user "foo" entered "bar" as the password and 867530= 9
as the PIN, the following management interface commands = should be
-issued:
+issued if flag =3D 0 or = 1 (i.e., FORMAT =3D 0):

username "= ;Auth" foo
password "Auth" "SCRV1:Ym= Fy:ODY3NTMwOQ=3D=3D"

("YmFy&= quot; is the base 64 encoding of "bar" and "ODY3NTMwOQ=3D=3D= " is the
base 64 encoding of "8675309".)=
+
+or, if flag =3D 2 or 3 (i.e., FORMAT = =3D 1):
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ username "Auth" foo=

+ password "Au= th" "bar8675309"
diff --git a/src/openvpn/ma= nage.c b/src/openvpn/manage.c
index 24f3121..05b5a1a 100644=
--- a/src/openvpn/manage.c
+++ b/src/openv= pn/manage.c
@@ -3544,7 +3544,8 @@
= if (sc)
{
buf_printf(= &alert_msg, " SC:%d,%s",
- BOOL_CAST(flags & GET_USER_PASS= _STATIC_CHALLENGE_ECHO),
+ BOOL_CAST(flags & GET_USER_PASS_STATIC_CHAL= LENGE_ECHO)
+ = |(BOOL_CAST(flags & GET_USER_PASS_STATIC_CHALLENGE_CONCA= T) << 1),
sc);
}

diff --git a/src/openvpn/mis= c.c b/src/openvpn/misc.c
index ef4ab69..70ba5e4 100644

--- a/src/openvpn/misc.c
+++ b/src/openvpn/misc= .c
@@ -439,17 +439,28 @@
= {
msg(M_FATAL, "ERROR: cou= ld not retrieve static challenge response");
= }
- = if (openvpn_base64_encode(up->password, strlen(up->passwo= rd), &pw64) =3D=3D -1
- || openvpn_base64_encode(response, strlen(respo= nse), &resp64) =3D=3D -1)
+ if (!(flags & GET_USER_PASS_STATIC_CHALLE= NGE_CONCAT))
{
- msg(M_FATAL, "= ERROR: could not base64-encode password/static_response");
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (ope= nvpn_base64_encode(up->password, strlen(up->password), &pw64) =3D= =3D -1
+ = || openvpn_base64_encode(response, strlen(response), &re= sp64) =3D=3D -1)
+ = {
+ }
+ buf_set_write(&packed_= resp, (uint8_t *)up->password, USER_PASS_LEN);
+ buf_printf(&packe= d_resp, "SCRV1:%s:%s", pw64, resp64);
+ string_clear(pw64);

+ = free(pw64);
+ = string_clear(resp64);
+ free(resp64);
= }
- = buf_set_write(&packed_resp, (uint8_t *)up->passwo= rd, USER_PASS_LEN);
- = buf_printf(&packed_resp, "SCRV1:%s:%s", pw6= 4, resp64);
- = string_clear(pw64);
- free(pw64);
- string_clear(resp64);
- free(resp64);
+ els= e
+ = {
+ = if (strlen(up->password) + strlen(response) >=3D USER_PASS_LE= N)
+ = {
+ = msg(M_FATAL, "ERROR: could not concatenate password/s= tatic_response: string too long");
+ }
+ strncat(up->password, = response, USER_PASS_LEN - strlen(up->password) - 1);
+ }
= }
#endif /* ifdef ENABLE_MANAGEMENT */
}
diff --git a/src/openvpn/misc.h= b/src/openvpn/misc.h
index a967ec8..cdfb0de 100644<= br>--- a/src/openvpn/misc.h
+++ b/src/openvpn/misc.h<= /span>
@@ -92,6 +92,7 @@
*/
str= uct static_challenge_info {
#define SC_ECHO (1<<= 0) /* echo response when typed by user */
+#define SC_CONCAT (1<<1) /* concatenate pas= sword and response and do not base64 encode */
unsigne= d int flags;

const char *challenge_t= ext;
@@ -118,6 +119,7 @@
#define GET_USER_= PASS_STATIC_CHALLENGE_ECHO (1<<9) /* SCRV1 protocol -- echo response= */

#define GET_USER_PASS_INLINE_CREDS (= 1<<10) /* indicates that auth_file is actually inline creds */

+#define GET_USER_PASS_STA= TIC_CHALLENGE_CONCAT (1<<11) /* indicates password and response shou= ld be concatenated */

/**
* Retrieves the user credentials from various sources depending on the = flags.
diff --git a/src/openvpn/options.c b/src/openvpn/opt= ions.c
index 36105ce..649f48b 100644
--- a/= src/openvpn/options.c
+++ b/src/openvpn/options.c@@ -518,8 +518,10 @@
" Ad= d domains to DNS domain search list\n"
"--au= th-retry t : How to handle auth failures. Set t to\n"
" none (default), interact, or nointeract.\n&q= uot;
- "--stati= c-challenge t e : Enable static challenge/response protocol using\n"
+ "--static-ch= allenge t e [<scrv1|concat>]: Enable static challenge/response protoc= ol using\n"
" challenge tex= t t, with e indicating echo flag (0|1)\n"
+ " and optional argumen= t scrv1 or concat to use SCRV1 protocol or"
+ " concatenate respon= se with password. Default is scrv1.\n"
"--co= nnect-timeout n : when polling possible remote servers to connect to\n"= ;
" in a round-robin fashion, sp= end no more than n seconds\n"
" = waiting for a response before trying the next server.\n"@@ -7948,7 +7950,7 @@
auth_retry_set(msgle= vel, p[1]);
}
#ifdef ENABLE_MANAGEMEN= T
- else if (streq(p= [0], "static-challenge") && p[1] && p[2] &&am= p; !p[3])
+ else i= f (streq(p[0], "static-challenge") && p[1] && p[2= ] && !p[4])
{
VERIFY_= PERMISSION(OPT_P_GENERAL);
options->sc_info.cha= llenge_text =3D p[1];
@@ -7956,6 +7958,15 @@
{

options->sc_info.flags |=3D SC= _ECHO;
}
+ if (p[3] && streq(p[3], "concat"))<= /span>
+ {
= + options->sc_inf= o.flags |=3D SC_CONCAT;
+ }
+ = else if (p[3] && !streq(p[3], "scrv1"))
+ {

+ msg(msglevel, "--static-chal= lenge: unknown format indicator '%s'", p[3]);
+ goto err;
+ }
}
#endif
else if (streq(p[0], "msg-= channel") && p[1])
diff --git a/src/openvpn/ss= l.c b/src/openvpn/ssl.c
index c2c9c29..8c72d0b 100644
--- a/src/openvpn/ssl.c
+++ b/src/openvpn/ssl.c<= /span>
@@ -315,6 +315,10 @@
{<= br> flags |=3D GET_USER_PASS_STATIC_CHALLENGE_ECHO;
}
+ if (sci->flags & SC_CONCAT)
+ {
+ flags |=3D GET_USER_PASS_STA= TIC_CHALLENGE_CONCAT;
+ }
get_user_pass_cr(&auth_use= r_pass,
auth_file,
= UP_TYPE_AUTH,

To view, visit change 665. To unsubscribe, or for help writing mail f= ilters, visit settings.<= /p>

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I59a90446bfe73d8856516025a58= a6f62cc98ab0d
Gerrit-Change-Number: 665
Gerrit-PatchSet: 4
Gerrit-Owner: selvanair <selva.nair@...1354...= ..>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: cron2 <gert@...1296...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--+8/v/l3pXWg=--