mirror of https://github.com/wolfSSL/wolfssh.git
commit
77acddc7a6
|
@ -452,6 +452,9 @@ static int wolfSSH_FwdDefaultActions(WS_FwdCbAction action, void* vCtx,
|
||||||
ctx->state = FWD_STATE_INIT;
|
ctx->state = FWD_STATE_INIT;
|
||||||
}
|
}
|
||||||
else if (action == WOLFSSH_FWD_REMOTE_SETUP) {
|
else if (action == WOLFSSH_FWD_REMOTE_SETUP) {
|
||||||
|
struct sockaddr_in addr;
|
||||||
|
socklen_t addrSz = 0;
|
||||||
|
|
||||||
ctx->hostName = WSTRDUP(name, NULL, 0);
|
ctx->hostName = WSTRDUP(name, NULL, 0);
|
||||||
ctx->hostPort = port;
|
ctx->hostPort = port;
|
||||||
|
|
||||||
|
@ -461,8 +464,6 @@ static int wolfSSH_FwdDefaultActions(WS_FwdCbAction action, void* vCtx,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
struct sockaddr_in addr;
|
|
||||||
socklen_t addrSz = 0;
|
|
||||||
|
|
||||||
WMEMSET(&addr, 0, sizeof addr);
|
WMEMSET(&addr, 0, sizeof addr);
|
||||||
if (WSTRCMP(name, "") == 0 ||
|
if (WSTRCMP(name, "") == 0 ||
|
||||||
|
@ -477,9 +478,11 @@ static int wolfSSH_FwdDefaultActions(WS_FwdCbAction action, void* vCtx,
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("Not using IPv6 yet.\n");
|
printf("Not using IPv6 yet.\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
ret = WS_FWD_SETUP_E;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret == 0) {
|
||||||
ret = bind(ctx->listenFd,
|
ret = bind(ctx->listenFd,
|
||||||
(const struct sockaddr*)&addr, addrSz);
|
(const struct sockaddr*)&addr, addrSz);
|
||||||
}
|
}
|
||||||
|
@ -1269,13 +1272,11 @@ static THREAD_RETURN WOLFSSH_THREAD server_worker(void* vArgs)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WS_SFTP_COMPLETE:
|
|
||||||
#ifdef WOLFSSH_SFTP
|
#ifdef WOLFSSH_SFTP
|
||||||
|
case WS_SFTP_COMPLETE:
|
||||||
ret = sftp_worker(threadCtx);
|
ret = sftp_worker(threadCtx);
|
||||||
#else
|
|
||||||
err_sys("SFTP not compiled in. Please use --enable-sftp");
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
case WS_SUCCESS:
|
case WS_SUCCESS:
|
||||||
ret = ssh_worker(threadCtx);
|
ret = ssh_worker(threadCtx);
|
||||||
|
@ -2091,15 +2092,18 @@ static void ShowUsage(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void SignalTcpReady(func_args* serverArgs, word16 port)
|
static INLINE void SignalTcpReady(func_args* serverArgs, word16 port)
|
||||||
{
|
{
|
||||||
#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) && !defined(__MINGW32__)
|
#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) && \
|
||||||
|
!defined(__MINGW32__) && !defined(SINGLE_THREADED)
|
||||||
tcp_ready* ready = serverArgs->signal;
|
tcp_ready* ready = serverArgs->signal;
|
||||||
pthread_mutex_lock(&ready->mutex);
|
if (ready != NULL) {
|
||||||
ready->ready = 1;
|
pthread_mutex_lock(&ready->mutex);
|
||||||
ready->port = port;
|
ready->ready = 1;
|
||||||
pthread_cond_signal(&ready->cond);
|
ready->port = port;
|
||||||
pthread_mutex_unlock(&ready->mutex);
|
pthread_cond_signal(&ready->cond);
|
||||||
|
pthread_mutex_unlock(&ready->mutex);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
(void)serverArgs;
|
(void)serverArgs;
|
||||||
(void)port;
|
(void)port;
|
||||||
|
@ -2135,95 +2139,106 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
|
|
||||||
int argc = serverArgs->argc;
|
int argc = serverArgs->argc;
|
||||||
char** argv = serverArgs->argv;
|
char** argv = serverArgs->argv;
|
||||||
serverArgs->return_code = 0;
|
serverArgs->return_code = EXIT_SUCCESS;
|
||||||
|
|
||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
while ((ch = mygetopt(argc, argv, "?1a:d:efEp:R:Ni:j:I:J:K:P:")) != -1) {
|
const char* optlist = "?1a:d:efEp:R:Ni:j:I:J:K:P:";
|
||||||
switch (ch) {
|
myoptind = 0;
|
||||||
case '?' :
|
while ((ch = mygetopt(argc, argv, optlist)) != -1) {
|
||||||
ShowUsage();
|
switch (ch) {
|
||||||
WEXIT(EXIT_SUCCESS);
|
case '?' :
|
||||||
|
ShowUsage();
|
||||||
|
serverArgs->return_code = MY_EX_USAGE;
|
||||||
|
return 0;
|
||||||
|
|
||||||
case '1':
|
case '1':
|
||||||
multipleConnections = 0;
|
multipleConnections = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'a':
|
case 'a':
|
||||||
#ifdef WOLFSSH_CERTS
|
#ifdef WOLFSSH_CERTS
|
||||||
caCert = myoptarg;
|
caCert = myoptarg;
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
case 'e' :
|
|
||||||
userEcc = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'E':
|
|
||||||
peerEcc = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'f':
|
|
||||||
#ifdef WOLFSSH_SHELL
|
|
||||||
echo = 1;
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'p':
|
|
||||||
if (myoptarg == NULL) {
|
|
||||||
err_sys("NULL port value");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
port = (word16)atoi(myoptarg);
|
|
||||||
#if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API)
|
|
||||||
if (port == 0)
|
|
||||||
err_sys("port number cannot be 0");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
break;
|
||||||
break;
|
case 'e' :
|
||||||
|
userEcc = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'R':
|
case 'E':
|
||||||
readyFile = myoptarg;
|
peerEcc = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'N':
|
case 'f':
|
||||||
nonBlock = 1;
|
#ifdef WOLFSSH_SHELL
|
||||||
break;
|
echo = 1;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
|
||||||
case 'd':
|
case 'p':
|
||||||
defaultSftpPath = myoptarg;
|
if (myoptarg == NULL) {
|
||||||
break;
|
err_sys("NULL port value");
|
||||||
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
port = (word16)atoi(myoptarg);
|
||||||
|
#if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API)
|
||||||
|
if (port == 0) {
|
||||||
|
err_sys("port number cannot be 0");
|
||||||
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'j':
|
case 'R':
|
||||||
userPubKey = myoptarg;
|
readyFile = myoptarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'I':
|
case 'N':
|
||||||
sshPubKeyList = StrListAdd(sshPubKeyList, myoptarg);
|
nonBlock = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'J':
|
case 'd':
|
||||||
pemPubKeyList = StrListAdd(pemPubKeyList, myoptarg);
|
defaultSftpPath = myoptarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'K':
|
case 'j':
|
||||||
derPubKeyList = StrListAdd(derPubKeyList, myoptarg);
|
userPubKey = myoptarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'P':
|
case 'I':
|
||||||
passwdList = StrListAdd(passwdList, myoptarg);
|
sshPubKeyList = StrListAdd(sshPubKeyList, myoptarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case 'J':
|
||||||
ShowUsage();
|
pemPubKeyList = StrListAdd(pemPubKeyList, myoptarg);
|
||||||
WEXIT(MY_EX_USAGE);
|
break;
|
||||||
|
|
||||||
|
case 'K':
|
||||||
|
derPubKeyList = StrListAdd(derPubKeyList, myoptarg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'P':
|
||||||
|
passwdList = StrListAdd(passwdList, myoptarg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
ShowUsage();
|
||||||
|
serverArgs->return_code = MY_EX_USAGE;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
myoptind = 0; /* reset for test cases */
|
myoptind = 0; /* reset for test cases */
|
||||||
wc_InitMutex(&doneLock);
|
wc_InitMutex(&doneLock);
|
||||||
|
|
||||||
#ifdef WOLFSSH_TEST_BLOCK
|
#ifdef WOLFSSH_TEST_BLOCK
|
||||||
if (!nonBlock) {
|
if (!nonBlock) {
|
||||||
err_sys("Use -N when testing forced non blocking");
|
err_sys("Use -N when testing forced non blocking");
|
||||||
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2241,13 +2256,15 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
|
|
||||||
if (wolfSSH_Init() != WS_SUCCESS) {
|
if (wolfSSH_Init() != WS_SUCCESS) {
|
||||||
fprintf(stderr, "Couldn't initialize wolfSSH.\n");
|
fprintf(stderr, "Couldn't initialize wolfSSH.\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = wolfSSH_CTX_new(WOLFSSH_ENDPOINT_SERVER, NULL);
|
ctx = wolfSSH_CTX_new(WOLFSSH_ENDPOINT_SERVER, NULL);
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
fprintf(stderr, "Couldn't allocate SSH CTX data.\n");
|
fprintf(stderr, "Couldn't allocate SSH CTX data.\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
WMEMSET(&pwMapList, 0, sizeof(pwMapList));
|
WMEMSET(&pwMapList, 0, sizeof(pwMapList));
|
||||||
|
@ -2297,7 +2314,8 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
keyLoadBuf = (byte*)WMALLOC(EXAMPLE_KEYLOAD_BUFFER_SZ,
|
keyLoadBuf = (byte*)WMALLOC(EXAMPLE_KEYLOAD_BUFFER_SZ,
|
||||||
NULL, 0);
|
NULL, 0);
|
||||||
if (keyLoadBuf == NULL) {
|
if (keyLoadBuf == NULL) {
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
keyLoadBuf = buf;
|
keyLoadBuf = buf;
|
||||||
|
@ -2307,12 +2325,14 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
bufSz = load_key(peerEcc, keyLoadBuf, bufSz);
|
bufSz = load_key(peerEcc, keyLoadBuf, bufSz);
|
||||||
if (bufSz == 0) {
|
if (bufSz == 0) {
|
||||||
fprintf(stderr, "Couldn't load first key file.\n");
|
fprintf(stderr, "Couldn't load first key file.\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
if (wolfSSH_CTX_UsePrivateKey_buffer(ctx, keyLoadBuf, bufSz,
|
if (wolfSSH_CTX_UsePrivateKey_buffer(ctx, keyLoadBuf, bufSz,
|
||||||
WOLFSSH_FORMAT_ASN1) < 0) {
|
WOLFSSH_FORMAT_ASN1) < 0) {
|
||||||
fprintf(stderr, "Couldn't use first key buffer.\n");
|
fprintf(stderr, "Couldn't use first key buffer.\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
peerEcc = !peerEcc;
|
peerEcc = !peerEcc;
|
||||||
|
@ -2321,12 +2341,14 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
bufSz = load_key(peerEcc, keyLoadBuf, bufSz);
|
bufSz = load_key(peerEcc, keyLoadBuf, bufSz);
|
||||||
if (bufSz == 0) {
|
if (bufSz == 0) {
|
||||||
fprintf(stderr, "Couldn't load second key file.\n");
|
fprintf(stderr, "Couldn't load second key file.\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
if (wolfSSH_CTX_UsePrivateKey_buffer(ctx, keyLoadBuf, bufSz,
|
if (wolfSSH_CTX_UsePrivateKey_buffer(ctx, keyLoadBuf, bufSz,
|
||||||
WOLFSSH_FORMAT_ASN1) < 0) {
|
WOLFSSH_FORMAT_ASN1) < 0) {
|
||||||
fprintf(stderr, "Couldn't use second key buffer.\n");
|
fprintf(stderr, "Couldn't use second key buffer.\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userPubKey) {
|
if (userPubKey) {
|
||||||
|
@ -2339,13 +2361,15 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
/* create temp buffer and load in file */
|
/* create temp buffer and load in file */
|
||||||
if (userBufSz == 0) {
|
if (userBufSz == 0) {
|
||||||
fprintf(stderr, "Couldn't find size of file %s.\n", userPubKey);
|
fprintf(stderr, "Couldn't find size of file %s.\n", userPubKey);
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
userBuf = (byte*)WMALLOC(userBufSz, NULL, 0);
|
userBuf = (byte*)WMALLOC(userBufSz, NULL, 0);
|
||||||
if (userBuf == NULL) {
|
if (userBuf == NULL) {
|
||||||
fprintf(stderr, "WMALLOC failed\n");
|
fprintf(stderr, "WMALLOC failed\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
load_file(userPubKey, userBuf, &userBufSz);
|
load_file(userPubKey, userBuf, &userBufSz);
|
||||||
LoadPublicKeyBuffer(userBuf, userBufSz, &pwMapList);
|
LoadPublicKeyBuffer(userBuf, userBufSz, &pwMapList);
|
||||||
|
@ -2363,20 +2387,23 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
if (certBufSz == 0) {
|
if (certBufSz == 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Couldn't find size of file %s.\n", caCert);
|
"Couldn't find size of file %s.\n", caCert);
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
certBuf = (byte*)WMALLOC(certBufSz, NULL, 0);
|
certBuf = (byte*)WMALLOC(certBufSz, NULL, 0);
|
||||||
if (certBuf == NULL) {
|
if (certBuf == NULL) {
|
||||||
fprintf(stderr, "WMALLOC failed\n");
|
fprintf(stderr, "WMALLOC failed\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
load_file(caCert, certBuf, &certBufSz);
|
load_file(caCert, certBuf, &certBufSz);
|
||||||
ret = wolfSSH_CTX_AddRootCert_buffer(ctx, certBuf, certBufSz,
|
ret = wolfSSH_CTX_AddRootCert_buffer(ctx, certBuf, certBufSz,
|
||||||
WOLFSSH_FORMAT_PEM);
|
WOLFSSH_FORMAT_PEM);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
fprintf(stderr, "Couldn't add root cert\n");
|
fprintf(stderr, "Couldn't add root cert\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
WFREE(certBuf, NULL, 0);
|
WFREE(certBuf, NULL, 0);
|
||||||
}
|
}
|
||||||
|
@ -2423,7 +2450,8 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
/* wait for network and storage device */
|
/* wait for network and storage device */
|
||||||
if (NETBOOT_Wait_For_Network_Up(NU_SUSPEND) != NU_SUCCESS) {
|
if (NETBOOT_Wait_For_Network_Up(NU_SUSPEND) != NU_SUCCESS) {
|
||||||
fprintf(stderr, "Couldn't find network.\r\n");
|
fprintf(stderr, "Couldn't find network.\r\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 15 && ret != NU_SUCCESS; i++)
|
for(i = 0; i < 15 && ret != NU_SUCCESS; i++)
|
||||||
|
@ -2435,7 +2463,8 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
|
|
||||||
if (ret != NU_SUCCESS) {
|
if (ret != NU_SUCCESS) {
|
||||||
fprintf(stderr, "Couldn't find storage device.\r\n");
|
fprintf(stderr, "Couldn't find storage device.\r\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -2444,9 +2473,11 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
if (readyFile != NULL) {
|
if (readyFile != NULL) {
|
||||||
#ifdef NO_FILESYSTEM
|
#ifdef NO_FILESYSTEM
|
||||||
fprintf(stderr, "cannot create readyFile with no file system.\r\n");
|
fprintf(stderr, "cannot create readyFile with no file system.\r\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
#endif
|
return 0;
|
||||||
|
#else
|
||||||
port = 0;
|
port = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
tcp_listen(&listenFd, &port, 1);
|
tcp_listen(&listenFd, &port, 1);
|
||||||
/* write out port number listing to, to user set ready file */
|
/* write out port number listing to, to user set ready file */
|
||||||
|
@ -2477,7 +2508,8 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
NULL, 0);
|
NULL, 0);
|
||||||
if (threadCtx == NULL) {
|
if (threadCtx == NULL) {
|
||||||
fprintf(stderr, "Couldn't allocate thread context data.\n");
|
fprintf(stderr, "Couldn't allocate thread context data.\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
WMEMSET(threadCtx, 0, sizeof *threadCtx);
|
WMEMSET(threadCtx, 0, sizeof *threadCtx);
|
||||||
|
|
||||||
|
@ -2485,7 +2517,8 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
if (ssh == NULL) {
|
if (ssh == NULL) {
|
||||||
WFREE(threadCtx, NULL, 0);
|
WFREE(threadCtx, NULL, 0);
|
||||||
fprintf(stderr, "Couldn't allocate SSH data.\n");
|
fprintf(stderr, "Couldn't allocate SSH data.\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
wolfSSH_SetUserAuthCtx(ssh, &pwMapList);
|
wolfSSH_SetUserAuthCtx(ssh, &pwMapList);
|
||||||
/* Use the session object for its own highwater callback ctx */
|
/* Use the session object for its own highwater callback ctx */
|
||||||
|
@ -2497,7 +2530,8 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
#ifdef WOLFSSH_SFTP
|
#ifdef WOLFSSH_SFTP
|
||||||
if (SetDefaultSftpPath(ssh, defaultSftpPath) != 0) {
|
if (SetDefaultSftpPath(ssh, defaultSftpPath) != 0) {
|
||||||
fprintf(stderr, "Couldn't store default sftp path.\n");
|
fprintf(stderr, "Couldn't store default sftp path.\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2514,7 +2548,8 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
* 0.0.0.0 if ip adder any */
|
* 0.0.0.0 if ip adder any */
|
||||||
if (NU_Get_Sock_Name(listenFd, &sock, &addrLength) != NU_SUCCESS) {
|
if (NU_Get_Sock_Name(listenFd, &sock, &addrLength) != NU_SUCCESS) {
|
||||||
fprintf(stderr, "Couldn't find network.\r\n");
|
fprintf(stderr, "Couldn't find network.\r\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
WMEMCPY(ipaddr, &sock.ip_num, MAX_ADDRESS_SIZE);
|
WMEMCPY(ipaddr, &sock.ip_num, MAX_ADDRESS_SIZE);
|
||||||
|
@ -2531,8 +2566,11 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
clientFd = accept(listenFd, (struct sockaddr*)&clientAddr,
|
clientFd = accept(listenFd, (struct sockaddr*)&clientAddr,
|
||||||
&clientAddrSz);
|
&clientAddrSz);
|
||||||
#endif
|
#endif
|
||||||
if (clientFd == -1)
|
if (clientFd == -1) {
|
||||||
err_sys("tcp accept failed");
|
err_sys("tcp accept failed");
|
||||||
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (nonBlock)
|
if (nonBlock)
|
||||||
tcp_set_nonblocking(&clientFd);
|
tcp_set_nonblocking(&clientFd);
|
||||||
|
@ -2560,12 +2598,16 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
|
|
||||||
} while (multipleConnections && !quit);
|
} while (multipleConnections && !quit);
|
||||||
|
|
||||||
|
if (listenFd != 0) {
|
||||||
|
WCLOSESOCKET(listenFd);
|
||||||
|
}
|
||||||
wc_FreeMutex(&doneLock);
|
wc_FreeMutex(&doneLock);
|
||||||
PwMapListDelete(&pwMapList);
|
PwMapListDelete(&pwMapList);
|
||||||
wolfSSH_CTX_free(ctx);
|
wolfSSH_CTX_free(ctx);
|
||||||
if (wolfSSH_Cleanup() != WS_SUCCESS) {
|
if (wolfSSH_Cleanup() != WS_SUCCESS) {
|
||||||
fprintf(stderr, "Couldn't clean up wolfSSH.\n");
|
fprintf(stderr, "Couldn't clean up wolfSSH.\n");
|
||||||
WEXIT(EXIT_FAILURE);
|
serverArgs->return_code = EXIT_FAILURE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#if !defined(WOLFSSH_NO_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
|
#if !defined(WOLFSSH_NO_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
|
||||||
wc_ecc_fp_free(); /* free per thread cache */
|
wc_ecc_fp_free(); /* free per thread cache */
|
||||||
|
@ -2578,40 +2620,45 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
|
||||||
#endif /* NO_WOLFSSH_SERVER */
|
#endif /* NO_WOLFSSH_SERVER */
|
||||||
|
|
||||||
|
|
||||||
#ifndef NO_MAIN_DRIVER
|
|
||||||
void wolfSSL_Debugging_ON(void);
|
void wolfSSL_Debugging_ON(void);
|
||||||
|
|
||||||
|
int wolfSSH_Echoserver(int argc, char** argv)
|
||||||
|
{
|
||||||
|
func_args args;
|
||||||
|
|
||||||
|
WMEMSET(&args, 0, sizeof(args));
|
||||||
|
args.argc = argc;
|
||||||
|
args.argv = argv;
|
||||||
|
|
||||||
|
WSTARTTCP();
|
||||||
|
|
||||||
|
#ifdef DEBUG_WOLFSSH
|
||||||
|
wolfSSL_Debugging_ON();
|
||||||
|
wolfSSH_Debugging_ON();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(WOLFSSL_NUCLEUS) && !defined(INTEGRITY) && !defined(__INTEGRITY)
|
||||||
|
ChangeToWolfSshRoot();
|
||||||
|
#endif
|
||||||
|
#ifndef NO_WOLFSSH_SERVER
|
||||||
|
echoserver_test(&args);
|
||||||
|
#else
|
||||||
|
printf("wolfSSH compiled without server support\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
wolfSSH_Cleanup();
|
||||||
|
|
||||||
|
return args.return_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NO_MAIN_DRIVER
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
func_args args;
|
return wolfSSH_Echoserver(argc, argv);
|
||||||
|
|
||||||
args.argc = argc;
|
|
||||||
args.argv = argv;
|
|
||||||
args.return_code = 0;
|
|
||||||
args.user_auth = NULL;
|
|
||||||
|
|
||||||
WSTARTTCP();
|
|
||||||
|
|
||||||
#ifdef DEBUG_WOLFSSH
|
|
||||||
wolfSSL_Debugging_ON();
|
|
||||||
wolfSSH_Debugging_ON();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef WOLFSSL_NUCLEUS
|
|
||||||
ChangeToWolfSshRoot();
|
|
||||||
#endif
|
|
||||||
#ifndef NO_WOLFSSH_SERVER
|
|
||||||
echoserver_test(&args);
|
|
||||||
#else
|
|
||||||
printf("wolfSSH compiled without server support\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
wolfSSH_Cleanup();
|
|
||||||
|
|
||||||
return args.return_code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int myoptind = 0;
|
int myoptind = 0;
|
||||||
char* myoptarg = NULL;
|
char* myoptarg = NULL;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
|
|
||||||
THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args);
|
THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args);
|
||||||
|
int wolfSSH_Echoserver(int argc, char** argv);
|
||||||
|
|
||||||
|
|
||||||
#endif /* _WOLFSSH_EXAMPLES_ECHOSERVER_H_ */
|
#endif /* _WOLFSSH_EXAMPLES_ECHOSERVER_H_ */
|
||||||
|
|
243
tests/api.c
243
tests/api.c
|
@ -51,11 +51,18 @@ int myoptind = 0;
|
||||||
char* myoptarg = NULL;
|
char* myoptarg = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLFSSH_NO_ABORT
|
||||||
|
#define WABORT() abort()
|
||||||
|
#else
|
||||||
|
#define WABORT()
|
||||||
|
#endif
|
||||||
|
|
||||||
#define Fail(description, result) do { \
|
#define Fail(description, result) do { \
|
||||||
printf("\nERROR - %s line %d failed with:", __FILE__, __LINE__); \
|
printf("\nERROR - %s line %d failed with:", __FILE__, __LINE__); \
|
||||||
printf("\n expected: "); printf description; \
|
fputs("\n expected: ", stdout); printf description; \
|
||||||
printf("\n result: "); printf result; printf("\n\n"); \
|
fputs("\n result: ", stdout); printf result; fputs("\n\n", stdout); \
|
||||||
abort(); \
|
fflush(stdout); \
|
||||||
|
WABORT(); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define Assert(test, description, result) if (!(test)) Fail(description, result)
|
#define Assert(test, description, result) if (!(test)) Fail(description, result)
|
||||||
|
@ -65,15 +72,14 @@ char* myoptarg = NULL;
|
||||||
#define AssertNotNull(x) Assert( (x), ("%s is not null", #x), (#x " => NULL"))
|
#define AssertNotNull(x) Assert( (x), ("%s is not null", #x), (#x " => NULL"))
|
||||||
|
|
||||||
#define AssertNull(x) do { \
|
#define AssertNull(x) do { \
|
||||||
void* _x = (void *) (x); \
|
PEDANTIC_EXTENSION void* _x = (void*)(x); \
|
||||||
\
|
\
|
||||||
Assert(!_x, ("%s is null", #x), (#x " => %p", _x)); \
|
Assert(!_x, ("%s is null", #x), (#x " => %p", _x)); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define AssertInt(x, y, op, er) do { \
|
#define AssertInt(x, y, op, er) do { \
|
||||||
int _x = x; \
|
int _x = (int)(x); \
|
||||||
int _y = y; \
|
int _y = (int)(y); \
|
||||||
\
|
|
||||||
Assert(_x op _y, ("%s " #op " %s", #x, #y), ("%d " #er " %d", _x, _y)); \
|
Assert(_x op _y, ("%s " #op " %s", #x, #y), ("%d " #er " %d", _x, _y)); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
@ -85,10 +91,9 @@ char* myoptarg = NULL;
|
||||||
#define AssertIntLE(x, y) AssertInt(x, y, <=, >)
|
#define AssertIntLE(x, y) AssertInt(x, y, <=, >)
|
||||||
|
|
||||||
#define AssertStr(x, y, op, er) do { \
|
#define AssertStr(x, y, op, er) do { \
|
||||||
const char* _x = x; \
|
const char* _x = (const char*)(x); \
|
||||||
const char* _y = y; \
|
const char* _y = (const char*)(y); \
|
||||||
int _z = strcmp(_x, _y); \
|
int _z = (_x && _y) ? strcmp(_x, _y) : -1; \
|
||||||
\
|
|
||||||
Assert(_z op 0, ("%s " #op " %s", #x, #y), \
|
Assert(_z op 0, ("%s " #op " %s", #x, #y), \
|
||||||
("\"%s\" " #er " \"%s\"", _x, _y));\
|
("\"%s\" " #er " \"%s\"", _x, _y));\
|
||||||
} while(0)
|
} while(0)
|
||||||
|
@ -100,98 +105,26 @@ char* myoptarg = NULL;
|
||||||
#define AssertStrGE(x, y) AssertStr(x, y, >=, <)
|
#define AssertStrGE(x, y) AssertStr(x, y, >=, <)
|
||||||
#define AssertStrLE(x, y) AssertStr(x, y, <=, >)
|
#define AssertStrLE(x, y) AssertStr(x, y, <=, >)
|
||||||
|
|
||||||
|
#define AssertPtr(x, y, op, er) do { \
|
||||||
|
PRAGMA_GCC_DIAG_PUSH; \
|
||||||
|
/* remarkably, without this inhibition, */ \
|
||||||
|
/* the _Pragma()s make the declarations warn. */ \
|
||||||
|
PRAGMA_GCC("GCC diagnostic ignored \"-Wdeclaration-after-statement\""); \
|
||||||
|
/* inhibit "ISO C forbids conversion of function pointer */ \
|
||||||
|
/* to object pointer type [-Werror=pedantic]" */ \
|
||||||
|
PRAGMA_GCC("GCC diagnostic ignored \"-Wpedantic\""); \
|
||||||
|
void* _x = (void*)(x); \
|
||||||
|
void* _y = (void*)(y); \
|
||||||
|
Assert(_x op _y, ("%s " #op " %s", #x, #y), ("%p " #er " %p", _x, _y)); \
|
||||||
|
PRAGMA_GCC_DIAG_POP; \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#if defined(WOLFSSH_SFTP) && !defined(NO_WOLFSSH_CLIENT)
|
#define AssertPtrEq(x, y) AssertPtr(x, y, ==, !=)
|
||||||
|
#define AssertPtrNE(x, y) AssertPtr(x, y, !=, ==)
|
||||||
#include "examples/echoserver/echoserver.h"
|
#define AssertPtrGT(x, y) AssertPtr(x, y, >, <=)
|
||||||
|
#define AssertPtrLT(x, y) AssertPtr(x, y, <, >=)
|
||||||
byte userPassword[256];
|
#define AssertPtrGE(x, y) AssertPtr(x, y, >=, <)
|
||||||
static int sftpUserAuth(byte authType, WS_UserAuthData* authData, void* ctx)
|
#define AssertPtrLE(x, y) AssertPtr(x, y, <=, >)
|
||||||
{
|
|
||||||
int ret = WOLFSSH_USERAUTH_INVALID_AUTHTYPE;
|
|
||||||
|
|
||||||
if (authType == WOLFSSH_USERAUTH_PASSWORD) {
|
|
||||||
const char* defaultPassword = (const char*)ctx;
|
|
||||||
word32 passwordSz;
|
|
||||||
|
|
||||||
ret = WOLFSSH_USERAUTH_SUCCESS;
|
|
||||||
if (defaultPassword != NULL) {
|
|
||||||
passwordSz = (word32)strlen(defaultPassword);
|
|
||||||
memcpy(userPassword, defaultPassword, passwordSz);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf("Expecting password set for test cases\n");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret == WOLFSSH_USERAUTH_SUCCESS) {
|
|
||||||
authData->sf.password.password = userPassword;
|
|
||||||
authData->sf.password.passwordSz = passwordSz;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef NO_WOLFSSH_CLIENT
|
|
||||||
/* preforms connection to port, sets WOLFSSH_CTX and WOLFSSH on success
|
|
||||||
* caller needs to free ctx and ssh when done
|
|
||||||
*/
|
|
||||||
static void sftp_client_connect(WOLFSSH_CTX** ctx, WOLFSSH** ssh, int port)
|
|
||||||
{
|
|
||||||
SOCKET_T sockFd = WOLFSSH_SOCKET_INVALID;
|
|
||||||
SOCKADDR_IN_T clientAddr;
|
|
||||||
socklen_t clientAddrSz = sizeof(clientAddr);
|
|
||||||
int ret;
|
|
||||||
char* host = (char*)wolfSshIp;
|
|
||||||
const char* username = "jill";
|
|
||||||
const char* password = "upthehill";
|
|
||||||
|
|
||||||
if (ctx == NULL || ssh == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
*ctx = wolfSSH_CTX_new(WOLFSSH_ENDPOINT_CLIENT, NULL);
|
|
||||||
if (*ctx == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
wolfSSH_SetUserAuth(*ctx, sftpUserAuth);
|
|
||||||
*ssh = wolfSSH_new(*ctx);
|
|
||||||
if (*ssh == NULL) {
|
|
||||||
wolfSSH_CTX_free(*ctx);
|
|
||||||
*ctx = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
build_addr(&clientAddr, host, port);
|
|
||||||
tcp_socket(&sockFd);
|
|
||||||
ret = connect(sockFd, (const struct sockaddr *)&clientAddr, clientAddrSz);
|
|
||||||
if (ret != 0){
|
|
||||||
wolfSSH_free(*ssh);
|
|
||||||
wolfSSH_CTX_free(*ctx);
|
|
||||||
*ctx = NULL;
|
|
||||||
*ssh = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
wolfSSH_SetUserAuthCtx(*ssh, (void*)password);
|
|
||||||
ret = wolfSSH_SetUsername(*ssh, username);
|
|
||||||
if (ret == WS_SUCCESS)
|
|
||||||
ret = wolfSSH_set_fd(*ssh, (int)sockFd);
|
|
||||||
|
|
||||||
if (ret == WS_SUCCESS)
|
|
||||||
ret = wolfSSH_SFTP_connect(*ssh);
|
|
||||||
|
|
||||||
if (ret != WS_SUCCESS){
|
|
||||||
wolfSSH_free(*ssh);
|
|
||||||
wolfSSH_CTX_free(*ctx);
|
|
||||||
*ctx = NULL;
|
|
||||||
*ssh = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* NO_WOLFSSH_CLIENT */
|
|
||||||
#endif /* WOLFSSH_SFTP */
|
|
||||||
|
|
||||||
|
|
||||||
enum WS_TestEndpointTypes {
|
enum WS_TestEndpointTypes {
|
||||||
|
@ -658,6 +591,7 @@ static void test_wolfSSH_CertMan(void)
|
||||||
|
|
||||||
|
|
||||||
#ifdef WOLFSSH_SCP
|
#ifdef WOLFSSH_SCP
|
||||||
|
|
||||||
static int my_ScpRecv(WOLFSSH* ssh, int state, const char* basePath,
|
static int my_ScpRecv(WOLFSSH* ssh, int state, const char* basePath,
|
||||||
const char* fileName, int fileMode, word64 mTime, word64 aTime,
|
const char* fileName, int fileMode, word64 mTime, word64 aTime,
|
||||||
word32 totalFileSz, byte* buf, word32 bufSz, word32 fileOffset,
|
word32 totalFileSz, byte* buf, word32 bufSz, word32 fileOffset,
|
||||||
|
@ -680,12 +614,10 @@ static int my_ScpRecv(WOLFSSH* ssh, int state, const char* basePath,
|
||||||
|
|
||||||
return WS_SCP_ABORT; /* error out for test function */
|
return WS_SCP_ABORT; /* error out for test function */
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static void test_wolfSSH_SCP_CB(void)
|
static void test_wolfSSH_SCP_CB(void)
|
||||||
{
|
{
|
||||||
#ifdef WOLFSSH_SCP
|
|
||||||
WOLFSSH_CTX* ctx;
|
WOLFSSH_CTX* ctx;
|
||||||
WOLFSSH* ssh;
|
WOLFSSH* ssh;
|
||||||
int i = 3, j = 4; /* arbitrary value */
|
int i = 3, j = 4; /* arbitrary value */
|
||||||
|
@ -708,12 +640,107 @@ static void test_wolfSSH_SCP_CB(void)
|
||||||
|
|
||||||
wolfSSH_free(ssh);
|
wolfSSH_free(ssh);
|
||||||
wolfSSH_CTX_free(ctx);
|
wolfSSH_CTX_free(ctx);
|
||||||
#endif /* WOLFSSH_NO_CLIENT */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else /* WOLFSSH_SCP */
|
||||||
|
static void test_wolfSSH_SCP_CB(void) { ; }
|
||||||
|
#endif /* WOLFSSH_SCP */
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(WOLFSSH_SFTP) && !defined(NO_WOLFSSH_CLIENT) && \
|
||||||
|
!defined(SINGLE_THREADED)
|
||||||
|
|
||||||
|
#include "examples/echoserver/echoserver.h"
|
||||||
|
|
||||||
|
byte userPassword[256];
|
||||||
|
|
||||||
|
static int sftpUserAuth(byte authType, WS_UserAuthData* authData, void* ctx)
|
||||||
|
{
|
||||||
|
int ret = WOLFSSH_USERAUTH_INVALID_AUTHTYPE;
|
||||||
|
|
||||||
|
if (authType == WOLFSSH_USERAUTH_PASSWORD) {
|
||||||
|
const char* defaultPassword = (const char*)ctx;
|
||||||
|
word32 passwordSz;
|
||||||
|
|
||||||
|
ret = WOLFSSH_USERAUTH_SUCCESS;
|
||||||
|
if (defaultPassword != NULL) {
|
||||||
|
passwordSz = (word32)strlen(defaultPassword);
|
||||||
|
memcpy(userPassword, defaultPassword, passwordSz);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Expecting password set for test cases\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret == WOLFSSH_USERAUTH_SUCCESS) {
|
||||||
|
authData->sf.password.password = userPassword;
|
||||||
|
authData->sf.password.passwordSz = passwordSz;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* preforms connection to port, sets WOLFSSH_CTX and WOLFSSH on success
|
||||||
|
* caller needs to free ctx and ssh when done
|
||||||
|
*/
|
||||||
|
static void sftp_client_connect(WOLFSSH_CTX** ctx, WOLFSSH** ssh, int port)
|
||||||
|
{
|
||||||
|
SOCKET_T sockFd = WOLFSSH_SOCKET_INVALID;
|
||||||
|
SOCKADDR_IN_T clientAddr;
|
||||||
|
socklen_t clientAddrSz = sizeof(clientAddr);
|
||||||
|
int ret;
|
||||||
|
char* host = (char*)wolfSshIp;
|
||||||
|
const char* username = "jill";
|
||||||
|
const char* password = "upthehill";
|
||||||
|
|
||||||
|
if (ctx == NULL || ssh == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ctx = wolfSSH_CTX_new(WOLFSSH_ENDPOINT_CLIENT, NULL);
|
||||||
|
if (*ctx == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wolfSSH_SetUserAuth(*ctx, sftpUserAuth);
|
||||||
|
*ssh = wolfSSH_new(*ctx);
|
||||||
|
if (*ssh == NULL) {
|
||||||
|
wolfSSH_CTX_free(*ctx);
|
||||||
|
*ctx = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
build_addr(&clientAddr, host, port);
|
||||||
|
tcp_socket(&sockFd);
|
||||||
|
ret = connect(sockFd, (const struct sockaddr *)&clientAddr, clientAddrSz);
|
||||||
|
if (ret != 0){
|
||||||
|
wolfSSH_free(*ssh);
|
||||||
|
wolfSSH_CTX_free(*ctx);
|
||||||
|
*ctx = NULL;
|
||||||
|
*ssh = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wolfSSH_SetUserAuthCtx(*ssh, (void*)password);
|
||||||
|
ret = wolfSSH_SetUsername(*ssh, username);
|
||||||
|
if (ret == WS_SUCCESS)
|
||||||
|
ret = wolfSSH_set_fd(*ssh, (int)sockFd);
|
||||||
|
|
||||||
|
if (ret == WS_SUCCESS)
|
||||||
|
ret = wolfSSH_SFTP_connect(*ssh);
|
||||||
|
|
||||||
|
if (ret != WS_SUCCESS){
|
||||||
|
wolfSSH_free(*ssh);
|
||||||
|
wolfSSH_CTX_free(*ctx);
|
||||||
|
*ctx = NULL;
|
||||||
|
*ssh = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void test_wolfSSH_SFTP_SendReadPacket(void)
|
static void test_wolfSSH_SFTP_SendReadPacket(void)
|
||||||
{
|
{
|
||||||
#if defined(WOLFSSH_SFTP) && !defined(NO_WOLFSSH_CLIENT)
|
|
||||||
func_args ser;
|
func_args ser;
|
||||||
tcp_ready ready;
|
tcp_ready ready;
|
||||||
int argsCount;
|
int argsCount;
|
||||||
|
@ -818,9 +845,11 @@ static void test_wolfSSH_SFTP_SendReadPacket(void)
|
||||||
wolfSSH_free(ssh);
|
wolfSSH_free(ssh);
|
||||||
wolfSSH_CTX_free(ctx);
|
wolfSSH_CTX_free(ctx);
|
||||||
ThreadJoin(serThread);
|
ThreadJoin(serThread);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else /* WOLFSSH_SFTP && !NO_WOLFSSH_CLIENT && !SINGLE_THREADED */
|
||||||
|
static void test_wolfSSH_SFTP_SendReadPacket(void) { ; }
|
||||||
|
#endif /* WOLFSSH_SFTP && !NO_WOLFSSH_CLIENT && !SINGLE_THREADED */
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_WINDOWS_API
|
#ifdef USE_WINDOWS_API
|
||||||
|
|
|
@ -61,7 +61,8 @@ char* myoptarg = NULL;
|
||||||
#endif /* !NO_TESTSUITE_MAIN_DRIVER */
|
#endif /* !NO_TESTSUITE_MAIN_DRIVER */
|
||||||
|
|
||||||
|
|
||||||
#if !defined(NO_WOLFSSH_SERVER) && !defined(NO_WOLFSSH_CLIENT)
|
#if !defined(NO_WOLFSSH_SERVER) && !defined(NO_WOLFSSH_CLIENT) && \
|
||||||
|
!defined(SINGLE_THREADED)
|
||||||
|
|
||||||
static int tsClientUserAuth(byte authType, WS_UserAuthData* authData, void* ctx)
|
static int tsClientUserAuth(byte authType, WS_UserAuthData* authData, void* ctx)
|
||||||
{
|
{
|
||||||
|
@ -166,15 +167,15 @@ int wolfSSH_TestsuiteTest(int argc, char** argv)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* !NO_WOLFSSH_SERVER && !NO_WOLFSSH_CLIENT */
|
#else /* !NO_WOLFSSH_SERVER && !NO_WOLFSSH_CLIENT && !SINGLE_THREADED */
|
||||||
|
|
||||||
int TestsuiteTest(int argc, char** argv)
|
int wolfSSH_TestsuiteTest(int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !NO_WOLFSSH_SERVER && !NO_WOLFSSH_CLIENT */
|
#endif /* !NO_WOLFSSH_SERVER && !NO_WOLFSSH_CLIENT && !SINGLE_THREADED */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,11 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define WEXIT(n) exit((n))
|
#if defined(INTEGRITY) || defined(__INTEGRITY)
|
||||||
|
#define WEXIT(n) return (0)
|
||||||
|
#else
|
||||||
|
#define WEXIT(n) exit((n))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef WOLFSSH_HANDLE
|
#ifndef WOLFSSH_HANDLE
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
* This file contains some utility code shared between the wolfSSH test
|
* This file contains some utility code shared between the wolfSSH test
|
||||||
* tools and examples. This is divided into a few sets of functions that
|
* tools and examples. This is divided into a few sets of functions that
|
||||||
* may be enabled with flags included before including this file:
|
* may be enabled with flags included before including this file:
|
||||||
*
|
*
|
||||||
* WOLFSSH_TEST_CLIENT: Client utility functions
|
* WOLFSSH_TEST_CLIENT: Client utility functions
|
||||||
* WOLFSSH_TEST_SERVER: Server utility functions
|
* WOLFSSH_TEST_SERVER: Server utility functions
|
||||||
* WOLFSSH_TEST_LOCKING: Mutex wrappers
|
* WOLFSSH_TEST_LOCKING: Mutex wrappers
|
||||||
|
@ -217,6 +217,11 @@ static INLINE void err_sys(const char* msg)
|
||||||
printf("wolfSSH error: %s\n", msg);
|
printf("wolfSSH error: %s\n", msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#elif defined(INTEGRITY) || defined(__INTEGRITY)
|
||||||
|
static INLINE void err_sys(const char* msg)
|
||||||
|
{
|
||||||
|
printf("wolfSSH error: %s\n", msg);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
static INLINE WS_NORETURN void err_sys(const char* msg)
|
static INLINE WS_NORETURN void err_sys(const char* msg)
|
||||||
{
|
{
|
||||||
|
@ -751,8 +756,8 @@ static INLINE void InitTcpReady(tcp_ready* ready)
|
||||||
ready->ready = 0;
|
ready->ready = 0;
|
||||||
ready->port = 0;
|
ready->port = 0;
|
||||||
ready->srfName = NULL;
|
ready->srfName = NULL;
|
||||||
#ifdef SINGLE_THREADED
|
#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) && \
|
||||||
#elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
|
!defined(__MINGW32__) && !defined(SINGLE_THREADED)
|
||||||
pthread_mutex_init(&ready->mutex, 0);
|
pthread_mutex_init(&ready->mutex, 0);
|
||||||
pthread_cond_init(&ready->cond, 0);
|
pthread_cond_init(&ready->cond, 0);
|
||||||
#endif
|
#endif
|
||||||
|
@ -761,9 +766,8 @@ static INLINE void InitTcpReady(tcp_ready* ready)
|
||||||
|
|
||||||
static INLINE void FreeTcpReady(tcp_ready* ready)
|
static INLINE void FreeTcpReady(tcp_ready* ready)
|
||||||
{
|
{
|
||||||
#ifdef SINGLE_THREADED
|
#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) && \
|
||||||
(void)ready;
|
!defined(__MINGW32__) && !defined(SINGLE_THREADED)
|
||||||
#elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
|
|
||||||
pthread_mutex_destroy(&ready->mutex);
|
pthread_mutex_destroy(&ready->mutex);
|
||||||
pthread_cond_destroy(&ready->cond);
|
pthread_cond_destroy(&ready->cond);
|
||||||
#else
|
#else
|
||||||
|
@ -774,7 +778,8 @@ static INLINE void FreeTcpReady(tcp_ready* ready)
|
||||||
|
|
||||||
static INLINE void WaitTcpReady(func_args* args)
|
static INLINE void WaitTcpReady(func_args* args)
|
||||||
{
|
{
|
||||||
#if defined(_POSIX_THREADS) && !defined(__MINGW32__)
|
#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) && \
|
||||||
|
!defined(__MINGW32__) && !defined(SINGLE_THREADED)
|
||||||
pthread_mutex_lock(&args->signal->mutex);
|
pthread_mutex_lock(&args->signal->mutex);
|
||||||
|
|
||||||
if (!args->signal->ready)
|
if (!args->signal->ready)
|
||||||
|
@ -853,20 +858,25 @@ static INLINE void ThreadStart(THREAD_FUNC fun, void* args, THREAD_TYPE* thread)
|
||||||
#else
|
#else
|
||||||
pthread_create(thread, 0, fun, args);
|
pthread_create(thread, 0, fun, args);
|
||||||
#endif
|
#endif
|
||||||
return;
|
|
||||||
#elif defined(WOLFSSL_TIRTOS)
|
#elif defined(WOLFSSL_TIRTOS)
|
||||||
/* Initialize the defaults and set the parameters. */
|
{
|
||||||
Task_Params taskParams;
|
/* Initialize the defaults and set the parameters. */
|
||||||
Task_Params_init(&taskParams);
|
Task_Params taskParams;
|
||||||
taskParams.arg0 = (UArg)args;
|
Task_Params_init(&taskParams);
|
||||||
taskParams.stackSize = 65535;
|
taskParams.arg0 = (UArg)args;
|
||||||
*thread = Task_create((Task_FuncPtr)fun, &taskParams, NULL);
|
taskParams.stackSize = 65535;
|
||||||
if (*thread == NULL) {
|
*thread = Task_create((Task_FuncPtr)fun, &taskParams, NULL);
|
||||||
printf("Failed to create new Task\n");
|
if (*thread == NULL) {
|
||||||
|
printf("Failed to create new Task\n");
|
||||||
|
}
|
||||||
|
Task_yield();
|
||||||
}
|
}
|
||||||
Task_yield();
|
#elif defined(USE_WINDOWS_API)
|
||||||
#else
|
|
||||||
*thread = (THREAD_TYPE)_beginthreadex(0, 0, fun, args, 0, 0);
|
*thread = (THREAD_TYPE)_beginthreadex(0, 0, fun, args, 0, 0);
|
||||||
|
#else
|
||||||
|
(void)fun;
|
||||||
|
(void)args;
|
||||||
|
(void)thread;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -885,12 +895,16 @@ static INLINE void ThreadJoin(THREAD_TYPE thread)
|
||||||
}
|
}
|
||||||
Task_yield();
|
Task_yield();
|
||||||
}
|
}
|
||||||
|
#elif defined(USE_WINDOWS_API)
|
||||||
|
{
|
||||||
|
int res = WaitForSingleObject((HANDLE)thread, INFINITE);
|
||||||
|
assert(res == WAIT_OBJECT_0);
|
||||||
|
res = CloseHandle((HANDLE)thread);
|
||||||
|
assert(res);
|
||||||
|
(void)res; /* Suppress un-used variable warning */
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
int res = WaitForSingleObject((HANDLE)thread, INFINITE);
|
(void)thread;
|
||||||
assert(res == WAIT_OBJECT_0);
|
|
||||||
res = CloseHandle((HANDLE)thread);
|
|
||||||
assert(res);
|
|
||||||
(void)res; /* Suppress un-used variable warning */
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -911,10 +925,14 @@ static INLINE void ThreadDetach(THREAD_TYPE thread)
|
||||||
Task_yield();
|
Task_yield();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#elif defined(USE_WINDOWS_API)
|
||||||
|
{
|
||||||
|
int res = CloseHandle((HANDLE)thread);
|
||||||
|
assert(res);
|
||||||
|
(void)res; /* Suppress un-used variable warning */
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
int res = CloseHandle((HANDLE)thread);
|
(void)thread;
|
||||||
assert(res);
|
|
||||||
(void)res; /* Suppress un-used variable warning */
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue