@@ -872,6 +872,9 @@ WOLFSSH_CTX* CtxInit(WOLFSSH_CTX* ctx, byte side, void* heap)
872872 ctx->algoListCipher = cannedEncAlgoNames;
873873 ctx->algoListMac = cannedMacAlgoNames;
874874 ctx->algoListKeyAccepted = cannedKeyAlgoNames;
875+ #ifdef WOLFSSH_KEYBOARD_INTERACTIVE
876+ ctx->keyboardAuthCb = NULL;
877+ #endif
875878
876879 count = (word32)(sizeof(ctx->privateKey)
877880 / sizeof(ctx->privateKey[0]));
@@ -6421,11 +6424,16 @@ static int DoUserAuthInfoResponse(WOLFSSH* ssh,
64216424
64226425
64236426 if (ssh == NULL || buf == NULL || len == 0 || idx == NULL) {
6424-
64256427 ret = WS_BAD_ARGUMENT;
64266428 }
64276429
6430+ if ((ret == WS_SUCCESS) && (ssh->authId != ID_USERAUTH_KEYBOARD)) {
6431+ WLOG(WS_LOG_DEBUG, "DoUserAuthInfoResponse on non-keyboard auth");
6432+ ret = WS_FATAL_ERROR;
6433+ }
6434+
64286435 if (ret == WS_SUCCESS) {
6436+ WMEMSET(&authData, 0, sizeof(authData));
64296437 begin = *idx;
64306438 kb = &authData.sf.keyboard;
64316439 authData.type = WOLFSSH_USERAUTH_KEYBOARD;
@@ -7784,6 +7792,7 @@ static int DoUserAuthRequest(WOLFSSH* ssh,
77847792 authData.authName = buf + begin;
77857793 begin += authData.authNameSz;
77867794 authNameId = NameToId((char*)authData.authName, authData.authNameSz);
7795+ ssh->authId = authNameId;
77877796
77887797 if (authNameId == ID_USERAUTH_PASSWORD)
77897798 ret = DoUserAuthRequestPassword(ssh, &authData, buf, len, &begin);
@@ -8044,6 +8053,8 @@ static int DoUserAuthInfoRequest(WOLFSSH* ssh, byte* buf, word32 len,
80448053 ret = SendUserAuthKeyboardResponse(ssh);
80458054 }
80468055
8056+ ssh->authId = ID_USERAUTH_KEYBOARD;
8057+
80478058 WLOG(WS_LOG_DEBUG, "Leaving DoUserAuthInfoRequest(), ret = %d", ret);
80488059
80498060 return ret;
@@ -13348,6 +13359,11 @@ int SendUserAuthKeyboardRequest(WOLFSSH* ssh, WS_UserAuthData* authData)
1334813359 ret = WS_BAD_ARGUMENT;
1334913360 }
1335013361
13362+ if (ssh->ctx->keyboardAuthCb == NULL) {
13363+ WLOG(WS_LOG_DEBUG, "SendUserAuthKeyboardRequest called with no Cb set");
13364+ ret = WS_BAD_USAGE;
13365+ }
13366+
1335113367 if (ret == WS_SUCCESS) {
1335213368 ret = ssh->ctx->keyboardAuthCb(&authData->sf.keyboard,
1335313369 ssh->keyboardAuthCtx);
0 commit comments