Skip to content

Commit 597a71b

Browse files
authored
Merge pull request #802 from LinuxJedi/kbi-fixes
Keyboard Interactive bug fixes
2 parents ee9bc3b + 3e4d9c0 commit 597a71b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/internal.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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);

tests/auth.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,11 @@ int wolfSSH_AuthTest(int argc, char** argv)
586586
defined(NO_FILESYSTEM) || !defined(WOLFSSH_KEYBOARD_INTERACTIVE)
587587
return 77;
588588
#else
589+
590+
#if defined(DEBUG_WOLFSSH)
591+
wolfSSH_Debugging_ON();
592+
#endif
593+
589594
AssertIntEQ(wolfSSH_Init(), WS_SUCCESS);
590595

591596
#if defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,2)

0 commit comments

Comments
 (0)