Skip to content

Commit fd29780

Browse files
ejohnstownpadelsbach
authored andcommitted
DoProtoId: case-sensitive SSH- prefix match
- Per RFC 4253 4.2 use WSTRNCMP instead of WSTRNCASECMP for prefix and full-ID comparisons. - Update client tests; add server test vectors expecting rejection of lowercase/mixed case. Issue: F-2865
1 parent be4aa44 commit fd29780

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/internal.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10923,7 +10923,7 @@ int DoProtoId(WOLFSSH* ssh)
1092310923
}
1092410924

1092510925
if (ssh->inputBuffer.length >= 4
10926-
&& WSTRNCASECMP((char*)ssh->inputBuffer.buffer, "SSH-", 4) == 0)
10926+
&& WSTRNCMP((char*)ssh->inputBuffer.buffer, "SSH-", 4) == 0)
1092710927
break;
1092810928

1092910929
if (!allowBanner) {
@@ -10952,8 +10952,8 @@ int DoProtoId(WOLFSSH* ssh)
1095210952
eolSz = (*eol == '\r') ? 2 : 1;
1095310953

1095410954
if (ssh->inputBuffer.length >= SSH_PROTO_SZ
10955-
&& WSTRNCASECMP((char*)ssh->inputBuffer.buffer,
10956-
ssh->ctx->sshProtoIdStr, SSH_PROTO_SZ) == 0) {
10955+
&& WSTRNCMP((char*)ssh->inputBuffer.buffer,
10956+
ssh->ctx->sshProtoIdStr, SSH_PROTO_SZ) == 0) {
1095710957

1095810958
if (ssh->ctx->side == WOLFSSH_ENDPOINT_SERVER)
1095910959
ssh->clientState = CLIENT_VERSION_DONE;

tests/unit.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,21 @@ static const ProtoIdTestVector protoIdTestVectors[] = {
8787
"SSH-2.0-wolfSSHv" LIBWOLFSSH_VERSION_STRING "\n",
8888
0, WS_SUCCESS, WOLFSSH_ENDPOINT_CLIENT },
8989

90-
/* Case-insensitive match. DoProtoId uses WSTRNCASECMP. */
90+
/* Case rejection. DoProtoId uses WSTRNCMP. */
9191
{ "lowercase ssh prefix",
9292
"ssh-2.0-wolfSSHv" LIBWOLFSSH_VERSION_STRING "\r\n",
93-
0, WS_SUCCESS, WOLFSSH_ENDPOINT_CLIENT },
93+
0, WS_SOCKET_ERROR_E, WOLFSSH_ENDPOINT_CLIENT },
9494
{ "mixed case SSH prefix",
9595
"Ssh-2.0-wolfSSHv" LIBWOLFSSH_VERSION_STRING "\r\n",
96-
0, WS_SUCCESS, WOLFSSH_ENDPOINT_CLIENT },
96+
0, WS_SOCKET_ERROR_E, WOLFSSH_ENDPOINT_CLIENT },
97+
98+
/* Case rejection. DoProtoId uses WSTRNCMP. */
99+
{ "lowercase ssh prefix",
100+
"ssh-2.0-wolfSSHv" LIBWOLFSSH_VERSION_STRING "\r\n",
101+
0, WS_VERSION_E, WOLFSSH_ENDPOINT_SERVER },
102+
{ "mixed case SSH prefix",
103+
"Ssh-2.0-wolfSSHv" LIBWOLFSSH_VERSION_STRING "\r\n",
104+
0, WS_VERSION_E, WOLFSSH_ENDPOINT_SERVER },
97105

98106
/* OpenSSH peer identification. */
99107
{ "OpenSSH version string",

0 commit comments

Comments
 (0)