libssh: add files for idf

This commit is contained in:
2025-07-07 10:26:57 +09:00
parent 7caa4acdf8
commit 32d16cda41
7 changed files with 501 additions and 0 deletions

119
CMakeLists.txt Normal file
View File

@@ -0,0 +1,119 @@
set(LIBSSH_SRC libssh/src)
set(LIBSSH_INCLUDE libssh/include)
set(LIBSSH_SRCS
${LIBSSH_SRC}/agent.c
${LIBSSH_SRC}/auth.c
${LIBSSH_SRC}/base64.c
${LIBSSH_SRC}/bignum.c
${LIBSSH_SRC}/buffer.c
${LIBSSH_SRC}/callbacks.c
${LIBSSH_SRC}/channels.c
${LIBSSH_SRC}/client.c
${LIBSSH_SRC}/config.c
${LIBSSH_SRC}/connect.c
${LIBSSH_SRC}/connector.c
${LIBSSH_SRC}/crypto_common.c
${LIBSSH_SRC}/curve25519.c
${LIBSSH_SRC}/dh.c
${LIBSSH_SRC}/ecdh.c
${LIBSSH_SRC}/error.c
${LIBSSH_SRC}/getpass.c
${LIBSSH_SRC}/gzip.c
${LIBSSH_SRC}/init.c
${LIBSSH_SRC}/kdf.c
${LIBSSH_SRC}/kex.c
${LIBSSH_SRC}/known_hosts.c
${LIBSSH_SRC}/knownhosts.c
${LIBSSH_SRC}/legacy.c
${LIBSSH_SRC}/log.c
${LIBSSH_SRC}/match.c
${LIBSSH_SRC}/messages.c
${LIBSSH_SRC}/misc.c
${LIBSSH_SRC}/options.c
${LIBSSH_SRC}/packet.c
${LIBSSH_SRC}/packet_cb.c
${LIBSSH_SRC}/packet_crypt.c
${LIBSSH_SRC}/pcap.c
${LIBSSH_SRC}/pki.c
${LIBSSH_SRC}/pki_container_openssh.c
${LIBSSH_SRC}/poll.c
${LIBSSH_SRC}/session.c
${LIBSSH_SRC}/scp.c
${LIBSSH_SRC}/socket.c
${LIBSSH_SRC}/string.c
${LIBSSH_SRC}/threads.c
${LIBSSH_SRC}/wrapper.c
${LIBSSH_SRC}/external/bcrypt_pbkdf.c
${LIBSSH_SRC}/external/blowfish.c
${LIBSSH_SRC}/config_parser.c
${LIBSSH_SRC}/token.c
${LIBSSH_SRC}/pki_ed25519_common.c
)
set(LIBSSH_SRCS
${LIBSSH_SRCS}
${LIBSSH_SRC}/threads/noop.c
)
set(LIBSSH_SRCS
${LIBSSH_SRCS}
${LIBSSH_SRC}/threads/mbedtls.c
${LIBSSH_SRC}/libmbedcrypto.c
${LIBSSH_SRC}/mbedcrypto_missing.c
${LIBSSH_SRC}/pki_mbedcrypto.c
${LIBSSH_SRC}/ecdh_mbedcrypto.c
${LIBSSH_SRC}/getrandom_mbedcrypto.c
${LIBSSH_SRC}/md_mbedcrypto.c
${LIBSSH_SRC}/dh_key.c
${LIBSSH_SRC}/pki_ed25519.c
${LIBSSH_SRC}/external/ed25519.c
${LIBSSH_SRC}/external/curve25519_ref.c
${LIBSSH_SRC}/external/fe25519.c
${LIBSSH_SRC}/external/ge25519.c
${LIBSSH_SRC}/external/sc25519.c
)
set(LIBSSH_SRCS
${LIBSSH_SRCS}
${LIBSSH_SRC}/external/chacha.c
${LIBSSH_SRC}/external/poly1305.c
${LIBSSH_SRC}/chachapoly.c
)
if (CONFIG_LIBSSH_SFTP)
set(LIBSSH_SRCS
${LIBSSH_SRCS}
${LIBSSH_SRC}/sftp.c
${LIBSSH_SRC}/sftp_common.c
${LIBSSH_SRC}/sftp_aio.c
)
if (CONFIG_LIBSSH_SERVER)
set(LIBSSH_SRCS
${LIBSSH_SRCS}
${LIBSSH_SRC}/sftpserver.c
)
endif (CONFIG_LIBSSH_SERVER)
endif (CONFIG_LIBSSH_SFTP)
if (CONFIG_LIBSSH_SERVER)
set(LIBSSH_SRCS
${LIBSSH_SRCS}
${LIBSSH_SRC}/server.c
${LIBSSH_SRC}/bind.c
${LIBSSH_SRC}/bind_config.c
)
endif (CONFIG_LIBSSH_SERVER)
set(LIBSSH_SRCS
${LIBSSH_SRCS}
${LIBSSH_SRC}/dh-gex.c
)
idf_component_register(SRCS "${LIBSSH_SRCS}"
INCLUDE_DIRS compat "${LIBSSH_INCLUDE}"
REQUIRES lwip mbedtls)
target_compile_options(${COMPONENT_LIB} PRIVATE
-Wno-error=format; -Wno-error=char-subscripts -Wno-error=int-conversion)

