Skip to content

Commit 80760b5

Browse files
authored
Merge pull request #213 from JacobBarthelmeh/testing
be more lenient on CR with protocol exchange
2 parents d75e826 + 6dd22d2 commit 80760b5

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/internal.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,14 @@ static int GetInputText(WOLFSSH* ssh, byte** pEol)
14261426
eol = WSTRNSTR((const char*)ssh->inputBuffer.buffer, "\r\n",
14271427
ssh->inputBuffer.length);
14281428

1429+
/* section 4.2 in RFC 4253 states that can be lenient on the CR for
1430+
* interop with older or undocumented versions of SSH */
1431+
if (!eol) {
1432+
WLOG(WS_LOG_DEBUG, "Checking for old version of protocol exchange");
1433+
eol = WSTRNSTR((const char*)ssh->inputBuffer.buffer, "\n",
1434+
ssh->inputBuffer.length);
1435+
}
1436+
14291437
if (eol)
14301438
gotLine = 1;
14311439

@@ -2254,6 +2262,8 @@ static int DoKexInit(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
22542262
}
22552263

22562264
if (ret == WS_SUCCESS) {
2265+
byte SSH_PROTO_EOL_SZ = 2;
2266+
22572267
strSz = (word32)WSTRLEN(sshProtoIdStr) - SSH_PROTO_EOL_SZ;
22582268
c32toa(strSz, scratchLen);
22592269
ret = wc_HashUpdate(&ssh->handshake->hash, enmhashId,
@@ -5339,6 +5349,7 @@ int DoProtoId(WOLFSSH* ssh)
53395349
int ret;
53405350
word32 idSz;
53415351
byte* eol;
5352+
byte SSH_PROTO_EOL_SZ = 1;
53425353

53435354
if ( (ret = GetInputText(ssh, &eol)) < 0) {
53445355
WLOG(WS_LOG_DEBUG, "get input text failed");
@@ -5367,6 +5378,9 @@ int DoProtoId(WOLFSSH* ssh)
53675378
ssh->clientOpenSSH = 1;
53685379
}
53695380

5381+
if (*eol == '\r') {
5382+
SSH_PROTO_EOL_SZ++;
5383+
}
53705384
*eol = 0;
53715385

53725386
idSz = (word32)WSTRLEN((char*)ssh->inputBuffer.buffer);

wolfssh/internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ enum {
123123
#define SHA1_96_SZ 12
124124
#define UINT32_SZ 4
125125
#define SSH_PROTO_SZ 7 /* "SSH-2.0" */
126-
#define SSH_PROTO_EOL_SZ 2 /* Just the CRLF */
127126
#define AEAD_IMP_IV_SZ 4
128127
#define AEAD_EXP_IV_SZ 8
129128
#define AEAD_NONCE_SZ (AEAD_IMP_IV_SZ+AEAD_EXP_IV_SZ)

0 commit comments

Comments
 (0)