diff --git a/src/ssh.c b/src/ssh.c index e25037925..49303f75a 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -3032,7 +3032,37 @@ size_t wolfSSH_GetText(WOLFSSH *ssh, WS_Text id, char *str, size_t strSz) return ret < 0 ? 0 : (size_t)ret; } -void wolfSSH_SetKeyingCompletionCb(WOLFSSH_CTX* ctx, WS_CallbackKeyingCompletion cb) + +int wolfSSH_SetKeyingCb(WOLFSSH_CTX* ctx, WS_CallbackKeying cb) +{ + int ret = WS_SSH_CTX_NULL_E; + + WLOG(WS_LOG_DEBUG, "Entering wolfSSH_SetKeyingCb()"); + + if (ctx != NULL) { + ctx->keyingCb = cb; + ret = WS_SUCCESS; + } + + return ret; +} + +int wolfSSH_SetKeyingCtx(WOLFSSH* ssh, void* ctx) +{ + int ret = WS_SSH_NULL_E; + + WLOG(WS_LOG_DEBUG, "Entering wolfSSH_SetKeyingCtx()"); + + if (ssh) { + ssh->keyingCtx = ctx; + ret = WS_SUCCESS; + } + + return ret; +} + +void wolfSSH_SetKeyingCompletionCb(WOLFSSH_CTX* ctx, + WS_CallbackKeyingCompletion cb) { WLOG(WS_LOG_DEBUG, "Entering wolfSSH_SetKeyingCompletionCb()"); diff --git a/wolfssh/internal.h b/wolfssh/internal.h index 7aa36d87b..aa0d109ac 100644 --- a/wolfssh/internal.h +++ b/wolfssh/internal.h @@ -497,6 +497,8 @@ struct WOLFSSH_CTX { void* heap; /* heap hint */ WS_CallbackIORecv ioRecvCb; /* I/O Receive Callback */ WS_CallbackIOSend ioSendCb; /* I/O Send Callback */ + WS_CallbackKeying keyingCb; /* Keying begin callback */ + WS_CallbackKeyingCompletion keyingCompletionCb; /* Keying complete */ WS_CallbackUserAuth userAuthCb; /* User Authentication Callback */ WS_CallbackUserAuthTypes userAuthTypesCb; /* Authentication Types Allowed */ WS_CallbackUserAuthResult userAuthResultCb; /* User Authentication Result */ @@ -549,7 +551,6 @@ struct WOLFSSH_CTX { #ifdef WOLFSSH_AGENT byte agentEnabled; #endif /* WOLFSSH_AGENT */ - WS_CallbackKeyingCompletion keyingCompletionCb; }; @@ -676,6 +677,8 @@ struct WOLFSSH { void* globalReqCtx; /* Global Request CB context */ void* reqSuccessCtx; /* Global Request Sucess CB context */ void* reqFailureCtx; /* Global Request Failure CB context */ + void* keyingCtx; /* Keying begin CB context */ + void* keyingCompletionCtx; /* Keying completion CB context */ void* channelOpenCtx; /* Channel Open CB context */ void* channelReqCtx; /* Channel Request CB context */ void* channelEofCtx; /* Channel EOF CB context */ @@ -876,7 +879,6 @@ struct WOLFSSH { #if defined(WOLFSSH_TERM) || defined(WOLFSSH_SHELL) word32 exitStatus; #endif - void* keyingCompletionCtx; }; diff --git a/wolfssh/ssh.h b/wolfssh/ssh.h index 8f6a2a115..134bc4568 100644 --- a/wolfssh/ssh.h +++ b/wolfssh/ssh.h @@ -152,11 +152,14 @@ typedef enum WS_Text { WOLFSSH_API size_t wolfSSH_GetText(WOLFSSH *ssh, WS_Text id, char *str, size_t strSz); +typedef void (*WS_CallbackKeying)(void *ctx, int rekey); +WOLFSSH_API int wolfSSH_SetKeyingCb(WOLFSSH_CTX* ctx, WS_CallbackKeying cb); +WOLFSSH_API int wolfSSH_SetKeyingCtx(WOLFSSH* ssh, void* ctx); + typedef void (*WS_CallbackKeyingCompletion)(void *); -WOLFSSH_API void wolfSSH_SetKeyingCompletionCb(WOLFSSH_CTX*, - WS_CallbackKeyingCompletion); -WOLFSSH_API void wolfSSH_SetKeyingCompletionCbCtx(WOLFSSH*, - void*); +WOLFSSH_API void wolfSSH_SetKeyingCompletionCb(WOLFSSH_CTX* ctx, + WS_CallbackKeyingCompletion cb); +WOLFSSH_API void wolfSSH_SetKeyingCompletionCbCtx(WOLFSSH* ssh, void* ctx); #define WS_CHANNEL_ID_SELF 0 #define WS_CHANNEL_ID_PEER 1