@@ -1709,14 +1709,17 @@ static void StrListFree(StrList* list)
17091709}
17101710
17111711
1712- /* Map user names to passwords */
1712+ /* Map user names to passwords and keyboard auth prompts */
17131713/* Use arrays for username and p. The password or public key can
17141714 * be hashed and the hash stored here. Then I won't need the type. */
17151715typedef struct PwMap {
17161716 byte type ;
17171717 byte username [32 ];
17181718 word32 usernameSz ;
17191719 byte p [WC_SHA256_DIGEST_SIZE ];
1720+ #ifdef WOLFSSH_KEYBOARD_INTERACTIVE
1721+ WS_UserAuthData_Keyboard * keyboard ;
1722+ #endif
17201723 struct PwMap * next ;
17211724} PwMap ;
17221725
@@ -1752,6 +1755,24 @@ static PwMap* PwMapNew(PwMapList* list, byte type, const byte* username,
17521755}
17531756
17541757
1758+ #ifdef WOLFSSH_KEYBOARD_INTERACTIVE
1759+ /* Create new node for list of auths, adding keyboard auth prompts */
1760+ static PwMap * PwMapKeyboardNew (PwMapList * list , byte type , const byte * username ,
1761+ word32 usernameSz , const byte * p , word32 pSz ,
1762+ WS_UserAuthData_Keyboard * keyboard )
1763+ {
1764+ PwMap * map ;
1765+
1766+ map = PwMapNew (list , type , username , usernameSz , p , pSz );
1767+ if (map ) {
1768+ map -> keyboard = keyboard ;
1769+ }
1770+
1771+ return map ;
1772+ }
1773+ #endif
1774+
1775+
17551776static void PwMapListDelete (PwMapList * list )
17561777{
17571778 if (list != NULL ) {
@@ -2013,7 +2034,8 @@ static int LoadPasswdList(StrList* strList, PwMapList* mapList)
20132034 return count ;
20142035}
20152036#ifdef WOLFSSH_KEYBOARD_INTERACTIVE
2016- static int LoadKeyboardList (StrList * strList , PwMapList * mapList )
2037+ static int LoadKeyboardList (StrList * strList , PwMapList * mapList ,
2038+ WS_UserAuthData_Keyboard * kbAuthData )
20172039{
20182040 char names [256 ];
20192041 char * passwd ;
@@ -2026,9 +2048,10 @@ static int LoadKeyboardList(StrList* strList, PwMapList* mapList)
20262048 * passwd = 0 ;
20272049 passwd ++ ;
20282050
2029- PwMapNew (mapList , WOLFSSH_USERAUTH_KEYBOARD ,
2051+ PwMapKeyboardNew (mapList , WOLFSSH_USERAUTH_KEYBOARD ,
20302052 (byte * )names , (word32 )WSTRLEN (names ),
2031- (byte * )passwd , (word32 )WSTRLEN (passwd ));
2053+ (byte * )passwd , (word32 )WSTRLEN (passwd ),
2054+ kbAuthData );
20322055 }
20332056 else {
20342057 fprintf (stderr , "Ignoring password: %s\n" , names );
@@ -2192,6 +2215,7 @@ static int wsUserAuth(byte authType,
21922215#endif
21932216#ifdef WOLFSSH_KEYBOARD_INTERACTIVE
21942217 authType != WOLFSSH_USERAUTH_KEYBOARD &&
2218+ authType != WOLFSSH_USERAUTH_KEYBOARD_SETUP &&
21952219#endif
21962220 authType != WOLFSSH_USERAUTH_PUBLICKEY ) {
21972221
@@ -2315,6 +2339,14 @@ static int wsUserAuth(byte authType,
23152339 }
23162340 #ifdef WOLFSSH_KEYBOARD_INTERACTIVE
23172341 else if (authData -> type == WOLFSSH_USERAUTH_KEYBOARD ) {
2342+ if (authType == WOLFSSH_USERAUTH_KEYBOARD_SETUP ) {
2343+ /* setup the keyboard auth prompts */
2344+ WMEMCPY (& authData -> sf .keyboard , map -> keyboard ,
2345+ sizeof (WS_UserAuthData_Keyboard ));
2346+ return WS_SUCCESS ;
2347+ }
2348+
2349+ /* do keyboard auth prompts */
23182350 if (WMEMCMP (map -> p , authHash , WC_SHA256_DIGEST_SIZE ) == 0 ) {
23192351 return WOLFSSH_USERAUTH_SUCCESS ;
23202352 }
@@ -2338,15 +2370,6 @@ static int wsUserAuth(byte authType,
23382370 return WOLFSSH_USERAUTH_INVALID_USER ;
23392371}
23402372
2341- #ifdef WOLFSSH_KEYBOARD_INTERACTIVE
2342- static int keyboardCallback (WS_UserAuthData_Keyboard * kbAuth , void * ctx )
2343- {
2344- WS_UserAuthData_Keyboard * kbAuthData = (WS_UserAuthData_Keyboard * ) ctx ;
2345- WMEMCPY (kbAuth , kbAuthData , sizeof (WS_UserAuthData_Keyboard ));
2346-
2347- return WS_SUCCESS ;
2348- }
2349- #endif
23502373
23512374#ifdef WOLFSSH_SFTP
23522375/*
@@ -2800,9 +2823,6 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
28002823
28012824#ifdef WOLFSSH_KEYBOARD_INTERACTIVE
28022825 if (keyboardList ) {
2803- LoadKeyboardList (keyboardList , & pwMapList );
2804- StrListFree (keyboardList );
2805- keyboardList = NULL ;
28062826 kbAuthData .promptCount = 1 ;
28072827 kbAuthData .promptName = NULL ;
28082828 kbAuthData .promptNameSz = 0 ;
@@ -2825,7 +2845,9 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
28252845 ES_ERROR ("Error allocating promptEcho" );
28262846 }
28272847 kbAuthData .promptEcho [0 ] = 0 ;
2828- wolfSSH_SetKeyboardAuthPrompts (ctx , keyboardCallback );
2848+ LoadKeyboardList (keyboardList , & pwMapList , & kbAuthData );
2849+ StrListFree (keyboardList );
2850+ keyboardList = NULL ;
28292851 }
28302852#endif
28312853
@@ -3035,9 +3057,6 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
30353057 #endif
30363058 wolfSSH_SetUserAuthCtx (ssh , & pwMapList );
30373059 wolfSSH_SetKeyingCompletionCbCtx (ssh , (void * )ssh );
3038- #ifdef WOLFSSH_KEYBOARD_INTERACTIVE
3039- wolfSSH_SetKeyboardAuthCtx (ssh , & kbAuthData );
3040- #endif
30413060
30423061 /* Use the session object for its own highwater callback ctx */
30433062 if (defaultHighwater > 0 ) {
0 commit comments