From: "cron2 (Code Review)" Attention is cur=
rently required from: selvanair. cron2 submitted this change.management: add base64 multi=
-line input for passwords
Allow management clients to send long pass=
words via the
usual multi-line base64 encoded protocol.
A client =
declares MCV 5 support and sends a 'password <type>'
line,=
followed by as many lines (each up to 1024 bytes) as
needed, in base64 =
encoded format, terminated by 'END'.
This is useful when a p=
assword is a JIT-generated use-once
token.
Declare management ver=
sion 6 for this feature.
Change-Id: Ib99f171fb69d51f2260b44edf8ebe21=
ac958f233
Signed-off-by: Luca Boccassi <luca.boccassi@...277...>Acked-by: Selva Nair <selva.nair@...277...>
Gerrit URL: https://=
gerrit.openvpn.net/c/openvpn/+/1593
Message-Id: <20260330180900.16608=
-1-gert@...1296...>
URL: https://www.mail-archive.com/openvpn-devel@...465...=
ists.sourceforge.net/msg36360.html
Signed-off-by: Gert Doering <gert@=
...1296...>
---
M doc/management-notes.txt
M src/openvpn/manage=
.c
M src/openvpn/manage.h
3 files changed, 106 insertions(+), 3 delet=
ions(-)
--- a/doc/management=
-notes.txt
+++ b/doc/management-notes.txt
@=
@ -326,6 +326,22 @@
The escaping rules are the same as f=
or the config file.
See the "Command Parsing" =
section below for more info.
+ If the password is too long to fit in a single=
command line
+ (lon=
ger than 256 bytes), the management interface client should
+ use the multi-line base64 format =
instead. This requires that
+ the management client has announced version >=3D 5 via the
+ "version" =
command:
+
=
+ password "Auth"<=
/span>
+ [BASE64_PASSWORD=
_LINE]
+ ...
+ END
+
+ In this format, the password is base64-encoded and spl=
it across
+ multiple=
lines, followed by END. Each line can be at most 1024
+ bytes. This is the same format used =
by pk-sig and certificate
+ commands. Requires OpenVPN management version >=3D 6.
=
+
The PASSWO=
RD real-time message type can also be used to
indicate p=
assword or other types of authentication failure:
<=
br>@@ -513,6 +529,7 @@
>PK_SIGN:[base64] =
-- version 2 or greater
>PK_SIGN:[base64],[al=
g] -- version 3 or greater
>PASSWORD:Need '=
Auth' username -- version 4 or greater
+ multiline password from client -- version 5 or g=
reater
COMMAND -- auth-retry
<=
span> ---------------------
diff --git a/src/openvpn/manage=
.c b/src/openvpn/manage.c
index 6cab7db..c22a2a4 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/m=
anage.c
@@ -31,6 +31,7 @@
#include "e=
rror.h"
#include "fdmisc.h"
#include "options.h"
+#include "base64.h"
#include "=
sig.h"
#include "event.h"
=
#include "otime.h"
@@ -68,6 +69,7 @@ MCV_PKSIGN =3D 2,
MCV_PKSIGN_ALG =3D 3,
MCV_USERNAME_ONLY =3D 4,
+ MCV_MULTILINE_PASSWORD =3D 5,
};<=
/span>
struct management *management; /* GLOBAL=
*/
@@ -105,6 +107,8 @@
msg(M_CLIENT, =
" where action is reply string.");=
msg(M_CLIENT, "net : (Windows only) =
Show network info and routing table.");
msg(M_CLI=
ENT, "password type p : Enter password p for a queried OpenVPN =
password.");
+ =
msg(M_CLIENT, "password type : (version >=3D5) Enter pas=
sword base64-encoded on");
+ msg(M_CLIENT, " subsequent lin=
es followed by END.");
msg(M_CLIENT, "remote=
type [host port] : Override remote directive, type=3DACCEPT|MOD|SKIP."=
;);
msg(M_CLIENT, "remote-entry-count : Get n=
umber of available remote entries.");
msg(M_CLIEN=
T, "remote-entry-get i|all [j]: Get remote entry at index =3D i to to=
j-1 or all.");
@@ -1019,6 +1023,41 @@
}
}
+/**
+ * Enter multi-line base64 mode for receiving a password that exce=
eds the
+ * single-li=
ne parameter size limit. The management client sends:
+ *
+ * password TYPE
+ * <base64-encoded password line 1>
+ * <base64-encoded password line =
2>
+ * ...=
+ * END
+ *
+ * @param man The management interface struct=
+ * @param type =
The type of password being entered (e.g. "Auth", "Priva=
te Key", etc)
+ =
*/
+static void
+man_query_password_base64=
(struct management *man, const char *type)
+{
+ const bool needed =3D ((man->connection.up_query_mode =3D=3D UP=
_QUERY_PASS
+ =
|| man->connection.up_query_mode =3D=3D UP_QUERY_USER_=
PASS)
+ =
&& man->connection.up_query_type);
+ if (!needed)
+ {
+ msg(M_CLIENT, "ERROR: no password is curre=
ntly needed at this time");
+ return;
+ }
+ i=
f (!man->connection.up_query_type || !streq(man->connection.up_query_=
type, type))
+ {=
span>
+ msg(M_CLIENT,=
"ERROR: password of type '%s' entered, but we need one of typ=
e '%s'",
+ type, man->connection.up_query_type);
+ return;
+ }
+ struct man_connection *mc =3D &man->connection;=
+ mc->in_extra=
_cmd =3D IEC_PASSWORD;
+ in_extra_reset(mc, IER_NEW);
+}
+=
span>
static void
in_extra_dispatch(struct manag=
ement *man)
{
@@ -1052,6 +1091,41 @@
man->connection.ext_cert_input =3D man->conne=
ction.in_extra;
man->connection.in_extra =
=3D NULL;
return;
+
+ case IEC_PASSWORD:
+ {
+ char decoded[USER_PASS_LEN];
+ CLEAR(decoded);
+
+ buffer_list_aggregate(man->connection.in_extr=
a,
+ =
OPENVPN_BASE64_LENGTH(USER_PASS_LEN) + 1024);+ struct buffer *buf =
=3D buffer_list_peek(man->connection.in_extra);
+
+ if (buf && BLEN(buf) > 0)
+ if (OPENVPN_BASE64_DECOD=
ED_LENGTH(BLEN(buf)) >=3D USER_PASS_LEN)
+ {
+ msg(M_CLIENT, "ERROR: passwo=
rd too long");
+=
buf_clear(buf);
+ break;
+ }
+ int len =3D openvpn_base64_decode(BSTR=
(buf), decoded,
+ =
USER_PASS_LEN - 1);
<=
span style=3D"color: hsl(120, 100%, 40%);">+ if (len < 0)=
+ {=
span>
+ m=
sg(M_CLIENT, "ERROR: could not base64-decode password");+ buf_clea=
r(buf);
+ =
break;
+ =
}
+ =
decoded[len] =3D '\0';
+ buf_clear(buf);
+ }
+
+ man_query_password(man, man->connection.up_query_ty=
pe,
+ =
decoded);
+ secure_memzero(decoded, sizeof(decoded));
+ break;
+ }
}
in_extra_reset(&man->connection, IER_RESET);=
}
@@ -1598,9 +1672,20 @@
}<=
/span>
else if (streq(p[0], "password"))
=
{
- i=
f (man_need(man, p, 2, 0))
+ if (man_need(man, p, 1, MN_AT_LEAST))
=
{
- man_q=
uery_password(man, p[1], p[2]);
+ if (p[2])
+ {
+ man_query_password(man, p[1], p[2]);
+ else if (man->connection.=
client_version >=3D MCV_MULTILINE_PASSWORD)
+ {
+ man_query_password_base64(man, p[1]);<=
/span>
+ }=
+ else
+ {
+ msg(M_CLIENT, "=
;ERROR: the 'password' command requires 2 parameters");=
+ } }
}
else if (streq(p=
[0], "forget-passwords"))
diff --git a/src/openvp=
n/manage.h b/src/openvpn/manage.h
index e5ad23f..27d3b60 10=
0644
--- a/src/openvpn/manage.h
+++ b/src/o=
penvpn/manage.h
@@ -50,7 +50,7 @@
#include=
"socket_util.h"
#include "mroute.h"=
span>
-#defi=
ne MANAGEMENT_VERSION 5
+#define MANAGEMENT_VERSION 6 #define MANAGEMENT_N_PASSWORD_RETRIES 3
#de=
fine MANAGEMENT_LOG_HISTORY_INITIAL_SIZE 100
#define MANAG=
EMENT_ECHO_BUFFER_SIZE 100
@@ -297,6 +297,7 @@
#define IEC_RSA_SIGN 3
#define IEC_CERTIFI=
CATE 4
#define IEC_PK_SIGN 5
+#define IEC_PASSWORD 6
=
int in_extra_cmd;
struct buffer_list *in_extra;
unsigned long in_extra_cid;
To view, visit change 1593. To unsubscribe, or for help writing mail filt= ers, visit setti= ngs.