42#if defined(ENABLE_SYSTEMD)
44query_user_exec_systemd(
void)
70 const unsigned int flags,
const char *static_challenge)
77parse_line(
const char *line,
char **p,
const int n,
const char *file,
const int line_num,
132 assert_string_equal(up.
password,
"ok");
143 assert_string_equal(up.
password,
"cancel");
157 assert_string_equal(up.
username,
"iuser");
158 assert_string_equal(up.
password,
"ipassword");
167 get_user_pass_cr(&up,
"#iuser and 커뮤니티\n//ipasswörd!\nsome other content\nnot relevant",
170 assert_string_equal(up.
username,
"#iuser and 커뮤니티");
171 assert_string_equal(up.
password,
"//ipasswörd!");
180 assert_true(
get_user_pass_cr(&up,
"\tiuser\r\nipass\xffwo\x1erd",
"UT", flags, NULL));
182 assert_string_equal(up.
username,
"iuser");
183 assert_string_equal(up.
password,
"ipass\xffword");
192 assert_string_equal(up.
username,
"");
193 assert_string_equal(up.
password,
"");
203 assert_string_equal(up.
username,
"iuser");
204 assert_string_equal(up.
password,
"cpassword");
213 assert_string_equal(up.
username,
"user");
214 assert_string_equal(up.
password,
"ipassword");
225 assert_string_equal(up.
username,
"user");
226 assert_string_equal(up.
password,
"cpassword");
244 expect_assert_failure(
get_user_pass_cr(&up,
"\nipassword\n",
"UT", flags, NULL));
253 unsigned int flags = 0;
262 assert_string_equal(up.
username,
"cuser");
263 assert_string_equal(up.
password,
"cpassword");
273 assert_string_equal(up.
username,
"user");
274 assert_string_equal(up.
password,
"cpassword");
285 assert_string_equal(up.
username,
"user");
286 assert_string_equal(up.
password,
"");
296 assert_string_equal(up.
username,
"cuser");
297 assert_string_equal(up.
password,
"[[BLANK]]");
308 unsigned int flags = 0;
324 unsigned int flags = 0;
326 char authfile[PATH_MAX] = { 0 };
333 assert_string_equal(up.
username,
"fuser");
334 assert_string_equal(up.
password,
"fpassword");
344 assert_string_equal(up.
username,
"");
345 assert_string_equal(up.
password,
"");
356 assert_string_equal(up.
username,
"fuser");
357 assert_string_equal(up.
password,
"cpassword");
367 assert_string_equal(up.
username,
"user");
368 assert_string_equal(up.
password,
"fuser");
376 assert_non_null(authfile);
378 const char *endings[] = {
"",
"\n",
"\n\n",
"\nfpassword\n",
"\r\nfpassword\r\n" };
380 const bool inline_mode[] = {
false,
true };
381 for (
size_t mode = 0; mode <
SIZE(inline_mode); mode++)
383 const bool use_inline_creds = inline_mode[mode];
384 for (
size_t i = 0; i <
SIZE(lengths); i++)
386 for (
size_t j = 0; j <
SIZE(endings); j++)
390 memset(creds,
'u', lengths[i]);
391 strcpy(creds + lengths[i], endings[j]);
392 if (!use_inline_creds)
396 assert_true(fputs(creds, fp) >= 0);
397 assert_int_equal(fclose(fp), 0);
400 const bool missing_password = j < 3;
401 if (missing_password)
404 "Enter UT Password:");
408 assert_true(
get_user_pass_cr(&up, use_inline_creds ? creds : authfile,
"UT",
413 assert_string_equal(up.
username, creds);
415 missing_password ?
"cpassword" :
"fpassword");
423#ifdef ENABLE_MANAGEMENT
429 const char *challenge =
"CRV1:R,E:Om01u7Fh4LrGBS7uh0SWmzwabUiGiW6l:Y3Ix:Please enter token PIN";
433 "CHALLENGE: Please enter token PIN");
438 assert_string_equal(up.
username,
"cr1");
439 assert_string_equal(up.
password,
"CRV1::Om01u7Fh4LrGBS7uh0SWmzwabUiGiW6l::challenge_response");
447 const char *challenge =
"Please enter token PIN";
456 "CHALLENGE: Please enter token PIN");
461 assert_string_equal(up.
username,
"cuser");
463 assert_string_equal(up.
password,
"SCRV1:Y3Bhc3N3b3Jk:Y2hhbGxlbmdlX3Jlc3BvbnNl");
475 "CHALLENGE: Please enter token PIN");
480 assert_string_equal(up.
username,
"c1user");
482 assert_string_equal(up.
password,
"c1password0123456");
491 "CHALLENGE: Please enter token PIN");
494 assert_true(
get_user_pass_cr(&up,
"iuser\nipassword",
"UT", flags, challenge));
496 assert_string_equal(up.
username,
"iuser");
498 assert_string_equal(up.
password,
"SCRV1:aXBhc3N3b3Jk:Y2hhbGxlbmdlX3Jlc3BvbnNl");
510 unsigned int flags = 0;
512 char authfile[PATH_MAX] = { 0 };
532#ifdef ENABLE_MANAGEMENT
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
size_t strlcpy(char *dest, const char *src, size_t maxlen)
struct _query_user query_user[QUERY_USER_NUMSLOTS]
Global variable, declared in console.c.
bool query_user_exec_builtin(void)
Loop through configured query_user slots, using the built-in method for querying the user.
#define QUERY_USER_NUMSLOTS
bool get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *prefix, const unsigned int flags, const char *auth_challenge)
Retrieves the user credentials from various sources depending on the flags.
#define GET_USER_PASS_STATIC_CHALLENGE_CONCAT
indicates password and response should be concatenated
#define GET_USER_PASS_PASSWORD_ONLY
#define GET_USER_PASS_USERNAME_ONLY
indicate that only username should be prompted for auth-user-pass
#define GET_USER_PASS_INLINE_CREDS
indicates that auth_file is actually inline creds
#define GET_USER_PASS_STATIC_CHALLENGE
SCRV1 protocol – static challenge.
#define GET_USER_PASS_NEED_OK
#define GET_USER_PASS_DYNAMIC_CHALLENGE
CRV1 protocol – dynamic challenge.
Garbage collection arena used to keep track of dynamically allocated memory.
char password[USER_PASS_LEN]
char username[USER_PASS_LEN]
static void openvpn_unit_test_setup(void)
Sets up the environment for unit tests like making both stderr and stdout non-buffered to avoid messa...
static void openvpn_test_get_srcdir_dir(char *buf, size_t bufsize, const char *filename)
Helper function to get a file path from the unit test directory to open it or pass its path to anothe...
int parse_line(const char *line, char **p, const int n, const char *file, const int line_num, msglvl_t msglevel, struct gc_arena *gc)
static void reset_user_pass(struct user_pass *up)
const struct CMUnitTest user_pass_tests[]
bool query_user_exec_builtin(void)
Loop through configured query_user slots, using the built-in method for querying the user.
static void test_get_user_pass_long_username(void **state)
bool protect_buffer_win32(char *buf, DWORD len)
Encrypt a region of memory using CryptProtectMemory() with access restricted to the current process.
static void test_get_user_pass_authfile_file_assertions(void **state)
bool unprotect_buffer_win32(char *buf, DWORD len)
Decrypt a previously encrypted region of memory using CryptUnProtectMemory() with access restricted t...
static void test_get_user_pass_defined(void **state)
static void test_get_user_pass_static_challenge(void **state)
bool management_query_user_pass(struct management *man, struct user_pass *up, const char *type, const unsigned int flags, const char *static_challenge)
static void test_get_user_pass_authfile_stdin_assertions(void **state)
static void test_get_user_pass_authfile_stdin(void **state)
void management_auth_failure(const struct management *man, const char *type, const char *reason)
static void test_get_user_pass_needok(void **state)
static void test_get_user_pass_authfile_file(void **state)
static void test_get_user_pass_dynamic_challenge(void **state)
static void test_get_user_pass_inline_creds(void **state)
static void test_get_user_pass_inline_creds_assertions(void **state)