From: "cron2 (Code Review)" Date: Sat, 30 Dec 2023 15:47:46 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <2e67e905f41433fecf0294a8c513ed3a3d509330-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Zju9HXOtovM="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: misc: make get_auth_challenge static List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: plaisthos , openvpn-devel --Zju9HXOtovM= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/47= 6?usp=3Demail ) Change subject: misc: make get_auth_challenge static ...................................................................... misc: make get_auth_challenge static Not used outside of misc.c. Rename to parse_auth_challenge since it really just parses the string that you put in into the struct. Add doxygen documentation. v2: - change if(auth_challenge) to ASSERT(auth_challenge) Change-Id: I0abeec9f862aea1f6a8fdf350fa0008cf2e5d613 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Message-Id: <20231230143248.1625-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg27= 864.html Signed-off-by: Gert Doering --- M src/openvpn/misc.c M src/openvpn/misc.h M src/openvpn/ssl.h 3 files changed, 79 insertions(+), 85 deletions(-) diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c index bce63ed..08f274d 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -124,6 +124,83 @@ } return true; } + +/** + * Parses an authentication challenge string and returns an auth_challenge= _info structure. + * The authentication challenge string should follow the dynamic challenge= /response protocol. + * + * See doc/management-notes.txt for more info on the the dynamic challenge= /response protocol + * implemented here. + * + * @param auth_challenge The authentication challenge string to parse. Can= 't be NULL. + * @param gc The gc_arena structure for memory allocation. + * + * @return A pointer to the parsed auth_challenge_info struc= ture, or NULL if parsing fails. + */ +static struct auth_challenge_info * +parse_auth_challenge(const char *auth_challenge, struct gc_arena *gc) +{ + ASSERT(auth_challenge); + + struct auth_challenge_info *ac; + const int len =3D strlen(auth_challenge); + char *work =3D (char *) gc_malloc(len+1, false, gc); + char *cp; + + struct buffer b; + buf_set_read(&b, (const uint8_t *)auth_challenge, len); + + ALLOC_OBJ_CLEAR_GC(ac, struct auth_challenge_info, gc); + + /* parse prefix */ + if (!buf_parse(&b, ':', work, len)) + { + return NULL; + } + if (strcmp(work, "CRV1")) + { + return NULL; + } + + /* parse flags */ + if (!buf_parse(&b, ':', work, len)) + { + return NULL; + } + for (cp =3D work; *cp !=3D '\0'; ++cp) + { + const char c =3D *cp; + if (c =3D=3D 'E') + { + ac->flags |=3D CR_ECHO; + } + else if (c =3D=3D 'R') + { + ac->flags |=3D CR_RESPONSE; + } + } + + /* parse state ID */ + if (!buf_parse(&b, ':', work, len)) + { + return NULL; + } + ac->state_id =3D string_alloc(work, gc); + + /* parse user name */ + if (!buf_parse(&b, ':', work, len)) + { + return NULL; + } + ac->user =3D (char *) gc_malloc(strlen(work)+1, true, gc); + openvpn_base64_decode(work, (void *)ac->user, -1); + + /* parse challenge text */ + ac->challenge_text =3D string_alloc(BSTR(&b), gc); + + return ac; +} + #endif /* ifdef ENABLE_MANAGEMENT */ /* @@ -287,7 +364,7 @@ #ifdef ENABLE_MANAGEMENT if (auth_challenge && (flags & GET_USER_PASS_DYNAMIC_CHALLENGE= ) && response_from_stdin) { - struct auth_challenge_info *ac =3D get_auth_challenge(auth= _challenge, &gc); + struct auth_challenge_info *ac =3D parse_auth_challenge(au= th_challenge, &gc); if (ac) { char *response =3D (char *) gc_malloc(USER_PASS_LEN, f= alse, &gc); @@ -392,83 +469,6 @@ return true; } -#ifdef ENABLE_MANAGEMENT - -/* - * See management/management-notes.txt for more info on the - * the dynamic challenge/response protocol implemented here. - */ -struct auth_challenge_info * -get_auth_challenge(const char *auth_challenge, struct gc_arena *gc) -{ - if (auth_challenge) - { - struct auth_challenge_info *ac; - const int len =3D strlen(auth_challenge); - char *work =3D (char *) gc_malloc(len+1, false, gc); - char *cp; - - struct buffer b; - buf_set_read(&b, (const uint8_t *)auth_challenge, len); - - ALLOC_OBJ_CLEAR_GC(ac, struct auth_challenge_info, gc); - - /* parse prefix */ - if (!buf_parse(&b, ':', work, len)) - { - return NULL; - } - if (strcmp(work, "CRV1")) - { - return NULL; - } - - /* parse flags */ - if (!buf_parse(&b, ':', work, len)) - { - return NULL; - } - for (cp =3D work; *cp !=3D '\0'; ++cp) - { - const char c =3D *cp; - if (c =3D=3D 'E') - { - ac->flags |=3D CR_ECHO; - } - else if (c =3D=3D 'R') - { - ac->flags |=3D CR_RESPONSE; - } - } - - /* parse state ID */ - if (!buf_parse(&b, ':', work, len)) - { - return NULL; - } - ac->state_id =3D string_alloc(work, gc); - - /* parse user name */ - if (!buf_parse(&b, ':', work, len)) - { - return NULL; - } - ac->user =3D (char *) gc_malloc(strlen(work)+1, true, gc); - openvpn_base64_decode(work, (void *)ac->user, -1); - - /* parse challenge text */ - ac->challenge_text =3D string_alloc(BSTR(&b), gc); - - return ac; - } - else - { - return NULL; - } -} - -#endif /* ifdef ENABLE_MANAGEMENT */ - void purge_user_pass(struct user_pass *up, const bool force) { diff --git a/src/openvpn/misc.h b/src/openvpn/misc.h index 70a24dd..d51609d 100644 --- a/src/openvpn/misc.h +++ b/src/openvpn/misc.h @@ -86,8 +86,6 @@ const char *challenge_text; }; -struct auth_challenge_info *get_auth_challenge(const char *auth_challenge,= struct gc_arena *gc); - /* * Challenge response info on client as pushed by server. */ diff --git a/src/openvpn/ssl.h b/src/openvpn/ssl.h index 6ba6ff8..71b99db 100644 --- a/src/openvpn/ssl.h +++ b/src/openvpn/ssl.h @@ -410,11 +410,7 @@ bool ssl_clean_auth_token(void); #ifdef ENABLE_MANAGEMENT -/* - * ssl_get_auth_challenge will parse the server-pushed auth-failed - * reason string and return a dynamically allocated - * auth_challenge_info struct. - */ + void ssl_purge_auth_challenge(void); void ssl_put_auth_challenge(const char *cr_str); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/476?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: I0abeec9f862aea1f6a8fdf350fa0008cf2e5d613 Gerrit-Change-Number: 476 Gerrit-PatchSet: 6 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: merged --Zju9HXOtovM= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

