Skip to content

Commit

Permalink
Init zephyr support
Browse files Browse the repository at this point in the history
- SSH
- SFTP
- SCP
  • Loading branch information
julek-wolfssl committed Oct 2, 2023
1 parent e5f4b69 commit 37412ff
Show file tree
Hide file tree
Showing 32 changed files with 1,315 additions and 174 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/zephyr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Zephyr tests

on:
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]

jobs:
run_test:
name: Build and run
strategy:
matrix:
config:
- zephyr-ref: v3.4.0
zephyr-sdk: 0.16.1
runs-on: ubuntu-latest
# This should be a safe limit for the tests to run.
timeout-minutes: 15
steps:
- name: Install dependencies
run: |
# Don't prompt for anything
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
# most of the ci-base zephyr docker image packages
sudo apt-get install -y zip bridge-utils uml-utilities \
git cmake ninja-build gperf ccache dfu-util device-tree-compiler wget \
python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 \
autoconf automake bison build-essential ca-certificates cargo ccache chrpath cmake \
cpio device-tree-compiler dfu-util diffstat dos2unix doxygen file flex g++ gawk gcc \
gcovr git git-core gnupg gperf gtk-sharp2 help2man iproute2 lcov libcairo2-dev \
libglib2.0-dev libgtk2.0-0 liblocale-gettext-perl libncurses5-dev libpcap-dev \
libpopt0 libsdl1.2-dev libsdl2-dev libssl-dev libtool libtool-bin locales make \
net-tools ninja-build openssh-client parallel pkg-config python3-dev python3-pip \
python3-ply python3-setuptools python-is-python3 qemu rsync socat srecord sudo \
texinfo unzip wget ovmf xz-utils
- name: Install west
run: sudo pip install west

- name: Init west workspace
run: west init --mr ${{ matrix.config.zephyr-ref }} zephyr

- name: Update west.yml
working-directory: zephyr/zephyr
run: |
REF=$(echo '${{ github.ref }}' | sed -e 's/\//\\\//g')
sed -e 's/remotes:/remotes:\n \- name: wolfssl\n url\-base: https:\/\/github.com\/wolfssl/' -i west.yml
sed -e "s/remotes:/remotes:\n \- name: wolfssh\n url\-base: https:\/\/github.com\/${{ github.repository_owner }}/" -i west.yml
sed -e "s/projects:/projects:\n \- name: wolfssh\n path: modules\/lib\/wolfssh\n remote: wolfssh\n revision: $REF/" -i west.yml
sed -e 's/projects:/projects:\n \- name: wolfssl\n path: modules\/crypto\/wolfssl\n remote: wolfssl\n revision: master/' -i west.yml
- name: Update west workspace
working-directory: zephyr
run: west update -n -o=--depth=1

- name: Export zephyr
working-directory: zephyr
run: west zephyr-export

- name: Install pip dependencies
working-directory: zephyr
run: sudo pip install -r zephyr/scripts/requirements.txt

- name: Install zephyr SDK
run: |
wget -q https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{ matrix.config.zephyr-sdk }}/zephyr-sdk-${{ matrix.config.zephyr-sdk }}_linux-x86_64.tar.xz
tar xf zephyr-sdk-${{ matrix.config.zephyr-sdk }}_linux-x86_64.tar.xz
cd zephyr-sdk-${{ matrix.config.zephyr-sdk }}
./setup.sh -h -c
- name: Run wolfssh tests
id: wolfssh-test
working-directory: zephyr
run: |
./zephyr/scripts/twister --testsuite-root modules/lib/wolfssh --test zephyr/samples/tests/sample.lib.wolfssh_tests -vvv
rm -rf zephyr/twister-out
- name: Zip failure logs
if: ${{ failure() && steps.wolfssh-test.outcome == 'failure' }}
run: |
zip -9 -r logs.zip zephyr/twister-out
- name: Upload failure logs
if: ${{ failure() && steps.wolfssh-test.outcome == 'failure' }}
uses: actions/upload-artifact@v3
with:
name: zephyr-client-test-logs
path: logs.zip
retention-days: 5
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ Debug
Release
DLL Debug
DLL Release

# Eclipse
.cproject
.project
.settings
32 changes: 17 additions & 15 deletions examples/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
#include <wolfssl/wolfcrypt/ecc.h>
#include "examples/client/client.h"
#include "examples/client/common.h"
#if !defined(USE_WINDOWS_API) && !defined(MICROCHIP_PIC32)
#if !defined(USE_WINDOWS_API) && !defined(MICROCHIP_PIC32) && \
defined(WOLFSSH_TERM) && !defined(NO_FILESYSTEM)
#include <termios.h>
#endif

Expand Down Expand Up @@ -124,15 +125,6 @@ static const char* certName = NULL;
static const char* caCert = NULL;


#if defined(WOLFSSH_AGENT)
static inline void ato32(const byte* c, word32* u32)
{
*u32 = (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3];
}
#endif