9
Kconfig Normal file
View File

@@ -0,0 +1,9 @@
menu "libssh"
config LIBSSH_SERVER
bool "support ssh server"
default y
config LIBSSH_SFTP
bool "support sftp"
default n
endmenu

291
compat/config.h Normal file
View File

@@ -0,0 +1,291 @@
#ifndef CONFIG_H
#define CONFIG_H
#include <sdkconfig.h>
/* Name of package */
#define PACKAGE "libssh"
/* Version number of package */
#define VERSION "0.11.2"
#define SYSCONFDIR "etc"
#define BINARYDIR "libssh"
#define SOURCEDIR "libssh"
/* Global bind configuration file path */
#define GLOBAL_BIND_CONFIG "/etc/ssh/libssh_server_config"
/* Global client configuration file path */
#define GLOBAL_CLIENT_CONFIG "/etc/ssh/ssh_config"
/************************** HEADER FILES *************************/
/* Define to 1 if you have the <argp.h> header file. */
// #define HAVE_ARGP_H 1
/* #undef HAVE_ARGP_H */
/* Define to 1 if you have the <aprpa/inet.h> header file. */
#define HAVE_ARPA_INET_H 1
/* Define to 1 if you have the <glob.h> header file. */
#define HAVE_GLOB_H 1
/* Define to 1 if you have the <valgrind/valgrind.h> header file. */
/* #undef HAVE_VALGRIND_VALGRIND_H */
/* Define to 1 if you have the <pty.h> header file. */
#define HAVE_PTY_H 1
/* Define to 1 if you have the <utmp.h> header file. */
#define HAVE_UTMP_H 1
/* Define to 1 if you have the <util.h> header file. */
/* #undef HAVE_UTIL_H */
/* Define to 1 if you have the <libutil.h> header file. */
/* #undef HAVE_LIBUTIL_H */
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <sys/utime.h> header file. */
/* #undef HAVE_SYS_UTIME_H */
/* Define to 1 if you have the <io.h> header file. */
/* #undef HAVE_IO_H */
/* Define to 1 if you have the <termios.h> header file. */
#define HAVE_TERMIOS_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <ifaddrs.h> header file. */
// #undef HAVE_IFADDRS_H
/* Define to 1 if you have the <openssl/aes.h> header file. */
/* #undef HAVE_OPENSSL_AES_H */
/* Define to 1 if you have the <wspiapi.h> header file. */
/* #undef HAVE_WSPIAPI_H */
/* Define to 1 if you have the <openssl/des.h> header file. */
/* #undef HAVE_OPENSSL_DES_H */
/* Define to 1 if you have the <openssl/ecdh.h> header file. */
/* #undef HAVE_OPENSSL_ECDH_H */
/* Define to 1 if you have the <openssl/ec.h> header file. */
/* #undef HAVE_OPENSSL_EC_H */
/* Define to 1 if you have the <openssl/ecdsa.h> header file. */
/* #undef HAVE_OPENSSL_ECDSA_H */
/* Define to 1 if you have the <pthread.h> header file. */
/* #undef HAVE_PTHREAD_H */
/* Define to 1 if you have elliptic curve cryptography in openssl */
/* #undef HAVE_OPENSSL_ECC */
/* Define to 1 if you have elliptic curve cryptography in gcrypt */
/* #undef HAVE_GCRYPT_ECC */
/* Define to 1 if you have elliptic curve cryptography */
#define HAVE_ECC 1
/* Define to 1 if you have gl_flags as a glob_t struct member */
#define HAVE_GLOB_GL_FLAGS_MEMBER 1
/* Define to 1 if you have gcrypt with ChaCha20/Poly1305 support */
/* #undef HAVE_GCRYPT_CHACHA_POLY */
/*************************** FUNCTIONS ***************************/
/* Define to 1 if you have the `EVP_chacha20' function. */
/* #undef HAVE_OPENSSL_EVP_CHACHA20 */
/* Define to 1 if you have the `EVP_KDF_CTX_new_id' or `EVP_KDF_CTX_new` function. */
/* #undef HAVE_OPENSSL_EVP_KDF_CTX */
/* Define to 1 if you have the `FIPS_mode' function. */
/* #undef HAVE_OPENSSL_FIPS_MODE */
/* Define to 1 if you have the `snprintf' function. */
#define HAVE_SNPRINTF 1
/* Define to 1 if you have the `_snprintf' function. */
/* #undef HAVE__SNPRINTF */
/* Define to 1 if you have the `_snprintf_s' function. */
/* #undef HAVE__SNPRINTF_S */
/* Define to 1 if you have the `vsnprintf' function. */
#define HAVE_VSNPRINTF 1
/* Define to 1 if you have the `_vsnprintf' function. */
/* #undef HAVE__VSNPRINTF */
/* Define to 1 if you have the `_vsnprintf_s' function. */
/* #undef HAVE__VSNPRINTF_S */
/* Define to 1 if you have the `isblank' function. */
#define HAVE_ISBLANK 1
/* Define to 1 if you have the `strncpy' function. */
#define HAVE_STRNCPY 1
/* Define to 1 if you have the `strndup' function. */
#define HAVE_STRNDUP 1
/* Define to 1 if you have the `cfmakeraw' function. */
#define HAVE_CFMAKERAW 1
/* Define to 1 if you have the `getaddrinfo' function. */
#define HAVE_GETADDRINFO 1
/* Define to 1 if you have the `poll' function. */
#define HAVE_POLL 1
/* Define to 1 if you have the `select' function. */
#define HAVE_SELECT 1
/* Define to 1 if you have the `clock_gettime' function. */
#define HAVE_CLOCK_GETTIME 1
/* Define to 1 if you have the `ntohll' function. */
/* #undef HAVE_NTOHLL */
/* Define to 1 if you have the `htonll' function. */
/* #undef HAVE_HTONLL */
/* Define to 1 if you have the `strtoull' function. */
// #define HAVE_STRTOULL 1
/* Define to 1 if you have the `__strtoull' function. */
/* #undef HAVE___STRTOULL */
/* Define to 1 if you have the `_strtoui64' function. */
/* #undef HAVE__STRTOUI64 */
/* Define to 1 if you have the `glob' function. */
// #undef HAVE_GLOB
/* Define to 1 if you have the `explicit_bzero' function. */
// #undef HAVE_EXPLICIT_BZERO
/* Define to 1 if you have the `memset_s' function. */
/* #undef HAVE_MEMSET_S */
/* Define to 1 if you have the `SecureZeroMemory' function. */
/* #undef HAVE_SECURE_ZERO_MEMORY */
/* Define to 1 if you have the `cmocka_set_test_filter' function. */
/* #undef HAVE_CMOCKA_SET_TEST_FILTER */
/* Define to 1 if we have support for blowfish */
/* #undef HAVE_BLOWFISH */
/*************************** LIBRARIES ***************************/
/* Define to 1 if you have the `crypto' library (-lcrypto). */
/* #undef HAVE_LIBCRYPTO */
/* Define to 1 if you have the `gcrypt' library (-lgcrypt). */
/* #undef HAVE_LIBGCRYPT */
/* Define to 1 if you have the 'mbedTLS' library (-lmbedtls). */
#define HAVE_LIBMBEDCRYPTO 1
/* Define to 1 if you have the `pthread' library (-lpthread). */
// #undef HAVE_PTHREAD
/* Define to 1 if you have the `cmocka' library (-lcmocka). */
/* #undef HAVE_CMOCKA */
/**************************** OPTIONS ****************************/
#define HAVE_GCC_THREAD_LOCAL_STORAGE 1
/* #undef HAVE_MSC_THREAD_LOCAL_STORAGE */
// #undef HAVE_FALLTHROUGH_ATTRIBUTE
#define HAVE_UNUSED_ATTRIBUTE 1
#define HAVE_WEAK_ATTRIBUTE 1
#define HAVE_CONSTRUCTOR_ATTRIBUTE 1
#define HAVE_DESTRUCTOR_ATTRIBUTE 1
#define HAVE_GCC_VOLATILE_MEMORY_PROTECTION 1
// #define HAVE_COMPILER__FUNC__ 1
#define HAVE_COMPILER__FUNCTION__ 1
/* #undef HAVE_GCC_BOUNDED_ATTRIBUTE */
/* Define to 1 if you want to enable GSSAPI */
/* #undef WITH_GSSAPI */
/* Define to 1 if you want to enable ZLIB */
#ifdef CONFIG_LIBSSH_ZLIB
#define WITH_ZLIB
#endif
/* Define to 1 if you want to enable SFTP */
#ifdef CONFIG_LIBSSH_SFTP
#define WITH_SFTP 1
#endif
/* Define to 1 if you want to enable server support */
#ifdef CONFIG_LIBSSH_SERVER
#define WITH_SERVER 1
#endif
/* Define to 1 if you want to enable DH group exchange algorithms */
#define WITH_GEX 1
/* Define to 1 if you want to enable insecure none cipher and MAC */
/* #undef WITH_INSECURE_NONE */
/* Define to 1 if you want to allow libssh to execute arbitrary commands from
* configuration files or options (match exec, proxy commands and OpenSSH-based
* proxy-jumps). */
/* #undef WITH_EXEC */
/* Define to 1 if you want to enable blowfish cipher support */
/* #undef WITH_BLOWFISH_CIPHER */
/* Define to 1 if you want to enable debug output for crypto functions */
/* #undef DEBUG_CRYPTO */
/* Define to 1 if you want to enable debug output for packet functions */
/* #undef DEBUG_PACKET */
/* Define to 1 if you want to enable pcap output support (experimental) */
/* #undef WITH_PCAP */
/* Define to 1 if you want to enable calltrace debug output */
/* #undef DEBUG_CALLTRACE */
/* Define to 1 if you want to enable NaCl support */
/* #undef WITH_NACL */
/* Define to 1 if you want to enable PKCS #11 URI support */
/* #undef WITH_PKCS11_URI */
/* Define to 1 if we want to build a support for PKCS #11 provider. */
/* #undef WITH_PKCS11_PROVIDER */
/*************************** ENDIAN *****************************/
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */
/* #undef WORDS_BIGENDIAN */
#ifndef HAVE_STRTOULL
#define HAVE_STRTOULL 1
#endif
#include "stubs.h"
#endif // CONFIG_H

