Skip to content

Commit 0927043

Browse files
Add support for keyboard-interactive auth using userAuthCb
Co-Authored-By: andrew@wolfssl.com <andrew@wolfssl.com>
1 parent ee9bc3b commit 0927043

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/internal.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13349,8 +13349,31 @@ int SendUserAuthKeyboardRequest(WOLFSSH* ssh, WS_UserAuthData* authData)
1334913349
}
1335013350

1335113351
if (ret == WS_SUCCESS) {
13352-
ret = ssh->ctx->keyboardAuthCb(&authData->sf.keyboard,
13353-
ssh->keyboardAuthCtx);
13352+
/* Set responseCount to 0 to indicate this is a prompt setup call */
13353+
authData->sf.keyboard.responseCount = 0;
13354+
13355+
/* First try using userAuthCb if it's set */
13356+
if (ssh->ctx->userAuthCb != NULL) {
13357+
WLOG(WS_LOG_DEBUG, "SUAKR: Calling userAuthCb for prompt setup");
13358+
ret = ssh->ctx->userAuthCb(WOLFSSH_USERAUTH_KEYBOARD,
13359+
authData, ssh->userAuthCtx);
13360+
13361+
/* If userAuthCb doesn't return SUCCESS_ANOTHER, fall back to keyboardAuthCb */
13362+
if (ret != WOLFSSH_USERAUTH_SUCCESS_ANOTHER) {
13363+
WLOG(WS_LOG_DEBUG, "SUAKR: userAuthCb didn't return SUCCESS_ANOTHER, falling back");
13364+
ret = ssh->ctx->keyboardAuthCb(&authData->sf.keyboard,
13365+
ssh->keyboardAuthCtx);
13366+
}
13367+
else {
13368+
WLOG(WS_LOG_DEBUG, "SUAKR: userAuthCb returned SUCCESS_ANOTHER, proceeding");
13369+
ret = WS_SUCCESS;
13370+
}
13371+
}
13372+
else {
13373+
/* Fall back to keyboardAuthCb if userAuthCb is not set */
13374+
ret = ssh->ctx->keyboardAuthCb(&authData->sf.keyboard,
13375+
ssh->keyboardAuthCtx);
13376+
}
1335413377
}
1335513378

1335613379
if (authData->sf.keyboard.promptCount > 0 &&

wolfssh/ssh.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@ typedef struct WS_UserAuthData {
360360
} sf;
361361
} WS_UserAuthData;
362362

363+
/* User Authentication callback
364+
* For keyboard-interactive authentication:
365+
* - When responseCount is 0, the callback is being called to set up prompts
366+
* Return WOLFSSH_USERAUTH_SUCCESS_ANOTHER to proceed with sending prompts
367+
* - When responseCount > 0, the callback is being called to validate responses
368+
* Return WOLFSSH_USERAUTH_SUCCESS_ANOTHER to request more prompts
369+
*/
363370
typedef int (*WS_CallbackUserAuth)(byte, WS_UserAuthData*, void*);
364371
WOLFSSH_API void wolfSSH_SetUserAuth(WOLFSSH_CTX*, WS_CallbackUserAuth);
365372
typedef int (*WS_CallbackUserAuthTypes)(WOLFSSH* ssh, void* ctx);

0 commit comments

Comments
 (0)