Merge pull request #26 from ejohnstown/banner-config

Update the banner
pull/29/head
dgarske 2017-06-12 11:16:11 -07:00 committed by GitHub
commit a0d40e0cd1
5 changed files with 57 additions and 13 deletions

View File

@ -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];

View File

@ -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);

View File

@ -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)
{

View File

@ -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;
};

View File

@ -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);