Skip to content

Commit ceb4158

Browse files
update example client for rekey and sanity check on window update after read attempt
1 parent 15d94ff commit ceb4158

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

examples/client/client.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ static THREAD_RET readInput(void* in)
332332
ret = wolfSSH_stream_send(args->ssh, buf, sz);
333333
wc_UnLockMutex(&args->lock);
334334
if (ret <= 0) {
335+
if (ret == WS_REKEYING) {
336+
continue;
337+
}
335338
fprintf(stderr, "Couldn't send data\n");
336339
return THREAD_RET_SUCCESS;
337340
}
@@ -462,8 +465,16 @@ static THREAD_RET readPeer(void* in)
462465
continue;
463466
}
464467
#endif /* WOLFSSH_AGENT */
468+
else if (ret == WS_REKEYING) {
469+
wolfSSH_worker(args->ssh, NULL);
470+
ret = 0;
471+
}
465472
}
466473
else if (ret != WS_EOF) {
474+
if (ret == 0) {
475+
bytes = 0;
476+
continue;
477+
}
467478
err_sys("Stream read failed.");
468479
}
469480
}

src/ssh.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,11 @@ int wolfSSH_stream_read(WOLFSSH* ssh, byte* buf, word32 bufSz)
11031103
return WS_ERROR;
11041104
}
11051105

1106+
if (ssh->isKeying) {
1107+
ssh->error = WS_REKEYING;
1108+
return WS_FATAL_ERROR;
1109+
}
1110+
11061111
inputBuffer = &ssh->channelList->inputBuffer;
11071112
ssh->error = WS_SUCCESS;
11081113

@@ -1132,7 +1137,7 @@ int wolfSSH_stream_read(WOLFSSH* ssh, byte* buf, word32 bufSz)
11321137
}
11331138

11341139
/* update internal input buffer based on data read */
1135-
if (ret == WS_SUCCESS) {
1140+
if (ret == WS_SUCCESS && !ssh->isKeying) {
11361141
int n;
11371142

11381143
n = min(bufSz, inputBuffer->length - inputBuffer->idx);
@@ -2778,6 +2783,11 @@ int wolfSSH_ChannelRead(WOLFSSH_CHANNEL* channel, byte* buf, word32 bufSz)
27782783
if (channel == NULL || buf == NULL || bufSz == 0)
27792784
return WS_BAD_ARGUMENT;
27802785

2786+
if (channel->ssh->isKeying) {
2787+
channel->ssh->error = WS_REKEYING;
2788+
return WS_REKEYING;
2789+
}
2790+
27812791
bufSz = _ChannelRead(channel, buf, bufSz);
27822792

27832793
WLOG(WS_LOG_DEBUG, "Leaving wolfSSH_ChannelRead(), bytesRxd = %d",

0 commit comments

Comments
 (0)