@@ -15445,55 +15445,80 @@ static int BuildUserAuthRequestPublicKey(WOLFSSH* ssh,
1544515445int SendUserAuthKeyboardResponse(WOLFSSH* ssh)
1544615446{
1544715447 byte* output;
15448+ int authRet = WOLFSSH_USERAUTH_FAILURE;
1544815449 int ret = WS_SUCCESS;
1544915450 word32 idx;
1545015451 word32 payloadSz = 0;
1545115452 word32 prompt;
1545215453 WS_UserAuthData authData;
1545315454
15454- WLOG(WS_LOG_DEBUG, "Entering SendUserAuthKeyboardResponse()" );
15455+ WMEMSET(&authData, 0, sizeof(authData) );
1545515456
15456- authData.type = WOLFSSH_USERAUTH_KEYBOARD;
15457- authData.username = (const byte*)ssh->userName;
15458- authData.usernameSz = ssh->userNameSz;
15459- authData.sf.keyboard.promptCount = ssh->kbAuth.promptCount;
15460- authData.sf.keyboard.promptName = ssh->kbAuth.promptName;
15461- authData.sf.keyboard.promptNameSz = ssh->kbAuth.promptName ?
15462- (word32)WSTRLEN((char*)ssh->kbAuth.promptName) : 0;
15463- authData.sf.keyboard.promptInstruction = ssh->kbAuth.promptInstruction;
15464- authData.sf.keyboard.promptInstructionSz = ssh->kbAuth.promptInstruction ?
15465- (word32)WSTRLEN((char*)ssh->kbAuth.promptInstruction) : 0;
15466- authData.sf.keyboard.promptLanguage = ssh->kbAuth.promptLanguage;
15467- authData.sf.keyboard.promptLanguageSz = ssh->kbAuth.promptLanguage ?
15468- (word32)WSTRLEN((char*)ssh->kbAuth.promptLanguage) : 0;
15469- authData.sf.keyboard.prompts = ssh->kbAuth.prompts;
15470- authData.sf.keyboard.promptEcho = ssh->kbAuth.promptEcho;
15471- authData.sf.keyboard.responseCount = 0;
15472-
15473- WLOG(WS_LOG_DEBUG, "SUAR: Calling the userauth callback");
15474- ret = ssh->ctx->userAuthCb(WOLFSSH_USERAUTH_KEYBOARD, &authData,
15475- ssh->userAuthCtx);
15457+ WLOG(WS_LOG_DEBUG, "Entering SendUserAuthKeyboardResponse()");
1547615458
15477- WFREE(ssh->kbAuth.promptName, ssh->ctx->heap, 0);
15478- WFREE(ssh->kbAuth.promptInstruction, ssh->ctx->heap, 0);
15479- WFREE(ssh->kbAuth.promptLanguage, ssh->ctx->heap, 0);
15480- WFREE(ssh->kbAuth.promptEcho, ssh->ctx->heap, 0);
15481- for (prompt = 0; prompt < ssh->kbAuth.promptCount; prompt++) {
15482- WFREE((void*)ssh->kbAuth.prompts[prompt], ssh->ctx->heap, 0);
15459+ if (ssh == NULL || ssh->ctx == NULL) {
15460+ ret = WS_BAD_ARGUMENT;
1548315461 }
15484- WFREE(ssh->kbAuth.prompts, ssh->ctx->heap, 0);
15485-
15486- if (ret != WOLFSSH_USERAUTH_SUCCESS) {
15487- WLOG(WS_LOG_DEBUG, "SUAR: Couldn't get keyboard auth");
15488- ret = WS_FATAL_ERROR;
15462+ if (ret == WS_SUCCESS && ssh->ctx->userAuthCb == NULL) {
15463+ ret = WS_INVALID_STATE_E;
1548915464 }
15490- else if (ssh->kbAuth.promptCount != authData.sf.keyboard.responseCount) {
15491- WLOG(WS_LOG_DEBUG,
15492- "SUAR: Keyboard auth response count does not match request count");
15493- ret = WS_USER_AUTH_E;
15465+
15466+ if (ret == WS_SUCCESS) {
15467+ authData.type = WOLFSSH_USERAUTH_KEYBOARD;
15468+ authData.username = (const byte*)ssh->userName;
15469+ authData.usernameSz = ssh->userNameSz;
15470+ authData.sf.keyboard.promptCount = ssh->kbAuth.promptCount;
15471+ authData.sf.keyboard.promptName = ssh->kbAuth.promptName;
15472+ authData.sf.keyboard.promptNameSz = ssh->kbAuth.promptName ?
15473+ (word32)WSTRLEN((char*)ssh->kbAuth.promptName) : 0;
15474+ authData.sf.keyboard.promptInstruction = ssh->kbAuth.promptInstruction;
15475+ authData.sf.keyboard.promptInstructionSz = ssh->kbAuth.promptInstruction ?
15476+ (word32)WSTRLEN((char*)ssh->kbAuth.promptInstruction) : 0;
15477+ authData.sf.keyboard.promptLanguage = ssh->kbAuth.promptLanguage;
15478+ authData.sf.keyboard.promptLanguageSz = ssh->kbAuth.promptLanguage ?
15479+ (word32)WSTRLEN((char*)ssh->kbAuth.promptLanguage) : 0;
15480+ authData.sf.keyboard.prompts = ssh->kbAuth.prompts;
15481+ authData.sf.keyboard.promptEcho = ssh->kbAuth.promptEcho;
15482+ authData.sf.keyboard.responseCount = 0;
15483+
15484+ WLOG(WS_LOG_DEBUG, "SUAR: Calling the userauth callback");
15485+ authRet = ssh->ctx->userAuthCb(WOLFSSH_USERAUTH_KEYBOARD, &authData,
15486+ ssh->userAuthCtx);
15487+ }
15488+
15489+ if (ret == WS_SUCCESS) {
15490+ if (authRet != WOLFSSH_USERAUTH_SUCCESS) {
15491+ WLOG(WS_LOG_DEBUG, "SUAR: Couldn't get keyboard auth");
15492+ ret = WS_FATAL_ERROR;
15493+ }
15494+ else if (ssh->kbAuth.promptCount != authData.sf.keyboard.responseCount) {
15495+ WLOG(WS_LOG_DEBUG,
15496+ "SUAR: Keyboard auth response count does not match request count");
15497+ ret = WS_USER_AUTH_E;
15498+ }
15499+ else {
15500+ WLOG(WS_LOG_DEBUG, "SUAR: Callback successful keyboard");
15501+ }
1549415502 }
15495- else {
15496- WLOG(WS_LOG_DEBUG, "SUAR: Callback successful keyboard");
15503+
15504+ if (ssh != NULL && ssh->ctx != NULL) {
15505+ WFREE(ssh->kbAuth.promptName, ssh->ctx->heap, 0);
15506+ WFREE(ssh->kbAuth.promptInstruction, ssh->ctx->heap, 0);
15507+ WFREE(ssh->kbAuth.promptLanguage, ssh->ctx->heap, 0);
15508+ WFREE(ssh->kbAuth.promptEcho, ssh->ctx->heap, 0);
15509+ if (ssh->kbAuth.prompts != NULL) {
15510+ for (prompt = 0; prompt < ssh->kbAuth.promptCount; prompt++) {
15511+ WFREE((void*)ssh->kbAuth.prompts[prompt], ssh->ctx->heap, 0);
15512+ }
15513+ }
15514+ WFREE(ssh->kbAuth.prompts, ssh->ctx->heap, 0);
15515+
15516+ ssh->kbAuth.promptName = NULL;
15517+ ssh->kbAuth.promptInstruction = NULL;
15518+ ssh->kbAuth.promptLanguage = NULL;
15519+ ssh->kbAuth.promptEcho = NULL;
15520+ ssh->kbAuth.prompts = NULL;
15521+ ssh->kbAuth.promptCount = 0;
1549715522 }
1549815523
1549915524 payloadSz = MSG_ID_SZ;
@@ -15505,13 +15530,13 @@ int SendUserAuthKeyboardResponse(WOLFSSH* ssh)
1550515530 ret = PreparePacket(ssh, payloadSz);
1550615531 }
1550715532
15508- output = ssh->outputBuffer.buffer;
15509- idx = ssh->outputBuffer.length;
15510-
15511- output[idx++] = MSGID_USERAUTH_INFO_RESPONSE;
15533+ if (ret == WS_SUCCESS) {
15534+ output = ssh->outputBuffer.buffer;
15535+ idx = ssh->outputBuffer.length;
1551215536
15513- if (ret == WS_SUCCESS)
15537+ output[idx++] = MSGID_USERAUTH_INFO_RESPONSE;
1551415538 ret = BuildUserAuthResponseKeyboard(ssh, output, &idx, &authData);
15539+ }
1551515540
1551615541 if (ret == WS_SUCCESS) {
1551715542 ssh->outputBuffer.length = idx;
0 commit comments