@@ -491,6 +491,9 @@ const char* GetErrorString(int err)
491491 case WS_KDF_E:
492492 return "KDF error";
493493
494+ case WS_DISCONNECT:
495+ return "peer sent disconnect";
496+
494497 default:
495498 return "Unknown error code";
496499 }
@@ -5758,6 +5761,9 @@ static int KeyAgree_client(WOLFSSH* ssh, byte hashId, const byte* f, word32 fSz)
57585761}
57595762
57605763
5764+ static INLINE byte SigTypeForId(byte id);
5765+
5766+
57615767static int DoKexDhReply(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
57625768{
57635769 struct wolfSSH_sigKeyBlock *sigKeyBlock_ptr = NULL;
@@ -6007,9 +6013,10 @@ static int DoKexDhReply(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
60076013#ifndef WOLFSSH_NO_RSA
60086014 int tmpIdx = begin - sigSz;
60096015#endif
6010- /* Skip past the sig name. Check it, though. Other SSH
6011- * implementations do the verify based on the name, despite what
6012- * was agreed upon. XXX*/
6016+ const char* expectedSigName =
6017+ IdToName(SigTypeForId(ssh->handshake->pubKeyId));
6018+ word32 expectedSigNameSz = (word32)WSTRLEN(expectedSigName);
6019+
60136020 begin = 0;
60146021 ret = GetUint32(&scratch, sig, sigSz, &begin);
60156022 if (ret == WS_SUCCESS) {
@@ -6020,6 +6027,16 @@ static int DoKexDhReply(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
60206027 ret = WS_PARSE_E;
60216028 }
60226029 }
6030+ if (ret == WS_SUCCESS) {
6031+ if (scratch != expectedSigNameSz ||
6032+ WMEMCMP(sig + begin, expectedSigName, scratch) != 0) {
6033+ WLOG(WS_LOG_DEBUG,
6034+ "signature name %.*s did not match negotiated %s",
6035+ (int)scratch, (const char*)(sig + begin),
6036+ expectedSigName);
6037+ ret = WS_PARSE_E;
6038+ }
6039+ }
60236040 if (ret == WS_SUCCESS) {
60246041 begin += scratch;
60256042 ret = GetUint32(&scratch, sig, sigSz, &begin);
@@ -6475,7 +6492,6 @@ static int DoDisconnect(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
64756492 const char* reasonStr = NULL;
64766493 word32 begin = *idx;
64776494
6478- WOLFSSH_UNUSED(ssh);
64796495 WOLFSSH_UNUSED(len);
64806496 WOLFSSH_UNUSED(reasonStr);
64816497
@@ -6524,7 +6540,8 @@ static int DoDisconnect(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
65246540
65256541 *idx = begin;
65266542
6527- return WS_SUCCESS;
6543+ ssh->error = WS_DISCONNECT;
6544+ return WS_DISCONNECT;
65286545}
65296546
65306547
@@ -8629,6 +8646,7 @@ static int DoChannelOpen(WOLFSSH* ssh,
86298646 int isDirect = 0;
86308647#endif /* WOLFSSH_FWD */
86318648 WOLFSSH_CHANNEL* newChannel = NULL;
8649+ byte channelAppended = 0;
86328650 int ret = WS_SUCCESS;
86338651 word32 fail_reason = OPEN_OK;
86348652
@@ -8723,9 +8741,13 @@ static int DoChannelOpen(WOLFSSH* ssh,
87238741 }
87248742 }
87258743 #endif /* WOLFSSH_FWD */
8726- ChannelAppend(ssh, newChannel);
8727-
8728- ssh->clientState = CLIENT_CHANNEL_OPEN_DONE;
8744+ if (ret == WS_SUCCESS) {
8745+ ret = ChannelAppend(ssh, newChannel);
8746+ if (ret == WS_SUCCESS) {
8747+ channelAppended = 1;
8748+ ssh->clientState = CLIENT_CHANNEL_OPEN_DONE;
8749+ }
8750+ }
87298751 }
87308752 }
87318753
@@ -8735,19 +8757,24 @@ static int DoChannelOpen(WOLFSSH* ssh,
87358757 else {
87368758 const char *description = NULL;
87378759
8738- if (fail_reason == OPEN_ADMINISTRATIVELY_PROHIBITED)
8760+ if (newChannel != NULL && !channelAppended) {
8761+ ChannelDelete(newChannel, ssh->ctx->heap);
8762+ newChannel = NULL;
8763+ }
8764+
8765+ if (fail_reason == OPEN_OK) {
8766+ fail_reason = OPEN_ADMINISTRATIVELY_PROHIBITED;
8767+ description = "Channel open failed.";
8768+ }
8769+ else if (fail_reason == OPEN_ADMINISTRATIVELY_PROHIBITED)
87398770 description = "Administratively prohibited.";
87408771 else if (fail_reason == OPEN_UNKNOWN_CHANNEL_TYPE)
87418772 description = "Channel type not supported.";
87428773 else if (fail_reason == OPEN_RESOURCE_SHORTAGE)
87438774 description = "Not enough resources.";
87448775
8745- if (description != NULL) {
8746- ret = SendChannelOpenFail(ssh, peerChannelId,
8747- fail_reason, description, "en");
8748- }
8749- else
8750- ret = SendRequestSuccess(ssh, 0); /* XXX Is this right? */
8776+ ret = SendChannelOpenFail(ssh, peerChannelId,
8777+ fail_reason, description, "en");
87518778 }
87528779
87538780#ifdef WOLFSSH_FWD
@@ -10594,7 +10621,6 @@ static int PreparePacket(WOLFSSH* ssh, word32 payloadSz)
1059410621 return ret;
1059510622}
1059610623
10597-
1059810624static int BundlePacket(WOLFSSH* ssh)
1059910625{
1060010626 byte* output = NULL;
@@ -17563,7 +17589,7 @@ int wolfSSH_oct2dec(WOLFSSH* ssh, byte* oct, word32 octSz)
1756317589
1756417590 for (i = 0; i < octSz; i++)
1756517591 {
17566- if (oct[i] < '0' || oct[0 ] > '7') {
17592+ if (oct[i] < '0' || oct[i ] > '7') {
1756717593 ret = WS_BAD_ARGUMENT;
1756817594 break;
1756917595 }
0 commit comments