mirror of https://github.com/wolfSSL/wolfssh.git
commit
a0d40e0cd1
|
@ -40,6 +40,8 @@
|
|||
#endif
|
||||
|
||||
|
||||
static const char echoserverBanner[] = "wolfSSH Example Echo Server\n";
|
||||
|
||||
typedef int SOCKET_T;
|
||||
#ifdef TEST_IPV6
|
||||
typedef struct sockaddr_in6 SOCKADDR_IN_T;
|
||||
|
@ -650,6 +652,7 @@ int main(void)
|
|||
|
||||
memset(&pwMapList, 0, sizeof(pwMapList));
|
||||
wolfSSH_SetUserAuth(ctx, wsUserAuth);
|
||||
wolfSSH_CTX_SetBanner(ctx, echoserverBanner);
|
||||
|
||||
{
|
||||
uint8_t buf[SCRATCH_BUFFER_SIZE];
|
||||
|
|
|
@ -227,6 +227,19 @@ static void HandshakeInfoFree(HandshakeInfo* hs, void* heap)
|
|||
}
|
||||
|
||||
|
||||
#ifdef DEBUG_WOLFSSH
|
||||
|
||||
static const char cannedBanner[] =
|
||||
"CANNED BANNER\r\n"
|
||||
"This server is an example test server. "
|
||||
"It should have its own banner, but\r\n"
|
||||
"it is currently using a canned one in "
|
||||
"the library. Be happy or not.\r\n";
|
||||
static const uint32_t cannedBannerSz = sizeof(cannedBanner) - 1;
|
||||
|
||||
#endif /* DEBUG_WOLFSSH */
|
||||
|
||||
|
||||
WOLFSSH_CTX* CtxInit(WOLFSSH_CTX* ctx, void* heap)
|
||||
{
|
||||
WLOG(WS_LOG_DEBUG, "Entering CtxInit()");
|
||||
|
@ -245,6 +258,10 @@ WOLFSSH_CTX* CtxInit(WOLFSSH_CTX* ctx, void* heap)
|
|||
#endif /* WOLFSSH_USER_IO */
|
||||
ctx->highwaterMark = DEFAULT_HIGHWATER_MARK;
|
||||
ctx->highwaterCb = wsHighwater;
|
||||
#ifdef DEBUG_WOLFSSH
|
||||
ctx->banner = cannedBanner;
|
||||
ctx->bannerSz = cannedBannerSz;
|
||||
#endif /* DEBUG_WOLFSSH */
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
@ -4001,37 +4018,36 @@ int SendUserAuthPkOk(WOLFSSH* ssh,
|
|||
}
|
||||
|
||||
|
||||
static const char cannedBanner[] =
|
||||
"CANNED BANNER\r\n"
|
||||
"This server is an example test server. "
|
||||
"It should have its own banner, but\r\n"
|
||||
"it is currently using a canned one in "
|
||||
"the library. Be happy or not.\r\n";
|
||||
static const uint32_t cannedBannerSz = sizeof(cannedBanner) - 1;
|
||||
|
||||
|
||||
int SendUserAuthBanner(WOLFSSH* ssh)
|
||||
{
|
||||
uint8_t* output;
|
||||
uint32_t idx;
|
||||
int ret = WS_SUCCESS;
|
||||
const char* banner;
|
||||
uint32_t bannerSz = 0;
|
||||
|
||||
if (ssh == NULL)
|
||||
ret = WS_BAD_ARGUMENT;
|
||||
|
||||
if (ssh->ctx->banner != NULL && ssh->ctx->bannerSz > 0) {
|
||||
banner = ssh->ctx->banner;
|
||||
bannerSz = ssh->ctx->bannerSz;
|
||||
}
|
||||
|
||||
if (ret == WS_SUCCESS)
|
||||
ret = PreparePacket(ssh, MSG_ID_SZ + (LENGTH_SZ * 2) +
|
||||
cannedBannerSz + cannedLangTagSz);
|
||||
bannerSz + cannedLangTagSz);
|
||||
|
||||
if (ret == WS_SUCCESS) {
|
||||
output = ssh->outputBuffer.buffer;
|
||||
idx = ssh->outputBuffer.length;
|
||||
|
||||
output[idx++] = MSGID_USERAUTH_BANNER;
|
||||
c32toa(cannedBannerSz, output + idx);
|
||||
c32toa(bannerSz, output + idx);
|
||||
idx += LENGTH_SZ;
|
||||
WMEMCPY(output + idx, cannedBanner, cannedBannerSz);
|
||||
idx += cannedBannerSz;
|
||||
if (bannerSz > 0)
|
||||
WMEMCPY(output + idx, banner, bannerSz);
|
||||
idx += bannerSz;
|
||||
c32toa(cannedLangTagSz, output + idx);
|
||||
idx += LENGTH_SZ;
|
||||
WMEMCPY(output + idx, cannedLangTag, cannedLangTagSz);
|
||||
|
|
22
src/ssh.c
22
src/ssh.c
|
@ -527,6 +527,28 @@ static int ProcessBuffer(WOLFSSH_CTX* ctx, const uint8_t* in, uint32_t inSz,
|
|||
}
|
||||
|
||||
|
||||
int wolfSSH_CTX_SetBanner(WOLFSSH_CTX* ctx,
|
||||
const char* newBanner)
|
||||
{
|
||||
uint32_t newBannerSz = 0;
|
||||
|
||||
WLOG(WS_LOG_DEBUG, "Entering wolfSSH_CTX_SetBanner()");
|
||||
|
||||
if (ctx == NULL)
|
||||
return WS_BAD_ARGUMENT;
|
||||
|
||||
if (newBanner != NULL) {
|
||||
WLOG(WS_LOG_INFO, " setting banner to: \"%s\"", newBanner);
|
||||
newBannerSz = (uint32_t)WSTRLEN(newBanner);
|
||||
}
|
||||
|
||||
ctx->banner = newBanner;
|
||||
ctx->bannerSz = newBannerSz;
|
||||
|
||||
return WS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int wolfSSH_CTX_UsePrivateKey_buffer(WOLFSSH_CTX* ctx,
|
||||
const uint8_t* in, uint32_t inSz, int format)
|
||||
{
|
||||
|
|
|
@ -153,6 +153,8 @@ struct WOLFSSH_CTX {
|
|||
uint8_t* privateKey; /* Owned by CTX */
|
||||
uint32_t privateKeySz;
|
||||
uint32_t highwaterMark;
|
||||
const char* banner;
|
||||
uint32_t bannerSz;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -124,6 +124,7 @@ WOLFSSH_API void wolfSSH_SetUserAuth(WOLFSSH_CTX*, WS_CallbackUserAuth);
|
|||
WOLFSSH_API void wolfSSH_SetUserAuthCtx(WOLFSSH*, void*);
|
||||
WOLFSSH_API void* wolfSSH_GetUserAuthCtx(WOLFSSH*);
|
||||
|
||||
WOLFSSH_API int wolfSSH_CTX_SetBanner(WOLFSSH_CTX*, const char*);
|
||||
WOLFSSH_API int wolfSSH_CTX_UsePrivateKey_buffer(WOLFSSH_CTX*,
|
||||
const uint8_t*, uint32_t, int);
|
||||
|
||||
|
|
Loading…
Reference in New Issue