@@ -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. */
655694static 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