From: "selvanair (Code Review)" Attention is cur=
rently required from: plaisthos. selvanair would like plaisthos to review this change.
Add an optional username-only flag for auth=
-user-pass
Specify "--auth-user-pass username-only" for op=
envpn to prompt
for only username, not password. Prompt via management i=
nterface
uses the usual ">PASSWORD 'Auth' " prompt =
with type "username"
instead of "username/password".=
Internally, the password gets set as "[[BLANK]]" which is=
currently
used as tag for blank password.
Not compatible with --=
static-challenge or when username and
password are inlined or read from =
a file. In such cases, the user
hard-code a dummy password in the file i=
nstead.
Change-Id: I788f76e6a70a9c20bca3367140d2741bd0551582
Sign=
ed-off-by: Selva Nair <selva.nair@...277...>
---
M doc/man-sect=
ions/client-options.rst
M doc/management-notes.txt
M src/openvpn/init=
.c
M src/openvpn/manage.c
M src/openvpn/manage.h
M src/openvpn/mis=
c.c
M src/openvpn/misc.h
M src/openvpn/options.c
M src/openvpn/opt=
ions.h
M src/openvpn/ssl.c
M src/openvpn/ssl.h
M src/openvpn/ssl_c=
ommon.h
12 files changed, 82 insertions(+), 14 deletions(-)git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes=
/48/1548/1
diff --git a/doc/man-sections/client-options.rst b/doc/m=
an-sections/client-options.rst
index b9ae7ce..ebe32a9 10064=
4
--- a/doc/man-sections/client-options.rst
+++ b/doc/man-sections/client-options.rst
@@ -68,7 +68,9 @=
@
auth-user-pass up
- lines. If the pa=
ssword line is missing, OpenVPN will prompt for one.
+ lines or a flag named :code:`username-o=
nly` to indicate no password
+ should be prompted for. In the former case, if the password line=
is missing
+ in the=
file, OpenVPN will prompt for one.
If=
``up`` is omitted, username/password will be prompted from the
<=
span> console.
@@ -84,6 +86,14 @@
wher=
e password is optional, and will be prompted from the console if
=
missing.
+ The :code:`username-only` flag is meant to be used with S=
SO authentication
+ =
and is incompatible with the ``--static-challenge`` option and legacy
+ ``dynamic challenge`` p=
rotocol. When no password is requested from the user,
+ a dummy password :code:`[[BLANK]]` is g=
enerated internally and submitted to
+ the server. See management-notes.txt for how this option=
affects username/password
+ prompt via the management interface. For the console, it simply el=
iminates
+ the passw=
ord prompt.
+<=
br> The server configuration must specify an ``--auth-user-pass-ver=
ify``
script to verify the username/password provided by=
the client.
diff --git a/doc/management-=
notes.txt b/doc/management-notes.txt
index 1a5c311..31fd557=
100644
--- a/doc/management-notes.txt
+++ =
b/doc/management-notes.txt
@@ -304,6 +304,19 @@
<=
span> username "Auth" foo
password "=
;Auth" bar
+ Example 3:
+
+ >PASS=
WORD:Need 'Auth' username
+
+ Ope=
nVPN needs a --auth-user-pass username. The
+ management interface client should respond:
+
+ username "Auth" foo<=
br>+
+ In this case the user should not be prompted=
for a password.
+ S=
upport for such username-only prompting is conditional on the
+
<=
span> The username/password itself can be in quotes, and special characters such as double quote or backslash must be escaped,
for example,
diff --git a/src/openvpn/init=
.c b/src/openvpn/init.c
index 70c0b5d..1246cfb 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.=
c
@@ -655,10 +655,10 @@
enable_aut=
h_user_pass();
#ifdef ENABLE_MANAGEMENT
=
auth_user_pass_setup(c->options.auth_user_pass_file, c->option=
s.auth_user_pass_file_inline,
- &c->options.sc_info);
+ =
c->options.auth_user_pass_username_only, &c->options.sc_info);
#else
auth_user_pass_setup(c->op=
tions.auth_user_pass_file, c->options.auth_user_pass_file_inline,=
- =
NULL);
+ =
c->options.auth_user_pass_username_only, NULL);<=
br> #endif
}
}
=
@@ -3383,6 +3383,7 @@
}
to.auth_u=
ser_pass_file =3D options->auth_user_pass_file;
to.=
auth_user_pass_file_inline =3D options->auth_user_pass_file_inline;
+ to.auth_user_pass_us=
ername_only =3D options->auth_user_pass_username_only;
=
to.auth_token_generate =3D options->auth_token_generate;
<=
span> to.auth_token_lifetime =3D options->auth_token_lifetime;
to.auth_token_renewal =3D options->auth_token_renewal;=
span>
diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index 37ae6b3..776deef 100644
--- a/src/openvp=
n/manage.c
+++ b/src/openvpn/manage.c
@@ -5=
8,9 +58,6 @@
#define MANAGEMENT_ECHO_FLAGS 0
-/* tag for blank username/password */
-static const char blank_up[] =3D "[[BLANK]]&quo=
t;;
-
=
struct management *management; /* GLOBAL */
@@ -729,6 +726,13 @@<=
/span>
{
switch (man->connection.up_query=
_mode)
{
+ case UP_QUERY_USERNAME:
+ if (strlen(man->connection.up_query.us=
ername))
+ =
{
+ m=
an->connection.up_query.defined =3D true;
+ }
+ break;
+
case UP_QUERY_USER_PASS:=
if (!strlen(man->connection.up_query.username))=
span>
{
@@ -783,7 +787,9 @@
man_query_username(struct management *man, const char *type, const =
char *string)
{
const bool needed =3D=
- ((man->con=
nection.up_query_mode =3D=3D UP_QUERY_USER_PASS) && man->connect=
ion.up_query_type);
+=
((man->connection.up_query_mode =3D=3D UP_QUERY_USER_PASS=
+ || man->conne=
ction.up_query_mode =3D=3D UP_QUERY_USERNAME)
+ && man->connection.up_query_t=
ype);
man_query_user_pass(man, type, string, needed, &=
quot;username", man->connection.up_query.username,
=
USER_PASS_LEN);
}
@@ -3538,6 +3544,12 @@
prefix =3D "PASSW=
ORD";
alert_type =3D "password"=
;
}
+ else if ((man->connection.client_version > 2) &&=
amp; (flags & GET_USER_PASS_USERNAME_ONLY))
+ {
+ up_query_mode =3D UP_QUERY_USERNAME;+ prefix =3D "=
;PASSWORD";
+ =
alert_type =3D "username";
+ }
else
{
up_query_mode =3D UP_QUERY_U=
SER_PASS;
diff --git a/src/openvpn/manage.h b/src/openvpn/m=
anage.h
index 38f437f..e5ad23f 100644
--- a=
/src/openvpn/manage.h
+++ b/src/openvpn/manage.h
=
@@ -264,6 +264,7 @@
#define UP_QUERY_PASS 2
#define UP_QUERY_NEED_OK 3
#define UP_QUER=
Y_NEED_STR 4
+#defin=
e UP_QUERY_USERNAME 5
/* states */
#define MS_INITIAL 0 /* all sockets are closed */=
diff --git a/src/openvpn/misc.c b/src/openvpn/misc.cindex 9ff281c..8f687a8 100644
--- a/src/openvpn/misc.c<=
/span>
+++ b/src/openvpn/misc.c
@@ -216,6 +216,12 =
@@
msg(M_WARN, "Note: previous '%s=
9; credentials failed", prefix);
}
=
+ /* U=
se tag for blank password if we are not prompting for one */
+ =
{
+ =
strncpy(up->password, blank_up, sizeof(up->password));
+
#ifdef ENABLE_MANAGEMEN=
T
/*
* Get username/pass=
word from management interface?
@@ -389,7 +395,7 @@<=
br> query_user_add(BSTR(&user_prompt), up->=
;username, USER_PASS_LEN, true);
}<=
br>
- =
if (password_from_stdin)
+ if (password_from_stdin && !(flags & =
GET_USER_PASS_USERNAME_ONLY))
{
=
query_user_add(BSTR(&pass_prompt), up->pa=
ssword, USER_PASS_LEN, false);
}
diff --git a/src/openvpn/misc.h b/src/openvpn/misc.h
index e9cfadb..76bcac3 100644
--- a/src/openvpn/misc.h
+++ b/src/openvpn/misc.h
@@ -48,6 +48,9 @@
* Get and store a username/password
*/
+/* ta=
g for blank username/password */
+static const char blank_up[] =3D "[[BLANK]]";=
+
struct u=
ser_pass
{
bool defined;@@ -123,6 +126,8 @@
#define GET_USER_PASS_INLINE_CREDS=
(1 << 10)
/** indicates password and res=
ponse should be concatenated */
#define GET_USER_PASS_STAT=
IC_CHALLENGE_CONCAT (1 << 11)
+/** indicate that only username should be prompted for auth=
-user-pass */
+#defin=
e GET_USER_PASS_USERNAME_ONLY (1 << 12)
=
span>
/**
* Retrieves the user credentials from=
various sources depending on the flags.
diff --git a/src/o=
penvpn/options.c b/src/openvpn/options.c
index 2bca647..091=
d388 100644
--- a/src/openvpn/options.c
+++=
b/src/openvpn/options.c
@@ -511,7 +511,8 @@
" and a pass=
word on the second. If either the password or both\n"
=
" the username and the password are omitted Open=
VPN will prompt\n"
- " for them from console.\n"
+ " =
will be prompted for from console or management interface.\n"<=
/span>
"--pull : Accept certain config file op=
tions from the peer as if they\n"
" =
were part of the local config file. Must be specified\n"
" when connecting to a '--mode =
server' remote host.\n"
@@ -3925,6 +3926,10 @@
{
o->auth_token_renewal =3D o=
->renegotiate_seconds;
}
+ if (o->auth_user_pass_username_only &am=
p;& o->sc_info.challenge_text)
+ {
+ msg(M_USAGE, "'auth-user-pass username-only' canno=
t be used with static challenge");
+ }
pre_connect_save(o);<=
br> }
@@ -7728,7 +7733,13 @@=
else if (streq(p[0], "auth-user-pass") && =
!p[2])
{
VERIFY_PERMISSION(OP=
T_P_GENERAL | OPT_P_INLINE);
- if (p[1])
+ options->auth_user_pass_username_only =3D false;
=
+ if (p[1] && st=
req(p[1], "username-only"))
+ {
+ options->auth_user_pass_username_only =3D true;
+ options->=
auth_user_pass_file =3D "stdin";
+ }
+ else if (p[1])
{ options->auth_user_pass_file =3D p[1];
=
options->auth_user_pass_file_inline =3D is_inline;diff --git a/src/openvpn/options.h b/src/openvpn/options.hindex 16cfdb5..ffb9534 100644
--- a/src/openvpn/opt=
ions.h
+++ b/src/openvpn/options.h
@@ -558,=
6 +558,7 @@
unsigned int push_update_options_found; /*=
tracks which option types have been reset in current PUSH_UPDATE sequence =
*/
const char *auth_user_pass_file;
=
bool auth_user_pass_file_inline;
+ bool auth_user_pass_username_only;
=
struct options_pre_connect *pre_connect;
int scheduled_exit_interval;
diff --git a/src/openvpn=
/ssl.c b/src/openvpn/ssl.c
index 69d0e4e..962f5df 100644
--- a/src/openvpn/ssl.c
+++ b/src/openvpn/ssl=
.c
@@ -290,7 +290,8 @@
}
=
void
=
-auth_user_pass_setup(const char *auth_file, bool is_inline, const struct s=
tatic_challenge_info *sci)
+auth_user_pass_setup(const char *auth_file, bool is_inline, bool use=
rname_only,
+ =
const struct static_challenge_info *sci)
{
unsigned int flags =3D GET_USER_PASS_MANAGEMENT;<=
br>
@@ -298,6 +299,10 @@
{
flags |=3D GET_USER_PASS_INLINE_CREDS;
}
+ if (user=
name_only)
+ {
+ flags |=3D GET_=
USER_PASS_USERNAME_ONLY;
+ }
if (!auth_user_pass.defin=
ed && !auth_token.defined)
{
@=
@ -2099,10 +2104,12 @@
{
#ifdef ENABL=
E_MANAGEMENT
auth_user_pass_setup(session->opt-=
>auth_user_pass_file,
- session->opt->auth_user_pass_file_inl=
ine, session->opt->sci);
+ session->opt->auth_user_pass_=
file_inline,
+ =
session->opt->auth_user_pass_username_only, ses=
sion->opt->sci);
#else
auth=
_user_pass_setup(session->opt->auth_user_pass_file,
- session-&g=
t;opt->auth_user_pass_file_inline, NULL);
+ session->opt->a=
uth_user_pass_file_inline,
+ session->opt->auth_user_pass_user=
name_only, NULL);
#endif
struct u=
ser_pass *up =3D &auth_user_pass;
dif=
f --git a/src/openvpn/ssl.h b/src/openvpn/ssl.h
index 28a3b=
78..5822336 100644
--- a/src/openvpn/ssl.h
=
+++ b/src/openvpn/ssl.h
@@ -389,7 +389,7 @@
* credentials stored in the file, however, if is_inline is true then aut=
h_file
* contains the username/password inline.
*/
-void auth_=
user_pass_setup(const char *auth_file, bool is_inline,
+void auth_user_pass_setup(const char *au=
th_file, bool is_inline, bool username_only,
=
const struct static_challenge_info *sc_info);
=
/*
diff --git a/src/openvpn/ssl_common.h=
b/src/openvpn/ssl_common.h
index fba01bb..6f310a5 100644=
span>
--- a/src/openvpn/ssl_common.h
+++ b/src/ope=
nvpn/ssl_common.h
@@ -396,6 +396,7 @@
=
const char *export_peer_cert_dir;
const char *auth_use=
r_pass_file;
bool auth_user_pass_file_inline;+ bool auth_user_pass_user=
name_only;
bool auth_token_generate;=
/**< Generate auth-tokens on successful
=
* user/pass auth,seet via
To view, visit change 1548. To unsubscribe, or for help writing mail filt= ers, visit setti= ngs.