Skip to content

Commit 6773c7c

Browse files
committed
wolfSSH: new SSH backend
Adds support for SFTP (not SCP) using WolfSSH. Closes #4231
1 parent ad0aa27 commit 6773c7c

File tree

8 files changed

+1247
-17
lines changed

8 files changed

+1247
-17
lines changed

configure.ac

+36-4
Original file line numberDiff line numberDiff line change
@@ -2795,17 +2795,23 @@ dnl **********************************************************************
27952795
dnl Default to compiler & linker defaults for LIBSSH2 files & libraries.
27962796
OPT_LIBSSH2=off
27972797
AC_ARG_WITH(libssh2,dnl
2798-
AC_HELP_STRING([--with-libssh2=PATH],[Where to look for libssh2, PATH points to the LIBSSH2 installation; when possible, set the PKG_CONFIG_PATH environment variable instead of using this option])
2799-
AC_HELP_STRING([--with-libssh2], [enable LIBSSH2]),
2798+
AC_HELP_STRING([--with-libssh2=PATH],[Where to look for libssh2, PATH points to the libssh2 installation; when possible, set the PKG_CONFIG_PATH environment variable instead of using this option])
2799+
AC_HELP_STRING([--with-libssh2], [enable libssh2]),
28002800
OPT_LIBSSH2=$withval, OPT_LIBSSH2=no)
28012801

28022802

28032803
OPT_LIBSSH=off
28042804
AC_ARG_WITH(libssh,dnl
2805-
AC_HELP_STRING([--with-libssh=PATH],[Where to look for libssh, PATH points to the LIBSSH installation; when possible, set the PKG_CONFIG_PATH environment variable instead of using this option])
2806-
AC_HELP_STRING([--with-libssh], [enable LIBSSH]),
2805+
AC_HELP_STRING([--with-libssh=PATH],[Where to look for libssh, PATH points to the libssh installation; when possible, set the PKG_CONFIG_PATH environment variable instead of using this option])
2806+
AC_HELP_STRING([--with-libssh], [enable libssh]),
28072807
OPT_LIBSSH=$withval, OPT_LIBSSH=no)
28082808

2809+
OPT_WOLFSSH=off
2810+
AC_ARG_WITH(wolfssh,dnl
2811+
AC_HELP_STRING([--with-wolfssh=PATH],[Where to look for wolfssh, PATH points to the wolfSSH installation; when possible, set the PKG_CONFIG_PATH environment variable instead of using this option])
2812+
AC_HELP_STRING([--with-wolfssh], [enable wolfssh]),
2813+
OPT_WOLFSSH=$withval, OPT_WOLFSSH=no)
2814+
28092815
if test X"$OPT_LIBSSH2" != Xno; then
28102816
dnl backup the pre-libssh2 variables
28112817
CLEANLDFLAGS="$LDFLAGS"
@@ -2952,6 +2958,28 @@ elif test X"$OPT_LIBSSH" != Xno; then
29522958
CPPFLAGS=$CLEANCPPFLAGS
29532959
LIBS=$CLEANLIBS
29542960
fi
2961+
elif test X"$OPT_WOLFSSH" != Xno; then
2962+
dnl backup the pre-wolfssh variables
2963+
CLEANLDFLAGS="$LDFLAGS"
2964+
CLEANCPPFLAGS="$CPPFLAGS"
2965+
CLEANLIBS="$LIBS"
2966+
2967+
2968+
if test "$OPT_WOLFSSH" != yes; then
2969+
WOLFCONFIG="$OPT_WOLFSSH/bin/wolfssh-config"
2970+
LDFLAGS="$LDFLAGS `$WOLFCONFIG --libs`"
2971+
CPPFLAGS="$CPPFLAGS `$WOLFCONFIG --cflags`"
2972+
fi
2973+
2974+
AC_CHECK_LIB(wolfssh, wolfSSH_Init)
2975+
2976+
AC_CHECK_HEADERS(wolfssh/ssh.h,
2977+
curl_ssh_msg="enabled (wolfSSH)"
2978+
WOLFSSH_ENABLED=1
2979+
AC_DEFINE(USE_WOLFSSH, 1, [if wolfSSH is in use])
2980+
AC_SUBST(USE_WOLFSSH, [1])
2981+
)
2982+
29552983
fi
29562984

29572985
dnl **********************************************************************
@@ -4761,6 +4789,10 @@ if test "x$USE_LIBSSH" = "x1"; then
47614789
SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS SCP"
47624790
SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS SFTP"
47634791
fi
4792+
if test "x$USE_WOLFSSH" = "x1"; then
4793+
SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS SCP"
4794+
SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS SFTP"
4795+
fi
47644796
if test "x$CURL_DISABLE_RTSP" != "x1"; then
47654797
SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS RTSP"
47664798
fi

lib/Makefile.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ LIB_VQUIC_CFILES = vquic/ngtcp2.c vquic/quiche.c
4242

4343
LIB_VQUIC_HFILES = vquic/ngtcp2.h vquic/quiche.h
4444

45-
LIB_VSSH_CFILES = vssh/libssh2.c vssh/libssh.c
45+
LIB_VSSH_CFILES = vssh/libssh2.c vssh/libssh.c vssh/wolfssh.c
4646

