Skip to content

Commit 5da86d4

Browse files
wolfsshd: mark AuthorizedKeysFile as explicitly set in public setter
1 parent 1efd647 commit 5da86d4

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

apps/wolfsshd/configuration.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,6 @@ static int HandleConfigOption(WOLFSSHD_CONFIG** conf, int opt,
10641064

10651065
switch (opt) {
10661066
case OPT_AUTH_KEYS_FILE:
1067-
(*conf)->authKeysFileSet = 1;
10681067
ret = wolfSSHD_ConfigSetAuthKeysFile(*conf, value);
10691068
break;
10701069
case OPT_PRIV_SEP:
@@ -1395,6 +1394,14 @@ int wolfSSHD_ConfigSetAuthKeysFile(WOLFSSHD_CONFIG* conf, const char* file)
13951394
if (file != NULL) {
13961395
ret = CreateString(&conf->authKeysFile, file,
13971396
(int)WSTRLEN(file), conf->heap);
1397+
/* mark the authorized keys file as explicitly configured so
1398+
* certificate public-key logins are still checked against it */
1399+
if (ret == WS_SUCCESS) {
1400+
conf->authKeysFileSet = 1;
1401+
}
1402+
}
1403+
else {
1404+
conf->authKeysFileSet = 0;
13981405
}
13991406
}
14001407

apps/wolfsshd/test/test_configuration.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ static int test_ConfigCopy(void)
305305
ret = wolfSSHD_ConfigSetHostCertFile(head, "/etc/ssh/host_cert.pub");
306306
if (ret == WS_SUCCESS)
307307
ret = wolfSSHD_ConfigSetUserCAKeysFile(head, "/etc/ssh/ca.pub");
308-
/* AuthorizedKeysFile must go through PCL so authKeysFileSet flag is set */
308+
/* AuthorizedKeysFile via PCL to also exercise the config-parse path; the
309+
* authKeysFileSet flag is set either way and must survive the copy */
309310
if (ret == WS_SUCCESS) ret = PCL("AuthorizedKeysFile .ssh/authorized_keys");
310311

311312
/* scalar fields */
@@ -651,6 +652,44 @@ static int test_IncludeRecursionBound(void)
651652
return ret;
652653
}
653654

655+
/* The public wolfSSHD_ConfigSetAuthKeysFile setter must mark the authorized
656+
* keys file as explicitly configured, otherwise certificate public-key logins
657+
* skip the authorized-keys check and rely on CA validation alone. */
658+
static int test_ConfigSetAuthKeysFile(void)
659+
{
660+
int ret = WS_SUCCESS;
661+
WOLFSSHD_CONFIG* conf;
662+
663+
conf = wolfSSHD_ConfigNew(NULL);
664+
if (conf == NULL)
665+
ret = WS_MEMORY_E;
666+
667+
/* fresh config has no explicit authorized keys file */
668+
if (ret == WS_SUCCESS) {
669+
if (wolfSSHD_ConfigGetAuthKeysFileSet(conf) != 0)
670+
ret = WS_FATAL_ERROR;
671+
}
672+
673+
/* configuring a file through the public setter must set the flag */
674+
if (ret == WS_SUCCESS)
675+
ret = wolfSSHD_ConfigSetAuthKeysFile(conf, ".ssh/authorized_keys");
676+
if (ret == WS_SUCCESS) {
677+
if (wolfSSHD_ConfigGetAuthKeysFileSet(conf) == 0)
678+
ret = WS_FATAL_ERROR;
679+
}
680+
681+
/* removing the file must clear the flag again */
682+
if (ret == WS_SUCCESS)
683+
ret = wolfSSHD_ConfigSetAuthKeysFile(conf, NULL);
684+
if (ret == WS_SUCCESS) {
685+
if (wolfSSHD_ConfigGetAuthKeysFileSet(conf) != 0)
686+
ret = WS_FATAL_ERROR;
687+
}
688+
689+
wolfSSHD_ConfigFree(conf);
690+
return ret;
691+
}
692+
654693
/* Verifies ConfigFree releases all string fields - most useful under ASan. */
655694
static int test_ConfigFree(void)
656695
{
@@ -1013,6 +1052,7 @@ const TEST_CASE testCases[] = {
10131052
TEST_DECL(test_MatchUnsupportedSelector),
10141053
TEST_DECL(test_CAKeysFileDiffers),
10151054
TEST_DECL(test_IncludeRecursionBound),
1055+
TEST_DECL(test_ConfigSetAuthKeysFile),
10161056
TEST_DECL(test_ConfigFree),
10171057
#ifdef WOLFSSL_BASE64_ENCODE
10181058
TEST_DECL(test_CheckAuthKeysLine),

0 commit comments

Comments
 (0)