View File

@@ -0,0 +1,25 @@
//
// Created by shinys on 25. 7. 1.
//
#ifndef LIBSSH_VERSION_H
#define LIBSSH_VERSION_H
/* libssh version macros */
#define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c))
#define SSH_VERSION_DOT(a, b, c) a ##.## b ##.## c
#define SSH_VERSION(a, b, c) SSH_VERSION_DOT(a, b, c)
/* libssh version */
#define LIBSSH_VERSION_MAJOR 0
#define LIBSSH_VERSION_MINOR 11
#define LIBSSH_VERSION_MICRO 2
#define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \
LIBSSH_VERSION_MINOR, \
LIBSSH_VERSION_MICRO)
#define LIBSSH_VERSION SSH_VERSION(LIBSSH_VERSION_MAJOR, \
LIBSSH_VERSION_MINOR, \
LIBSSH_VERSION_MICRO)
#endif //LIBSSH_VERSION_H

10
compat/poll.h Normal file
View File

@@ -0,0 +1,10 @@
//
// Created by shinys on 25. 7. 1.
//
#ifndef POOL_H
#define POOL_H
#include <sys/poll.h>
#endif //POOL_H

40
compat/stubs.h Normal file
View File

@@ -0,0 +1,40 @@
//
// Created by shinys on 25. 7. 1.
//
#ifndef STUBS_H
#define STUBS_H
#include <net/if.h>
#include <pwd.h>
#include <glob.h>
#if !defined(GLOB_NOMATCH)
#define GLOB_NOMATCH -3
#endif
#define gai_strerror(ecode) "unknown error"
#define getuid() getuid_stub() (uid_t)0
static inline int getpwuid_r_stub(struct passwd **result) { errno = ENOENT; *result = NULL; return 1; }
#define getpwuid_r(uid,passwd,buffer,buflen,result) getpwuid_r_stub(result)
static inline struct passwd *getpwnam_stub() { errno = ENOENT; return NULL; }
#define getpwnam(name) getpwnam_stub()
static inline int gethostname_stub(char *name, size_t namelen) {strlcpy(name, "esp32", namelen); return 0; }
#define gethostname(name, namelen) gethostname_stub(name, namelen)
static inline pid_t waitpid_stub() { errno = ENOSYS; return (pid_t)-1; }
#define waitpid(pid,status,options) waitpid_stub()
static inline int glob_stub() { errno = ENOENT; return GLOB_NOMATCH; }
#define glob(pattern, flags, errfunc, pglob) glob_stub()
#define globfree(pglob) do { } while(0)
static inline int socketpair_stub() { errno = ENOSYS; return -1; }
#define socketpair(d, type, protocol, sv) socketpair_stub()
#endif //STUBS_H

7
idf_component.yml Normal file
View File

@@ -0,0 +1,7 @@
version: "0.11.2"
description: "A port of libssh as an ESP-IDF component"
url: "https://git.sys114.com/shinys000114/libssh_esp"
license: "GNU Lesser General Public License"
tags:
- ssh
- networking