@@ -7792,6 +7792,84 @@ static void test_wolfSSH_KeyboardInteractive(void)
77927792#else /* WOLFSSH_SFTP && !NO_WOLFSSH_CLIENT && !SINGLE_THREADED */
77937793static void test_wolfSSH_KeyboardInteractive (void ) { ; }
77947794#endif /* WOLFSSH_SFTP && !NO_WOLFSSH_CLIENT && !SINGLE_THREADED */
7795+
7796+ #ifndef NO_WOLFSSH_SERVER
7797+
7798+ /* Supplies the prompt set the test installed as the userAuth context. */
7799+ static int emptyPromptUserAuth (byte authType , WS_UserAuthData * authData ,
7800+ void * ctx )
7801+ {
7802+ if (authType == WOLFSSH_USERAUTH_KEYBOARD_SETUP ) {
7803+ WMEMCPY (& authData -> sf .keyboard , (WS_UserAuthData_Keyboard * )ctx ,
7804+ sizeof (WS_UserAuthData_Keyboard ));
7805+ return WOLFSSH_USERAUTH_SUCCESS ;
7806+ }
7807+ return WOLFSSH_USERAUTH_FAILURE ;
7808+ }
7809+
7810+
7811+ /* The sender must refuse a setup callback that supplies an empty prompt.
7812+ * Refused before sizing, so no keyed session is needed. */
7813+ static void test_wolfSSH_KeyboardInteractive_emptyPrompt (void )
7814+ {
7815+ WOLFSSH_CTX * ctx = NULL ;
7816+ WOLFSSH * ssh = NULL ;
7817+ WS_UserAuthData authData ;
7818+ WS_UserAuthData_Keyboard prompts ;
7819+ byte * promptText [1 ];
7820+ word32 promptLengths [1 ];
7821+ byte promptEcho [1 ];
7822+
7823+ promptText [0 ] = (byte * )"Password: " ;
7824+ promptLengths [0 ] = 10 ;
7825+ promptEcho [0 ] = 0 ;
7826+ WMEMSET (& prompts , 0 , sizeof (prompts ));
7827+ prompts .promptCount = 1 ;
7828+ prompts .prompts = promptText ;
7829+ prompts .promptLengths = promptLengths ;
7830+ prompts .promptEcho = promptEcho ;
7831+
7832+ AssertNotNull (ctx = wolfSSH_CTX_new (WOLFSSH_ENDPOINT_SERVER , NULL ));
7833+ wolfSSH_SetUserAuth (ctx , emptyPromptUserAuth );
7834+ AssertNotNull (ssh = wolfSSH_new (ctx ));
7835+ wolfSSH_SetUserAuthCtx (ssh , & prompts );
7836+
7837+ /* Control: the intact prompt set clears validation. It fails later, on
7838+ * an unkeyed session, but not as bad usage. */
7839+ WMEMSET (& authData , 0 , sizeof (authData ));
7840+ AssertIntNE (SendUserAuthKeyboardRequest (ssh , & authData ), WS_BAD_USAGE );
7841+
7842+ /* Zero-length prompt. */
7843+ promptLengths [0 ] = 0 ;
7844+ WMEMSET (& authData , 0 , sizeof (authData ));
7845+ AssertIntEQ (SendUserAuthKeyboardRequest (ssh , & authData ), WS_BAD_USAGE );
7846+
7847+ /* Non-zero length, no buffer. */
7848+ promptLengths [0 ] = 10 ;
7849+ promptText [0 ] = NULL ;
7850+ WMEMSET (& authData , 0 , sizeof (authData ));
7851+ AssertIntEQ (SendUserAuthKeyboardRequest (ssh , & authData ), WS_BAD_USAGE );
7852+
7853+ /* A prompt longer than the payload bound. */
7854+ promptLengths [0 ] = WOLFSSH_MAX_PROMPT_SZ + 1 ;
7855+ promptText [0 ] = (byte * )"Password: " ;
7856+ WMEMSET (& authData , 0 , sizeof (authData ));
7857+ AssertIntEQ (SendUserAuthKeyboardRequest (ssh , & authData ), WS_BAD_USAGE );
7858+
7859+ /* Prompt count with the arrays unset. */
7860+ prompts .prompts = NULL ;
7861+ prompts .promptLengths = NULL ;
7862+ prompts .promptEcho = NULL ;
7863+ WMEMSET (& authData , 0 , sizeof (authData ));
7864+ AssertIntEQ (SendUserAuthKeyboardRequest (ssh , & authData ), WS_BAD_USAGE );
7865+
7866+ wolfSSH_free (ssh );
7867+ wolfSSH_CTX_free (ctx );
7868+ }
7869+
7870+ #else /* NO_WOLFSSH_SERVER */
7871+ static void test_wolfSSH_KeyboardInteractive_emptyPrompt (void ) { ; }
7872+ #endif /* NO_WOLFSSH_SERVER */
77957873#endif /* WOLFSSH_KEYBOARD_INTERACTIVE */
77967874
77977875#endif /* WOLFSSH_TEST_BLOCK */
@@ -7897,6 +7975,7 @@ int wolfSSH_ApiTest(int argc, char** argv)
78977975#endif
78987976#ifdef WOLFSSH_KEYBOARD_INTERACTIVE
78997977 test_wolfSSH_KeyboardInteractive ();
7978+ test_wolfSSH_KeyboardInteractive_emptyPrompt ();
79007979#endif
79017980
79027981 /* SCP tests */
0 commit comments