diff --git a/src/internal.c b/src/internal.c index 4eb23e6..ccf0a13 100644 --- a/src/internal.c +++ b/src/internal.c @@ -1426,6 +1426,14 @@ static int GetInputText(WOLFSSH* ssh, byte** pEol) eol = WSTRNSTR((const char*)ssh->inputBuffer.buffer, "\r\n", ssh->inputBuffer.length); + /* section 4.2 in RFC 4253 states that can be lenient on the CR for + * interop with older or undocumented versions of SSH */ + if (!eol) { + WLOG(WS_LOG_DEBUG, "Checking for old version of protocol exchange"); + eol = WSTRNSTR((const char*)ssh->inputBuffer.buffer, "\n", + ssh->inputBuffer.length); + } + if (eol) gotLine = 1; @@ -2254,6 +2262,8 @@ static int DoKexInit(WOLFSSH* ssh, byte* buf, word32 len, word32* idx) } if (ret == WS_SUCCESS) { + byte SSH_PROTO_EOL_SZ = 2; + strSz = (word32)WSTRLEN(sshProtoIdStr) - SSH_PROTO_EOL_SZ; c32toa(strSz, scratchLen); ret = wc_HashUpdate(&ssh->handshake->hash, enmhashId, @@ -5339,6 +5349,7 @@ int DoProtoId(WOLFSSH* ssh) int ret; word32 idSz; byte* eol; + byte SSH_PROTO_EOL_SZ = 1; if ( (ret = GetInputText(ssh, &eol)) < 0) { WLOG(WS_LOG_DEBUG, "get input text failed"); @@ -5367,6 +5378,9 @@ int DoProtoId(WOLFSSH* ssh) ssh->clientOpenSSH = 1; } + if (*eol == '\r') { + SSH_PROTO_EOL_SZ++; + } *eol = 0; idSz = (word32)WSTRLEN((char*)ssh->inputBuffer.buffer); diff --git a/wolfssh/internal.h b/wolfssh/internal.h index 0cf6253..6dbee1c 100644 --- a/wolfssh/internal.h +++ b/wolfssh/internal.h @@ -123,7 +123,6 @@ enum { #define SHA1_96_SZ 12 #define UINT32_SZ 4 #define SSH_PROTO_SZ 7 /* "SSH-2.0" */ -#define SSH_PROTO_EOL_SZ 2 /* Just the CRLF */ #define AEAD_IMP_IV_SZ 4 #define AEAD_EXP_IV_SZ 8 #define AEAD_NONCE_SZ (AEAD_IMP_IV_SZ+AEAD_EXP_IV_SZ)