misc: make get_auth_challenge static

No= t used outside of misc.c.

Rename to parse_auth_challenge since it re= ally just parses
the string that you put in into the struct.

Add = doxygen documentation.

v2:
- change if(auth_challenge) to ASSERT= (auth_challenge)

Change-Id: I0abeec9f862aea1f6a8fdf350fa0008cf2e5d61= 3
Signed-off-by: Frank Lichtenheld <frank@...2641...>
Acked-by:= Gert Doering <gert@...1296...>
Message-Id: <20231230143248.162= 5-1-gert@...1296...>
URL: https://www.mail-archive.com/openvpn-devel@= lists.sourceforge.net/msg27864.html
Signed-off-by: Gert Doering <gert= @...1296...>
---
M src/openvpn/misc.c
M src/openvpn/misc.h
M= src/openvpn/ssl.h
3 files changed, 79 insertions(+), 85 deletions(-)
diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c
ind= ex bce63ed..08f274d 100644
--- a/src/openvpn/misc.c<= br>+++ b/src/openvpn/misc.c
@@ -124,6 +124,83 @@
}
return true;
}

+
+/**
+ * Parses an authentication challenge string and returns = an auth_challenge_info structure.
+ * The authentication challenge string should follow the dyna= mic challenge/response protocol.
+ *
+ * S= ee doc/management-notes.txt for more info on the the dynamic challenge/resp= onse protocol
+ * imp= lemented here.
+ *
+ * @param auth_challen= ge The authentication challenge string to parse. Can't be NULL.<= br>+ * @param gc Th= e gc_arena structure for memory allocation.
+ *
+ * @return A pointer to the parsed auth_challenge_info= structure, or NULL if parsing fails.
+ */
+static struct auth_challenge_info *
+parse_auth_challenge(const char *auth_challenge, struct g= c_arena *gc)
+{
+ ASSERT(auth_challenge= );
+
+ struct auth_challenge_info *ac;<= /span>
+ const int len = =3D strlen(auth_challenge);
+ char *work =3D (char *) gc_malloc(len+1, false, gc);
= + char *cp;
+
+ struct buffer b;
+ buf_set_read(&b, (const uint8_t *)auth_challen= ge, len);
++ ALLOC_OBJ_CLEAR_GC(ac, st= ruct auth_challenge_info, gc);
+
+ /* p= arse prefix */
+ i= f (!buf_parse(&b, ':', work, len))
+ {
+ return NULL;
+ }
+= if (strcmp(work, "CRV1"))
+ {
+ return NULL;
+ }
+=
+ /* parse flags */
+ if (!buf_parse(&= b, ':', work, len))
+ {
+ = return NULL;
+ }=
+ for (cp =3D wor= k; *cp !=3D '\0'; ++cp)
+ {
+ = const char c =3D *cp;
+ if (c =3D=3D 'E')
+ {
+ ac->flags |=3D CR_ECHO;
+ }
+ else if (c =3D=3D 'R')
+ {

+ ac->flags |=3D CR_RESPONSE;
+ }
+ }

+
+ /* parse state ID */
+ if (!buf_parse(&b, ':', work, len))+ {
+ return NULL;
+ }
+ ac->state_id =3D string_alloc(work, gc);=
+
+ /* parse user name */
+ if (!buf_parse(&b, ':',= work, len))
+ {
+ return NULL;<= /span>
+ }
+ ac->user =3D (char *) gc_ma= lloc(strlen(work)+1, true, gc);

+ openvpn_base64_decode(work, (void *)ac->user, -1);
+
+ /* parse challenge text */
+ ac->challenge_text =3D str= ing_alloc(BSTR(&b), gc);

+
+ return= ac;
+}
+