4747
LIB_VSSH_HFILES = vssh/ssh.h
4848

lib/easy.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* | (__| |_| | _ <| |___
66
* \___|\___/|_| \_\_____|
77
*
8-
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
8+
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
99
*
1010
* This software is licensed as described in the file COPYING, which
1111
* you should have received as part of this distribution. The terms
@@ -193,6 +193,13 @@ static CURLcode global_init(long flags, bool memoryfuncs)
193193
}
194194
#endif
195195

196+
#ifdef USE_WOLFSSH
197+
if(WS_SUCCESS != wolfSSH_Init()) {
198+
DEBUGF(fprintf(stderr, "Error: wolfSSH_Init failed\n"));
199+
return CURLE_FAILED_INIT;
200+
}
201+
#endif
202+
196203
if(flags & CURL_GLOBAL_ACK_EINTR)
197204
Curl_ack_eintr = 1;
198205

@@ -272,6 +279,10 @@ void curl_global_cleanup(void)
272279

273280
Curl_ssh_cleanup();
274281

282+
#ifdef USE_WOLFSSH
283+
(void)wolfSSH_Cleanup();
284+
#endif
285+
275286
init_flags = 0;
276287
}
277288

lib/url.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* | (__| |_| | _ <| |___
66
* \___|\___/|_| \_\_____|
77
*
8-
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
8+
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
99
*
1010
* This software is licensed as described in the file COPYING, which
1111
* you should have received as part of this distribution. The terms
@@ -187,7 +187,7 @@ static const struct Curl_handler * const protocols[] = {
187187
&Curl_handler_tftp,
188188
#endif
189189

190-
#if defined(USE_SSH)
190+
#if defined(USE_SSH) && !defined(USE_WOLFSSH)
191191
&Curl_handler_scp,
192192
#endif
193193

lib/version.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* | (__| |_| | _ <| |___
66
* \___|\___/|_| \_\_____|
77
*
8-
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
8+
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
99
*
1010
* This software is licensed as described in the file COPYING, which
1111
* you should have received as part of this distribution. The terms
@@ -265,8 +265,10 @@ static const char * const protocols[] = {
265265
#ifndef CURL_DISABLE_RTSP
266266
"rtsp",
267267
#endif
268-
#if defined(USE_SSH)
268+
#if defined(USE_SSH) && !defined(USE_WOLFSSH)
269269
"scp",
270+
#endif
271+
#ifdef USE_SSH
270272
"sftp",
271273
#endif
272274
#if !defined(CURL_DISABLE_SMB) && defined(USE_NTLM) && \

lib/vssh/ssh.h

+15-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* | (__| |_| | _ <| |___
88
* \___|\___/|_| \_\_____|
99
*
10-
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
10+
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
1111
*
1212
* This software is licensed as described in the file COPYING, which
1313
* you should have received as part of this distribution. The terms
@@ -30,7 +30,10 @@
3030
#elif defined(HAVE_LIBSSH_LIBSSH_H)
3131
#include <libssh/libssh.h>
3232
#include <libssh/sftp.h>
33-
#endif /* HAVE_LIBSSH2_H */
33+
#elif defined(USE_WOLFSSH)
34+
#include <wolfssh/ssh.h>
35+
#include <wolfssh/wolfsftp.h>
36+
#endif
3437

3538
/****************************************************************************
3639
* SSH unique setup
@@ -188,16 +191,19 @@ struct ssh_conn {
188191
#ifdef HAVE_LIBSSH2_KNOWNHOST_API
189192
LIBSSH2_KNOWNHOSTS *kh;
190193
#endif
194+
#elif defined(USE_WOLFSSH)
195+
WOLFSSH *ssh_session;
196+
WOLFSSH_CTX *ctx;
197+
word32 handleSz;
198+
byte handle[WOLFSSH_MAX_HANDLE];
199+
curl_off_t offset;
191200
#endif /* USE_LIBSSH */
192201
};
193202

194203
#if defined(USE_LIBSSH)
195204

196205
#define CURL_LIBSSH_VERSION ssh_version(0)
197206

198-
extern const struct Curl_handler Curl_handler_scp;
199-
extern const struct Curl_handler Curl_handler_sftp;
200-
201207
#elif defined(USE_LIBSSH2)
202208

203209
/* Feature detection based on version numbers to better work with
@@ -237,11 +243,13 @@ extern const struct Curl_handler Curl_handler_sftp;
237243
#define CURL_LIBSSH2_VERSION LIBSSH2_VERSION
238244
#endif
239245

240-
extern const struct Curl_handler Curl_handler_scp;
241-
extern const struct Curl_handler Curl_handler_sftp;
242246
#endif /* USE_LIBSSH2 */
243247

244248
#ifdef USE_SSH
249+
250+
extern const struct Curl_handler Curl_handler_scp;
251+
extern const struct Curl_handler Curl_handler_sftp;
252+
245253
/* generic SSH backend functions */
246254
CURLcode Curl_ssh_init(void);
247255
void Curl_ssh_cleanup(void);

0 commit comments

Comments
 (0)