static int NonBlockSSH_connect(WOLFSSH* ssh)
{
int ret;
Expand Down Expand Up @@ -174,7 +166,8 @@ static int NonBlockSSH_connect(WOLFSSH* ssh)
return ret;
}

#if !defined(SINGLE_THREADED) && !defined(WOLFSSL_NUCLEUS)
#if !defined(SINGLE_THREADED) && !defined(WOLFSSL_NUCLEUS) && \
defined(WOLFSSH_TERM) && !defined(NO_FILESYSTEM)

typedef struct thread_args {
WOLFSSH* ssh;
Expand Down Expand Up @@ -345,6 +338,12 @@ static THREAD_RET readInput(void* in)
return THREAD_RET_SUCCESS;
}

#if defined(WOLFSSH_AGENT)
static inline void ato32(const byte* c, word32* u32)
{
*u32 = (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3];
}
#endif

static THREAD_RET readPeer(void* in)
{
Expand Down Expand Up @@ -460,13 +459,13 @@ static THREAD_RET readPeer(void* in)
}
else {
printf("%s", buf);
fflush(stdout);
WFFLUSH(stdout);
}
#else
if (write(STDOUT_FILENO, buf, ret) < 0) {
perror("write to stdout error ");
}
fflush(stdout);
WFFLUSH(stdout);
#endif
}
if (wolfSSH_stream_peek(args->ssh, buf, bufSz) <= 0) {
Expand Down Expand Up @@ -640,6 +639,8 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
char** argv = ((func_args*)args)->argv;
((func_args*)args)->return_code = 0;

(void)keepOpen;

while ((ch = mygetopt(argc, argv, "?ac:h:i:j:p:tu:xzNP:RJ:A:Xe")) != -1) {
switch (ch) {
case 'h':
Expand Down Expand Up @@ -859,7 +860,8 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
if (ret != WS_SUCCESS)
err_sys("Couldn't connect SSH stream.");

#if !defined(SINGLE_THREADED) && !defined(WOLFSSL_NUCLEUS)
#if !defined(SINGLE_THREADED) && !defined(WOLFSSL_NUCLEUS) && \
defined(WOLFSSH_TERM) && !defined(NO_FILESYSTEM)
if (keepOpen) /* set up for psuedo-terminal */
ClientSetEcho(2);

Expand Down Expand Up @@ -995,7 +997,7 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
wc_ecc_fp_free(); /* free per thread cache */
#endif

return 0;
WOLFSSL_RETURN_FROM_THREAD(0);
}

#endif /* NO_WOLFSSH_CLIENT */
Expand Down
18 changes: 13 additions & 5 deletions examples/client/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@

#define WOLFSSH_TEST_CLIENT

#include <stdio.h>
#include <wolfssh/ssh.h>
#include <wolfssh/internal.h>
#include <wolfssh/wolfsftp.h>
#include <wolfssh/port.h>
#include <wolfssl/wolfcrypt/ecc.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
#include <wolfssl/wolfcrypt/coding.h>
#include "examples/client/common.h"
#ifndef USE_WINDOWS_API
#if !defined(USE_WINDOWS_API) && !defined(MICROCHIP_PIC32) && \
!defined(WOLFSSH_ZEPHYR)
#include <termios.h>
#endif

Expand Down Expand Up @@ -487,11 +490,13 @@ int ClientUserAuth(byte authType,
passwordSz = (word32)strlen(defaultPassword);
memcpy(userPassword, defaultPassword, passwordSz);
}
#ifdef WOLFSSH_TERM
else {
printf("Password: ");
fflush(stdout);
WFFLUSH(stdout);
ClientSetEcho(0);
if (fgets((char*)userPassword, sizeof(userPassword), stdin) == NULL) {
if (WFGETS((char*)userPassword, sizeof(userPassword), stdin)
== NULL) {
fprintf(stderr, "Getting password failed.\n");
ret = WOLFSSH_USERAUTH_FAILURE;
}
Expand All @@ -505,8 +510,9 @@ int ClientUserAuth(byte authType,
#ifdef USE_WINDOWS_API
printf("\r\n");
#endif
fflush(stdout);
WFFLUSH(stdout);
}
#endif

if (ret == WOLFSSH_USERAUTH_SUCCESS) {
authData->sf.password.password = userPassword;
Expand All @@ -518,6 +524,7 @@ int ClientUserAuth(byte authType,
}


#ifdef WOLFSSH_TERM
/* type = 2 : shell / execute command settings
* type = 0 : password
* type = 1 : restore default
Expand Down Expand Up @@ -604,6 +611,7 @@ int ClientSetEcho(int type)

return 0;
}
#endif


/* Set certificate to use and public key.
Expand Down Expand Up @@ -662,7 +670,7 @@ int ClientSetPrivateKey(const char* privKeyName, int userEcc)
&isPrivate, NULL);
#else
printf("file system not compiled in!\n");
ret = WC_NOT_COMPILED;
ret = NOT_COMPILED_IN;
#endif
}

Expand Down
Loading

0 comments on commit 37412ff

Please sign in to comment.