#endif /* ifdef= ENABLE_MANAGEMENT */

/*
@@ -287,7 +364,7 @@

#ifdef ENABLE_MANAGEMENT
if (auth_challenge && (flags & GET_USER_PASS_D= YNAMIC_CHALLENGE) && response_from_stdin)

= {
- = struct auth_challenge_info *ac =3D get_auth_challenge(auth_challenge, &= gc);
+ = struct auth_challenge_info *ac =3D parse_auth_challenge(auth_challenge, &a= mp;gc);
if (ac)
= {
char *response =3D (char *) g= c_malloc(USER_PASS_LEN, false, &gc);
@@ -392,83 +469,6 = @@
return true;
}

-#ifdef ENABLE_MANAGEMEN= T
-
-/*
- * See management/management-notes.txt for more info on the<= /span>
- * the dynamic challen= ge/response protocol implemented here.
- */
-s= truct auth_challenge_info *
-get_auth_challenge(const char *auth_challenge, struct gc_arena *gc)
-{
- if (auth_challenge)
- {
- struct auth_challenge_info *ac;
- const int len =3D strlen(auth_c= hallenge);
- cha= r *work =3D (char *) gc_malloc(len+1, false, gc);
- char *cp;
-
- buf_set_read(&b, (const uint8_t *)auth_challenge, len);
-
- ALLOC_OBJ_CLEAR_GC(ac, struct auth_= challenge_info, gc);
-<= /span>
- /* parse prefi= x */
- if (!buf_= parse(&b, ':', work, len))
- {
- return NULL;
- }
- = if (strcmp(work, "CRV1"))
- {
- return NULL;
- }
-
- /* parse flags *= /
- if (!buf_par= se(&b, ':', work, len))
- {
- return NULL;
- }
- = for (cp =3D work; *cp !=3D '\0'; ++cp)
- {
- const char c =3D *cp;
- if (c =3D=3D 'E')
<= span style=3D"color: hsl(0, 100%, 40%);">- {

- ac->flags |=3D CR_ECHO= ;
- }=
- else if (c =3D= =3D 'R')
- = {
- = ac->flags |=3D CR_RESPONSE;
- }
- }
-<= br>- /* parse state ID */<= /span>
- if (!buf_parse= (&b, ':', work, len))
- {
-= return NULL;
- a= c->state_id =3D string_alloc(work, gc);
-
-= /* parse user name */
- if (!buf_parse(&b, ':', work, len))
<= span style=3D"color: hsl(0, 100%, 40%);">- {

- return NULL;
- }
- ac->user =3D (char *) gc_malloc(strlen(wo= rk)+1, true, gc);
- = openvpn_base64_decode(work, (void *)ac->user, -1);
-
- /* parse challenge text */
- ac->challenge_text =3D string_alloc(= BSTR(&b), gc);
-
- return ac;
- }
- else
- {
- }
-}
-

-#endif /* ifdef ENABLE_MANAGEMENT */
-
void
= purge_user_pass(struct user_pass *up, const bool force)
{<= /span>
diff --git a/src/openvpn/misc.h b/src/openvpn/misc.h=
index 70a24dd..d51609d 100644
--- a/src/openvpn/m= isc.h
+++ b/src/openvpn/misc.h
@@ -86,8 +86= ,6 @@
const char *challenge_text;
};<= /span>

-stru= ct auth_challenge_info *get_auth_challenge(const char *auth_challenge, stru= ct gc_arena *gc);
-
/*
* Challenge response info on client as p= ushed by server.
*/
diff --git a/src/open= vpn/ssl.h b/src/openvpn/ssl.h
index 6ba6ff8..71b99db 100644=
--- a/src/openvpn/ssl.h
+++ b/src/openvpn/= ssl.h
@@ -410,11 +410,7 @@
bool ssl_clean_= auth_token(void);

#ifdef ENABLE_MANAGEME= NT
-/*
- * ssl_get_auth_challenge will parse t= he server-pushed auth-failed
- * reason string and return a dynamically allocated
- * auth_challenge_info struct.<= br>- */
+
void ssl_purge_auth_challen= ge(void);

void ssl_put_auth_challenge(co= nst char *cr_str);

To view, visit change 476= . To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I0abeec9f862aea1f6a8fdf350fa= 0008cf2e5d613
Gerrit-Change-Number: 476
Gerrit-PatchSet: 6
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: merged
--Zju9HXOtovM=--