Skip to content

Commit af45bc3

Browse files
update example client for rekey and sanity check on window update after read attempt
1 parent 5fa6c0f commit af45bc3

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
@@ -342,6 +342,9 @@ static THREAD_RET readInput(void* in)
342342
ret = wolfSSH_stream_send(args->ssh, buf, sz);
343343
wc_UnLockMutex(&args->lock);
344344
if (ret <= 0) {
345+
if (ret == WS_REKEYING) {
346+
continue;
347+
}
345348
fprintf(stderr, "Couldn't send data\n");
346349
return THREAD_RET_SUCCESS;
347350
}
@@ -472,8 +475,16 @@ static THREAD_RET readPeer(void* in)
472475
continue;
473476
}
474477
#endif /* WOLFSSH_AGENT */
478+
else if (ret == WS_REKEYING) {
479+
wolfSSH_worker(args->ssh, NULL);
480+
ret = 0;
481+
}
475482
}
476483
else if (ret != WS_EOF) {
484+
if (ret == 0) {
485+
bytes = 0;
486+
continue;
487+
}
477488
err_sys("Stream read failed.");
478489
}
479490
}

src/ssh.c

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

1138+
if (ssh->isKeying) {
1139+
ssh->error = WS_REKEYING;
1140+
return WS_FATAL_ERROR;
1141+
}
1142+
11381143
inputBuffer = &ssh->channelList->inputBuffer;
11391144
ssh->error = WS_SUCCESS;
11401145

@@ -1164,7 +1169,7 @@ int wolfSSH_stream_read(WOLFSSH* ssh, byte* buf, word32 bufSz)
11641169
}
11651170

11661171
/* update internal input buffer based on data read */
1167-
if (ret == WS_SUCCESS) {
1172+
if (ret == WS_SUCCESS && !ssh->isKeying) {
11681173
int n;
11691174

11701175
n = min(bufSz, inputBuffer->length - inputBuffer->idx);
@@ -2901,6 +2906,11 @@ int wolfSSH_ChannelRead(WOLFSSH_CHANNEL* channel, byte* buf, word32 bufSz)
29012906
if (channel == NULL || buf == NULL || bufSz == 0)
29022907
return WS_BAD_ARGUMENT;
29032908

2909+
if (channel->ssh->isKeying) {
2910+
channel->ssh->error = WS_REKEYING;
2911+
return WS_REKEYING;
2912+
}
2913+
29042914
bufSz = _ChannelRead(channel, buf, bufSz);
29052915

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

0 commit comments

Comments
 (0)