Skip to content

Commit c86b633

Browse files
committed
Add validation for accept request and reply
Validates that the requested/accepted service in DoServiceRequest and DoServiceAccept is 'ssh-userauth', disconnecting if not. Includes intentional Windows build error for Jenkins supervisor testing.
1 parent e8f54ae commit c86b633

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

src/internal.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,9 @@ void CtxResourceFree(WOLFSSH_CTX* ctx)
11021102

11031103
#if defined(WOLFSSH_SSHD) && !defined(WOLFSSH_RESIZE_NO_DEFUALT)
11041104
#if defined(USE_WINDOWS_API)
1105+
/* Intentional compile error for Windows build testing */
1106+
#error "Injected Windows build failure for Jenkins supervisor testing"
1107+
11051108
static int WS_TermResize(WOLFSSH* ssh, word32 col, word32 row, word32 colP,
11061109
word32 rowP, void* usrCtx)
11071110
{
@@ -6534,6 +6537,20 @@ static int DoServiceRequest(WOLFSSH* ssh,
65346537

65356538
ret = GetString(name, &nameSz, buf, len, idx);
65366539

6540+
/* Requested service must be 'ssh-userauth' */
6541+
if (ret == WS_SUCCESS) {
6542+
const char* nameUserAuth = IdToName(ID_SERVICE_USERAUTH);
6543+
if (nameUserAuth == NULL
6544+
|| nameSz != (word32)XSTRLEN(nameUserAuth)
6545+
|| XMEMCMP(name, nameUserAuth, nameSz) != 0) {
6546+
WLOG(WS_LOG_DEBUG, "Requested unsupported service: %s", name);
6547+
/* Terminate session, ignore result of disconnect attempt */
6548+
(void)SendDisconnect(ssh,
6549+
WOLFSSH_DISCONNECT_SERVICE_NOT_AVAILABLE);
6550+
ret = WS_INVALID_STATE_E;
6551+
}
6552+
}
6553+
65376554
if (ret == WS_SUCCESS) {
65386555
WLOG(WS_LOG_DEBUG, "Requesting service: %s", name);
65396556
ssh->clientState = CLIENT_USERAUTH_REQUEST_DONE;
@@ -6552,6 +6569,20 @@ static int DoServiceAccept(WOLFSSH* ssh,
65526569

65536570
ret = GetString(name, &nameSz, buf, len, idx);
65546571

6572+
/* Accepted service must be 'ssh-userauth' */
6573+
if (ret == WS_SUCCESS) {
6574+
const char* nameUserAuth = IdToName(ID_SERVICE_USERAUTH);
6575+
if (nameUserAuth == NULL
6576+
|| nameSz != (word32)XSTRLEN(nameUserAuth)
6577+
|| XMEMCMP(name, nameUserAuth, nameSz) != 0) {
6578+
WLOG(WS_LOG_DEBUG, "Accepted unexpected service: %s", name);
6579+
/* Terminate session, ignore result of disconnect attempt */
6580+
(void)SendDisconnect(ssh,
6581+
WOLFSSH_DISCONNECT_SERVICE_NOT_AVAILABLE);
6582+
ret = WS_INVALID_STATE_E;
6583+
}
6584+
}
6585+
65556586
if (ret == WS_SUCCESS) {
65566587
WLOG(WS_LOG_DEBUG, "Accepted service: %s", name);
65576588
ssh->serverState = SERVER_USERAUTH_REQUEST_DONE;

0 commit comments

Comments
 (0)