Skip to content

Commit 2bf79c4

Browse files
committed
WiP KBI bug fixes
* `keyboardAuthCb` was not initalized correctly, meaning we could enable the mode without callback. * `SendUserAuthKeyboardRequest` didn't check `keyboardAuthCb` for `NULL`. * `DoUserAuthInfoResponse` left `authData` partially uninitialized. * `DoUserAuthInfoResponse` new checks that KB auth is in progress.
1 parent ee9bc3b commit 2bf79c4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/internal.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ WOLFSSH_CTX* CtxInit(WOLFSSH_CTX* ctx, byte side, void* heap)
872872
ctx->algoListCipher = cannedEncAlgoNames;
873873
ctx->algoListMac = cannedMacAlgoNames;
874874
ctx->algoListKeyAccepted = cannedKeyAlgoNames;
875+
ctx->keyboardAuthCb = NULL;
875876

876877
count = (word32)(sizeof(ctx->privateKey)
877878
/ sizeof(ctx->privateKey[0]));
@@ -6421,11 +6422,16 @@ static int DoUserAuthInfoResponse(WOLFSSH* ssh,
64216422

64226423

64236424
if (ssh == NULL || buf == NULL || len == 0 || idx == NULL) {
6424-
64256425
ret = WS_BAD_ARGUMENT;
64266426
}
64276427

6428+
if ((ret == WS_SUCCESS) && (ssh->authId != ID_USERAUTH_KEYBOARD)) {
6429+
WLOG(WS_LOG_DEBUG, "DoUserAuthInfoResponse on non-keyboard auth");
6430+
ret = WS_FATAL_ERROR;
6431+
}
6432+
64286433
if (ret == WS_SUCCESS) {
6434+
WMEMSET(&authData, 0, sizeof(authData));
64296435
begin = *idx;
64306436
kb = &authData.sf.keyboard;
64316437
authData.type = WOLFSSH_USERAUTH_KEYBOARD;
@@ -7784,6 +7790,7 @@ static int DoUserAuthRequest(WOLFSSH* ssh,
77847790
authData.authName = buf + begin;
77857791
begin += authData.authNameSz;
77867792
authNameId = NameToId((char*)authData.authName, authData.authNameSz);
7793+
ssh->authId = authNameId;
77877794

77887795
if (authNameId == ID_USERAUTH_PASSWORD)
77897796
ret = DoUserAuthRequestPassword(ssh, &authData, buf, len, &begin);
@@ -8044,6 +8051,8 @@ static int DoUserAuthInfoRequest(WOLFSSH* ssh, byte* buf, word32 len,
80448051
ret = SendUserAuthKeyboardResponse(ssh);
80458052
}
80468053

8054+
ssh->authId = ID_USERAUTH_KEYBOARD;
8055+
80478056
WLOG(WS_LOG_DEBUG, "Leaving DoUserAuthInfoRequest(), ret = %d", ret);
80488057

80498058
return ret;
@@ -13348,6 +13357,11 @@ int SendUserAuthKeyboardRequest(WOLFSSH* ssh, WS_UserAuthData* authData)
1334813357
ret = WS_BAD_ARGUMENT;
1334913358
}
1335013359

13360+
if (ssh->ctx->keyboardAuthCb == NULL) {
13361+
WLOG(WS_LOG_DEBUG, "SendUserAuthKeyboardRequest called with no Cb set");
13362+
ret = WS_BAD_USAGE;
13363+
}
13364+
1335113365
if (ret == WS_SUCCESS) {
1335213366
ret = ssh->ctx->keyboardAuthCb(&authData->sf.keyboard,
1335313367
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)