├── .arcconfig ├── .clang-format ├── .editorconfig ├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .gitlab-ci.yml ├── .gitlab-ci ├── clang-format-check.sh ├── git-check-signoff-trailer.sh └── shellcheck.sh ├── .gitleaks.toml ├── AUTHORS ├── BSD ├── CHANGELOG ├── CMakeLists.txt ├── CONTRIBUTING.md ├── COPYING ├── CPackConfig.cmake ├── CTestConfig.cmake ├── CompilerChecks.cmake ├── ConfigureChecks.cmake ├── DefineOptions.cmake ├── INSTALL ├── README ├── README.markdown ├── README.mbedtls ├── README.md ├── SMP ├── .gitattributes ├── .gitignore ├── SMP.patch ├── appveyor.yml ├── config.h ├── libssh.sln ├── libssh.vcxproj ├── libssh.vcxproj.filters ├── libssh │ └── libssh_version.h ├── libssh_deps.sln ├── libssh_deps_with_latest_sdk.bat ├── libssh_files.props ├── libssh_winrt.vcxproj ├── libssh_winrt.vcxproj.filters ├── libssh_with_latest_sdk.bat ├── project_get_dependencies.bat ├── readme.txt ├── smp_deps.props └── smp_winrt_deps.props ├── cmake ├── Modules │ ├── AddCCompilerFlag.cmake │ ├── AddCMockaTest.cmake │ ├── COPYING-CMAKE-SCRIPTS │ ├── CheckCCompilerFlagSSP.cmake │ ├── CodeCoverage.cmake │ ├── DefineCMakeDefaults.cmake │ ├── DefineCompilerFlags.cmake │ ├── DefinePlatformDefaults.cmake │ ├── ExtractSymbols.cmake │ ├── FindABIMap.cmake │ ├── FindArgp.cmake │ ├── FindCMocka.cmake │ ├── FindGCrypt.cmake │ ├── FindGSSAPI.cmake │ ├── FindMbedTLS.cmake │ ├── FindNSIS.cmake │ ├── FindNaCl.cmake │ ├── Findsofthsm.cmake │ ├── GenerateMap.cmake │ ├── GetFilesList.cmake │ └── MacroEnsureOutOfSourceBuild.cmake └── Toolchain-cross-m32.cmake ├── config.h.cmake ├── doc ├── CMakeLists.txt ├── README.gitlab.freebsd.md ├── authentication.dox ├── command.dox ├── curve25519-sha256@libssh.org.txt ├── doc_coverage.sh ├── forwarding.dox ├── guided_tour.dox ├── introduction.dox ├── linking.dox ├── mainpage.dox ├── pkcs11.dox ├── scp.dox ├── sftp.dox ├── sftp_aio.dox ├── shell.dox ├── tbd.dox ├── that_style │ ├── LICENSE │ ├── README.md │ ├── header.html │ ├── img │ │ ├── doc.svg │ │ ├── folderclosed.svg │ │ ├── folderopen.svg │ │ ├── mag_glass.svg │ │ ├── nav_edge_inter.svg │ │ ├── nav_edge_left.svg │ │ ├── nav_edge_right.svg │ │ ├── splitbar_handle.svg │ │ ├── sync_off.png │ │ └── sync_on.png │ ├── js │ │ └── striped_bg.js │ └── that_style.css └── threading.dox ├── examples ├── CMakeLists.txt ├── authentication.c ├── connect_ssh.c ├── examples_common.h ├── exec.c ├── keygen.c ├── keygen2.c ├── knownhosts.c ├── libssh_scp.c ├── libsshpp.cpp ├── libsshpp_noexcept.cpp ├── proxy.c ├── sample_sftpserver.c ├── samplesftp.c ├── samplesshd-cb.c ├── samplesshd-kbdint.c ├── scp_download.c ├── senddata.c ├── ssh_X11_client.c ├── ssh_client.c ├── ssh_server.c ├── sshd_direct-tcpip.c └── sshnetcat.c ├── include ├── CMakeLists.txt └── libssh │ ├── CMakeLists.txt │ ├── agent.h │ ├── auth.h │ ├── bignum.h │ ├── bind.h │ ├── bind_config.h │ ├── blf.h │ ├── buffer.h │ ├── bytearray.h │ ├── callbacks.h │ ├── chacha.h │ ├── chacha20-poly1305-common.h │ ├── channels.h │ ├── config.h │ ├── config_parser.h │ ├── crypto.h │ ├── curve25519.h │ ├── dh-gex.h │ ├── dh.h │ ├── ecdh.h │ ├── ed25519.h │ ├── fe25519.h │ ├── ge25519.h │ ├── gssapi.h │ ├── kex.h │ ├── keys.h │ ├── knownhosts.h │ ├── legacy.h │ ├── libcrypto.h │ ├── libgcrypt.h │ ├── libmbedcrypto.h │ ├── libssh.h │ ├── libssh_version.h.cmake │ ├── libsshpp.hpp │ ├── messages.h │ ├── misc.h │ ├── options.h │ ├── packet.h │ ├── pcap.h │ ├── pki.h │ ├── pki_priv.h │ ├── poll.h │ ├── poly1305.h │ ├── priv.h │ ├── sc25519.h │ ├── scp.h │ ├── server.h │ ├── session.h │ ├── sftp.h │ ├── sftp_priv.h │ ├── sftpserver.h │ ├── socket.h │ ├── ssh2.h │ ├── string.h │ ├── threads.h │ ├── token.h │ └── wrapper.h ├── libssh.pc.cmake ├── src ├── ABI │ ├── current │ ├── libssh-4.10.0.symbols │ ├── libssh-4.10.1.symbols │ ├── libssh-4.5.0.symbols │ ├── libssh-4.5.1.symbols │ ├── libssh-4.6.0.symbols │ ├── libssh-4.7.0.symbols │ ├── libssh-4.7.1.symbols │ ├── libssh-4.7.2.symbols │ ├── libssh-4.7.3.symbols │ ├── libssh-4.7.4.symbols │ ├── libssh-4.8.0.symbols │ ├── libssh-4.8.1.symbols │ ├── libssh-4.9.0.symbols │ ├── libssh-4.9.1.symbols │ ├── libssh-4.9.2.symbols │ ├── libssh-4.9.3.symbols │ ├── libssh-4.9.4.symbols │ ├── libssh-4.9.5.symbols │ └── libssh-4.9.6.symbols ├── CMakeLists.txt ├── agent.c ├── auth.c ├── base64.c ├── bignum.c ├── bind.c ├── bind_config.c ├── buffer.c ├── callbacks.c ├── chachapoly.c ├── channels.c ├── client.c ├── config.c ├── config_parser.c ├── connect.c ├── connector.c ├── crypto_common.c ├── curve25519.c ├── dh-gex.c ├── dh.c ├── dh_crypto.c ├── dh_key.c ├── ecdh.c ├── ecdh_crypto.c ├── ecdh_gcrypt.c ├── ecdh_mbedcrypto.c ├── error.c ├── external │ ├── bcrypt_pbkdf.c │ ├── blowfish.c │ ├── chacha.c │ ├── curve25519_ref.c │ ├── ed25519.c │ ├── fe25519.c │ ├── ge25519.c │ ├── ge25519_base.data │ ├── poly1305.c │ └── sc25519.c ├── gcrypt_missing.c ├── getpass.c ├── getrandom_crypto.c ├── getrandom_gcrypt.c ├── getrandom_mbedcrypto.c ├── gssapi.c ├── gzip.c ├── init.c ├── kdf.c ├── kex.c ├── known_hosts.c ├── knownhosts.c ├── legacy.c ├── libcrypto-compat.h ├── libcrypto.c ├── libgcrypt.c ├── libmbedcrypto.c ├── libssh.map ├── log.c ├── match.c ├── mbedcrypto-compat.h ├── mbedcrypto_missing.c ├── md_crypto.c ├── md_gcrypt.c ├── md_mbedcrypto.c ├── messages.c ├── misc.c ├── options.c ├── packet.c ├── packet_cb.c ├── packet_crypt.c ├── pcap.c ├── pki.c ├── pki_container_openssh.c ├── pki_crypto.c ├── pki_ed25519.c ├── pki_ed25519_common.c ├── pki_gcrypt.c ├── pki_mbedcrypto.c ├── poll.c ├── scp.c ├── server.c ├── session.c ├── sftp.c ├── sftp_aio.c ├── sftp_common.c ├── sftpserver.c ├── socket.c ├── string.c ├── threads.c ├── threads │ ├── libcrypto.c │ ├── libgcrypt.c │ ├── mbedtls.c │ ├── noop.c │ ├── pthread.c │ └── winlocks.c ├── token.c ├── ttyopts.c └── wrapper.c └── tests ├── CMakeLists.txt ├── benchmarks ├── CMakeLists.txt ├── bench1.sh ├── bench2.sh ├── bench_raw.c ├── bench_scp.c ├── bench_sftp.c ├── benchmarks.c ├── benchmarks.h └── latency.c ├── chmodtest.c ├── chroot_wrapper.c ├── client ├── CMakeLists.txt ├── torture_algorithms.c ├── torture_auth.c ├── torture_auth_cert.c ├── torture_auth_common.c ├── torture_auth_pkcs11.c ├── torture_client_callbacks.c ├── torture_client_config.c ├── torture_client_global_requests.c ├── torture_connect.c ├── torture_forward.c ├── torture_gssapi_auth.c ├── torture_hostkey.c ├── torture_knownhosts.c ├── torture_knownhosts_verify.c ├── torture_proxycommand.c ├── torture_proxyjump.c ├── torture_rekey.c ├── torture_request_env.c ├── torture_request_pty_modes.c ├── torture_scp.c ├── torture_session.c ├── torture_sftp_aio.c ├── torture_sftp_benchmark.c ├── torture_sftp_canonicalize_path.c ├── torture_sftp_dir.c ├── torture_sftp_expand_path.c ├── torture_sftp_ext.c ├── torture_sftp_fsync.c ├── torture_sftp_hardlink.c ├── torture_sftp_home_directory.c ├── torture_sftp_init.c ├── torture_sftp_limits.c ├── torture_sftp_packet_read.c ├── torture_sftp_read.c ├── torture_sftp_rename.c └── torture_sftp_setstat.c ├── cmdline.c ├── ctest-default.cmake ├── etc ├── group.in ├── hosts.in ├── pam.d │ └── sshd.in ├── pam_matrix_passdb.in ├── passwd.in └── shadow.in ├── external_override ├── CMakeLists.txt ├── chacha20_override.c ├── chacha20_override.h ├── curve25519_override.c ├── curve25519_override.h ├── ed25519_override.c ├── ed25519_override.h ├── poly1305_override.c ├── poly1305_override.h └── torture_override.c ├── fs_wrapper.c ├── fuzz ├── CMakeLists.txt ├── README.md ├── fuzzer.c ├── ssh_bind_config_fuzzer.c ├── ssh_client_config_fuzzer.c ├── ssh_client_fuzzer.c ├── ssh_client_fuzzer_corpus │ └── 0f9d75a6c1d365115772a502d42b6e48f453198a ├── ssh_known_hosts_fuzzer.c ├── ssh_known_hosts_fuzzer_corpus │ └── d7c0eade3f3b70d94b1a7090e09eb8607da0ace4 ├── ssh_privkey_fuzzer.c ├── ssh_privkey_fuzzer_corpus │ └── 855ce609b52aec530bf631a78da7038bed99040a ├── ssh_pubkey_fuzzer.c ├── ssh_pubkey_fuzzer_corpus │ └── b2c9f01394a2835b2cd7c520395a4977143e8d23 ├── ssh_server_fuzzer.c └── ssh_server_fuzzer_corpus │ └── fd7bd24a85e712fb59159a512b69d34ca21c8383 ├── generate.py ├── gss └── kdcsetup.sh ├── keys ├── certauth │ ├── id_rsa │ ├── id_rsa-cert.pub │ └── id_rsa.pub ├── id_ecdsa ├── id_ecdsa.pub ├── id_ed25519 ├── id_ed25519.pub ├── id_rsa ├── id_rsa.pub ├── id_rsa_protected ├── id_rsa_protected.pub ├── pkcs11 │ ├── id_pkcs11_ecdsa_256 │ ├── id_pkcs11_ecdsa_256.pub │ ├── id_pkcs11_ecdsa_256_openssh.pub │ ├── id_pkcs11_ecdsa_384 │ ├── id_pkcs11_ecdsa_384.pub │ ├── id_pkcs11_ecdsa_384_openssh.pub │ ├── id_pkcs11_ecdsa_521 │ ├── id_pkcs11_ecdsa_521.pub │ ├── id_pkcs11_ecdsa_521_openssh.pub │ ├── id_pkcs11_ed25519 │ ├── id_pkcs11_ed25519.pub │ ├── id_pkcs11_rsa │ ├── id_pkcs11_rsa.pub │ └── id_pkcs11_rsa_openssh.pub ├── ssh_host_ecdsa_key ├── ssh_host_ecdsa_key.pub ├── ssh_host_key ├── ssh_host_key.pub ├── ssh_host_rsa_key ├── ssh_host_rsa_key.pub └── user_ca ├── pkcs11 └── setup-softhsm-tokens.sh ├── pkd ├── CMakeLists.txt ├── pkd_client.h ├── pkd_daemon.c ├── pkd_daemon.h ├── pkd_hello.c ├── pkd_keyutil.c ├── pkd_keyutil.h ├── pkd_util.c └── pkd_util.h ├── server ├── CMakeLists.txt ├── test_server │ ├── CMakeLists.txt │ ├── default_cb.c │ ├── default_cb.h │ ├── main.c │ ├── sftpserver_cb.c │ ├── test_server.c │ └── test_server.h ├── torture_gssapi_server_auth.c ├── torture_gssapi_server_auth_cb.c ├── torture_gssapi_server_delegation.c ├── torture_server_algorithms.c ├── torture_server_auth_kbdint.c ├── torture_server_config.c ├── torture_server_default.c └── torture_sftpserver.c ├── ssh_ping.c ├── suppressions └── lsan.supp ├── test_socket.c ├── tests_config.h.cmake ├── torture.c ├── torture.h ├── torture_cmocka.c ├── torture_cmocka.h ├── torture_key.c ├── torture_key.h ├── torture_pki.c ├── torture_pki.h ├── unittests ├── CMakeLists.txt ├── hello world.sh ├── torture_bignum.c ├── torture_bind_config.c ├── torture_buffer.c ├── torture_bytearray.c ├── torture_callbacks.c ├── torture_channel.c ├── torture_config.c ├── torture_config_match_localnetwork.c ├── torture_crypto.c ├── torture_hashes.c ├── torture_init.c ├── torture_isipaddr.c ├── torture_keyfiles.c ├── torture_knownhosts_parsing.c ├── torture_list.c ├── torture_misc.c ├── torture_moduli.c ├── torture_options.c ├── torture_packet.c ├── torture_packet_filter.c ├── torture_pki.c ├── torture_pki_dsa.c ├── torture_pki_ecdsa.c ├── torture_pki_ecdsa_uri.c ├── torture_pki_ed25519.c ├── torture_pki_rsa.c ├── torture_pki_rsa_uri.c ├── torture_push_pop_dir.c ├── torture_rand.c ├── torture_server_x11.c ├── torture_session_keys.c ├── torture_temp_dir.c ├── torture_temp_file.c ├── torture_threads_buffer.c ├── torture_threads_crypto.c ├── torture_threads_init.c ├── torture_threads_pki_rsa.c ├── torture_tokens.c └── torture_unit_server.c └── valgrind.supp /.arcconfig: -------------------------------------------------------------------------------- 1 | { 2 | "phabricator.uri" : "https://bugs.libssh.org/", 3 | "history.immutable": true 4 | } 5 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | # https://clang.llvm.org/docs/ClangFormatStyleOptions.html 3 | BasedOnStyle: LLVM 4 | IndentWidth: 4 5 | UseTab: Never 6 | AllowShortIfStatementsOnASingleLine: false 7 | BreakBeforeBraces: Custom 8 | BraceWrapping: 9 | AfterEnum: false 10 | AfterFunction: true 11 | AfterStruct: false 12 | AfterUnion: false 13 | AfterExternBlock: false 14 | BeforeElse: false 15 | BeforeWhile: false 16 | IndentCaseLabels: false 17 | IndentCaseBlocks: false 18 | ColumnLimit: 80 19 | AlignAfterOpenBracket: Align 20 | AllowAllParametersOfDeclarationOnNextLine: false 21 | BinPackArguments: false 22 | BinPackParameters: false 23 | AllowAllArgumentsOnNextLine: false 24 | AllowShortFunctionsOnASingleLine: Empty 25 | # TODO with Clang 19, replace the below with 26 | # BreakAfterReturnType: ExceptShortType 27 | AlwaysBreakAfterReturnType: AllDefinitions 28 | AlignEscapedNewlines: Left 29 | ForEachMacros: ['ssh_callbacks_iterate'] 30 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | max_line_length = 80 6 | end_of_line = lf 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.{c,h}] 11 | indent_style = space 12 | indent_size = 4 13 | tab_width = 4 14 | 15 | [{CMakeLists.txt,*.cmake}] 16 | indent_style = space 17 | indent_size = 4 18 | tab_width = 4 -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Context 4 | 5 | 6 | ## Expected Behavior 7 | 8 | 9 | ## Actual Behavior 10 | 11 | 12 | ## Steps to Reproduce 13 | 14 | 1. 15 | 2. 16 | 3. 17 | 4. 18 | 19 | ## Your Environment 20 | 21 | * Version Used: 22 | * Operating System and Version: 23 | * Compiler and Version(s): 24 | 25 | ## Possible Fix 26 | 27 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Context 4 | 5 | 6 | ## Current and Suggested Behavior 7 | 8 | 9 | ## Steps to Explain Enhancement 10 | 11 | 1. 12 | 2. 13 | 3. 14 | 4. 15 | 16 | ## Your Test Environment 17 | 18 | * Version Used: 19 | * Operating System and Version(s): 20 | * Compiler and version(s): -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.o 3 | *.swp 4 | *~$ 5 | cscope.* 6 | compile_commands.json 7 | /.cache 8 | /.clangd 9 | tags 10 | /build 11 | /obj* 12 | doc/tags.xml 13 | -------------------------------------------------------------------------------- /.gitlab-ci/clang-format-check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Based on Github Action 3 | # https://github.com/yshui/git-clang-format-lint 4 | 5 | diff=$(git-clang-format --diff --commit "$CI_MERGE_REQUEST_DIFF_BASE_SHA") 6 | [ "$diff" = "no modified files to format" ] && exit 0 7 | [ "$diff" = "clang-format did not modify any files" ] && exit 0 8 | 9 | printf "You have introduced coding style breakages, suggested changes:\n\n" 10 | 11 | echo "${diff}" | colordiff 12 | exit 1 13 | -------------------------------------------------------------------------------- /.gitlab-ci/git-check-signoff-trailer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $# != 1 ]; then 4 | echo "Usage: $0 UPSTREAM_COMMIT_SHA" 5 | exit 1 6 | fi 7 | 8 | failed=0 9 | 10 | if [ -z "$CI_COMMIT_SHA" ]; then 11 | echo "CI_COMMIT_SHA is not set" 12 | exit 1 13 | fi 14 | 15 | CI_COMMIT_RANGE="$1..$CI_COMMIT_SHA" 16 | 17 | red='\033[0;31m' 18 | blue='\033[0;34m' 19 | 20 | echo -e "${blue}Checking commit range: $CI_COMMIT_RANGE" 21 | echo 22 | echo 23 | 24 | for commit in $(git rev-list "$CI_COMMIT_RANGE"); do 25 | git show -s --format=%B "$commit" | grep "^Signed-off-by: " >/dev/null 2>&1 26 | ret=$? 27 | if [ $ret -eq 1 ]; then 28 | echo -e "${red} >>> Missing Signed-off-by trailer in commit $commit" 29 | failed=$(("$failed" + 1)) 30 | fi 31 | done 32 | 33 | echo 34 | echo 35 | 36 | exit $failed 37 | -------------------------------------------------------------------------------- /.gitlab-ci/shellcheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Simplified and de-github-ed version of 3 | # https://github.com/ludeeus/action-shellcheck/blob/master/action.yaml 4 | 5 | statuscode=0 6 | 7 | declare -a filepaths 8 | shebangregex="^#! */[^ ]*/(env *)?[abk]*sh" 9 | set -f # temporarily disable globbing so that globs in inputs aren't expanded 10 | 11 | while IFS= read -r -d '' file; do 12 | filepaths+=("$file") 13 | done < <(find . \ 14 | -type f \ 15 | '(' \ 16 | -name '*.bash' \ 17 | -o -name '.bashrc' \ 18 | -o -name 'bashrc' \ 19 | -o -name '.bash_aliases' \ 20 | -o -name '.bash_completion' \ 21 | -o -name '.bash_login' \ 22 | -o -name '.bash_logout' \ 23 | -o -name '.bash_profile' \ 24 | -o -name 'bash_profile' \ 25 | -o -name '*.ksh' \ 26 | -o -name 'suid_profile' \ 27 | -o -name '*.zsh' \ 28 | -o -name '.zlogin' \ 29 | -o -name 'zlogin' \ 30 | -o -name '.zlogout' \ 31 | -o -name 'zlogout' \ 32 | -o -name '.zprofile' \ 33 | -o -name 'zprofile' \ 34 | -o -name '.zsenv' \ 35 | -o -name 'zsenv' \ 36 | -o -name '.zshrc' \ 37 | -o -name 'zshrc' \ 38 | -o -name '*.sh' \ 39 | -o -path '*/.profile' \ 40 | -o -path '*/profile' \ 41 | -o -name '*.shlib' \ 42 | ')' \ 43 | -print0) 44 | 45 | while IFS= read -r -d '' file; do 46 | head -n1 "$file" | grep -Eqs "$shebangregex" || continue 47 | filepaths+=("$file") 48 | done < <(find . \ 49 | -type f ! -name '*.*' -perm /111 \ 50 | -print0) 51 | 52 | shellcheck "${filepaths[@]}" || statuscode=$? 53 | 54 | set +f # re-enable globbing 55 | 56 | exit "$statuscode" 57 | -------------------------------------------------------------------------------- /.gitleaks.toml: -------------------------------------------------------------------------------- 1 | # 2 | # GitLeaks Repo Specific Configuration 3 | # 4 | # This allowlist is used to help Red Hat ignore false positives during its code 5 | # scans. 6 | 7 | [allowlist] 8 | paths = [ 9 | '''tests/*''', 10 | ] 11 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Author(s): 2 | Aris Adamantiadis (project initiator) 3 | 4 | Andreas Schneider (developer) 5 | 6 | Nick Zitzmann (mostly client SFTP stuff) 7 | 8 | Norbert Kiesel (getaddrinfo and other patches) 9 | 10 | Jean-Philippe Garcia Ballester (Port to libgcrypt and configure.in voodoo, debian packaging) 11 | 12 | Contributor(s): 13 | 14 | Laurent Bigonville (debian packaging) 15 | 16 | -------------------------------------------------------------------------------- /BSD: -------------------------------------------------------------------------------- 1 | Some parts are under the BSDv2 License : 2 | 3 | 4 | Copyright (c) 2000 Markus Friedl. All rights reserved. 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | -------------------------------------------------------------------------------- /CPackConfig.cmake: -------------------------------------------------------------------------------- 1 | ### GENERAL SETTINGS 2 | set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) 3 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The SSH Library") 4 | set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") 5 | set(CPACK_PACKAGE_VENDOR "The SSH Library Development Team") 6 | set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME}) 7 | set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING") 8 | 9 | set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) 10 | 11 | # SOURCE GENERATOR 12 | set(CPACK_SOURCE_GENERATOR "TXZ") 13 | set(CPACK_SOURCE_IGNORE_FILES "~$;[.]swp$;/[.]bare/;/[.]git/;/[.]git;/[.]clangd/;/[.]cache/;.gitignore;/build*;/obj*;tags;cscope.*;compile_commands.json;.*\.patch") 14 | set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") 15 | 16 | ### NSIS INSTALLER 17 | if (WIN32) 18 | set(CPACK_GENERATOR "ZIP") 19 | 20 | ### nsis generator 21 | find_package(NSIS) 22 | if (NSIS_MAKE) 23 | set(CPACK_GENERATOR "${CPACK_GENERATOR};NSIS") 24 | set(CPACK_NSIS_DISPLAY_NAME "The SSH Library") 25 | set(CPACK_NSIS_COMPRESSOR "/SOLID zlib") 26 | set(CPACK_NSIS_MENU_LINKS "https://www.libssh.org/" "libssh homepage") 27 | endif (NSIS_MAKE) 28 | endif (WIN32) 29 | 30 | set(CPACK_PACKAGE_INSTALL_DIRECTORY "libssh") 31 | 32 | set(CPACK_PACKAGE_FILE_NAME ${APPLICATION_NAME}-${CPACK_PACKAGE_VERSION}) 33 | 34 | set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries") 35 | set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C/C++ Headers") 36 | set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION 37 | "Libraries used to build programs which use libssh") 38 | set(CPACK_COMPONENT_HEADERS_DESCRIPTION 39 | "C/C++ header files for use with libssh") 40 | set(CPACK_COMPONENT_HEADERS_DEPENDS libraries) 41 | set(CPACK_COMPONENT_LIBRARIES_GROUP "Development") 42 | set(CPACK_COMPONENT_HEADERS_GROUP "Development") 43 | 44 | include(CPack) 45 | -------------------------------------------------------------------------------- /CTestConfig.cmake: -------------------------------------------------------------------------------- 1 | set(UPDATE_TYPE "true") 2 | 3 | set(CTEST_PROJECT_NAME "libssh") 4 | set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC") 5 | 6 | set(CTEST_DROP_METHOD "https") 7 | set(CTEST_DROP_SITE "test.libssh.org") 8 | set(CTEST_DROP_LOCATION "/submit.php?project=libssh") 9 | set(CTEST_DROP_SITE_CDASH TRUE) 10 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | _ _ _ _ 2 | (_) (_) (_) (_) 3 | (_) _ (_) _ _ _ _ _ (_) _ 4 | (_) (_) (_)(_) _ (_)(_) (_)(_) (_)(_) _ 5 | (_) (_) (_) (_) _ (_) _ (_) (_) (_) 6 | (_) (_) (_)(_)(_) (_)(_) (_)(_) (_) (_).org 7 | 8 | The SSH library 9 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10 | 11 | 1* Why ? 12 | -_-_-_-_-_ 13 | 14 | Why not ? :) I've began to work on my own implementation of the ssh protocol 15 | because i didn't like the currently public ones. 16 | Not any allowed you to import and use the functions as a powerful library, 17 | and so i worked on a library-based SSH implementation which was non-existing 18 | in the free and open source software world. 19 | 20 | 21 | 2* How/Who ? 22 | -_-_-_-_-_-_-_ 23 | 24 | If you downloaded this file, you must know what it is : a library for 25 | accessing ssh client services through C libraries calls in a simple manner. 26 | Everybody can use this software under the terms of the LGPL - see the COPYING 27 | file 28 | 29 | If you ask yourself how to compile libssh, please read INSTALL before anything. 30 | 31 | 3* Where ? 32 | -_-_-_-_-_-_ 33 | 34 | https://www.libssh.org 35 | 36 | 4* Contributing 37 | -_-_-_-_-_-_-_-_-_ 38 | 39 | Please read the file 'CONTRIBUTING.md' next to this README file. It explains 40 | our copyright policy and how you should send patches for upstream inclusion. 41 | 42 | Have fun and happy libssh hacking! 43 | 44 | The libssh Team 45 | -------------------------------------------------------------------------------- /README.mbedtls: -------------------------------------------------------------------------------- 1 | mbedTLS and libssh in multithreaded applications 2 | ================================================== 3 | 4 | To use libssh with mbedTLS in a multithreaded application, mbedTLS has to be 5 | built with threading support enabled. 6 | 7 | If threading support is not available and multi threading is used, ssh_init 8 | will fail. 9 | 10 | More information about building mbedTLS with threading support can be found 11 | in the mbedTLS documentation. 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![pipeline status](https://gitlab.com/libssh/libssh-mirror/badges/master/pipeline.svg)](https://gitlab.com/libssh/libssh-mirror/commits/master) 2 | [![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/libssh.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:libssh) 3 | 4 | ``` 5 | _ _ _ _ 6 | (_) (_) (_) (_) 7 | (_) _ (_) _ _ _ _ _ (_) _ 8 | (_) (_) (_)(_) _ (_)(_) (_)(_) (_)(_) _ 9 | (_) (_) (_) (_) _ (_) _ (_) (_) (_) 10 | (_) (_) (_)(_)(_) (_)(_) (_)(_) (_) (_).org 11 | 12 | The SSH library 13 | 14 | ``` 15 | 16 | # Why? 17 | 18 | Why not ? :) I've began to work on my own implementation of the ssh protocol 19 | because i didn't like the currently public ones. 20 | Not any allowed you to import and use the functions as a powerful library, 21 | and so i worked on a library-based SSH implementation which was non-existing 22 | in the free and open source software world. 23 | 24 | 25 | # How/Who? 26 | 27 | If you downloaded this file, you must know what it is : a library for 28 | accessing ssh client services through C libraries calls in a simple manner. 29 | Everybody can use this software under the terms of the LGPL - see the COPYING 30 | file 31 | 32 | If you ask yourself how to compile libssh, please read INSTALL before anything. 33 | 34 | # Where ? 35 | 36 | https://www.libssh.org 37 | 38 | # Contributing 39 | 40 | Please read the file 'CONTRIBUTING.md' next to this README file. It explains 41 | our copyright policy and how you should send patches for upstream inclusion. 42 | 43 | Have fun and happy libssh hacking! 44 | 45 | The libssh Team 46 | -------------------------------------------------------------------------------- /SMP/.gitattributes: -------------------------------------------------------------------------------- 1 | *.sln text eol=crlf 2 | *.vcxproj text eol=crlf 3 | *.vcxproj.filters text eol=crlf 4 | *.bat text eol=crlf -------------------------------------------------------------------------------- /SMP/.gitignore: -------------------------------------------------------------------------------- 1 | *.obj 2 | *.lib 3 | *.log 4 | *.tlog 5 | *.pdb 6 | *.ildb 7 | *.pgd 8 | *.pch 9 | *.manifest 10 | *.suo 11 | *.user 12 | *.sdf 13 | *.opensdf 14 | [Oo]bj/ 15 | *.exe 16 | !*.h 17 | !*.c 18 | !*.asm 19 | !*.def 20 | !*.rc 21 | *.sbr 22 | *.iobj 23 | *.ipdb 24 | .vs/ 25 | *.VC.db 26 | *.opendb 27 | *.ilk 28 | [Bb]in/ -------------------------------------------------------------------------------- /SMP/libssh/libssh_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2020 by Heiko Thiery 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef _LIBSSH_VERSION_H 22 | #define _LIBSSH_VERSION_H 23 | 24 | /* libssh version macros */ 25 | #define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c)) 26 | #define SSH_VERSION_DOT(a, b, c) a ##.## b ##.## c 27 | #define SSH_VERSION(a, b, c) SSH_VERSION_DOT(a, b, c) 28 | 29 | /* libssh version */ 30 | #define LIBSSH_VERSION_MAJOR 0 31 | #define LIBSSH_VERSION_MINOR 11 32 | #define LIBSSH_VERSION_MICRO 1 33 | 34 | #define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \ 35 | LIBSSH_VERSION_MINOR, \ 36 | LIBSSH_VERSION_MICRO) 37 | #define LIBSSH_VERSION SSH_VERSION(LIBSSH_VERSION_MAJOR, \ 38 | LIBSSH_VERSION_MINOR, \ 39 | LIBSSH_VERSION_MICRO) 40 | 41 | #endif /* _LIBSSH_VERSION_H */ 42 | -------------------------------------------------------------------------------- /SMP/libssh_deps_with_latest_sdk.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | SET PROJECT=libssh_deps 4 | 5 | @REM Detect the newest available Windows SDK 6 | CALL :GetWindowsSdkVer 7 | 8 | @REM Open the project 9 | %PROJECT%.sln 10 | 11 | EXIT /B 0 12 | 13 | :GetWindowsSdkVer 14 | SET WindowsTargetPlatformVersion= 15 | 16 | IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin10SdkVer 17 | IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin81SdkVer 18 | EXIT /B 0 19 | 20 | :GetWin10SdkVer 21 | CALL :GetWin10SdkVerHelper HKLM\SOFTWARE\Wow6432Node > nul 2>&1 22 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE\Wow6432Node > nul 2>&1 23 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKLM\SOFTWARE > nul 2>&1 24 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE > nul 2>&1 25 | IF errorlevel 1 EXIT /B 1 26 | EXIT /B 0 27 | 28 | :GetWin10SdkVerHelper 29 | @REM Get Windows 10 SDK installed folder 30 | FOR /F "tokens=1,2*" %%i IN ('reg query "%1\Microsoft\Microsoft SDKs\Windows\v10.0" /v "InstallationFolder"') DO ( 31 | IF "%%i"=="InstallationFolder" ( 32 | SET WindowsSdkDir=%%~k 33 | ) 34 | ) 35 | 36 | @REM get windows 10 sdk version number 37 | SETLOCAL enableDelayedExpansion 38 | IF NOT "%WindowsSdkDir%"=="" FOR /f %%i IN ('dir "%WindowsSdkDir%include\" /b /ad-h /on') DO ( 39 | @REM Skip if Windows.h is not found in %%i\um. This would indicate that only the UCRT MSIs were 40 | @REM installed for this Windows SDK version. 41 | IF EXIST "%WindowsSdkDir%include\%%i\um\Windows.h" ( 42 | SET result=%%i 43 | IF "!result:~0,3!"=="10." ( 44 | SET SDK=!result! 45 | IF "!result!"=="%VSCMD_ARG_WINSDK%" SET findSDK=1 46 | ) 47 | ) 48 | ) 49 | 50 | IF "%findSDK%"=="1" SET SDK=%VSCMD_ARG_WINSDK% 51 | ENDLOCAL & SET WindowsTargetPlatformVersion=%SDK% 52 | IF "%WindowsTargetPlatformVersion%"=="" ( 53 | EXIT /B 1 54 | ) 55 | EXIT /B 0 56 | 57 | :GetWin81SdkVer 58 | SET WindowsTargetPlatformVersion=8.1 59 | EXIT /B 0 60 | -------------------------------------------------------------------------------- /SMP/libssh_with_latest_sdk.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | SET PROJECT=libssh 4 | 5 | @REM Detect the newest available Windows SDK 6 | CALL :GetWindowsSdkVer 7 | 8 | @REM Open the project 9 | %PROJECT%.sln 10 | 11 | EXIT /B 0 12 | 13 | :GetWindowsSdkVer 14 | SET WindowsTargetPlatformVersion= 15 | 16 | IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin10SdkVer 17 | IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin81SdkVer 18 | EXIT /B 0 19 | 20 | :GetWin10SdkVer 21 | CALL :GetWin10SdkVerHelper HKLM\SOFTWARE\Wow6432Node > nul 2>&1 22 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE\Wow6432Node > nul 2>&1 23 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKLM\SOFTWARE > nul 2>&1 24 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE > nul 2>&1 25 | IF errorlevel 1 EXIT /B 1 26 | EXIT /B 0 27 | 28 | :GetWin10SdkVerHelper 29 | @REM Get Windows 10 SDK installed folder 30 | FOR /F "tokens=1,2*" %%i IN ('reg query "%1\Microsoft\Microsoft SDKs\Windows\v10.0" /v "InstallationFolder"') DO ( 31 | IF "%%i"=="InstallationFolder" ( 32 | SET WindowsSdkDir=%%~k 33 | ) 34 | ) 35 | 36 | @REM get windows 10 sdk version number 37 | SETLOCAL enableDelayedExpansion 38 | IF NOT "%WindowsSdkDir%"=="" FOR /f %%i IN ('dir "%WindowsSdkDir%include\" /b /ad-h /on') DO ( 39 | @REM Skip if Windows.h is not found in %%i\um. This would indicate that only the UCRT MSIs were 40 | @REM installed for this Windows SDK version. 41 | IF EXIST "%WindowsSdkDir%include\%%i\um\Windows.h" ( 42 | SET result=%%i 43 | IF "!result:~0,3!"=="10." ( 44 | SET SDK=!result! 45 | IF "!result!"=="%VSCMD_ARG_WINSDK%" SET findSDK=1 46 | ) 47 | ) 48 | ) 49 | 50 | IF "%findSDK%"=="1" SET SDK=%VSCMD_ARG_WINSDK% 51 | ENDLOCAL & SET WindowsTargetPlatformVersion=%SDK% 52 | IF "%WindowsTargetPlatformVersion%"=="" ( 53 | EXIT /B 1 54 | ) 55 | EXIT /B 0 56 | 57 | :GetWin81SdkVer 58 | SET WindowsTargetPlatformVersion=8.1 59 | EXIT /B 0 60 | -------------------------------------------------------------------------------- /SMP/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a small list of steps in order to build libssh into a msvc dll and/or lib file. 3 | 4 | The project contains Release and Debug builds for static lib files (Debug/Release) 5 | as well as dynamic shared dll files (DebugDLL/ReleaseDLL). Along with the standard 6 | windows dll/lib configurations mentioned above there are also equivalent variants that 7 | can be used to compile for WinRT/UWP (These configurations have a WinRT suffix). 8 | There are also architecture configurations for either 32bit (x86) or 64bit (x64) compilation. 9 | Choose whichever project configuration meets your requirements. 10 | 11 | The project configurations support being built with various different windows SDK versions. 12 | By default they will use the lowest SDK version that would be available for Visual Studio 13 | version 2013 and up (This is the 8.1 SDK). However a batch file is also included 14 | (libssh_with_latest_sdk.bat) which can be used to auto detect the newest available SDK 15 | installed on the host machine and then open the project using that as the compilation SDK. 16 | 17 | When using the WinRT/UWP project configurations the projects will automatically compile towards 18 | the default application target for the Version of Visual Studio being used: 19 | VS 2013: 8.1 20 | VS 2015: 8.1 21 | VS 2017+: 10.0.10240.0 22 | 23 | -------------------------------------------------------------------------------- /cmake/Modules/AddCCompilerFlag.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # add_c_compiler_flag("-Werror" SUPPORTED_CFLAGS) 3 | # 4 | # Copyright (c) 2018 Andreas Schneider 5 | # 6 | # Redistribution and use is allowed according to the terms of the BSD license. 7 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 8 | 9 | include(CheckCCompilerFlag) 10 | 11 | macro(add_c_compiler_flag _COMPILER_FLAG _OUTPUT_VARIABLE) 12 | string(TOUPPER ${_COMPILER_FLAG} _COMPILER_FLAG_NAME) 13 | string(REGEX REPLACE "^-" "" _COMPILER_FLAG_NAME "${_COMPILER_FLAG_NAME}") 14 | string(REGEX REPLACE "(-|=|\ )" "_" _COMPILER_FLAG_NAME "${_COMPILER_FLAG_NAME}") 15 | 16 | check_c_compiler_flag("${_COMPILER_FLAG}" WITH_${_COMPILER_FLAG_NAME}_FLAG) 17 | if (WITH_${_COMPILER_FLAG_NAME}_FLAG) 18 | #string(APPEND ${_OUTPUT_VARIABLE} "${_COMPILER_FLAG} ") 19 | list(APPEND ${_OUTPUT_VARIABLE} ${_COMPILER_FLAG}) 20 | endif() 21 | endmacro() 22 | -------------------------------------------------------------------------------- /cmake/Modules/COPYING-CMAKE-SCRIPTS: -------------------------------------------------------------------------------- 1 | Redistribution and use in source and binary forms, with or without 2 | modification, are permitted provided that the following conditions 3 | are met: 4 | 5 | 1. Redistributions of source code must retain the copyright 6 | notice, this list of conditions and the following disclaimer. 7 | 2. Redistributions in binary form must reproduce the copyright 8 | notice, this list of conditions and the following disclaimer in the 9 | documentation and/or other materials provided with the distribution. 10 | 3. The name of the author may not be used to endorse or promote products 11 | derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /cmake/Modules/CheckCCompilerFlagSSP.cmake: -------------------------------------------------------------------------------- 1 | # - Check whether the C compiler supports a given flag in the 2 | # context of a stack checking compiler option. 3 | 4 | # CHECK_C_COMPILER_FLAG_SSP(FLAG VARIABLE) 5 | # 6 | # FLAG - the compiler flag 7 | # VARIABLE - variable to store the result 8 | # 9 | # This actually calls check_c_source_compiles. 10 | # See help for CheckCSourceCompiles for a listing of variables 11 | # that can modify the build. 12 | 13 | # Copyright (c) 2006, Alexander Neundorf, 14 | # 15 | # Redistribution and use is allowed according to the terms of the BSD license. 16 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 17 | 18 | # Requires cmake 3.10 19 | #include_guard(GLOBAL) 20 | include(CheckCSourceCompiles) 21 | 22 | macro(CHECK_C_COMPILER_FLAG_SSP _FLAG _RESULT) 23 | set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") 24 | set(CMAKE_REQUIRED_FLAGS "${_FLAG}") 25 | 26 | check_c_source_compiles("int main(int argc, char **argv) { char buffer[256]; return buffer[argc]=0;}" ${_RESULT}) 27 | 28 | set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") 29 | endmacro(CHECK_C_COMPILER_FLAG_SSP) 30 | -------------------------------------------------------------------------------- /cmake/Modules/DefineCMakeDefaults.cmake: -------------------------------------------------------------------------------- 1 | # Always include srcdir and builddir in include path 2 | # This saves typing ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY} in 3 | # about every subdir 4 | # since cmake 2.4.0 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | # Put the include dirs which are in the source or build tree 8 | # before all other include dirs, so the headers in the sources 9 | # are preferred over the already installed ones 10 | # since cmake 2.4.1 11 | set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON) 12 | 13 | # Use colored output 14 | # since cmake 2.4.0 15 | set(CMAKE_COLOR_MAKEFILE ON) 16 | 17 | # Create the compile command database for clang by default 18 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 19 | 20 | # Always build with -fPIC 21 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 22 | -------------------------------------------------------------------------------- /cmake/Modules/DefinePlatformDefaults.cmake: -------------------------------------------------------------------------------- 1 | # Set system vars 2 | 3 | if (CMAKE_SYSTEM_NAME MATCHES "Linux") 4 | set(LINUX TRUE) 5 | endif(CMAKE_SYSTEM_NAME MATCHES "Linux") 6 | 7 | if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") 8 | set(FREEBSD TRUE) 9 | set(BSD TRUE) 10 | endif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") 11 | 12 | if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD") 13 | set(OPENBSD TRUE) 14 | set(BSD TRUE) 15 | endif (CMAKE_SYSTEM_NAME MATCHES "OpenBSD") 16 | 17 | if (CMAKE_SYSTEM_NAME MATCHES "NetBSD") 18 | set(NETBSD TRUE) 19 | set(BSD TRUE) 20 | endif (CMAKE_SYSTEM_NAME MATCHES "NetBSD") 21 | 22 | if (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") 23 | set(SOLARIS TRUE) 24 | endif (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") 25 | 26 | if (CMAKE_SYSTEM_NAME MATCHES "OS2") 27 | set(OS2 TRUE) 28 | endif (CMAKE_SYSTEM_NAME MATCHES "OS2") 29 | 30 | if (CMAKE_SYSTEM_NAME MATCHES "Darwin") 31 | set (OSX TRUE) 32 | endif (CMAKE_SYSTEM_NAME MATCHES "Darwin") 33 | -------------------------------------------------------------------------------- /cmake/Modules/FindArgp.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find ARGP 2 | # 3 | # The argp can be either shipped as part of libc (ex. glibc) or as a separate 4 | # library that requires additional linking (ex. Windows, Mac, musl libc, ...) 5 | # 6 | # Once done this will define 7 | # 8 | # ARGP_ROOT_DIR - Set this variable to the root installation of ARGP 9 | # 10 | # Read-Only variables: 11 | # ARGP_FOUND - system has ARGP 12 | # ARGP_INCLUDE_DIR - the ARGP include directory 13 | # ARGP_LIBRARIES - Link these to use ARGP 14 | # ARGP_DEFINITIONS - Compiler switches required for using ARGP 15 | # 16 | #============================================================================= 17 | # Copyright (c) 2011-2016 Andreas Schneider 18 | # 19 | # Distributed under the OSI-approved BSD License (the "License"); 20 | # see accompanying file Copyright.txt for details. 21 | # 22 | # This software is distributed WITHOUT ANY WARRANTY; without even the 23 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 24 | # See the License for more information. 25 | #============================================================================= 26 | # 27 | 28 | set(_ARGP_ROOT_HINTS 29 | ) 30 | 31 | set(_ARGP_ROOT_PATHS 32 | "$ENV{PROGRAMFILES}/argp" 33 | ) 34 | 35 | find_path(ARGP_ROOT_DIR 36 | NAMES 37 | include/argp.h 38 | HINTS 39 | ${_ARGP_ROOT_HINTS} 40 | PATHS 41 | ${_ARGP_ROOT_PATHS} 42 | ) 43 | mark_as_advanced(ARGP_ROOT_DIR) 44 | 45 | find_path(ARGP_INCLUDE_DIR 46 | NAMES 47 | argp.h 48 | PATHS 49 | ${ARGP_ROOT_DIR}/include 50 | ) 51 | 52 | find_library(ARGP_LIBRARY 53 | NAMES 54 | argp 55 | PATHS 56 | ${ARGP_ROOT_DIR}/lib 57 | ) 58 | 59 | if (ARGP_LIBRARY) 60 | set(ARGP_LIBRARIES 61 | ${ARGP_LIBRARIES} 62 | ${ARGP_LIBRARY} 63 | ) 64 | endif (ARGP_LIBRARY) 65 | 66 | include(FindPackageHandleStandardArgs) 67 | find_package_handle_standard_args(Argp DEFAULT_MSG ARGP_LIBRARIES ARGP_INCLUDE_DIR) 68 | 69 | # show the ARGP_INCLUDE_DIR and ARGP_LIBRARIES variables only in the advanced view 70 | mark_as_advanced(ARGP_INCLUDE_DIR ARGP_LIBRARIES) 71 | -------------------------------------------------------------------------------- /cmake/Modules/FindCMocka.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find CMocka 2 | # Once done this will define 3 | # 4 | # CMOCKA_ROOT_DIR - Set this variable to the root installation of CMocka 5 | # 6 | # Read-Only variables: 7 | # CMOCKA_FOUND - system has CMocka 8 | # CMOCKA_INCLUDE_DIR - the CMocka include directory 9 | # CMOCKA_LIBRARIES - Link these to use CMocka 10 | # CMOCKA_DEFINITIONS - Compiler switches required for using CMocka 11 | # 12 | #============================================================================= 13 | # Copyright (c) 2011-2012 Andreas Schneider 14 | # 15 | # Distributed under the OSI-approved BSD License (the "License"); 16 | # see accompanying file Copyright.txt for details. 17 | # 18 | # This software is distributed WITHOUT ANY WARRANTY; without even the 19 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 20 | # See the License for more information. 21 | #============================================================================= 22 | # 23 | 24 | set(_CMOCKA_ROOT_HINTS 25 | ) 26 | 27 | set(_CMOCKA_ROOT_PATHS 28 | "$ENV{PROGRAMFILES}/cmocka" 29 | ) 30 | 31 | find_path(CMOCKA_ROOT_DIR 32 | NAMES 33 | include/cmocka.h 34 | HINTS 35 | ${_CMOCKA_ROOT_HINTS} 36 | PATHS 37 | ${_CMOCKA_ROOT_PATHS} 38 | ) 39 | mark_as_advanced(CMOCKA_ROOT_DIR) 40 | 41 | find_path(CMOCKA_INCLUDE_DIR 42 | NAMES 43 | cmocka.h 44 | PATHS 45 | ${CMOCKA_ROOT_DIR}/include 46 | ) 47 | 48 | find_library(CMOCKA_LIBRARY 49 | NAMES 50 | cmocka 51 | PATHS 52 | ${CMOCKA_ROOT_DIR}/lib 53 | ) 54 | 55 | if (CMOCKA_LIBRARY) 56 | set(CMOCKA_LIBRARIES 57 | ${CMOCKA_LIBRARIES} 58 | ${CMOCKA_LIBRARY} 59 | ) 60 | endif (CMOCKA_LIBRARY) 61 | 62 | include(FindPackageHandleStandardArgs) 63 | find_package_handle_standard_args(CMocka DEFAULT_MSG CMOCKA_LIBRARIES CMOCKA_INCLUDE_DIR) 64 | 65 | # show the CMOCKA_INCLUDE_DIR and CMOCKA_LIBRARIES variables only in the advanced view 66 | mark_as_advanced(CMOCKA_INCLUDE_DIR CMOCKA_LIBRARIES) 67 | -------------------------------------------------------------------------------- /cmake/Modules/FindNSIS.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find NSIS 2 | # Once done this will define 3 | # 4 | # NSIS_ROOT_PATH - Set this variable to the root installation of NSIS 5 | # 6 | # Read-Only variables: 7 | # 8 | # NSIS_FOUND - system has NSIS 9 | # NSIS_MAKE - NSIS creator executable 10 | # 11 | #============================================================================= 12 | # Copyright (c) 2010-2013 Andreas Schneider 13 | # 14 | # Distributed under the OSI-approved BSD License (the "License"); 15 | # see accompanying file Copyright.txt for details. 16 | # 17 | # This software is distributed WITHOUT ANY WARRANTY; without even the 18 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | # See the License for more information. 20 | #============================================================================= 21 | # 22 | 23 | if (WIN32) 24 | set(_x86 "(x86)") 25 | 26 | set(_NSIS_ROOT_PATHS 27 | "$ENV{ProgramFiles}/NSIS" 28 | "$ENV{ProgramFiles${_x86}}/NSIS" 29 | "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\NSIS;Default]") 30 | 31 | find_path(NSIS_ROOT_PATH 32 | NAMES 33 | Include/Library.nsh 34 | PATHS 35 | ${_NSIS_ROOT_PATHS} 36 | ) 37 | mark_as_advanced(NSIS_ROOT_PATH) 38 | endif (WIN32) 39 | 40 | find_program(NSIS_MAKE 41 | NAMES 42 | makensis 43 | PATHS 44 | ${NSIS_ROOT_PATH} 45 | ) 46 | 47 | include(FindPackageHandleStandardArgs) 48 | find_package_handle_standard_args(NSIS DEFAULT_MSG NSIS_MAKE) 49 | 50 | if (NSIS_MAKE) 51 | set(NSIS_FOUND TRUE) 52 | endif (NSIS_MAKE) 53 | 54 | mark_as_advanced(NSIS_MAKE) 55 | -------------------------------------------------------------------------------- /cmake/Modules/FindNaCl.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find NaCl 2 | # Once done this will define 3 | # 4 | # NACL_FOUND - system has NaCl 5 | # NACL_INCLUDE_DIRS - the NaCl include directory 6 | # NACL_LIBRARIES - Link these to use NaCl 7 | # NACL_DEFINITIONS - Compiler switches required for using NaCl 8 | # 9 | # Copyright (c) 2010 Andreas Schneider 10 | # Copyright (c) 2013 Aris Adamantiadis 11 | # 12 | # Redistribution and use is allowed according to the terms of the New 13 | # BSD license. 14 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 15 | # 16 | 17 | 18 | if (NACL_LIBRARIES AND NACL_INCLUDE_DIRS) 19 | # in cache already 20 | set(NACL_FOUND TRUE) 21 | else (NACL_LIBRARIES AND NACL_INCLUDE_DIRS) 22 | 23 | find_path(NACL_INCLUDE_DIR 24 | NAMES 25 | nacl/crypto_box_curve25519xsalsa20poly1305.h 26 | PATHS 27 | /usr/include 28 | /usr/local/include 29 | /opt/local/include 30 | /sw/include 31 | ) 32 | 33 | find_library(NACL_LIBRARY 34 | NAMES 35 | nacl 36 | PATHS 37 | /usr/lib 38 | /usr/local/lib 39 | /opt/local/lib 40 | /sw/lib 41 | ) 42 | 43 | set(NACL_INCLUDE_DIRS 44 | ${NACL_INCLUDE_DIR} 45 | ) 46 | 47 | if (NACL_LIBRARY) 48 | set(NACL_LIBRARIES 49 | ${NACL_LIBRARIES} 50 | ${NACL_LIBRARY} 51 | ) 52 | endif (NACL_LIBRARY) 53 | 54 | include(FindPackageHandleStandardArgs) 55 | find_package_handle_standard_args(NaCl DEFAULT_MSG NACL_LIBRARIES NACL_INCLUDE_DIRS) 56 | 57 | # show the NACL_INCLUDE_DIRS and NACL_LIBRARIES variables only in the advanced view 58 | mark_as_advanced(NACL_INCLUDE_DIRS NACL_LIBRARIES) 59 | 60 | endif (NACL_LIBRARIES AND NACL_INCLUDE_DIRS) 61 | 62 | -------------------------------------------------------------------------------- /cmake/Modules/Findsofthsm.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find softhsm 2 | # Once done this will define 3 | # 4 | # SOFTHSM_FOUND - system has softhsm 5 | # SOFTHSM_LIBRARIES - Link these to use softhsm 6 | # 7 | #============================================================================= 8 | # Copyright (c) 2019 Sahana Prasad 9 | # 10 | # Distributed under the OSI-approved BSD License (the "License"); 11 | # see accompanying file Copyright.txt for details. 12 | # 13 | # This software is distributed WITHOUT ANY WARRANTY; without even the 14 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 | # See the License for more information. 16 | #============================================================================= 17 | # 18 | 19 | 20 | find_library(SOFTHSM2_LIBRARY 21 | NAMES 22 | softhsm2 23 | ) 24 | 25 | if (SOFTHSM2_LIBRARY) 26 | set(SOFTHSM_LIBRARIES 27 | ${SOFTHSM_LIBRARIES} 28 | ${SOFTHSM2_LIBRARY} 29 | ) 30 | endif (SOFTHSM2_LIBRARY) 31 | 32 | include(FindPackageHandleStandardArgs) 33 | find_package_handle_standard_args(softhsm DEFAULT_MSG SOFTHSM_LIBRARIES) 34 | 35 | # show the SOFTHSM_INCLUDE_DIR and SOFTHSM_LIBRARIES variables only in the advanced view 36 | mark_as_advanced(SOFTHSM_LIBRARIES) 37 | -------------------------------------------------------------------------------- /cmake/Modules/GetFilesList.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2018 Anderson Toshiyuki Sasaki 3 | # 4 | # Redistribution and use is allowed according to the terms of the New 5 | # BSD license. 6 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 7 | # 8 | 9 | #.rst: 10 | # GetFilesList 11 | # ------------ 12 | # 13 | # This is a helper script for FindABImap.cmake. 14 | # 15 | # Search in the provided directories for files matching the provided pattern. 16 | # The list of files is then written to the output file. 17 | # 18 | # Expected defined variables 19 | # -------------------------- 20 | # 21 | # ``DIRECTORIES``: 22 | # Required, expects a list of directories paths. 23 | # 24 | # ``FILES_PATTERNS``: 25 | # Required, expects a list of patterns to be used to search files 26 | # 27 | # ``OUTPUT_PATH``: 28 | # Required, expects the output file path. 29 | 30 | if (NOT DEFINED DIRECTORIES) 31 | message(SEND_ERROR "DIRECTORIES not defined") 32 | endif() 33 | 34 | if (NOT DEFINED FILES_PATTERNS) 35 | message(SEND_ERROR "FILES_PATTERNS not defined") 36 | endif() 37 | 38 | if (NOT DEFINED OUTPUT_PATH) 39 | message(SEND_ERROR "OUTPUT_PATH not defined") 40 | endif() 41 | 42 | string(REPLACE " " ";" DIRECTORIES_LIST "${DIRECTORIES}") 43 | string(REPLACE " " ";" FILES_PATTERNS_LIST "${FILES_PATTERNS}") 44 | 45 | # Create the list of expressions for the files 46 | set(glob_expressions) 47 | foreach(dir ${DIRECTORIES_LIST}) 48 | foreach(exp ${FILES_PATTERNS_LIST}) 49 | list(APPEND glob_expressions 50 | "${dir}/${exp}" 51 | ) 52 | endforeach() 53 | endforeach() 54 | 55 | # Create the list of files 56 | file(GLOB files ${glob_expressions}) 57 | 58 | # Write to the output 59 | file(WRITE ${OUTPUT_PATH} "${files}") 60 | -------------------------------------------------------------------------------- /cmake/Modules/MacroEnsureOutOfSourceBuild.cmake: -------------------------------------------------------------------------------- 1 | # - MACRO_ENSURE_OUT_OF_SOURCE_BUILD() 2 | # MACRO_ENSURE_OUT_OF_SOURCE_BUILD() 3 | 4 | # Copyright (c) 2006, Alexander Neundorf, 5 | # 6 | # Redistribution and use is allowed according to the terms of the BSD license. 7 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 8 | 9 | macro (MACRO_ENSURE_OUT_OF_SOURCE_BUILD _errorMessage) 10 | 11 | string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" _insource) 12 | if (_insource) 13 | message(SEND_ERROR "${_errorMessage}") 14 | message(FATAL_ERROR "Remove the file CMakeCache.txt in ${CMAKE_SOURCE_DIR} first.") 15 | endif (_insource) 16 | 17 | endmacro (MACRO_ENSURE_OUT_OF_SOURCE_BUILD) 18 | -------------------------------------------------------------------------------- /cmake/Toolchain-cross-m32.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_C_FLAGS "-m32" CACHE STRING "C compiler flags" FORCE) 2 | set(CMAKE_CXX_FLAGS "-m32" CACHE STRING "C++ compiler flags" FORCE) 3 | 4 | set(LIB32 /usr/lib) # Fedora 5 | 6 | if(EXISTS /usr/lib32) 7 | set(LIB32 /usr/lib32) # Arch, Solus 8 | endif() 9 | 10 | set(CMAKE_SYSTEM_LIBRARY_PATH ${LIB32} CACHE STRING "system library search path" FORCE) 11 | set(CMAKE_LIBRARY_PATH ${LIB32} CACHE STRING "library search path" FORCE) 12 | 13 | # this is probably unlikely to be needed, but just in case 14 | set(CMAKE_EXE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "executable linker flags" FORCE) 15 | set(CMAKE_SHARED_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "shared library linker flags" FORCE) 16 | set(CMAKE_MODULE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "module linker flags" FORCE) 17 | 18 | # on Fedora and Arch and similar, point pkgconfig at 32 bit .pc files. We have 19 | # to include the regular system .pc files as well (at the end), because some 20 | # are not always present in the 32 bit directory 21 | if(EXISTS ${LIB32}/pkgconfig) 22 | set(ENV{PKG_CONFIG_LIBDIR} ${LIB32}/pkgconfig:/usr/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib64/pkgconfig) 23 | endiF() 24 | -------------------------------------------------------------------------------- /doc/README.gitlab.freebsd.md: -------------------------------------------------------------------------------- 1 | # Install a FreeBSD CI instance 2 | 3 | Install the following packages: 4 | 5 | ``` 6 | pkg install -y bash git gmake cmake cmocka openssl wget pkgconf ccache bash 7 | ``` 8 | 9 | Create gitlab-runner user: 10 | 11 | ``` 12 | pw group add -n gitlab-runner 13 | pw user add -n gitlab-runner -g gitlab-runner -s /usr/local/bin/bash 14 | mkdir /home/gitlab-runner 15 | chown gitlab-runner:gitlab-runner /home/gitlab-runner 16 | ``` 17 | 18 | Get the gitlab-runner binary for freebsd: 19 | 20 | ``` 21 | wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-freebsd-amd64 22 | chmod +x /usr/local/bin/gitlab-runner 23 | ``` 24 | 25 | Create a log file and allow access: 26 | 27 | ``` 28 | touch /var/log/gitlab_runner.log && chown gitlab-runner:gitlab-runner /var/log/gitlab_runner.log 29 | ``` 30 | 31 | We need a start script to run it on boot: 32 | 33 | ``` 34 | mkdir -p /usr/local/etc/rc.d 35 | cat > /usr/local/etc/rc.d/gitlab_runner << EOF 36 | #!/usr/local/bin/bash 37 | # PROVIDE: gitlab_runner 38 | # REQUIRE: DAEMON NETWORKING 39 | # BEFORE: 40 | # KEYWORD: 41 | 42 | . /etc/rc.subr 43 | 44 | name="gitlab_runner" 45 | rcvar="gitlab_runner_enable" 46 | 47 | load_rc_config $name 48 | 49 | user="gitlab-runner" 50 | user_home="/home/gitlab-runner" 51 | command="/usr/local/bin/gitlab-runner run" 52 | pidfile="/var/run/${name}.pid" 53 | 54 | start_cmd="gitlab_runner_start" 55 | stop_cmd="gitlab_runner_stop" 56 | status_cmd="gitlab_runner_status" 57 | 58 | gitlab_runner_start() 59 | { 60 | export USER=${user} 61 | export HOME=${user_home} 62 | 63 | if checkyesno ${rcvar}; then 64 | cd ${user_home} 65 | /usr/sbin/daemon -u ${user} -p ${pidfile} ${command} > /var/log/gitlab_runner.log 2>&1 66 | fi 67 | } 68 | 69 | gitlab_runner_stop() 70 | { 71 | if [ -f ${pidfile} ]; then 72 | kill `cat ${pidfile}` 73 | fi 74 | } 75 | 76 | gitlab_runner_status() 77 | { 78 | if [ ! -f ${pidfile} ] || kill -0 `cat ${pidfile}`; then 79 | echo "Service ${name} is not running." 80 | else 81 | echo "${name} appears to be running." 82 | fi 83 | } 84 | 85 | run_rc_command $1 86 | EOF 87 | chmod +x /usr/local/etc/rc.d/gitlab_runner 88 | ``` 89 | 90 | Register your gitlab-runner with your gitlab project 91 | 92 | ``` 93 | su gitlab-runner -c 'gitlab-runner register' 94 | ``` 95 | 96 | Start the gitlab runner service: 97 | 98 | ``` 99 | sysrc -f /etc/rc.conf "gitlab_runner_enable=YES" 100 | service gitlab_runner start 101 | ``` 102 | -------------------------------------------------------------------------------- /doc/doc_coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################################################ 3 | # .doc_coverage.sh # 4 | # Script to detect overall documentation coverage of libssh. The script uses # 5 | # doxygen to generate the documentation then parses it's output. # 6 | # # 7 | # maintainer: Norbert Pocs # 8 | ################################################################################ 9 | BUILD_DIR="$1" 10 | DOXYFILE_PATH="$BUILD_DIR/doc/Doxyfile.docs" 11 | INDEX_XML_PATH="$BUILD_DIR/doc/xml/index.xml" 12 | # filters 13 | F_EXCLUDE_FILES=' wrapper.h legacy.h crypto.h priv.h chacha.h curve25519.h ' 14 | F_UNDOC_FUNC='(function).*is not documented' 15 | F_FUNC='kind="function"' 16 | F_HEADERS='libssh_8h_|group__libssh__' 17 | F_CUT_BEFORE='.*' 18 | F_CUT_AFTER='<\/name><\/member>' 19 | # Doxygen options 20 | O_QUIET='QUIET=YES' 21 | O_GEN_XML='GENERATE_XML=YES' 22 | 23 | # check if build dir given 24 | if [ $# -eq 0 ]; then 25 | echo "Please provide the build directory e.g.: ./build" 26 | exit 255 27 | fi 28 | 29 | # modify doxyfile to our needs: 30 | # QUIET - less output 31 | # GENERATE_XML - xml needed to inspect all the functions 32 | # (note: the options are needed to be on separate lines) 33 | # We want to exclude irrelevant files 34 | MOD_DOXYFILE=$(cat "$DOXYFILE_PATH"; echo "$O_QUIET"; echo "$O_GEN_XML") 35 | MOD_DOXYFILE=${MOD_DOXYFILE//EXCLUDE_PATTERNS.*=/EXCLUDE_PATTERNS=$F_EXCLUDE_FILES/g} 36 | 37 | # call doxygen to get the warning messages 38 | # and also generate the xml for inspection 39 | DOXY_WARNINGS=$(echo "$MOD_DOXYFILE" | doxygen - 2>&1) 40 | 41 | # get the number of undocumented functions 42 | UNDOC_FUNC=$(echo "$DOXY_WARNINGS" | grep -cE "$F_UNDOC_FUNC") 43 | 44 | # filter out the lines consisting of functions of our interest 45 | FUNC_LINES=$(grep "$F_FUNC" "$INDEX_XML_PATH" | grep -E "$F_HEADERS") 46 | # cut the irrelevant information and leave just the function names 47 | ALL_FUNC=$(echo "$FUNC_LINES" | sed -e "s/$F_CUT_BEFORE//g" -e "s/$F_CUT_AFTER//") 48 | # remove duplicates and get the number of functions 49 | ALL_FUNC=$(echo "$ALL_FUNC" | sort - | uniq | wc -l) 50 | 51 | # percentage of the documented functions 52 | awk "BEGIN {printf \"Documentation coverage is %.2f%\n\", 100 - (${UNDOC_FUNC}/${ALL_FUNC}*100)}" 53 | -------------------------------------------------------------------------------- /doc/introduction.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @page libssh_tutorial The Tutorial 3 | @section introduction Introduction 4 | 5 | libssh is a C library that enables you to write a program that uses the 6 | SSH protocol. With it, you can remotely execute programs, transfer 7 | files, or use a secure and transparent tunnel for your remote programs. 8 | The SSH protocol is encrypted, ensures data integrity, and provides strong 9 | means of authenticating both the server of the client. The library hides 10 | a lot of technical details from the SSH protocol, but this does not 11 | mean that you should not try to know about and understand these details. 12 | 13 | libssh is a Free Software / Open Source project. The libssh library 14 | is distributed under LGPL license. The libssh project has nothing to do with 15 | "libssh2", which is a completely different and independent project. 16 | 17 | libssh can run on top of either libcrypto, mbedtls or libgcrypt (deprecated) 18 | general-purpose cryptographic libraries. 19 | 20 | This tutorial concentrates for its main part on the "client" side of libssh. 21 | To learn how to accept incoming SSH connections (how to write a SSH server), 22 | you'll have to jump to the end of this document. 23 | 24 | This tutorial describes libssh version 0.5.0. This version is a little different 25 | from the 0.4.X series. However, the examples should work with 26 | little changes on versions like 0.4.2 and later. 27 | 28 | 29 | Table of contents: 30 | 31 | @subpage libssh_tutor_guided_tour 32 | 33 | @subpage libssh_tutor_authentication 34 | 35 | @subpage libssh_tutor_shell 36 | 37 | @subpage libssh_tutor_command 38 | 39 | @subpage libssh_tutor_sftp 40 | 41 | @subpage libssh_tutor_scp 42 | 43 | @subpage libssh_tutor_forwarding 44 | 45 | @subpage libssh_tutor_threads 46 | 47 | @subpage libssh_tutor_pkcs11 48 | 49 | @subpage libssh_tutor_sftp_aio 50 | 51 | @subpage libssh_tutor_todo 52 | 53 | */ 54 | -------------------------------------------------------------------------------- /doc/linking.dox: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | @page libssh_linking The Linking HowTo 4 | 5 | @section dynamic Dynamic Linking 6 | 7 | On UNIX and Windows systems its the same, you need at least the libssh.h 8 | header file and the libssh shared library. 9 | 10 | @section static Static Linking 11 | 12 | @warning The libssh library is licensed under the LGPL! Make sure you 13 | understand what this means to your codebase if you want to distribute 14 | binaries and link statically against LGPL code! 15 | 16 | On UNIX systems linking against the static version of the library is the 17 | same as linking against the shared library. Both have the same name. Some 18 | build system require to use the full path to the static library. 19 | 20 | To be able to compile the application you're developing you need to either pass 21 | LIBSSH_STATIC as a define in the compiler command line or define it before you 22 | include libssh.h. This is required cause the dynamic library needs to specify 23 | the dllimport attribute. 24 | 25 | @code 26 | #define LIBSSH_STATIC 1 27 | #include 28 | @endcode 29 | 30 | If you're are statically linking with OpenSSL, read the "Linking your 31 | application" section in the NOTES.[OS] in the OpenSSL source tree! 32 | 33 | */ 34 | -------------------------------------------------------------------------------- /doc/tbd.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @page libssh_tutor_todo To be done 3 | 4 | *** To be written *** 5 | 6 | @section sshd Writing a libssh-based server 7 | 8 | *** To be written *** 9 | 10 | @section cpp The libssh C++ wrapper 11 | 12 | *** To be written *** 13 | 14 | */ 15 | -------------------------------------------------------------------------------- /doc/that_style/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jan-Lukas Wynen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /doc/that_style/README.md: -------------------------------------------------------------------------------- 1 | # that style 2 | A plain, more modern HTML style for Doxygen 3 | 4 | ## Requirements 5 | - Doxygen (tested with version 1.8.13) 6 | - *optional*: a sass/scss compiler if you want to modify the style 7 | 8 | ## Simple usage 9 | Tell Doxygen about the files for that style as shown in [doxyfile.conf](doxyfile.conf). You might need to adjust the 10 | paths depending on where you installed that style. 11 | When you run Doxygen, all files are copied into to generated HTML folder. So you don't need to keep the originals around 12 | unless you want to re-generate the documentation. 13 | 14 | ## Advanced 15 | that style uses a custom javascript to hack some nice stripes into some tables. It has to be loaded from HTML. Hence you need 16 | to use the provided custom header. Since its default content may change when Doxygen is updated, there might be syntax error in 17 | the generated HTML. If this is the case, you can remove the custom header (adjust your doxyfile.conf). This has no 18 | disadvantages other than removing the stripes. 19 | 20 | [that_style.css](that_style.css) was generated from the scss files in the folder [sass](sass). If you want to change the style, 21 | use those files in order to have better control. For instance, you can easily change most colors by modifying the variables 22 | in the beginning of [that_style.scss](sass/that_style.scss). 23 | -------------------------------------------------------------------------------- /doc/that_style/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $projectname: $title 9 | $title 10 | 11 | 12 | 13 | $treeview 14 | $search 15 | $mathjax 16 | 17 | 18 | $extrastylesheet 19 | 20 | 21 |
22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 38 | 39 | 40 | 41 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
33 |
$projectname 34 |  $projectnumber 35 |
36 |
$projectbrief
37 |
42 |
$projectbrief
43 |
$searchbox
54 |
55 | 56 | 57 | -------------------------------------------------------------------------------- /doc/that_style/img/sync_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/libssh/a2e4e969cf160789abaf0100e85b1a6c342d5d7e/doc/that_style/img/sync_off.png -------------------------------------------------------------------------------- /doc/that_style/img/sync_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/libssh/a2e4e969cf160789abaf0100e85b1a6c342d5d7e/doc/that_style/img/sync_on.png -------------------------------------------------------------------------------- /doc/that_style/js/striped_bg.js: -------------------------------------------------------------------------------- 1 | // Adds extra CSS classes "even" and "odd" to .memberdecls to allow 2 | // striped backgrounds. 3 | function MemberDeclsStriper () { 4 | var counter = 0; 5 | 6 | this.stripe = function() { 7 | $(".memberdecls tbody").children().each(function(i) { 8 | 9 | // reset counter at every heading -> always start with even 10 | if ($(this).is(".heading")) { 11 | counter = 0; 12 | } 13 | 14 | // add extra classes 15 | if (counter % 2 == 1) { 16 | $(this).addClass("odd"); 17 | } 18 | else { 19 | $(this).addClass("even"); 20 | } 21 | 22 | // advance counter at every separator 23 | // this is the only way to reliably detect which table rows belong together 24 | if ($(this).is('[class^="separator"]')) { 25 | counter++; 26 | } 27 | }); 28 | } 29 | } 30 | 31 | // execute the function 32 | $(document).ready(new MemberDeclsStriper().stripe); 33 | -------------------------------------------------------------------------------- /doc/threading.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @page libssh_tutor_threads Chapter 8: Threads with libssh 3 | @section threads_with_libssh How to use libssh with threads 4 | 5 | libssh may be used in multithreaded applications, but under several conditions : 6 | - Your system must support libpthread or, in Windows environment, 7 | CriticalSection based mutex control. 8 | - Since version 0.8.0, threads initialization is called automatically in the 9 | library constructor if libssh is dynamically linked. This means it is no 10 | longer necessary to call ssh_init()/ssh_finalize(). 11 | - If libssh is statically linked, threading must be initialized by calling 12 | ssh_init() before using any of libssh provided functions. This initialization 13 | must be done outside of any threading context. Don't forget to call 14 | ssh_finalize() to avoid memory leak 15 | - At all times, you may use different sessions inside threads, make parallel 16 | connections, read/write on different sessions and so on. You *cannot* use a 17 | single session (or channels for a single session) in several threads at the same 18 | time. This will most likely lead to internal state corruption. This limitation is 19 | being worked out and will maybe disappear later. 20 | 21 | @subsection threads_init Initialization of threads 22 | 23 | Since version 0.8.0, it is no longer necessary to call ssh_init()/ssh_finalize() 24 | if libssh is dynamically linked. 25 | 26 | If libssh is statically linked, call ssh_init() before using any of libssh 27 | provided functions. 28 | 29 | @subsection threads_pthread Using libpthread with libssh 30 | 31 | Since version 0.8.0, libpthread is the default threads library used by libssh. 32 | 33 | To use libpthread, simply link it to you application. 34 | 35 | If you are using libssh statically linked, don't forget to call ssh_init() 36 | before using any of libssh provided functions (and ssh_finalize() in the end). 37 | 38 | @subsection threads_other Using another threading library 39 | 40 | Since version 0.8.0, libssh does not support custom threading libraries. 41 | The change makes sense since the newer versions for libcrypto (OpenSSL) and 42 | libgcrypt don't support custom threading libraries. 43 | 44 | The default used threading library is libpthread. 45 | Alternatively, in Windows environment, CriticalSection based mutex control can 46 | be used. 47 | 48 | If your system does not support libpthread nor CriticalSection based mutex 49 | control, unfortunately, you cannot use libssh in multithreaded scenarios. 50 | 51 | Good luck ! 52 | */ 53 | -------------------------------------------------------------------------------- /examples/connect_ssh.c: -------------------------------------------------------------------------------- 1 | /* 2 | * connect_ssh.c 3 | * This file contains an example of how to connect to a 4 | * SSH server using libssh 5 | */ 6 | 7 | /* 8 | Copyright 2009 Aris Adamantiadis 9 | 10 | This file is part of the SSH Library 11 | 12 | You are free to copy this file, modify it in any way, consider it being public 13 | domain. This does not apply to the rest of the library though, but it is 14 | allowed to cut-and-paste working code from this file to any license of 15 | program. 16 | The goal is to show the API in action. It's not a reference on how terminal 17 | clients must be made or how a client should react. 18 | */ 19 | 20 | #include 21 | #include "examples_common.h" 22 | #include 23 | 24 | ssh_session connect_ssh(const char *host, const char *user,int verbosity){ 25 | ssh_session session; 26 | int auth=0; 27 | 28 | session=ssh_new(); 29 | if (session == NULL) { 30 | return NULL; 31 | } 32 | 33 | if(user != NULL){ 34 | if (ssh_options_set(session, SSH_OPTIONS_USER, user) < 0) { 35 | ssh_free(session); 36 | return NULL; 37 | } 38 | } 39 | 40 | if (ssh_options_set(session, SSH_OPTIONS_HOST, host) < 0) { 41 | ssh_free(session); 42 | return NULL; 43 | } 44 | ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity); 45 | if(ssh_connect(session)){ 46 | fprintf(stderr,"Connection failed : %s\n",ssh_get_error(session)); 47 | ssh_disconnect(session); 48 | ssh_free(session); 49 | return NULL; 50 | } 51 | if(verify_knownhost(session)<0){ 52 | ssh_disconnect(session); 53 | ssh_free(session); 54 | return NULL; 55 | } 56 | auth=authenticate_console(session); 57 | if(auth==SSH_AUTH_SUCCESS){ 58 | return session; 59 | } else if(auth==SSH_AUTH_DENIED){ 60 | fprintf(stderr,"Authentication failed\n"); 61 | } else { 62 | fprintf(stderr,"Error while authenticating : %s\n",ssh_get_error(session)); 63 | } 64 | ssh_disconnect(session); 65 | ssh_free(session); 66 | return NULL; 67 | } 68 | -------------------------------------------------------------------------------- /examples/examples_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2009 Aris Adamantiadis 3 | 4 | This file is part of the SSH Library 5 | 6 | You are free to copy this file, modify it in any way, consider it being public 7 | domain. This does not apply to the rest of the library though, but it is 8 | allowed to cut-and-paste working code from this file to any license of 9 | program. 10 | The goal is to show the API in action. It's not a reference on how terminal 11 | clients must be made or how a client should react. 12 | */ 13 | #ifndef EXAMPLES_COMMON_H_ 14 | #define EXAMPLES_COMMON_H_ 15 | 16 | #include 17 | 18 | /** Zero a structure */ 19 | #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) 20 | 21 | int authenticate_console(ssh_session session); 22 | int authenticate_kbdint(ssh_session session, const char *password); 23 | int verify_knownhost(ssh_session session); 24 | ssh_session connect_ssh(const char *hostname, const char *user, int verbosity); 25 | 26 | #endif /* EXAMPLES_COMMON_H_ */ 27 | -------------------------------------------------------------------------------- /examples/exec.c: -------------------------------------------------------------------------------- 1 | /* simple exec example */ 2 | #include 3 | 4 | #include 5 | #include "examples_common.h" 6 | 7 | int main(void) { 8 | ssh_session session; 9 | ssh_channel channel; 10 | char buffer[256]; 11 | int rbytes, wbytes, total = 0; 12 | int rc; 13 | 14 | session = connect_ssh("localhost", NULL, 0); 15 | if (session == NULL) { 16 | ssh_finalize(); 17 | return 1; 18 | } 19 | 20 | channel = ssh_channel_new(session); 21 | if (channel == NULL) { 22 | ssh_disconnect(session); 23 | ssh_free(session); 24 | ssh_finalize(); 25 | return 1; 26 | } 27 | 28 | rc = ssh_channel_open_session(channel); 29 | if (rc < 0) { 30 | goto failed; 31 | } 32 | 33 | rc = ssh_channel_request_exec(channel, "lsof"); 34 | if (rc < 0) { 35 | goto failed; 36 | } 37 | 38 | rbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0); 39 | if (rbytes <= 0) { 40 | goto failed; 41 | } 42 | 43 | do { 44 | wbytes = fwrite(buffer + total, 1, rbytes, stdout); 45 | if (wbytes <= 0) { 46 | goto failed; 47 | } 48 | 49 | total += wbytes; 50 | 51 | /* When it was not possible to write the whole buffer to stdout */ 52 | if (wbytes < rbytes) { 53 | rbytes -= wbytes; 54 | continue; 55 | } 56 | 57 | rbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0); 58 | total = 0; 59 | } while (rbytes > 0); 60 | 61 | if (rbytes < 0) { 62 | goto failed; 63 | } 64 | 65 | ssh_channel_send_eof(channel); 66 | ssh_channel_close(channel); 67 | ssh_channel_free(channel); 68 | ssh_disconnect(session); 69 | ssh_free(session); 70 | ssh_finalize(); 71 | 72 | return 0; 73 | failed: 74 | ssh_channel_close(channel); 75 | ssh_channel_free(channel); 76 | ssh_disconnect(session); 77 | ssh_free(session); 78 | ssh_finalize(); 79 | 80 | return 1; 81 | } 82 | -------------------------------------------------------------------------------- /examples/keygen.c: -------------------------------------------------------------------------------- 1 | /* keygen.c 2 | * Sample implementation of ssh-keygen using libssh 3 | */ 4 | 5 | /* 6 | Copyright 2019 Red Hat, Inc. 7 | 8 | Author: Jakub Jelen 9 | 10 | This file is part of the SSH Library 11 | 12 | You are free to copy this file, modify it in any way, consider it being public 13 | domain. This does not apply to the rest of the library though, but it is 14 | allowed to cut-and-paste working code from this file to any license of 15 | program. 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | int main(void) 22 | { 23 | ssh_key key = NULL; 24 | int rv; 25 | 26 | /* Generate a new ED25519 private key file */ 27 | rv = ssh_pki_generate(SSH_KEYTYPE_ED25519, 0, &key); 28 | if (rv != SSH_OK) { 29 | fprintf(stderr, "Failed to generate private key"); 30 | return -1; 31 | } 32 | 33 | /* Write it to a file testkey in the current directory */ 34 | rv = ssh_pki_export_privkey_file(key, NULL, NULL, NULL, "testkey"); 35 | if (rv != SSH_OK) { 36 | fprintf(stderr, "Failed to write private key file"); 37 | return -1; 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /examples/libsshpp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2010 Aris Adamantiadis 3 | 4 | This file is part of the SSH Library 5 | 6 | You are free to copy this file, modify it in any way, consider it being public 7 | domain. This does not apply to the rest of the library though, but it is 8 | allowed to cut-and-paste working code from this file to any license of 9 | program. 10 | */ 11 | 12 | /* This file demonstrates the use of the C++ wrapper to libssh */ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | int main(int argc, const char **argv){ 19 | ssh::Session session; 20 | try { 21 | if(argc>1) 22 | session.setOption(SSH_OPTIONS_HOST,argv[1]); 23 | else 24 | session.setOption(SSH_OPTIONS_HOST,"localhost"); 25 | session.connect(); 26 | session.userauthPublickeyAuto(); 27 | session.disconnect(); 28 | } catch (ssh::SshException e){ 29 | std::cout << "Error during connection : "; 30 | std::cout << e.getError() << std::endl; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /examples/libsshpp_noexcept.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2010 Aris Adamantiadis 3 | 4 | This file is part of the SSH Library 5 | 6 | You are free to copy this file, modify it in any way, consider it being public 7 | domain. This does not apply to the rest of the library though, but it is 8 | allowed to cut-and-paste working code from this file to any license of 9 | program. 10 | */ 11 | 12 | /* This file demonstrates the use of the C++ wrapper to libssh 13 | * specifically, without C++ exceptions 14 | */ 15 | 16 | #include 17 | #define SSH_NO_CPP_EXCEPTIONS 18 | #include 19 | 20 | int main(int argc, const char **argv){ 21 | ssh::Session session,s2; 22 | int err; 23 | if(argc>1) 24 | err=session.setOption(SSH_OPTIONS_HOST,argv[1]); 25 | else 26 | err=session.setOption(SSH_OPTIONS_HOST,"localhost"); 27 | if(err==SSH_ERROR) 28 | goto error; 29 | err=session.connect(); 30 | if(err==SSH_ERROR) 31 | goto error; 32 | err=session.userauthPublickeyAuto(); 33 | if(err==SSH_ERROR) 34 | goto error; 35 | 36 | return 0; 37 | error: 38 | std::cout << "Error during connection : "; 39 | std::cout << session.getError() << std::endl; 40 | return 1; 41 | } 42 | -------------------------------------------------------------------------------- /examples/senddata.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include "examples_common.h" 5 | 6 | #define LIMIT 0x100000000UL 7 | 8 | int main(void) { 9 | ssh_session session; 10 | ssh_channel channel; 11 | char buffer[1024*1024]; 12 | int rc; 13 | uint64_t total=0; 14 | uint64_t lastshown=4096; 15 | session = connect_ssh("localhost", NULL, 0); 16 | if (session == NULL) { 17 | return 1; 18 | } 19 | 20 | channel = ssh_channel_new(session); 21 | if (channel == NULL) { 22 | ssh_disconnect(session); 23 | return 1; 24 | } 25 | 26 | rc = ssh_channel_open_session(channel); 27 | if (rc < 0) { 28 | ssh_channel_close(channel); 29 | ssh_disconnect(session); 30 | return 1; 31 | } 32 | 33 | rc = ssh_channel_request_exec(channel, "cat > /dev/null"); 34 | if (rc < 0) { 35 | ssh_channel_close(channel); 36 | ssh_disconnect(session); 37 | return 1; 38 | } 39 | 40 | 41 | while ((rc = ssh_channel_write(channel, buffer, sizeof(buffer))) > 0) { 42 | total += rc; 43 | if(total/2 >= lastshown){ 44 | printf("written %llx\n", (long long unsigned int) total); 45 | lastshown=total; 46 | } 47 | if(total > LIMIT) 48 | break; 49 | } 50 | 51 | if (rc < 0) { 52 | printf("error : %s\n",ssh_get_error(session)); 53 | ssh_channel_close(channel); 54 | ssh_disconnect(session); 55 | return 1; 56 | } 57 | 58 | ssh_channel_send_eof(channel); 59 | ssh_channel_close(channel); 60 | 61 | ssh_disconnect(session); 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(libssh-headers-x C) 2 | 3 | add_subdirectory(libssh) 4 | -------------------------------------------------------------------------------- /include/libssh/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(libssh-headers C) 2 | 3 | set(libssh_HDRS 4 | callbacks.h 5 | libssh.h 6 | ssh2.h 7 | legacy.h 8 | libsshpp.hpp 9 | ) 10 | 11 | if (WITH_SFTP) 12 | set(libssh_HDRS 13 | ${libssh_HDRS} 14 | sftp.h 15 | ) 16 | endif (WITH_SFTP) 17 | 18 | if (WITH_SERVER) 19 | set(libssh_HDRS 20 | ${libssh_HDRS} 21 | server.h 22 | ) 23 | 24 | if (WITH_SFTP) 25 | set(libssh_HDRS 26 | ${libssh_HDRS} 27 | sftpserver.h 28 | ) 29 | endif (WITH_SFTP) 30 | endif (WITH_SERVER) 31 | 32 | install( 33 | FILES 34 | ${libssh_HDRS} 35 | DESTINATION 36 | ${CMAKE_INSTALL_INCLUDEDIR}/${APPLICATION_NAME} 37 | COMPONENT 38 | headers 39 | ) 40 | 41 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libssh_version.h.cmake 42 | ${libssh_BINARY_DIR}/include/libssh/libssh_version.h 43 | @ONLY) 44 | install(FILES ${libssh_BINARY_DIR}/include/libssh/libssh_version.h 45 | DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${APPLICATION_NAME} 46 | COMPONENT headers) 47 | -------------------------------------------------------------------------------- /include/libssh/bignum.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2014 by Aris Adamantiadis 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef BIGNUM_H_ 22 | #define BIGNUM_H_ 23 | 24 | #include "libssh/libcrypto.h" 25 | #include "libssh/libgcrypt.h" 26 | #include "libssh/libmbedcrypto.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | bignum ssh_make_string_bn(ssh_string string); 33 | ssh_string ssh_make_bignum_string(bignum num); 34 | void ssh_print_bignum(const char *which, const_bignum num); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif /* BIGNUM_H_ */ 41 | -------------------------------------------------------------------------------- /include/libssh/bind.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2010 by Aris Adamantiadis 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef BIND_H_ 22 | #define BIND_H_ 23 | 24 | #include "libssh/priv.h" 25 | #include "libssh/kex.h" 26 | #include "libssh/session.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | struct ssh_bind_struct { 33 | struct ssh_common_struct common; /* stuff common to ssh_bind and ssh_session */ 34 | struct ssh_bind_callbacks_struct *bind_callbacks; 35 | void *bind_callbacks_userdata; 36 | 37 | struct ssh_poll_handle_struct *poll; 38 | /* options */ 39 | char *wanted_methods[SSH_KEX_METHODS]; 40 | char *banner; 41 | char *ecdsakey; 42 | char *rsakey; 43 | char *ed25519key; 44 | ssh_key ecdsa; 45 | ssh_key rsa; 46 | ssh_key ed25519; 47 | char *bindaddr; 48 | socket_t bindfd; 49 | unsigned int bindport; 50 | int blocking; 51 | int toaccept; 52 | bool config_processed; 53 | char *config_dir; 54 | char *pubkey_accepted_key_types; 55 | char* moduli_file; 56 | int rsa_min_size; 57 | }; 58 | 59 | struct ssh_poll_handle_struct *ssh_bind_get_poll(struct ssh_bind_struct 60 | *sshbind); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* BIND_H_ */ 67 | -------------------------------------------------------------------------------- /include/libssh/chacha.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: chacha.h,v 1.3 2014/05/02 03:27:54 djm Exp $ */ 2 | 3 | /* 4 | chacha-merged.c version 20080118 5 | D. J. Bernstein 6 | Public domain. 7 | */ 8 | 9 | #ifndef CHACHA_H 10 | #define CHACHA_H 11 | 12 | struct chacha_ctx { 13 | uint32_t input[16]; 14 | }; 15 | 16 | #define CHACHA_MINKEYLEN 16 17 | #define CHACHA_NONCELEN 8 18 | #define CHACHA_CTRLEN 8 19 | #define CHACHA_STATELEN (CHACHA_NONCELEN+CHACHA_CTRLEN) 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | void chacha_keysetup(struct chacha_ctx *x, const uint8_t *k, uint32_t kbits) 26 | #ifdef HAVE_GCC_BOUNDED_ATTRIBUTE 27 | __attribute__((__bounded__(__minbytes__, 2, CHACHA_MINKEYLEN))) 28 | #endif 29 | ; 30 | void chacha_ivsetup(struct chacha_ctx *x, const uint8_t *iv, const uint8_t *ctr) 31 | #ifdef HAVE_GCC_BOUNDED_ATTRIBUTE 32 | __attribute__((__bounded__(__minbytes__, 2, CHACHA_NONCELEN))) 33 | __attribute__((__bounded__(__minbytes__, 3, CHACHA_CTRLEN))) 34 | #endif 35 | ; 36 | void chacha_encrypt_bytes(struct chacha_ctx *x, const uint8_t *m, 37 | uint8_t *c, uint32_t bytes) 38 | #ifdef HAVE_GCC_BOUNDED_ATTRIBUTE 39 | __attribute__((__bounded__(__buffer__, 2, 4))) 40 | __attribute__((__bounded__(__buffer__, 3, 4))) 41 | #endif 42 | ; 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif /* CHACHA_H */ 49 | -------------------------------------------------------------------------------- /include/libssh/chacha20-poly1305-common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2020 Red Hat, Inc. 5 | * 6 | * Author: Jakub Jelen 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | /* 24 | * chacha20-poly1305.h file 25 | * This file includes definitions needed for Chacha20-poly1305 AEAD cipher 26 | * using different crypto backends. 27 | */ 28 | 29 | #ifndef CHACHA20_POLY1305_H 30 | #define CHACHA20_POLY1305_H 31 | 32 | #define CHACHA20_BLOCKSIZE 64 33 | #define CHACHA20_KEYLEN 32 34 | 35 | #define POLY1305_TAGLEN 16 36 | /* size of the keys k1 and k2 as defined in specs */ 37 | #define POLY1305_KEYLEN 32 38 | 39 | #ifdef _MSC_VER 40 | #pragma pack(push, 1) 41 | #endif 42 | struct ssh_packet_header { 43 | uint32_t length; 44 | uint8_t payload[]; 45 | } 46 | #if defined(__GNUC__) 47 | __attribute__ ((packed)) 48 | #endif 49 | #ifdef _MSC_VER 50 | #pragma pack(pop) 51 | #endif 52 | ; 53 | 54 | #endif /* CHACHA20_POLY1305_H */ 55 | -------------------------------------------------------------------------------- /include/libssh/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h - parse the ssh config file 3 | * 4 | * This file is part of the SSH Library 5 | * 6 | * Copyright (c) 2009-2018 by Andreas Schneider 7 | * 8 | * The SSH Library is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation; either version 2.1 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * The SSH Library is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | * License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with the SSH Library; see the file COPYING. If not, write to 20 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 21 | * MA 02111-1307, USA. 22 | */ 23 | 24 | #ifndef LIBSSH_CONFIG_H_ 25 | #define LIBSSH_CONFIG_H_ 26 | 27 | 28 | enum ssh_config_opcode_e { 29 | /* Unknown opcode */ 30 | SOC_UNKNOWN = -3, 31 | /* Known and not applicable to libssh */ 32 | SOC_NA = -2, 33 | /* Known but not supported by current libssh version */ 34 | SOC_UNSUPPORTED = -1, 35 | SOC_HOST, 36 | SOC_MATCH, 37 | SOC_HOSTNAME, 38 | SOC_PORT, 39 | SOC_USERNAME, 40 | SOC_IDENTITY, 41 | SOC_CIPHERS, 42 | SOC_MACS, 43 | SOC_COMPRESSION, 44 | SOC_TIMEOUT, 45 | SOC_STRICTHOSTKEYCHECK, 46 | SOC_KNOWNHOSTS, 47 | SOC_PROXYCOMMAND, 48 | SOC_PROXYJUMP, 49 | SOC_GSSAPISERVERIDENTITY, 50 | SOC_GSSAPICLIENTIDENTITY, 51 | SOC_GSSAPIDELEGATECREDENTIALS, 52 | SOC_INCLUDE, 53 | SOC_BINDADDRESS, 54 | SOC_GLOBALKNOWNHOSTSFILE, 55 | SOC_LOGLEVEL, 56 | SOC_HOSTKEYALGORITHMS, 57 | SOC_KEXALGORITHMS, 58 | SOC_GSSAPIAUTHENTICATION, 59 | SOC_KBDINTERACTIVEAUTHENTICATION, 60 | SOC_PASSWORDAUTHENTICATION, 61 | SOC_PUBKEYAUTHENTICATION, 62 | SOC_PUBKEYACCEPTEDKEYTYPES, 63 | SOC_REKEYLIMIT, 64 | SOC_IDENTITYAGENT, 65 | SOC_IDENTITIESONLY, 66 | SOC_CONTROLMASTER, 67 | SOC_CONTROLPATH, 68 | SOC_CERTIFICATE, 69 | 70 | SOC_MAX /* Keep this one last in the list */ 71 | }; 72 | #endif /* LIBSSH_CONFIG_H_ */ 73 | -------------------------------------------------------------------------------- /include/libssh/curve25519.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2013 by Aris Adamantiadis 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation, 9 | * version 2.1 of the License. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef CURVE25519_H_ 22 | #define CURVE25519_H_ 23 | 24 | #include "config.h" 25 | #include "libssh.h" 26 | 27 | #ifdef WITH_NACL 28 | 29 | #include 30 | #define CURVE25519_PUBKEY_SIZE crypto_scalarmult_curve25519_BYTES 31 | #define CURVE25519_PRIVKEY_SIZE crypto_scalarmult_curve25519_SCALARBYTES 32 | #define crypto_scalarmult_base crypto_scalarmult_curve25519_base 33 | #define crypto_scalarmult crypto_scalarmult_curve25519 34 | #else 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #define CURVE25519_PUBKEY_SIZE 32 41 | #define CURVE25519_PRIVKEY_SIZE 32 42 | int crypto_scalarmult_base(unsigned char *q, const unsigned char *n); 43 | int crypto_scalarmult(unsigned char *q, const unsigned char *n, const unsigned char *p); 44 | #endif /* WITH_NACL */ 45 | 46 | #ifdef HAVE_ECC 47 | #define HAVE_CURVE25519 1 48 | #endif 49 | 50 | typedef unsigned char ssh_curve25519_pubkey[CURVE25519_PUBKEY_SIZE]; 51 | typedef unsigned char ssh_curve25519_privkey[CURVE25519_PRIVKEY_SIZE]; 52 | 53 | 54 | int ssh_client_curve25519_init(ssh_session session); 55 | void ssh_client_curve25519_remove_callbacks(ssh_session session); 56 | 57 | #ifdef WITH_SERVER 58 | void ssh_server_curve25519_init(ssh_session session); 59 | #endif /* WITH_SERVER */ 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif /* CURVE25519_H_ */ 66 | -------------------------------------------------------------------------------- /include/libssh/dh-gex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2016 by Aris Adamantiadis 5 | * 6 | * The SSH Library is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation; either version 2.1 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * The SSH Library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 14 | * License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with the SSH Library; see the file COPYING. If not, write to 18 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 19 | * MA 02111-1307, USA. 20 | */ 21 | 22 | 23 | #ifndef SRC_DH_GEX_H_ 24 | #define SRC_DH_GEX_H_ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | int ssh_client_dhgex_init(ssh_session session); 31 | void ssh_client_dhgex_remove_callbacks(ssh_session session); 32 | 33 | #ifdef WITH_SERVER 34 | void ssh_server_dhgex_init(ssh_session session); 35 | #endif /* WITH_SERVER */ 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* SRC_DH_GEX_H_ */ 42 | -------------------------------------------------------------------------------- /include/libssh/ecdh.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2011 by Aris Adamantiadis 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef ECDH_H_ 22 | #define ECDH_H_ 23 | 24 | #include "config.h" 25 | #include "libssh/callbacks.h" 26 | 27 | #ifdef HAVE_LIBCRYPTO 28 | #ifdef HAVE_OPENSSL_ECDH_H 29 | 30 | #ifdef HAVE_ECC 31 | #define HAVE_ECDH 1 32 | #endif 33 | 34 | #endif /* HAVE_OPENSSL_ECDH_H */ 35 | #endif /* HAVE_LIBCRYPTO */ 36 | 37 | #ifdef HAVE_GCRYPT_ECC 38 | #define HAVE_ECDH 1 39 | #endif 40 | 41 | #ifdef HAVE_LIBMBEDCRYPTO 42 | #define HAVE_ECDH 1 43 | #endif 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | extern struct ssh_packet_callbacks_struct ssh_ecdh_client_callbacks; 50 | /* Backend-specific functions. */ 51 | int ssh_client_ecdh_init(ssh_session session); 52 | void ssh_client_ecdh_remove_callbacks(ssh_session session); 53 | int ecdh_build_k(ssh_session session); 54 | 55 | #ifdef WITH_SERVER 56 | extern struct ssh_packet_callbacks_struct ssh_ecdh_server_callbacks; 57 | void ssh_server_ecdh_init(ssh_session session); 58 | SSH_PACKET_CALLBACK(ssh_packet_server_ecdh_init); 59 | #endif /* WITH_SERVER */ 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif /* ECDH_H_ */ 66 | -------------------------------------------------------------------------------- /include/libssh/ge25519.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ge25519.h,v 1.3 2013/12/09 11:03:45 markus Exp $ */ 2 | 3 | /* 4 | * Public Domain, Authors: Daniel J. Bernstein, Niels Duif, Tanja Lange, 5 | * Peter Schwabe, Bo-Yin Yang. 6 | * Copied from supercop-20130419/crypto_sign/ed25519/ref/ge25519.h 7 | */ 8 | 9 | #ifndef GE25519_H 10 | #define GE25519_H 11 | 12 | #include "fe25519.h" 13 | #include "sc25519.h" 14 | 15 | #define ge25519 crypto_sign_ed25519_ref_ge25519 16 | #define ge25519_base crypto_sign_ed25519_ref_ge25519_base 17 | #define ge25519_unpackneg_vartime crypto_sign_ed25519_ref_unpackneg_vartime 18 | #define ge25519_pack crypto_sign_ed25519_ref_pack 19 | #define ge25519_isneutral_vartime crypto_sign_ed25519_ref_isneutral_vartime 20 | #define ge25519_double_scalarmult_vartime crypto_sign_ed25519_ref_double_scalarmult_vartime 21 | #define ge25519_scalarmult_base crypto_sign_ed25519_ref_scalarmult_base 22 | 23 | typedef struct 24 | { 25 | fe25519 x; 26 | fe25519 y; 27 | fe25519 z; 28 | fe25519 t; 29 | } ge25519; 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | extern const ge25519 ge25519_base; 36 | 37 | int ge25519_unpackneg_vartime(ge25519 *r, const unsigned char p[32]); 38 | 39 | void ge25519_pack(unsigned char r[32], const ge25519 *p); 40 | 41 | int ge25519_isneutral_vartime(const ge25519 *p); 42 | 43 | void ge25519_double_scalarmult_vartime(ge25519 *r, const ge25519 *p1, const sc25519 *s1, const ge25519 *p2, const sc25519 *s2); 44 | 45 | void ge25519_scalarmult_base(ge25519 *r, const sc25519 *s); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /include/libssh/keys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2009 by Aris Adamantiadis 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef KEYS_H_ 22 | #define KEYS_H_ 23 | 24 | #include "config.h" 25 | #include "libssh/libssh.h" 26 | #include "libssh/wrapper.h" 27 | 28 | struct ssh_public_key_struct { 29 | int type; 30 | const char *type_c; /* Don't free it ! it is static */ 31 | #if defined(HAVE_LIBGCRYPT) 32 | gcry_sexp_t rsa_pub; 33 | #elif defined(HAVE_LIBCRYPTO) 34 | EVP_PKEY *key_pub; 35 | #elif defined(HAVE_LIBMBEDCRYPTO) 36 | mbedtls_pk_context *rsa_pub; 37 | #endif 38 | }; 39 | 40 | struct ssh_private_key_struct { 41 | int type; 42 | #if defined(HAVE_LIBGCRYPT) 43 | gcry_sexp_t rsa_priv; 44 | #elif defined(HAVE_LIBCRYPTO) 45 | EVP_PKEY *key_priv; 46 | #elif defined(HAVE_LIBMBEDCRYPTO) 47 | mbedtls_pk_context *rsa_priv; 48 | #endif 49 | }; 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | const char *ssh_type_to_char(int type); 56 | int ssh_type_from_name(const char *name); 57 | 58 | ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif /* KEYS_H_ */ 65 | -------------------------------------------------------------------------------- /include/libssh/knownhosts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 20014 by Aris Adamantiadis 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | 22 | #ifndef SSH_KNOWNHOSTS_H_ 23 | #define SSH_KNOWNHOSTS_H_ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | struct ssh_list *ssh_known_hosts_get_algorithms(ssh_session session); 30 | char *ssh_known_hosts_get_algorithms_names(ssh_session session); 31 | enum ssh_known_hosts_e 32 | ssh_session_get_known_hosts_entry_file(ssh_session session, 33 | const char *filename, 34 | struct ssh_knownhosts_entry **pentry); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif /* SSH_KNOWNHOSTS_H_ */ 41 | -------------------------------------------------------------------------------- /include/libssh/libssh_version.h.cmake: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2020 by Heiko Thiery 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef _LIBSSH_VERSION_H 22 | #define _LIBSSH_VERSION_H 23 | 24 | /* libssh version macros */ 25 | #define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c)) 26 | #define SSH_VERSION_DOT(a, b, c) a ##.## b ##.## c 27 | #define SSH_VERSION(a, b, c) SSH_VERSION_DOT(a, b, c) 28 | 29 | /* libssh version */ 30 | #define LIBSSH_VERSION_MAJOR @libssh_VERSION_MAJOR@ 31 | #define LIBSSH_VERSION_MINOR @libssh_VERSION_MINOR@ 32 | #define LIBSSH_VERSION_MICRO @libssh_VERSION_PATCH@ 33 | 34 | #define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \ 35 | LIBSSH_VERSION_MINOR, \ 36 | LIBSSH_VERSION_MICRO) 37 | #define LIBSSH_VERSION SSH_VERSION(LIBSSH_VERSION_MAJOR, \ 38 | LIBSSH_VERSION_MINOR, \ 39 | LIBSSH_VERSION_MICRO) 40 | 41 | #endif /* _LIBSSH_VERSION_H */ 42 | -------------------------------------------------------------------------------- /include/libssh/options.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2011 Andreas Schneider 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef _OPTIONS_H 22 | #define _OPTIONS_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | int ssh_config_parse_file(ssh_session session, const char *filename); 29 | int ssh_config_parse_string(ssh_session session, const char *input); 30 | int ssh_options_set_algo(ssh_session session, 31 | enum ssh_kex_types_e algo, 32 | const char *list, 33 | char **place); 34 | int ssh_options_apply(ssh_session session); 35 | 36 | char *ssh_options_get_algo(ssh_session session, enum ssh_kex_types_e algo); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* _OPTIONS_H */ 43 | -------------------------------------------------------------------------------- /include/libssh/pcap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2009 by Aris Adamantiadis 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef PCAP_H_ 22 | #define PCAP_H_ 23 | 24 | #include "config.h" 25 | #include "libssh/libssh.h" 26 | 27 | #ifdef WITH_PCAP 28 | typedef struct ssh_pcap_context_struct* ssh_pcap_context; 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | int ssh_pcap_file_write_packet(ssh_pcap_file pcap, ssh_buffer packet, uint32_t original_len); 35 | 36 | ssh_pcap_context ssh_pcap_context_new(ssh_session session); 37 | void ssh_pcap_context_free(ssh_pcap_context ctx); 38 | 39 | enum ssh_pcap_direction{ 40 | SSH_PCAP_DIR_IN, 41 | SSH_PCAP_DIR_OUT 42 | }; 43 | void ssh_pcap_context_set_file(ssh_pcap_context, ssh_pcap_file); 44 | int ssh_pcap_context_write(ssh_pcap_context,enum ssh_pcap_direction direction, void *data, 45 | uint32_t len, uint32_t origlen); 46 | 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* WITH_PCAP */ 53 | #endif /* PCAP_H_ */ 54 | -------------------------------------------------------------------------------- /include/libssh/poly1305.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Public Domain poly1305 from Andrew Moon 3 | * poly1305-donna-unrolled.c from https://github.com/floodyberry/poly1305-donna 4 | */ 5 | 6 | #ifndef POLY1305_H 7 | #define POLY1305_H 8 | #include "libssh/chacha20-poly1305-common.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | void poly1305_auth(uint8_t out[POLY1305_TAGLEN], const uint8_t *m, size_t inlen, 15 | const uint8_t key[POLY1305_KEYLEN]) 16 | #ifdef HAVE_GCC_BOUNDED_ATTRIBUTE 17 | __attribute__((__bounded__(__minbytes__, 1, POLY1305_TAGLEN))) 18 | __attribute__((__bounded__(__buffer__, 2, 3))) 19 | __attribute__((__bounded__(__minbytes__, 4, POLY1305_KEYLEN))) 20 | #endif 21 | ; 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif /* POLY1305_H */ 28 | -------------------------------------------------------------------------------- /include/libssh/scp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2003-2009 by Aris Adamantiadis 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef _SCP_H 22 | #define _SCP_H 23 | 24 | enum ssh_scp_states { 25 | SSH_SCP_NEW, //Data structure just created 26 | SSH_SCP_WRITE_INITED, //Gave our intention to write 27 | SSH_SCP_WRITE_WRITING,//File was opened and currently writing 28 | SSH_SCP_READ_INITED, //Gave our intention to read 29 | SSH_SCP_READ_REQUESTED, //We got a read request 30 | SSH_SCP_READ_READING, //File is opened and reading 31 | SSH_SCP_ERROR, //Something bad happened 32 | SSH_SCP_TERMINATED //Transfer finished 33 | }; 34 | 35 | struct ssh_scp_struct { 36 | ssh_session session; 37 | int mode; 38 | int recursive; 39 | ssh_channel channel; 40 | char *location; 41 | enum ssh_scp_states state; 42 | uint64_t filelen; 43 | uint64_t processed; 44 | enum ssh_scp_request_types request_type; 45 | char *request_name; 46 | char *warning; 47 | int request_mode; 48 | }; 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | int ssh_scp_read_string(ssh_scp scp, char *buffer, size_t len); 55 | int ssh_scp_integer_mode(const char *mode); 56 | char *ssh_scp_string_mode(int mode); 57 | int ssh_scp_response(ssh_scp scp, char **response); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /include/libssh/sftpserver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2022 Zeyu Sheng 5 | * Copyright (c) 2023 Red Hat, Inc. 6 | * 7 | * Authors: Jakub Jelen 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef SFTP_SERVER_H 25 | #define SFTP_SERVER_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #include 32 | /** 33 | * @defgroup libssh_sftp_server The libssh SFTP server API 34 | * 35 | * @brief SFTP server handling functions 36 | * 37 | * TODO 38 | * 39 | * @{ 40 | */ 41 | 42 | #define SSH_SFTP_CALLBACK(name) \ 43 | static int name(sftp_client_message message) 44 | 45 | typedef int (*sftp_server_message_callback)(sftp_client_message message); 46 | 47 | struct sftp_message_handler 48 | { 49 | const char *name; 50 | const char *extended_name; 51 | uint8_t type; 52 | 53 | sftp_server_message_callback cb; 54 | }; 55 | 56 | LIBSSH_API int sftp_channel_default_subsystem_request(ssh_session session, 57 | ssh_channel channel, 58 | const char *subsystem, 59 | void *userdata); 60 | LIBSSH_API int sftp_channel_default_data_callback(ssh_session session, 61 | ssh_channel channel, 62 | void *data, 63 | uint32_t len, 64 | int is_stderr, 65 | void *userdata); 66 | 67 | /** @} */ 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* SFTP_SERVER_H */ 74 | -------------------------------------------------------------------------------- /include/libssh/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2009 by Aris Adamantiadis 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef STRING_H_ 22 | #define STRING_H_ 23 | #include "libssh/priv.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* must be 32 bits number + immediately our data */ 30 | #ifdef _MSC_VER 31 | #pragma pack(1) 32 | #endif 33 | struct ssh_string_struct { 34 | uint32_t size; 35 | unsigned char data[1]; 36 | } 37 | #if defined(__GNUC__) 38 | __attribute__ ((packed)) 39 | #endif 40 | #ifdef _MSC_VER 41 | #pragma pack() 42 | #endif 43 | ; 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* STRING_H_ */ 50 | -------------------------------------------------------------------------------- /include/libssh/threads.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2010 by Aris Adamantiadis 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef THREADS_H_ 22 | #define THREADS_H_ 23 | 24 | #include 25 | #include 26 | 27 | #if HAVE_PTHREAD 28 | 29 | #include 30 | #define SSH_MUTEX pthread_mutex_t 31 | 32 | #if defined(PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP) 33 | #define SSH_MUTEX_STATIC_INIT PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP 34 | #else 35 | #define SSH_MUTEX_STATIC_INIT PTHREAD_MUTEX_INITIALIZER 36 | #endif 37 | 38 | #elif (defined _WIN32) || (defined _WIN64) 39 | 40 | #include 41 | #include 42 | #define SSH_MUTEX CRITICAL_SECTION * 43 | #define SSH_MUTEX_STATIC_INIT NULL 44 | 45 | #else 46 | 47 | # define SSH_MUTEX void * 48 | #define SSH_MUTEX_STATIC_INIT NULL 49 | 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | int ssh_threads_init(void); 57 | void ssh_threads_finalize(void); 58 | const char *ssh_threads_get_type(void); 59 | 60 | void ssh_mutex_lock(SSH_MUTEX *mutex); 61 | void ssh_mutex_unlock(SSH_MUTEX *mutex); 62 | 63 | struct ssh_threads_callbacks_struct *ssh_threads_get_default(void); 64 | int crypto_thread_init(struct ssh_threads_callbacks_struct *user_callbacks); 65 | void crypto_thread_finalize(void); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* THREADS_H_ */ 72 | -------------------------------------------------------------------------------- /include/libssh/token.h: -------------------------------------------------------------------------------- 1 | /* 2 | * token.h - Tokens list handling 3 | * 4 | * This file is part of the SSH Library 5 | * 6 | * Copyright (c) 2019 by Red Hat, Inc. 7 | * 8 | * Author: Anderson Toshiyuki Sasaki 9 | * 10 | * The SSH Library is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation; either version 2.1 of the License, or (at your 13 | * option) any later version. 14 | * 15 | * The SSH Library is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 17 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | * License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with the SSH Library; see the file COPYING. If not, write to 22 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 23 | * MA 02111-1307, USA. 24 | */ 25 | 26 | #ifndef TOKEN_H_ 27 | #define TOKEN_H_ 28 | 29 | struct ssh_tokens_st { 30 | char *buffer; 31 | char **tokens; 32 | }; 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | struct ssh_tokens_st *ssh_tokenize(const char *chain, char separator); 39 | 40 | void ssh_tokens_free(struct ssh_tokens_st *tokens); 41 | 42 | char *ssh_find_matching(const char *available_d, 43 | const char *preferred_d); 44 | 45 | char *ssh_find_all_matching(const char *available_d, 46 | const char *preferred_d); 47 | 48 | char *ssh_remove_duplicates(const char *list); 49 | 50 | char *ssh_append_without_duplicates(const char *list, 51 | const char *appended_list); 52 | char *ssh_prefix_without_duplicates(const char *list, 53 | const char *prefixed_list); 54 | char *ssh_remove_all_matching(const char *list, 55 | const char *remove_list); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* TOKEN_H_ */ 62 | -------------------------------------------------------------------------------- /libssh.pc.cmake: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 4 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 5 | 6 | Name: @PROJECT_NAME@ 7 | Description: The SSH Library 8 | Version: @PROJECT_VERSION@ 9 | Libs: -L${libdir} -lssh 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /src/ABI/current: -------------------------------------------------------------------------------- 1 | 4.10.1 -------------------------------------------------------------------------------- /src/ABI/libssh-4.5.1.symbols: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/libssh/a2e4e969cf160789abaf0100e85b1a6c342d5d7e/src/ABI/libssh-4.5.1.symbols -------------------------------------------------------------------------------- /src/crypto_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2020 by Anderson Toshiyuki Sasaki - Red Hat, Inc. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "config.h" 22 | #include "libssh/crypto.h" 23 | 24 | int secure_memcmp(const void *s1, const void *s2, size_t n) 25 | { 26 | size_t i; 27 | uint8_t status = 0; 28 | const uint8_t *p1 = s1; 29 | const uint8_t *p2 = s2; 30 | 31 | for (i = 0; i < n; i++) { 32 | status |= (p1[i] ^ p2[i]); 33 | } 34 | 35 | return (status != 0); 36 | } 37 | -------------------------------------------------------------------------------- /src/getrandom_crypto.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2009 by Aris Adamantiadis 5 | * 6 | * The SSH Library is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation; either version 2.1 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * The SSH Library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 14 | * License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with the SSH Library; see the file COPYING. If not, write to 18 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 19 | * MA 02111-1307, USA. 20 | */ 21 | 22 | #include "config.h" 23 | 24 | #include "libssh/crypto.h" 25 | #include 26 | 27 | /** 28 | * @addtogroup libssh_misc 29 | * 30 | * @{ 31 | */ 32 | 33 | /** 34 | * @brief Get random bytes 35 | * 36 | * Make sure to always check the return code of this function! 37 | * 38 | * @param[in] where The buffer to fill with random bytes 39 | * 40 | * @param[in] len The size of the buffer to fill. 41 | * 42 | * @param[in] strong Use a strong or private RNG source. 43 | * 44 | * @return 1 on success, 0 on error. 45 | */ 46 | int 47 | ssh_get_random(void *where, int len, int strong) 48 | { 49 | #ifdef HAVE_OPENSSL_RAND_PRIV_BYTES 50 | if (strong) { 51 | /* Returns -1 when not supported, 0 on error, 1 on success */ 52 | return !!RAND_priv_bytes(where, len); 53 | } 54 | #else 55 | (void)strong; 56 | #endif /* HAVE_RAND_PRIV_BYTES */ 57 | 58 | /* Returns -1 when not supported, 0 on error, 1 on success */ 59 | return !!RAND_bytes(where, len); 60 | } 61 | 62 | /** 63 | * @} 64 | */ 65 | -------------------------------------------------------------------------------- /src/getrandom_gcrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2009 by Aris Adamantiadis 5 | * Copyright (C) 2016 g10 Code GmbH 6 | * 7 | * The SSH Library is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation; either version 2.1 of the License, or (at your 10 | * option) any later version. 11 | * 12 | * The SSH Library is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | * License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with the SSH Library; see the file COPYING. If not, write to 19 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 20 | * MA 02111-1307, USA. 21 | */ 22 | 23 | #include "config.h" 24 | 25 | #include "libssh/crypto.h" 26 | #include 27 | 28 | int 29 | ssh_get_random(void *where, int len, int strong) 30 | { 31 | /* variable not used in gcrypt */ 32 | (void)strong; 33 | 34 | /* not using GCRY_VERY_STRONG_RANDOM which is a bit overkill */ 35 | gcry_randomize(where, len, GCRY_STRONG_RANDOM); 36 | 37 | return 1; 38 | } 39 | -------------------------------------------------------------------------------- /src/getrandom_mbedcrypto.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2017 Sartura d.o.o. 5 | * 6 | * Author: Juraj Vijtiuk 7 | * 8 | * The SSH Library is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation; either version 2.1 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * The SSH Library is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | * License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with the SSH Library; see the file COPYING. If not, write to 20 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 21 | * MA 02111-1307, USA. 22 | */ 23 | 24 | #include "config.h" 25 | 26 | #include "libssh/crypto.h" 27 | #include "mbedcrypto-compat.h" 28 | 29 | mbedtls_ctr_drbg_context ssh_mbedtls_ctr_drbg; 30 | 31 | int 32 | ssh_mbedtls_random(void *where, int len, int strong) 33 | { 34 | int rc = 0; 35 | if (strong) { 36 | mbedtls_ctr_drbg_set_prediction_resistance(&ssh_mbedtls_ctr_drbg, 37 | MBEDTLS_CTR_DRBG_PR_ON); 38 | rc = mbedtls_ctr_drbg_random(&ssh_mbedtls_ctr_drbg, where, len); 39 | mbedtls_ctr_drbg_set_prediction_resistance(&ssh_mbedtls_ctr_drbg, 40 | MBEDTLS_CTR_DRBG_PR_OFF); 41 | } else { 42 | rc = mbedtls_ctr_drbg_random(&ssh_mbedtls_ctr_drbg, where, len); 43 | } 44 | 45 | return !rc; 46 | } 47 | 48 | int 49 | ssh_get_random(void *where, int len, int strong) 50 | { 51 | return ssh_mbedtls_random(where, len, strong); 52 | } 53 | -------------------------------------------------------------------------------- /src/libcrypto-compat.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBCRYPTO_COMPAT_H 2 | #define LIBCRYPTO_COMPAT_H 3 | 4 | #include 5 | 6 | #define NISTP256 "P-256" 7 | #define NISTP384 "P-384" 8 | #define NISTP521 "P-521" 9 | 10 | #if OPENSSL_VERSION_NUMBER < 0x30000000L 11 | #define EVP_PKEY_eq EVP_PKEY_cmp 12 | #endif /* OPENSSL_VERSION_NUMBER */ 13 | 14 | #endif /* LIBCRYPTO_COMPAT_H */ 15 | -------------------------------------------------------------------------------- /src/mbedcrypto-compat.h: -------------------------------------------------------------------------------- 1 | #ifndef MBEDCRYPTO_COMPAT_H 2 | #define MBEDCRYPTO_COMPAT_H 3 | 4 | /* mbedtls/version.h should be available for both v2 and v3 5 | * v3 defines the version inside build_info.h so if it isn't defined 6 | * in version.h we should have v3 7 | */ 8 | #include 9 | #include 10 | #ifdef MBEDTLS_VERSION_MAJOR 11 | #if MBEDTLS_VERSION_MAJOR < 3 12 | 13 | static inline size_t mbedtls_cipher_info_get_key_bitlen( 14 | const mbedtls_cipher_info_t *info) 15 | { 16 | if (info == NULL) { 17 | return 0; 18 | } 19 | return info->key_bitlen; 20 | } 21 | 22 | static inline size_t mbedtls_cipher_info_get_iv_size( 23 | const mbedtls_cipher_info_t *info) 24 | { 25 | if (info == NULL) { 26 | return 0; 27 | } 28 | return (size_t)info->iv_size; 29 | } 30 | 31 | #define MBEDTLS_PRIVATE(X) X 32 | #endif /* MBEDTLS_VERSION_MAJOR < 3 */ 33 | #else /* MBEDTLS_VERSION_MAJOR */ 34 | #include 35 | #if MBEDTLS_VERSION_MAJOR < 3 36 | #define MBEDTLS_PRIVATE(X) X 37 | #endif /* MBEDTLS_VERSION_MAJOR < 3 */ 38 | #endif /* MBEDTLS_VERSION_MAJOR */ 39 | #endif /* MBEDCRYPTO_COMPAT_H */ 40 | -------------------------------------------------------------------------------- /src/threads.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2010 by Aris Adamantiadis 5 | * 6 | * The SSH Library is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation; either version 2.1 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * The SSH Library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 14 | * License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with the SSH Library; see the file COPYING. If not, write to 18 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 19 | * MA 02111-1307, USA. 20 | */ 21 | 22 | /** 23 | * @defgroup libssh_threads The SSH threading functions 24 | * @ingroup libssh 25 | * 26 | * Threading with libssh 27 | * @{ 28 | */ 29 | 30 | #include "config.h" 31 | 32 | #include "libssh/priv.h" 33 | #include "libssh/crypto.h" 34 | #include "libssh/threads.h" 35 | 36 | static struct ssh_threads_callbacks_struct *user_callbacks = NULL; 37 | 38 | /** @internal 39 | * @brief inits the threading with the backend cryptographic libraries 40 | */ 41 | 42 | int ssh_threads_init(void) 43 | { 44 | static int threads_initialized = 0; 45 | int rc; 46 | 47 | if (threads_initialized) { 48 | return SSH_OK; 49 | } 50 | 51 | /* first initialize the user_callbacks with our default handlers if not 52 | * already the case 53 | */ 54 | if (user_callbacks == NULL){ 55 | user_callbacks = ssh_threads_get_default(); 56 | } 57 | 58 | /* Then initialize the crypto libraries threading callbacks */ 59 | rc = crypto_thread_init(user_callbacks); 60 | if (rc == SSH_OK) { 61 | threads_initialized = 1; 62 | } 63 | return rc; 64 | } 65 | 66 | void ssh_threads_finalize(void) 67 | { 68 | crypto_thread_finalize(); 69 | } 70 | 71 | int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct *cb) 72 | { 73 | 74 | int rc; 75 | 76 | if (user_callbacks != NULL) { 77 | crypto_thread_finalize(); 78 | } 79 | 80 | user_callbacks = cb; 81 | 82 | rc = crypto_thread_init(user_callbacks); 83 | 84 | return rc; 85 | } 86 | 87 | const char *ssh_threads_get_type(void) 88 | { 89 | if (user_callbacks != NULL) { 90 | return user_callbacks->type; 91 | } 92 | return NULL; 93 | } 94 | 95 | /** 96 | * @} 97 | */ 98 | -------------------------------------------------------------------------------- /src/threads/libcrypto.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2018 by Anderson Toshiyuki Sasaki 5 | * 6 | * The SSH Library is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation; either version 2.1 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * The SSH Library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 14 | * License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with the SSH Library; see the file COPYING. If not, write to 18 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 19 | * MA 02111-1307, USA. 20 | */ 21 | 22 | #include "config.h" 23 | #include "libssh/crypto.h" 24 | #include "libssh/threads.h" 25 | #include 26 | 27 | int crypto_thread_init(struct ssh_threads_callbacks_struct *cb) 28 | { 29 | (void) cb; 30 | return SSH_OK; 31 | } 32 | 33 | void crypto_thread_finalize(void) 34 | { 35 | return; 36 | } 37 | -------------------------------------------------------------------------------- /src/threads/libgcrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2018 by Anderson Toshiyuki Sasaki 5 | * 6 | * The SSH Library is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation; either version 2.1 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * The SSH Library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 14 | * License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with the SSH Library; see the file COPYING. If not, write to 18 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 19 | * MA 02111-1307, USA. 20 | */ 21 | 22 | #include "config.h" 23 | #include "libssh/crypto.h" 24 | #include "libssh/threads.h" 25 | #include 26 | 27 | #if (GCRYPT_VERSION_NUMBER >= 0x010600) 28 | /* libgcrypt >= 1.6 does not support custom callbacks */ 29 | GCRY_THREAD_OPTION_PTHREAD_IMPL; 30 | 31 | int crypto_thread_init(struct ssh_threads_callbacks_struct *user_callbacks) 32 | { 33 | (void) user_callbacks; 34 | 35 | return SSH_OK; 36 | } 37 | 38 | #else 39 | /* Libgcrypt < 1.6 specific way of handling thread callbacks */ 40 | 41 | static struct gcry_thread_cbs gcrypt_threads_callbacks; 42 | 43 | int crypto_thread_init(struct ssh_threads_callbacks_struct *user_callbacks) 44 | { 45 | int cmp; 46 | 47 | if (user_callbacks == NULL) { 48 | return SSH_OK; 49 | } 50 | 51 | cmp = strcmp(user_callbacks->type, "threads_noop"); 52 | if (cmp == 0) { 53 | gcrypt_threads_callbacks.option= GCRY_THREAD_OPTION_VERSION << 8 || 54 | GCRY_THREAD_OPTION_DEFAULT; 55 | } else { 56 | gcrypt_threads_callbacks.option= GCRY_THREAD_OPTION_VERSION << 8 || 57 | GCRY_THREAD_OPTION_USER; 58 | } 59 | 60 | gcrypt_threads_callbacks.mutex_init = user_callbacks->mutex_init; 61 | gcrypt_threads_callbacks.mutex_destroy = user_callbacks->mutex_destroy; 62 | gcrypt_threads_callbacks.mutex_lock = user_callbacks->mutex_lock; 63 | gcrypt_threads_callbacks.mutex_unlock = user_callbacks->mutex_unlock; 64 | gcry_control(GCRYCTL_SET_THREAD_CBS, &gcrypt_threads_callbacks); 65 | 66 | return SSH_OK; 67 | } 68 | 69 | #endif /* GCRYPT_VERSION_NUMBER */ 70 | 71 | void crypto_thread_finalize(void) 72 | { 73 | return; 74 | } 75 | -------------------------------------------------------------------------------- /src/threads/mbedtls.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2018 by Anderson Toshiyuki Sasaki 5 | * 6 | * The SSH Library is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation; either version 2.1 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * The SSH Library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 14 | * License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with the SSH Library; see the file COPYING. If not, write to 18 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 19 | * MA 02111-1307, USA. 20 | */ 21 | 22 | #include "config.h" 23 | #include "libssh/crypto.h" 24 | #include "libssh/threads.h" 25 | #include 26 | 27 | #include 28 | 29 | int crypto_thread_init(struct ssh_threads_callbacks_struct *user_callbacks) 30 | { 31 | int cmp; 32 | 33 | if (user_callbacks == NULL) { 34 | return SSH_OK; 35 | } 36 | 37 | cmp = strcmp(user_callbacks->type, "threads_noop"); 38 | if (cmp == 0) { 39 | return SSH_OK; 40 | } 41 | #ifdef MBEDTLS_THREADING_ALT 42 | else { 43 | if (user_callbacks != NULL) { 44 | crypto_thread_finalize(); 45 | } 46 | 47 | mbedtls_threading_set_alt(user_callbacks->mutex_init, 48 | user_callbacks->mutex_destroy, 49 | user_callbacks->mutex_lock, 50 | user_callbacks->mutex_unlock); 51 | } 52 | #elif defined MBEDTLS_THREADING_PTHREAD 53 | return SSH_OK; 54 | #else 55 | return SSH_ERROR; 56 | #endif 57 | } 58 | 59 | void crypto_thread_finalize(void) 60 | { 61 | #ifdef MBEDTLS_THREADING_ALT 62 | mbedtls_threading_free_alt(); 63 | #endif 64 | return; 65 | } 66 | -------------------------------------------------------------------------------- /src/threads/noop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2018 by Anderson Toshiyuki Sasaki 5 | * 6 | * The SSH Library is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation; either version 2.1 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * The SSH Library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 14 | * License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with the SSH Library; see the file COPYING. If not, write to 18 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 19 | * MA 02111-1307, USA. 20 | */ 21 | 22 | #include "config.h" 23 | #include "libssh/threads.h" 24 | #include 25 | 26 | static int threads_noop(void **lock) 27 | { 28 | (void)lock; 29 | 30 | return 0; 31 | } 32 | 33 | static unsigned long threads_id_noop (void) 34 | { 35 | return 1; 36 | } 37 | 38 | static struct ssh_threads_callbacks_struct ssh_threads_noop = 39 | { 40 | .type = "threads_noop", 41 | .mutex_init = threads_noop, 42 | .mutex_destroy = threads_noop, 43 | .mutex_lock = threads_noop, 44 | .mutex_unlock = threads_noop, 45 | .thread_id = threads_id_noop 46 | }; 47 | 48 | /* Threads interface implementation */ 49 | 50 | #if !(HAVE_PTHREAD) && !(defined _WIN32 || defined _WIN64) 51 | void ssh_mutex_lock(SSH_MUTEX *mutex) 52 | { 53 | (void) mutex; 54 | 55 | return; 56 | } 57 | 58 | void ssh_mutex_unlock(SSH_MUTEX *mutex) 59 | { 60 | (void) mutex; 61 | 62 | return; 63 | } 64 | 65 | struct ssh_threads_callbacks_struct *ssh_threads_get_default(void) 66 | { 67 | return &ssh_threads_noop; 68 | } 69 | #endif 70 | 71 | struct ssh_threads_callbacks_struct *ssh_threads_get_noop(void) 72 | { 73 | return &ssh_threads_noop; 74 | } 75 | -------------------------------------------------------------------------------- /tests/benchmarks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(libssh-benchmarks C) 2 | 3 | set(benchmarks_SRCS 4 | bench_scp.c bench_raw.c benchmarks.c latency.c 5 | ) 6 | if (WITH_SFTP) 7 | set(benchmarks_SRCS 8 | ${benchmarks_SRCS} 9 | bench_sftp.c 10 | ) 11 | endif (WITH_SFTP) 12 | 13 | include_directories(${libssh_BINARY_DIR}) 14 | 15 | add_executable(benchmarks ${benchmarks_SRCS}) 16 | 17 | target_link_libraries(benchmarks ssh::static pthread) 18 | -------------------------------------------------------------------------------- /tests/benchmarks/bench1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export CIPHER=aes128-cbc 3 | export DEST=localhost 4 | 5 | echo "Upload raw SSH statistics" 6 | echo "local machine: $(uname -a)" 7 | echo "Cipher : $CIPHER ; Destination : $DEST ($(ssh $DEST uname -a))" 8 | echo "Local ssh version: $(ssh -V 2>&1)" 9 | echo "Ping latency to $DEST": 10 | ping -q -c 1 -n $DEST 11 | echo "Destination $DEST SSHD version : $(echo | nc $DEST 22 | head -n1)" 12 | echo "ssh login latency :$( (command time -f user:%U ssh $DEST 'id > /dev/null') 2>&1)" 13 | ./generate.py | dd bs=4096 count=100000 | time ssh -c $CIPHER $DEST "dd bs=4096 of=/dev/null" 2>&1 14 | 15 | -------------------------------------------------------------------------------- /tests/benchmarks/bench2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export CIPHER=aes128-cbc 3 | export DEST=localhost 4 | 5 | echo "Upload raw SSH statistics" 6 | echo "local machine: $(uname -a)" 7 | echo "Cipher : $CIPHER ; Destination : $DEST ($(ssh $DEST uname -a))" 8 | echo "Local ssh version: $(samplessh -V 2>&1)" 9 | echo "Ping latency to $DEST": 10 | ping -q -c 1 -n $DEST 11 | echo "Destination $DEST SSHD version : $(echo | nc $DEST 22 | head -n1)" 12 | echo "ssh login latency :$( (command time -f user:%U samplessh $DEST 'id > /dev/null') 2>&1)" 13 | ./generate.py | dd bs=4096 count=100000 | strace samplessh -c $CIPHER $DEST "dd bs=4096 of=/dev/null" 2>&1 14 | 15 | -------------------------------------------------------------------------------- /tests/chmodtest.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include "examples_common.h" 5 | #include 6 | 7 | int main(void) { 8 | ssh_session session; 9 | sftp_session sftp; 10 | char buffer[1024*1024]; 11 | int rc; 12 | 13 | session = connect_ssh("localhost", NULL, 0); 14 | if (session == NULL) { 15 | return 1; 16 | } 17 | 18 | sftp=sftp_new(session); 19 | sftp_init(sftp); 20 | rc=sftp_rename(sftp,"/tmp/test","/tmp/test"); 21 | rc=sftp_rename(sftp,"/tmp/test","/tmp/test"); 22 | rc=sftp_chmod(sftp,"/tmp/test",0644); 23 | if (rc < 0) { 24 | printf("error : %s\n",ssh_get_error(sftp)); 25 | 26 | ssh_disconnect(session); 27 | return 1; 28 | } 29 | 30 | ssh_disconnect(session); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /tests/chroot_wrapper.c: -------------------------------------------------------------------------------- 1 | /* silent gcc */ 2 | int chroot(const char *); 3 | 4 | int chroot(const char *path) 5 | { 6 | (void)path; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/client/torture_sftp_canonicalize_path.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #define LIBSSH_STATIC 4 | 5 | #include "torture.h" 6 | #include "sftp.c" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | static int sshd_setup(void **state) 13 | { 14 | torture_setup_sshd_server(state, false); 15 | 16 | return 0; 17 | } 18 | 19 | static int sshd_teardown(void **state) { 20 | torture_teardown_sshd_server(state); 21 | 22 | return 0; 23 | } 24 | 25 | static int session_setup(void **state) 26 | { 27 | struct torture_state *s = *state; 28 | struct passwd *pwd; 29 | int rc; 30 | 31 | pwd = getpwnam("bob"); 32 | assert_non_null(pwd); 33 | 34 | rc = setuid(pwd->pw_uid); 35 | assert_return_code(rc, errno); 36 | 37 | s->ssh.session = torture_ssh_session(s, 38 | TORTURE_SSH_SERVER, 39 | NULL, 40 | TORTURE_SSH_USER_ALICE, 41 | NULL); 42 | assert_non_null(s->ssh.session); 43 | 44 | s->ssh.tsftp = torture_sftp_session(s->ssh.session); 45 | assert_non_null(s->ssh.tsftp); 46 | 47 | return 0; 48 | } 49 | 50 | static int session_teardown(void **state) 51 | { 52 | struct torture_state *s = *state; 53 | 54 | torture_rmdirs(s->ssh.tsftp->testdir); 55 | torture_sftp_close(s->ssh.tsftp); 56 | ssh_disconnect(s->ssh.session); 57 | ssh_free(s->ssh.session); 58 | 59 | return 0; 60 | } 61 | 62 | static void torture_sftp_canonicalize_path(void **state) 63 | { 64 | struct torture_state *s = *state; 65 | struct torture_sftp *t = s->ssh.tsftp; 66 | struct passwd *pwd = NULL; 67 | char *canonicalized_path = NULL; 68 | 69 | pwd = getpwnam(TORTURE_SSH_USER_ALICE); 70 | assert_non_null(pwd); 71 | 72 | canonicalized_path = sftp_canonicalize_path(t->sftp, "."); 73 | assert_non_null(canonicalized_path); 74 | 75 | assert_string_equal(canonicalized_path, pwd->pw_dir); 76 | 77 | SSH_STRING_FREE_CHAR(canonicalized_path); 78 | } 79 | 80 | int torture_run_tests(void) { 81 | int rc; 82 | struct CMUnitTest tests[] = { 83 | cmocka_unit_test_setup_teardown(torture_sftp_canonicalize_path, 84 | session_setup, 85 | session_teardown) 86 | }; 87 | 88 | ssh_init(); 89 | 90 | torture_filter_tests(tests); 91 | rc = cmocka_run_group_tests(tests, sshd_setup, sshd_teardown); 92 | 93 | ssh_finalize(); 94 | 95 | return rc; 96 | } 97 | 98 | -------------------------------------------------------------------------------- /tests/client/torture_sftp_ext.c: -------------------------------------------------------------------------------- 1 | #define LIBSSH_STATIC 2 | 3 | #include "config.h" 4 | 5 | #include "torture.h" 6 | #include "sftp.c" 7 | 8 | static void torture_sftp_ext_new(void **state) { 9 | sftp_ext x; 10 | 11 | (void) state; 12 | 13 | x = sftp_ext_new(); 14 | assert_non_null(x); 15 | assert_int_equal(x->count, 0); 16 | assert_null(x->name); 17 | assert_null(x->data); 18 | 19 | sftp_ext_free(x); 20 | } 21 | 22 | int torture_run_tests(void) { 23 | int rc; 24 | struct CMUnitTest tests[] = { 25 | cmocka_unit_test(torture_sftp_ext_new), 26 | }; 27 | 28 | ssh_init(); 29 | 30 | torture_filter_tests(tests); 31 | rc = cmocka_run_group_tests(tests, NULL, NULL); 32 | ssh_finalize(); 33 | 34 | return rc; 35 | } 36 | -------------------------------------------------------------------------------- /tests/cmdline.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include "torture.h" 3 | 4 | #ifdef HAVE_ARGP_H 5 | #include 6 | 7 | const char *argp_program_version = "libssh test 0.2"; 8 | const char *argp_program_bug_address = ""; 9 | 10 | static char **cmdline; 11 | 12 | /* Program documentation. */ 13 | static char doc[] = "libssh test test"; 14 | 15 | /* The options we understand. */ 16 | static struct argp_option options[] = { 17 | { 18 | .name = "verbose", 19 | .key = 'v', 20 | .arg = NULL, 21 | .flags = 0, 22 | .doc = "Make libssh test more verbose", 23 | .group = 0 24 | }, 25 | {NULL, 0, NULL, 0, NULL, 0} 26 | }; 27 | 28 | /* Parse a single option. */ 29 | static error_t parse_opt (int key, char *arg, struct argp_state *state) { 30 | /* Get the input argument from argp_parse, which we 31 | * know is a pointer to our arguments structure. 32 | */ 33 | struct argument_s *arguments = state->input; 34 | 35 | /* arg is currently not used */ 36 | (void) arg; 37 | 38 | switch (key) { 39 | case 'v': 40 | arguments->verbose++; 41 | break; 42 | case ARGP_KEY_ARG: 43 | /* End processing here. */ 44 | arguments->pattern = state->argv[state->next - 1]; 45 | cmdline = &state->argv [state->next - 1]; 46 | state->next = state->argc; 47 | break; 48 | default: 49 | return ARGP_ERR_UNKNOWN; 50 | } 51 | 52 | return 0; 53 | } 54 | 55 | /* Our argp parser. */ 56 | /* static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL}; */ 57 | static struct argp argp = {options, parse_opt, NULL, doc, NULL, NULL, NULL}; 58 | #endif /* HAVE_ARGP_H */ 59 | 60 | void torture_cmdline_parse(int argc, char **argv, struct argument_s *arguments) { 61 | /* 62 | * Parse our arguments; every option seen by parse_opt will 63 | * be reflected in arguments. 64 | */ 65 | #ifdef HAVE_ARGP_H 66 | argp_parse(&argp, argc, argv, 0, 0, arguments); 67 | #else 68 | (void) argc; 69 | (void) argv; 70 | (void) arguments; 71 | #endif /* HAVE_ARGP_H */ 72 | } 73 | -------------------------------------------------------------------------------- /tests/etc/group.in: -------------------------------------------------------------------------------- 1 | users:x:9000: 2 | sshd:x:65531: 3 | nobody:x:65533: 4 | nogroup:x:65534:nobody 5 | root:x:65532: 6 | -------------------------------------------------------------------------------- /tests/etc/hosts.in: -------------------------------------------------------------------------------- 1 | 127.0.0.10 server.libssh.site 2 | 127.0.0.21 client.libssh.site 3 | 4 | 127.0.0.11 kdc.libssh.site 5 | 6 | 123.0.0.11 testing 7 | fd00::5357:5f0a testing 8 | -------------------------------------------------------------------------------- /tests/etc/pam.d/sshd.in: -------------------------------------------------------------------------------- 1 | auth required @PAM_WRAPPER_MODULE_DIR@/pam_matrix.so passdb=@CMAKE_CURRENT_BINARY_DIR@/etc/pam_matrix_passdb 2 | account required @PAM_WRAPPER_MODULE_DIR@/pam_matrix.so passdb=@CMAKE_CURRENT_BINARY_DIR@/etc/pam_matrix_passdb 3 | password required @PAM_WRAPPER_MODULE_DIR@/pam_matrix.so passdb=@CMAKE_CURRENT_BINARY_DIR@/etc/pam_matrix_passdb 4 | session required @PAM_WRAPPER_MODULE_DIR@/pam_matrix.so passdb=@CMAKE_CURRENT_BINARY_DIR@/etc/pam_matrix_passdb 5 | -------------------------------------------------------------------------------- /tests/etc/pam_matrix_passdb.in: -------------------------------------------------------------------------------- 1 | bob:secret:sshd 2 | alice:secret:sshd 3 | charlie:secret:sshd 4 | doe:secret:sshd 5 | -------------------------------------------------------------------------------- /tests/etc/passwd.in: -------------------------------------------------------------------------------- 1 | bob:x:5000:9000:bob gecos:@HOMEDIR@/bob:/bin/sh 2 | alice:x:5001:9000:alice gecos:@HOMEDIR@/alice:/bin/sh 3 | charlie:x:5002:9000:charlie gecos:@HOMEDIR@/charlie:/bin/sh 4 | doe:x:5003:9000:doe gecos:@HOMEDIR@/doe:/bin/sh 5 | sshd:x:65530:65531:sshd:@HOMEDIR@:/sbin/nologin 6 | nobody:x:65533:65534:nobody gecos:@HOMEDIR@:/bin/false 7 | root:x:65534:65532:root gecos:@HOMEDIR@:/bin/false 8 | @LOCAL_USER@:x:@LOCAL_UID@:9000:local user:@HOMEDIR@:/bin/false 9 | -------------------------------------------------------------------------------- /tests/etc/shadow.in: -------------------------------------------------------------------------------- 1 | alice:$6$0jWkA8VP$MvBUvtGy38jWCZ5KtqnZEKQWXvvImDkDhDQII1kTqtAp3/xH31b71c.AjGkBFle.2QwCJQH7OzB/NXiMprusr/::0::::: 2 | bob:$6$0jWkA8VP$MvBUvtGy38jWCZ5KtqnZEKQWXvvImDkDhDQII1kTqtAp3/xH31b71c.AjGkBFle.2QwCJQH7OzB/NXiMprusr/::0::::: 3 | charlie:$6$0jWkA8VP$MvBUvtGy38jWCZ5KtqnZEKQWXvvImDkDhDQII1kTqtAp3/xH31b71c.AjGkBFle.2QwCJQH7OzB/NXiMprusr/::0::::: 4 | doe:$6$0jWkA8VP$MvBUvtGy38jWCZ5KtqnZEKQWXvvImDkDhDQII1kTqtAp3/xH31b71c.AjGkBFle.2QwCJQH7OzB/NXiMprusr/::0::::: 5 | -------------------------------------------------------------------------------- /tests/external_override/chacha20_override.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2021 by Anderson Toshiyuki Sasaki - Red Hat, Inc. 5 | * 6 | * The SSH Library is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation, either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * The SSH Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with the SSH Library; see the file COPYING. If not, 18 | * see . 19 | */ 20 | 21 | #include "libssh/chacha.h" 22 | 23 | void __wrap_chacha_keysetup(struct chacha_ctx *x, 24 | const uint8_t *k, 25 | uint32_t kbits) 26 | #ifdef HAVE_GCC_BOUNDED_ATTRIBUTE 27 | __attribute__((__bounded__(__minbytes__, 2, CHACHA_MINKEYLEN))) 28 | #endif 29 | ; 30 | 31 | void __wrap_chacha_ivsetup(struct chacha_ctx *x, 32 | const uint8_t *iv, 33 | const uint8_t *ctr) 34 | #ifdef HAVE_GCC_BOUNDED_ATTRIBUTE 35 | __attribute__((__bounded__(__minbytes__, 2, CHACHA_NONCELEN))) 36 | __attribute__((__bounded__(__minbytes__, 3, CHACHA_CTRLEN))) 37 | #endif 38 | ; 39 | 40 | void __wrap_chacha_encrypt_bytes(struct chacha_ctx *x, 41 | const uint8_t *m, 42 | uint8_t *c, 43 | uint32_t bytes) 44 | #ifdef HAVE_GCC_BOUNDED_ATTRIBUTE 45 | __attribute__((__bounded__(__buffer__, 2, 4))) 46 | __attribute__((__bounded__(__buffer__, 3, 4))) 47 | #endif 48 | ; 49 | 50 | bool internal_chacha20_function_called(void); 51 | void reset_chacha20_function_called(void); 52 | -------------------------------------------------------------------------------- /tests/external_override/curve25519_override.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2021 by Anderson Toshiyuki Sasaki - Red Hat, Inc. 5 | * 6 | * The SSH Library is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation, either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * The SSH Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with the SSH Library; see the file COPYING. If not, 18 | * see . 19 | */ 20 | 21 | #include "config.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "curve25519_override.h" 30 | 31 | static bool internal_function_called = false; 32 | 33 | int __wrap_crypto_scalarmult_base(unsigned char *q, 34 | const unsigned char *n) 35 | { 36 | fprintf(stderr, "%s: Internal implementation was called\n", __func__); 37 | internal_function_called = true; 38 | return crypto_scalarmult_base(q, n); 39 | } 40 | 41 | int __wrap_crypto_scalarmult(unsigned char *q, 42 | const unsigned char *n, 43 | const unsigned char *p) 44 | { 45 | fprintf(stderr, "%s: Internal implementation was called\n", __func__); 46 | internal_function_called = true; 47 | return crypto_scalarmult(q, n, p); 48 | } 49 | 50 | bool internal_curve25519_function_called(void) 51 | { 52 | return internal_function_called; 53 | } 54 | 55 | void reset_curve25519_function_called(void) 56 | { 57 | internal_function_called = false; 58 | } 59 | -------------------------------------------------------------------------------- /tests/external_override/curve25519_override.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2021 by Anderson Toshiyuki Sasaki - Red Hat, Inc. 5 | * 6 | * The SSH Library is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation, either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * The SSH Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with the SSH Library; see the file COPYING. If not, 18 | * see . 19 | */ 20 | 21 | #include "libssh/curve25519.h" 22 | 23 | int __wrap_crypto_scalarmult_base(unsigned char *q, 24 | const unsigned char *n); 25 | 26 | int __wrap_crypto_scalarmult(unsigned char *q, 27 | const unsigned char *n, 28 | const unsigned char *p); 29 | 30 | bool internal_curve25519_function_called(void); 31 | void reset_curve25519_function_called(void); 32 | -------------------------------------------------------------------------------- /tests/external_override/ed25519_override.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2021 by Anderson Toshiyuki Sasaki - Red Hat, Inc. 5 | * 6 | * The SSH Library is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation, either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * The SSH Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with the SSH Library; see the file COPYING. If not, 18 | * see . 19 | */ 20 | 21 | #include "libssh/ed25519.h" 22 | 23 | int __wrap_crypto_sign_ed25519_keypair(ed25519_pubkey pk, 24 | ed25519_privkey sk); 25 | 26 | int __wrap_crypto_sign_ed25519(unsigned char *sm, 27 | uint64_t *smlen, 28 | const unsigned char *m, 29 | uint64_t mlen, 30 | const ed25519_privkey sk); 31 | 32 | int __wrap_crypto_sign_ed25519_open(unsigned char *m, 33 | uint64_t *mlen, 34 | const unsigned char *sm, 35 | uint64_t smlen, 36 | const ed25519_pubkey pk); 37 | 38 | bool internal_ed25519_function_called(void); 39 | void reset_ed25519_function_called(void); 40 | -------------------------------------------------------------------------------- /tests/external_override/poly1305_override.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2021 by Anderson Toshiyuki Sasaki - Red Hat, Inc. 5 | * 6 | * The SSH Library is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation, either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * The SSH Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with the SSH Library; see the file COPYING. If not, 18 | * see . 19 | */ 20 | 21 | #include "config.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | static bool internal_function_called = false; 30 | 31 | void __wrap_poly1305_auth(uint8_t out[POLY1305_TAGLEN], 32 | const uint8_t *m, 33 | size_t inlen, 34 | const uint8_t key[POLY1305_KEYLEN]) 35 | #ifdef HAVE_GCC_BOUNDED_ATTRIBUTE 36 | __attribute__((__bounded__(__minbytes__, 1, POLY1305_TAGLEN))) 37 | __attribute__((__bounded__(__buffer__, 2, 3))) 38 | __attribute__((__bounded__(__minbytes__, 4, POLY1305_KEYLEN))) 39 | #endif 40 | { 41 | fprintf(stderr, "%s: Internal implementation was called\n", __func__); 42 | internal_function_called = true; 43 | poly1305_auth(out, m, inlen, key); 44 | } 45 | 46 | bool internal_poly1305_function_called(void) 47 | { 48 | return internal_function_called; 49 | } 50 | 51 | void reset_poly1305_function_called(void) 52 | { 53 | internal_function_called = false; 54 | } 55 | -------------------------------------------------------------------------------- /tests/external_override/poly1305_override.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2021 by Anderson Toshiyuki Sasaki - Red Hat, Inc. 5 | * 6 | * The SSH Library is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation, either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * The SSH Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with the SSH Library; see the file COPYING. If not, 18 | * see . 19 | */ 20 | 21 | #include "libssh/poly1305.h" 22 | 23 | void __wrap_poly1305_auth(uint8_t out[POLY1305_TAGLEN], 24 | const uint8_t *m, 25 | size_t inlen, 26 | const uint8_t key[POLY1305_KEYLEN]) 27 | #ifdef HAVE_GCC_BOUNDED_ATTRIBUTE 28 | __attribute__((__bounded__(__minbytes__, 1, POLY1305_TAGLEN))) 29 | __attribute__((__bounded__(__buffer__, 2, 3))) 30 | __attribute__((__bounded__(__minbytes__, 4, POLY1305_KEYLEN))) 31 | #endif 32 | ; 33 | 34 | bool internal_poly1305_function_called(void); 35 | void reset_poly1305_function_called(void); 36 | -------------------------------------------------------------------------------- /tests/fuzz/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(fuzzing CXX) 2 | 3 | macro(fuzzer name) 4 | add_executable(${name} ${name}.c) 5 | target_link_libraries(${name} 6 | PRIVATE 7 | ssh::static pthread) 8 | if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 9 | set_target_properties(${name} 10 | PROPERTIES 11 | COMPILE_FLAGS "-fsanitize=fuzzer" 12 | LINK_FLAGS "-fsanitize=fuzzer") 13 | # Run the fuzzer to make sure it works 14 | add_test(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name} -runs=1) 15 | else() 16 | target_sources(${name} PRIVATE fuzzer.c) 17 | # Run the fuzzer to make sure it works 18 | if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${name}_corpus") 19 | file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/${name}_corpus/*") 20 | set(i 0) 21 | foreach(file ${files}) 22 | add_test(${name}_${i} 23 | ${CMAKE_CURRENT_BINARY_DIR}/${name} ${file}) 24 | math(EXPR i "${i} + 1") 25 | endforeach() 26 | endif() 27 | endif() 28 | endmacro() 29 | 30 | fuzzer(ssh_client_fuzzer) 31 | fuzzer(ssh_client_config_fuzzer) 32 | fuzzer(ssh_known_hosts_fuzzer) 33 | fuzzer(ssh_privkey_fuzzer) 34 | fuzzer(ssh_pubkey_fuzzer) 35 | if (WITH_SERVER) 36 | fuzzer(ssh_server_fuzzer) 37 | fuzzer(ssh_bind_config_fuzzer) 38 | endif (WITH_SERVER) 39 | -------------------------------------------------------------------------------- /tests/fuzz/fuzzer.c: -------------------------------------------------------------------------------- 1 | /* Simpler gnu89 version of StandaloneFuzzTargetMain.c from LLVM */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int LLVMFuzzerTestOneInput (const unsigned char *data, size_t size); 8 | __attribute__((weak)) int LLVMFuzzerInitialize(int *argc, char ***argv); 9 | 10 | int 11 | main (int argc, char **argv) 12 | { 13 | FILE *f = NULL; 14 | size_t n_read, len; 15 | unsigned char *buf = NULL; 16 | 17 | if (argc < 2) { 18 | return 1; 19 | } 20 | 21 | if (LLVMFuzzerInitialize) { 22 | LLVMFuzzerInitialize(&argc, &argv); 23 | } 24 | 25 | f = fopen (argv[1], "r"); 26 | assert (f); 27 | fseek (f, 0, SEEK_END); 28 | len = ftell (f); 29 | fseek (f, 0, SEEK_SET); 30 | buf = (unsigned char*) malloc (len); 31 | n_read = fread (buf, 1, len, f); 32 | fclose (f); 33 | assert (n_read == len); 34 | LLVMFuzzerTestOneInput (buf, len); 35 | 36 | free (buf); 37 | printf ("Done!\n"); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /tests/fuzz/ssh_bind_config_fuzzer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Jakub Jelen 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #define LIBSSH_STATIC 1 23 | #include "libssh/libssh.h" 24 | #include "libssh/server.h" 25 | #include "libssh/bind_config.h" 26 | 27 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 28 | { 29 | ssh_bind bind = NULL; 30 | char *input = NULL; 31 | 32 | input = (char *)malloc(size + 1); 33 | if (!input) { 34 | return 1; 35 | } 36 | strncpy(input, (const char *)data, size); 37 | input[size] = '\0'; 38 | 39 | ssh_init(); 40 | 41 | bind = ssh_bind_new(); 42 | assert(bind != NULL); 43 | 44 | ssh_bind_config_parse_string(bind, input); 45 | 46 | ssh_bind_free(bind); 47 | ssh_finalize(); 48 | 49 | free(input); 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /tests/fuzz/ssh_client_config_fuzzer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Stanislav Zidek 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #define LIBSSH_STATIC 1 23 | #include "libssh/libssh.h" 24 | #include "libssh/options.h" 25 | 26 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 27 | { 28 | ssh_session session = NULL; 29 | char *input = NULL; 30 | 31 | input = (char *)malloc(size+1); 32 | if (!input) { 33 | return 1; 34 | } 35 | strncpy(input, (const char *)data, size); 36 | input[size] = '\0'; 37 | 38 | ssh_init(); 39 | 40 | session = ssh_new(); 41 | assert(session != NULL); 42 | 43 | /* Make sure we have default options set */ 44 | ssh_options_set(session, SSH_OPTIONS_SSH_DIR, NULL); 45 | ssh_options_set(session, SSH_OPTIONS_HOST, "example.com"); 46 | 47 | ssh_config_parse_string(session, input); 48 | 49 | ssh_free(session); 50 | ssh_finalize(); 51 | 52 | free(input); 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /tests/fuzz/ssh_client_fuzzer_corpus/0f9d75a6c1d365115772a502d42b6e48f453198a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/libssh/a2e4e969cf160789abaf0100e85b1a6c342d5d7e/tests/fuzz/ssh_client_fuzzer_corpus/0f9d75a6c1d365115772a502d42b6e48f453198a -------------------------------------------------------------------------------- /tests/fuzz/ssh_known_hosts_fuzzer_corpus/d7c0eade3f3b70d94b1a7090e09eb8607da0ace4: -------------------------------------------------------------------------------- 1 | 192.168.1.181192.168.1.181 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMFpHSPr8uIdAyDcX4IPPEaoxTGF1FbutTLNPahs3zx/wbeg2krUY9059QlUculZgRUjSshAFEBbacUzDIhvk6M= 2 | -------------------------------------------------------------------------------- /tests/fuzz/ssh_privkey_fuzzer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Jakub Jelen 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "config.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #define LIBSSH_STATIC 1 25 | #include "libssh/libssh.h" 26 | #include "libssh/priv.h" 27 | 28 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 29 | { 30 | ssh_key pkey = NULL; 31 | uint8_t *input = NULL; 32 | int rc; 33 | 34 | input = bin_to_base64(data, size); 35 | if (input == NULL) { 36 | return 1; 37 | } 38 | 39 | ssh_init(); 40 | 41 | rc = ssh_pki_import_privkey_base64((char *)input, NULL, NULL, NULL, &pkey); 42 | free(input); 43 | if (rc != SSH_OK) { 44 | return 1; 45 | } 46 | ssh_key_free(pkey); 47 | 48 | ssh_finalize(); 49 | 50 | return 0; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /tests/fuzz/ssh_privkey_fuzzer_corpus/855ce609b52aec530bf631a78da7038bed99040a: -------------------------------------------------------------------------------- 1 | -----BEGIN OPENSSH PRIVATE KEY----- 2 | b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW 3 | QyNTUxOQAAACCLo6vx1lX6ZZoe05lWTkuwrJUZN0T8hEer5UF9KPhOVgAAAKg+IRNSPiET 4 | UgAAAAtzc2gtZWQyNTUxOQAAACCLo6vx1lX6ZZoe05lWTkuwrJUZN0T8hEer5UF9KPhOVg 5 | AAAED2zFg52qYItoZaSUnir4VKubTxJveL9D2oWK7Prg/O24ujq/HWVfplmh7TmVZOS7Cs 6 | lRk3RPyER6vlQX0o+E5WAAAAHmpqZWxlbkB0NDcwcy5qamVsZW4ucmVkaGF0LmNvbQECAw 7 | QFBgc= 8 | -----END OPENSSH PRIVATE KEY----- 9 | -------------------------------------------------------------------------------- /tests/fuzz/ssh_pubkey_fuzzer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Jakub Jelen 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "config.h" 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #define LIBSSH_STATIC 1 23 | #include "libssh/libssh.h" 24 | #include "libssh/misc.h" 25 | 26 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 27 | { 28 | ssh_key pkey = NULL; 29 | char *filename = NULL; 30 | int fd; 31 | int rc; 32 | ssize_t sz; 33 | 34 | ssh_init(); 35 | 36 | filename = strdup("/tmp/libssh_pubkey_XXXXXX"); 37 | if (filename == NULL) { 38 | return -1; 39 | } 40 | fd = mkstemp(filename); 41 | if (fd == -1) { 42 | free(filename); 43 | close(fd); 44 | return -1; 45 | } 46 | sz = ssh_writen(fd, data, size); 47 | close(fd); 48 | if (sz == SSH_ERROR) { 49 | unlink(filename); 50 | free(filename); 51 | return -1; 52 | } 53 | 54 | rc = ssh_pki_import_pubkey_file(filename, &pkey); 55 | if (rc != SSH_OK) { 56 | unlink(filename); 57 | free(filename); 58 | return 1; 59 | } 60 | ssh_key_free(pkey); 61 | unlink(filename); 62 | free(filename); 63 | 64 | ssh_finalize(); 65 | 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /tests/fuzz/ssh_pubkey_fuzzer_corpus/b2c9f01394a2835b2cd7c520395a4977143e8d23: -------------------------------------------------------------------------------- 1 | ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIujq/HWVfplmh7TmVZOS7CslRk3RPyER6vlQX0o+E5W jjelen@t470s.jjelen.redhat.com 2 | -------------------------------------------------------------------------------- /tests/fuzz/ssh_server_fuzzer_corpus/fd7bd24a85e712fb59159a512b69d34ca21c8383: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/libssh/a2e4e969cf160789abaf0100e85b1a6c342d5d7e/tests/fuzz/ssh_server_fuzzer_corpus/fd7bd24a85e712fb59159a512b69d34ca21c8383 -------------------------------------------------------------------------------- /tests/generate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import os 3 | a="" 4 | for i in xrange(4096): 5 | a+=chr(i % 256); 6 | while True: 7 | try: 8 | os.write(1,a) 9 | except: 10 | exit(0) 11 | -------------------------------------------------------------------------------- /tests/gss/kdcsetup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | SOCKDIR=$1 4 | WORKDIR=$SOCKDIR/gss 5 | 6 | mkdir "$WORKDIR"/k "$WORKDIR"/d 7 | 8 | cat< "$WORKDIR"/k/kdc.conf 9 | [realms] 10 | LIBSSH.SITE = { 11 | database_name = $WORKDIR/principal 12 | key_stash_file = $WORKDIR/stash 13 | kdc_listen = $(hostname -f) 14 | kdc_tcp_listen = $(hostname -f) 15 | default_principal_flags = +preauth,+forwardable 16 | } 17 | [logging] 18 | kdc = FILE:$WORKDIR/kdc.log 19 | debug = true 20 | EOF 21 | 22 | cat< "$WORKDIR"/k/krb5.conf 23 | [libdefaults] 24 | default_realm = LIBSSH.SITE 25 | forwardable = true 26 | 27 | [realms] 28 | LIBSSH.SITE = { 29 | kdc = $(hostname -f) 30 | } 31 | [domain_realm] 32 | .$(hostname -d) = LIBSSH.SITE 33 | 34 | EOF 35 | 36 | kdb5_util -P foo create -s 37 | 38 | bash "$WORKDIR"/kadmin.sh 39 | 40 | krb5kdc -w 1 -P "$WORKDIR"/pid 41 | 42 | # Wait till KDC binds to the ports, 0x58 is port 88 43 | i=0 44 | while [ ! -S "$SOCKDIR"/T0B0058 ] && [ ! -S "$SOCKDIR"/U0B0058 ]; do 45 | i=$((i + 1)) 46 | [ "$i" -eq 5 ] && exit 1 47 | sleep 1 48 | done 49 | 50 | bash "$WORKDIR"/kinit.sh 51 | 52 | klist 53 | exit 0 54 | -------------------------------------------------------------------------------- /tests/keys/certauth/id_rsa: -------------------------------------------------------------------------------- 1 | -----BEGIN OPENSSH PRIVATE KEY----- 2 | b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn 3 | NhAAAAAwEAAQAAAQEA0DehrU/ohoimMKojFXdo1uEAcqx4fS87AjDUz8t4s436ppP+0+U3 4 | +qrhOCE/mXZvXewjTHltmEtCHNSbsWhYTjwrEQUDRNOVahn2PEQTcX/9itvsv9PX79Imbv 5 | ZsLR0f1FsmorkWpnDQmuga7hYBFBj4sV+VML5ieoK2OraUEq46ILsxqRgUTetkErlzX7S2 6 | SPE7vNM0ahmA+HNBuKNUD+BOtCzkqN54flGA9TZ7kapC7xqiRHK+ZzahQ2PFR4BxbVP1uT 7 | DsanbjKOpBC4hISao3hi4iUnyj0gJ8itmkhQS+oI/2KWSGW01/k9W7jOUXDSt7LGUTSW6s 8 | ILYHzmefCwAAA9B/6IFvf+iBbwAAAAdzc2gtcnNhAAABAQDQN6GtT+iGiKYwqiMVd2jW4Q 9 | ByrHh9LzsCMNTPy3izjfqmk/7T5Tf6quE4IT+Zdm9d7CNMeW2YS0Ic1JuxaFhOPCsRBQNE 10 | 05VqGfY8RBNxf/2K2+y/09fv0iZu9mwtHR/UWyaiuRamcNCa6BruFgEUGPixX5UwvmJ6gr 11 | Y6tpQSrjoguzGpGBRN62QSuXNftLZI8Tu80zRqGYD4c0G4o1QP4E60LOSo3nh+UYD1NnuR 12 | qkLvGqJEcr5nNqFDY8VHgHFtU/W5MOxqduMo6kELiEhJqjeGLiJSfKPSAnyK2aSFBL6gj/ 13 | YpZIZbTX+T1buM5RcNK3ssZRNJbqwgtgfOZ58LAAAAAwEAAQAAAQEAxjzxFU0LGWtortSN 14 | apaxnkPCZWuHm8gn6kILm3shg/IdPhORfrSxw1qF6ybcooN8LHPyd5D0oxaj70cMpK+vw2 15 | zNo/qdzh2UF9x375Dw4hL1lgslMM3EvXPbW7IJ9DnSYCAYfLyzr+ug8JsjaKJSjIvp2xYh 16 | uLLKl9FzJhtGhzDaJr9FCbSmd5R7Telz4En0Lwo/VxYvyzCoRwzhVUVqJZpdtF7/1du4tT 17 | agfPzPYY9zM9muR7AawtzMc4UFvMzl1OtjOHYtqSMVBZx44fRpXT3/fy7A98+7erd0zTWj 18 | s6gaz6I8VmRPk4iTdBH4KBzC8dGZQNMrY9SQ/ZANet8eYQAAAIBI8hS6bX00NpNXwOaEqr 19 | jZKf/u1W71KHpYBAY1w3xanGqPVOX5PEsFH6NLjqSLF75Bk22pvJvZ8EAaoISyvLSqqO5t 20 | 1vvjCjVKALSaVIFDcA20NpCXRugmVT1HeQNKHCTt3yOoraL8Sh9wlRbxLmlxgISYS6uH6e 21 | dEPa6qFshMVwAAAIEA7RFx7+mZJfrSJUu9pYiZJc6+Ns2WrSA2mgI+mIhWqreDK4Kw0a5g 22 | akqD0mb9oPHySnf3lCe+17yqNxH2fcX0G3B5LxiRnFVNm2wC4ZGvb+yMU2+0uSI/Sf8L1N 23 | sfWm+z4VC93Qhe0fIpuk8JAMNOwCvFcEFu5rr9sxHtPWjWtj0AAACBAODYXjs6jqsvW+3P 24 | e0efFp9kIezi8CejSxVXX0/zmWMCpTw1laiUmK41coKTKBSDZcNgrsF/ns1uCrPg6C2u/y 25 | evF8J+DeqU3vo1QhnRAJA2fLZk1Dr/GfAsp9mS9w6FdIQiQjQ0f/X9rYgAr9x4qMogYgrG 26 | zkb7k6FUoGgD7sbnAAAAE2xpYnNzaF90b3J0dXJlX2F1dGgBAgMEBQYH 27 | -----END OPENSSH PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /tests/keys/certauth/id_rsa-cert.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa-cert-v01@openssh.com AAAAHHNzaC1yc2EtY2VydC12MDFAb3BlbnNzaC5jb20AAAAgllK1Wz9hM1kUks5QXU/vXbDmzpQWMtFWObMvi9ymg38AAAADAQABAAABAQDQN6GtT+iGiKYwqiMVd2jW4QByrHh9LzsCMNTPy3izjfqmk/7T5Tf6quE4IT+Zdm9d7CNMeW2YS0Ic1JuxaFhOPCsRBQNE05VqGfY8RBNxf/2K2+y/09fv0iZu9mwtHR/UWyaiuRamcNCa6BruFgEUGPixX5UwvmJ6grY6tpQSrjoguzGpGBRN62QSuXNftLZI8Tu80zRqGYD4c0G4o1QP4E60LOSo3nh+UYD1NnuRqkLvGqJEcr5nNqFDY8VHgHFtU/W5MOxqduMo6kELiEhJqjeGLiJSfKPSAnyK2aSFBL6gj/YpZIZbTX+T1buM5RcNK3ssZRNJbqwgtgfOZ58LAAAAAAAAAAAAAAABAAAAE3RvcnR1cmVfYXV0aF9jYXJsb3MAAAAJAAAABWFsaWNlAAAAAAAAAAD//////////wAAAAAAAACCAAAAFXBlcm1pdC1YMTEtZm9yd2FyZGluZwAAAAAAAAAXcGVybWl0LWFnZW50LWZvcndhcmRpbmcAAAAAAAAAFnBlcm1pdC1wb3J0LWZvcndhcmRpbmcAAAAAAAAACnBlcm1pdC1wdHkAAAAAAAAADnBlcm1pdC11c2VyLXJjAAAAAAAAAAAAAAEXAAAAB3NzaC1yc2EAAAADAQABAAABAQCnA2n5vHzZbs/GvRkGloJNV1CXHIS5Xnrm05HusUJSWyPq3I1iCMHdYA7oezHa9GCFYbIenaYPy+G6USQRjYQz8SvAZo06SFNeJSsa1kAIqxzdPT9kBrRrYK39PZQPsYVfRPqZBdmc+jwrfz97IFEJyXMI47FoTGkgEq7eu3z2px/tdIZ34I5Hr5DDBxicZi4jluyRUJHfSPoBxyhF7OkPX4bYkrc691jeIQDxubl650WYLHgFfad0xTzBIFE6XUb55Dp5AgRdevSoso1Pe0IKFxxMVpP664LCbYK06Lv6kcotfFlpvUtR1yx8jToGcSoq5sSzTwvXSHCQQ9ZA1hvFAAABFAAAAAxyc2Etc2hhMi01MTIAAAEAeI9eUAWyL5DVWBj0vU2kKdGxMXQx1Y8R68DXwXhnxfLwilJPa6IFg+g988lpF5aZzvAiX6TgDtJAhzfuBU+ZREGfdclUQIpz3xwDG76Gmg/DpQHdmqU76n2Na32s6+4SsSmWWKx6cPPdjbCRS0VMSrMohLuDyPGMoC7RjLfDDxqW5TIbMtqQdOiPl/0PpR73Q0FjB50Ec12buQDkExlEOi2Y+yB830vuTJN3ds7bx6NXM1Jjftg/8D0SzNRAIYDQFnpyXKO6kNrN66o48E3mrnVHXuFBTf+kpdYrK+1LKQVk/hVLBHr+NuVmQltL0zcjJfiXj7i5ZqcsqR1UAU5hKg== libssh_torture_auth 2 | -------------------------------------------------------------------------------- /tests/keys/certauth/id_rsa.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQN6GtT+iGiKYwqiMVd2jW4QByrHh9LzsCMNTPy3izjfqmk/7T5Tf6quE4IT+Zdm9d7CNMeW2YS0Ic1JuxaFhOPCsRBQNE05VqGfY8RBNxf/2K2+y/09fv0iZu9mwtHR/UWyaiuRamcNCa6BruFgEUGPixX5UwvmJ6grY6tpQSrjoguzGpGBRN62QSuXNftLZI8Tu80zRqGYD4c0G4o1QP4E60LOSo3nh+UYD1NnuRqkLvGqJEcr5nNqFDY8VHgHFtU/W5MOxqduMo6kELiEhJqjeGLiJSfKPSAnyK2aSFBL6gj/YpZIZbTX+T1buM5RcNK3ssZRNJbqwgtgfOZ58L libssh_torture_auth 2 | -------------------------------------------------------------------------------- /tests/keys/id_ecdsa: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PRIVATE KEY----- 2 | MHcCAQEEIHbL0nzpzLS3ImIlhEffbDzPlIw/tn5QcfB64PbSiBl6oAoGCCqGSM49 3 | AwEHoUQDQgAERzA8X8OP7C3W/e1UNLh+21xIZVBiQ7i4Qb4xoOebRWuwzitEZon/ 4 | 8Dz+VpE29krJgCagqSt5RLllOx8eS2i8fw== 5 | -----END EC PRIVATE KEY----- 6 | -------------------------------------------------------------------------------- /tests/keys/id_ecdsa.pub: -------------------------------------------------------------------------------- 1 | ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEcwPF/Dj+wt1v3tVDS4fttcSGVQYkO4uEG+MaDnm0VrsM4rRGaJ//A8/laRNvZKyYAmoKkreUS5ZTsfHktovH8= comment 2 | -------------------------------------------------------------------------------- /tests/keys/id_ed25519: -------------------------------------------------------------------------------- 1 | -----BEGIN OPENSSH PRIVATE KEY----- 2 | b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW 3 | QyNTUxOQAAACCLo6vx1lX6ZZoe05lWTkuwrJUZN0T8hEer5UF9KPhOVgAAAKg+IRNSPiET 4 | UgAAAAtzc2gtZWQyNTUxOQAAACCLo6vx1lX6ZZoe05lWTkuwrJUZN0T8hEer5UF9KPhOVg 5 | AAAED2zFg52qYItoZaSUnir4VKubTxJveL9D2oWK7Prg/O24ujq/HWVfplmh7TmVZOS7Cs 6 | lRk3RPyER6vlQX0o+E5WAAAAHmpqZWxlbkB0NDcwcy5qamVsZW4ucmVkaGF0LmNvbQECAw 7 | QFBgc= 8 | -----END OPENSSH PRIVATE KEY----- 9 | -------------------------------------------------------------------------------- /tests/keys/id_ed25519.pub: -------------------------------------------------------------------------------- 1 | ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIujq/HWVfplmh7TmVZOS7CslRk3RPyER6vlQX0o+E5W jjelen@t470s.jjelen.redhat.com 2 | -------------------------------------------------------------------------------- /tests/keys/id_rsa: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEogIBAAKCAQEAs/fIz+Gy89XjUhXebNq2rs1K0RJEZXDbfcofb13ESDJ9fSbd 3 | +RlCUM6i+foEVV23xWdands2Bkn72tGinJadIgOWU+koxp+gRmtJLE/ONiAKJQqR 4 | K3eOJNBH6At96NMqJ4Gwv56G4W68uPgDwUVQwVIc6Ec6Rypiz7DE+S++gSvBQIVU 5 | Qt7XkPcXOyN5zuj5qDhZM4l6V7Og9LWj4/2IF5acvKjfIMpeqmnp9z6BTYZQtuQU 6 | 6b1VuEYhXyvM6LkMwndsVGh46kDKMmRQhyA8A6qvLAliMMq88k5gR4AeJeTnqDR/ 7 | Q120I6PMqYNl6TLTk8/KonOOPDR/XXGb3iF67wIDAQABAoIBAAVoL2dXf5nl1jOU 8 | Jp+cnpp33oSTiOyHTIDl/rXI2mnU4oJNFaQzRxPIcYsTIOgzrZ7HsShG+sOLm36C 9 | h+EugUARXYXd3nTBPP6AoK0tJKPpqIReYegtal7exxpIphrFpWGUeuv25lSFkDP6 10 | d5pp67gzMF0mLrEOq/NTe0eFULLuwa6+IKXU7deiU90pzi4jrjcIWNoGHSw1YYAZ 11 | TC8KAxA/tYH9myya5krRCjA9B345DJ9Wd71wX+RZNgbSkIri/6dDTtvsYvqcQKo0 12 | OZ3MUDJnKmkfPLP84qZPRoEwUI1gts1WUdoNK6LK7yOJmPL5FMyTwZx3XtDw3gAv 13 | TVhI7ikCgYEA5Ay0TCySPQAaC14WtjgIAmTa19mAtOFpbRxToi40WjXk3R6mMqyp 14 | biAcNecdZRC6zzgAUp8g1O3Yc1d9fG/3FpM5eUbIer7mMLTRuQQysoJY2Ayw9OEA 15 | qPHS/K6LPOD09aZo14fRUqVO8rwMbHtq2yhH8p3FM8WZRe5ms8zpyLUCgYEAygZ3 16 | RTMWbgcGdNoaPa5Ms9KRqAxKJLin2fE99KowZeJfvZN24sXExawQdy4BKVYT0H6e 17 | MNEIPiEBVA4a1GDk/tyOrEt684IsidROngJaGbqb+SYm6feQAioYu0wkG/I2hS12 18 | /Z/aK6wFz5hWzBv/YvJqC7xD1YwZm1QXDyAiL5MCgYAXz8fHqGPAoNEXXMSsVB9p 19 | +JPtM9W/jUXP0cRdy8tFnBkAiaG66tJqIEoxyqcEFYIb/vHxrpHkCc2vBXSh2KMJ 20 | JWg75IssXeB1N3wqgGi2wOt7659SgmfqPA3WunbpbWfGepC56IGPypj6uW3mqeBX 21 | b9ZLW/PqWviNF757iarjfQKBgGxKBPqRxM8bcumF0xUG7dRh5XN3ivKeDFL1Tels 22 | pF6odftPJSWvLqdqcLUBctvuaNaUWEUAdvOei3C70sPOYFEAdnWCTBhkyWzj4XQu 23 | /I7YCS0Gt0soSQfv+qvCx4Q3U+QVF7ghTDemkMLS/IuR4lXubMt3kcDQxRUOgQG5 24 | jrmDAoGALauF7ZyzEnQgsgMVzfm9znl5I2aIsLgdsAv3lINVrvtTKhddp7cdd+2j 25 | dwZlaMnLET/3MY/Cvf13vEsS+bdNXjsdQidqBL8pe5PXY/pafBhtduQuvGzlHJA5 26 | CEBnwB0SdtsXbzSpOAPZqea4Nz9MkQ8LMsINdPpxCuFhjeYa9Ow= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /tests/keys/id_rsa.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCz98jP4bLz1eNSFd5s2rauzUrREkRlcNt9yh9vXcRIMn19Jt35GUJQzqL5+gRVXbfFZ1qd2zYGSfva0aKclp0iA5ZT6SjGn6BGa0ksT842IAolCpErd44k0EfoC33o0yongbC/nobhbry4+APBRVDBUhzoRzpHKmLPsMT5L76BK8FAhVRC3teQ9xc7I3nO6PmoOFkziXpXs6D0taPj/YgXlpy8qN8gyl6qaen3PoFNhlC25BTpvVW4RiFfK8zouQzCd2xUaHjqQMoyZFCHIDwDqq8sCWIwyrzyTmBHgB4l5OeoNH9DXbQjo8ypg2XpMtOTz8qic448NH9dcZveIXrv asn@krikkit.cryptomilk.site 2 | -------------------------------------------------------------------------------- /tests/keys/id_rsa_protected: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | Proc-Type: 4,ENCRYPTED 3 | DEK-Info: AES-128-CBC,0B181CC88F75C33B7DEBE5C18B481F18 4 | 5 | rYtUw8FhEv48JmNTm3i1TEqEgElC629iaMQu/YzRV5zL/n83HwMKbRpAZ31Cch2a 6 | 8thZRQ6YsL/56vr+fKKVgDF7y3wmStp5sVkOQXMeZ9D746ZEGcYGnYH8JQhibDDB 7 | sTK2kQrmBERg7H8rOoNCzxxoK+VZl2Z+S+yLVq0//qxBfuluZwCdk9Tie69Cd/Dk 8 | PeBjOVPnFCavCKCWpUs/So8VQq9jXG84hRltwC0htSTEq+xfgNtS64f63WL6gEnB 9 | WZ5KSO1gyzKC5/YAB6LXPxIIVzfZYXiuOWV/t8DXZK/lvhqQ3gSyPZezSrX8wEMC 10 | xQeX41etQGjCcgxWH41iPCNTuoIKo2t/BPlfLJilJotmUSnYOxDmkZbLabuyS+0p 11 | WGtnEwFSrxQosx6u9GBHX94Ikex0bf00KzNpKExzAIRqTdesaviJ1QX/pRsvT/Xp 12 | TtH2aWV5kYNc+B+BrCQU7mlx/eEtXR2H5zJQxLSrTVKb1vUIHytufnPePk2BkcQ2 13 | CTE1xT+ZkUaY1WiCBxWgVTflL5FY9E6BerKEGVSfloso8tGCgsoO/Fch0Ho5/bXp 14 | T+3nQEY780KduKJ8xCJJDQgD8GbjNR6sCtcPrewqEsgrpAbJUKyXhU7klGC09zzI 15 | /JnNmdd10w2l/5A92GGrCgXnTYb8/w9J/qa6qyAAYU9/8rPo7ErGb7mKclmzz63j 16 | cksImoExfrr9CIr7wjrXFO0OoupmMegNOZtgwsN7i0FI8vWYc6a3IaFWSWfE29Ux 17 | rw9TK9L9pDvhCqS/WjW86S25muqnTSMQ/bhmiPw8z8tOjdi2YRqNcU2TyWoB2Mct 18 | W+w9G5dSukMwkXQ2RNjDo2GfuXLXpUe5zCVixI2wxYGvIqTGkDZn/u1Jdxy1IxNc 19 | qEsEZAOCVnJU1cQpB9ENsyrRUIsdQVWNQSvsUZz2XSELULwIFTcCTHr2PAJ5xzZ6 20 | VQy3DGEpZf7+yGACoi8LY8f5Ve5C9NciyA4/C/uvOUd7PhAf4g41mKw8+bAr8NFt 21 | ubeXTo0iI29FkmmebfM1sRBHvomGT7qYsHBW2pgqBrm3X9kFcQ9EFhr6S2ULMcIn 22 | 4iX1mbqvC0c1CUmZakkNg94FQp2zbUclAuDkg3BTA0gwbyudvx0ccBmzQ43/6AJ5 23 | xz1hrfusX5Vcjz6+i5WHJDK/mlUDwTV5GAhcmar9eEcFXJEosD+mrAalflz3Vc2X 24 | 5A9plGfKkaFdth8YUGjLr+O2O5ggkDpCMbjYo4HQ6/dslYvqvnavJYrRKrEZbtvj 25 | 8fR5E11tPrK1aKzPHO0VLKf4UHs57JNqicSlYGy78FSCPG4d17KQlFyzbXsfbsvp 26 | 9EQK4N2jwRNZAOHuTuoqQ8TNzDahdlmbBS2Akd3rVV9H1/eNeN3r6Demww+yixoy 27 | uPhjofn0P28eH7Gqiyhh20QYYqG7aky9IYMPnIBtA1hJp9MtMa1m8aHGxxZrUigj 28 | S62Q34JzA8A6Rwc2kTHRzXG2o6oQ3vCQfy0JGlmDlG2yofcn7YgrMCv+srTniuiA 29 | YBnOeic5cllYnDB9bpF2kufJT6CigoxP18HIw+jhYabuOTHO67MYf2En+is8vlQS 30 | -----END RSA PRIVATE KEY----- 31 | -------------------------------------------------------------------------------- /tests/keys/id_rsa_protected.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCz98jP4bLz1eNSFd5s2rauzUrREkRlcNt9yh9vXcRIMn19Jt35GUJQzqL5+gRVXbfFZ1qd2zYGSfva0aKclp0iA5ZT6SjGn6BGa0ksT842IAolCpErd44k0EfoC33o0yongbC/nobhbry4+APBRVDBUhzoRzpHKmLPsMT5L76BK8FAhVRC3teQ9xc7I3nO6PmoOFkziXpXs6D0taPj/YgXlpy8qN8gyl6qaen3PoFNhlC25BTpvVW4RiFfK8zouQzCd2xUaHjqQMoyZFCHIDwDqq8sCWIwyrzyTmBHgB4l5OeoNH9DXbQjo8ypg2XpMtOTz8qic448NH9dcZveIXrv asn@krikkit.cryptomilk.site 2 | -------------------------------------------------------------------------------- /tests/keys/pkcs11/id_pkcs11_ecdsa_256: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PRIVATE KEY----- 2 | MHcCAQEEIHdAXnAQz7Xy1DSC74tj4oPqcMFNld9f6sw/mnalVEjloAoGCCqGSM49 3 | AwEHoUQDQgAE5a5++ALfsz8CYb2pAzlWlj6ookcas3UmHaOsictgRgl7Nqdd9vTq 4 | QPQSbF4oRMhSbfTlqO924OJwzc1WaYKnFw== 5 | -----END EC PRIVATE KEY----- 6 | -------------------------------------------------------------------------------- /tests/keys/pkcs11/id_pkcs11_ecdsa_256.pub: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE5a5++ALfsz8CYb2pAzlWlj6ookca 3 | s3UmHaOsictgRgl7Nqdd9vTqQPQSbF4oRMhSbfTlqO924OJwzc1WaYKnFw== 4 | -----END PUBLIC KEY----- 5 | -------------------------------------------------------------------------------- /tests/keys/pkcs11/id_pkcs11_ecdsa_256_openssh.pub: -------------------------------------------------------------------------------- 1 | #ecdsa public key in openssh format for authorized_keys 2 | ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBOWufvgC37M/AmG9qQM5VpY+qKJHGrN1Jh2jrInLYEYJezanXfb06kD0EmxeKETIUm305ajvduDicM3NVmmCpxc= sprasad@linux.fritz.box 3 | -------------------------------------------------------------------------------- /tests/keys/pkcs11/id_pkcs11_ecdsa_384: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PRIVATE KEY----- 2 | MIGkAgEBBDCM82jhy7V0k9pYkhGeqk8xYcH72RgLnLmhY/9nuq5+9+e6bZr6sdR+ 3 | ZYknMIZB4rmgBwYFK4EEACKhZANiAAT/c5JrFJK9xmqVZpuDWcOULHYwnmdjBfa9 4 | 7W17gxC5m6armE67TQGD/3KwI7k7+3ngqGsYuA9UWSiyZxuhIa0FMegEN+hGylp6 5 | H/LokPiBQX7FMImJEHRMTr7ti9OJxYU= 6 | -----END EC PRIVATE KEY----- 7 | -------------------------------------------------------------------------------- /tests/keys/pkcs11/id_pkcs11_ecdsa_384.pub: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE/3OSaxSSvcZqlWabg1nDlCx2MJ5nYwX2 3 | ve1te4MQuZumq5hOu00Bg/9ysCO5O/t54KhrGLgPVFkosmcboSGtBTHoBDfoRspa 4 | eh/y6JD4gUF+xTCJiRB0TE6+7YvTicWF 5 | -----END PUBLIC KEY----- 6 | -------------------------------------------------------------------------------- /tests/keys/pkcs11/id_pkcs11_ecdsa_384_openssh.pub: -------------------------------------------------------------------------------- 1 | #ecdsa public key in openssh format for authorized_keys 2 | ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBP9zkmsUkr3GapVmm4NZw5QsdjCeZ2MF9r3tbXuDELmbpquYTrtNAYP/crAjuTv7eeCoaxi4D1RZKLJnG6EhrQUx6AQ36EbKWnof8uiQ+IFBfsUwiYkQdExOvu2L04nFhQ== sprasad@linux.fritz.box 3 | -------------------------------------------------------------------------------- /tests/keys/pkcs11/id_pkcs11_ecdsa_521: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PRIVATE KEY----- 2 | MIHcAgEBBEIAIFhJ0TIwP+05/nqBcBIit6DoynzszbP5B7K8tk6d+R741dByNe7x 3 | lsXvKpHkZ+oGn575LQmCJ1BQ+BENxj0G+b2gBwYFK4EEACOhgYkDgYYABADI9DFD 4 | 5j3ibs7pr0NRqf4AzMwq4J+OlvBl60fWGiNVvCsC4EQL99TAGcx8VryXybJZ9fmG 5 | C0obHdEYXaRddOpOQgGLzYGTYFzQmF91PLNHIUb1K2IGUN8V8Ehr9qYMGcF/2HFN 6 | VJ/7Iievz67wKcaVJiAoJ7zNpKpFE1fEUHqQSc9vdA== 7 | -----END EC PRIVATE KEY----- 8 | -------------------------------------------------------------------------------- /tests/keys/pkcs11/id_pkcs11_ecdsa_521.pub: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQAyPQxQ+Y94m7O6a9DUan+AMzMKuCf 3 | jpbwZetH1hojVbwrAuBEC/fUwBnMfFa8l8myWfX5hgtKGx3RGF2kXXTqTkIBi82B 4 | k2Bc0JhfdTyzRyFG9StiBlDfFfBIa/amDBnBf9hxTVSf+yInr8+u8CnGlSYgKCe8 5 | zaSqRRNXxFB6kEnPb3Q= 6 | -----END PUBLIC KEY----- 7 | -------------------------------------------------------------------------------- /tests/keys/pkcs11/id_pkcs11_ecdsa_521_openssh.pub: -------------------------------------------------------------------------------- 1 | #ecdsa public key in openssh format for authorized_keys 2 | ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBADI9DFD5j3ibs7pr0NRqf4AzMwq4J+OlvBl60fWGiNVvCsC4EQL99TAGcx8VryXybJZ9fmGC0obHdEYXaRddOpOQgGLzYGTYFzQmF91PLNHIUb1K2IGUN8V8Ehr9qYMGcF/2HFNVJ/7Iievz67wKcaVJiAoJ7zNpKpFE1fEUHqQSc9vdA== sprasad@linux.fritz.box 3 | -------------------------------------------------------------------------------- /tests/keys/pkcs11/id_pkcs11_ed25519: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MC4CAQAwBQYDK2VwBCIEINATLZmMLR6HQ2076Uj6VQDYcxPIXrBV2TLU9UyJZSpK 3 | -----END PRIVATE KEY----- 4 | -------------------------------------------------------------------------------- /tests/keys/pkcs11/id_pkcs11_ed25519.pub: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MCowBQYDK2VwAyEA3VoMJl9A48CsizGdLy4yKltC2Mz8UPvv6GmTKj2L3lY= 3 | -----END PUBLIC KEY----- 4 | -------------------------------------------------------------------------------- /tests/keys/pkcs11/id_pkcs11_rsa: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEowIBAAKCAQEAqsV/cOD8KGdJfTEZ+hemwBONeWEVZQsY05EorJ7prWcrRyHs 3 | wg3+AhwFGW17HVKBt2hgJSnmAbU6dYZ/2t4OYWvCCGIBGSbMQldfesuZ160OEu0i 4 | FCVZinAeUVn10iTxwMOM6oUQY75UF5tKg72WGuY5x5zolPAyDXkK0aJ/ZHB9dmfG 5 | v0zjutY2aURGYK+dzNT/xzFsKRQiBc7ROi5eMkXNpK+wgqFrs5Ydpj+xiGt6sowb 6 | 114hF6YyVdXpNw+EQrYqpFVRahUDxo2qFBFqXVrCJrmtdFf6Z03FnGwRnFumLVsc 7 | 1P9SLVIk4OFh9KndHIevCfj3vfFgQo/A1RzZqwIDAQABAoIBAF9/9xb/GsTVjilu 8 | ziIoG96KkLFyc26AWC/om6B9dhy891zeQfL7tDMlzEw+B32MaHJS8oGV/sSxvrF+ 9 | t/2D9PLSOj5J4GdaZRwslH6tYalVY+t9pXMyt/JNZQcFkg0lD/VG5oU4SMQe6hQR 10 | ighGe60rVuCkhQTVlogmSsCVaTyXKa5oUeZCIaO5gxxvTYsgZiF+U/wsmzoRm1kY 11 | WlqwqA3KM0p/AtFUNQD0iS3zoALwwsYg6MID657IbyyjEcnwpss+3hMV2SnQNpYY 12 | +sBccnS8YCGHkA/KYc0e1gUmFhQkTzeSnhgFg/W7JdTJdyHKCiisNMpWOtqtXano 13 | fiXFClECgYEA3dEMsF2AA5m14V68907J1Wi3Pf9cInmsrDlxpGcdyJiii4zeg1/w 14 | 6tLQ6H4+wFoRXTIcduNpZZS8al/zQXqQGH4A9Em38PLkOjPk5mdAV3KCv0LzMkPq 15 | IwgfBFBPRPUVUtfiydLpzqeTQZ6RxokqPy4JY4NEy22gfWsMhKq9YVcCgYEAxRan 16 | Ax0GnTpnZ9hYcJEi+fw7cmK6bX/fVzaNSqSirWNOgjlw1IHt/zp5jylW1HDbk7zJ 17 | 5fLnS78fm5WWq2Ov/U71C8KClKVWecKbdYDtuHs7VPM6b1jee/EUqkZevj+vPp4A 18 | 2vITwPCUk2EMwuPs8kcEwohfgbS3erNfBkDl8c0CgYAGzLa/3U3kTlz1+KqARkkH 19 | orsjSmWvpN03NleWe5a9JHivIHVdv54qBKZkyiHwUZKAsd2Pg28irwmLlT9mvXQX 20 | XB15X50k5L08T4TvzzB4vcjmRg4gd1aBFmmk/zU+3uh1bqrEFxQVwqtP8qVzWZcS 21 | 8r1U8Jw2RDkMPzDWDEnb5wKBgQCjxtsqXyhr52iehs2XXUQvcEcGGrzI2YYCtzZa 22 | XM1CQE+xL4JvVTks6q6xJK0fBFmzPyKXj25dJ4lghMIb0k8gtEg1aYGRfIOL0wfU 23 | cTsaHm2DfkuE09iuLfv6M1fvyIQcCLi1OIzpvAH7Jp6wJS91dUajUSfsZPxDXmMM 24 | k0mB0QKBgB2cD2IMG2d3dOOoBbIw8NvVDR6bpdF4DdYJlCpGa7sfzw3y9yXnejzW 25 | HQUZGvgvhMsMe9LolS0jE6D2MyOsZF3CPFLuDVemfMxDJRTqvsRAjuEPlz6co/uZ 26 | ZVKlh/bW/iakKpaW9vSF1dNwiyWJhzVkutBho3FzZKZSbIkfFztB 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /tests/keys/pkcs11/id_pkcs11_rsa.pub: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqsV/cOD8KGdJfTEZ+hem 3 | wBONeWEVZQsY05EorJ7prWcrRyHswg3+AhwFGW17HVKBt2hgJSnmAbU6dYZ/2t4O 4 | YWvCCGIBGSbMQldfesuZ160OEu0iFCVZinAeUVn10iTxwMOM6oUQY75UF5tKg72W 5 | GuY5x5zolPAyDXkK0aJ/ZHB9dmfGv0zjutY2aURGYK+dzNT/xzFsKRQiBc7ROi5e 6 | MkXNpK+wgqFrs5Ydpj+xiGt6sowb114hF6YyVdXpNw+EQrYqpFVRahUDxo2qFBFq 7 | XVrCJrmtdFf6Z03FnGwRnFumLVsc1P9SLVIk4OFh9KndHIevCfj3vfFgQo/A1RzZ 8 | qwIDAQAB 9 | -----END PUBLIC KEY----- 10 | -------------------------------------------------------------------------------- /tests/keys/pkcs11/id_pkcs11_rsa_openssh.pub: -------------------------------------------------------------------------------- 1 | #rsa public key in openssh format for authorized_keys 2 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqxX9w4PwoZ0l9MRn6F6bAE415YRVlCxjTkSisnumtZytHIezCDf4CHAUZbXsdUoG3aGAlKeYBtTp1hn/a3g5ha8IIYgEZJsxCV196y5nXrQ4S7SIUJVmKcB5RWfXSJPHAw4zqhRBjvlQXm0qDvZYa5jnHnOiU8DINeQrRon9kcH12Z8a/TOO61jZpREZgr53M1P/HMWwpFCIFztE6Ll4yRc2kr7CCoWuzlh2mP7GIa3qyjBvXXiEXpjJV1ek3D4RCtiqkVVFqFQPGjaoUEWpdWsImua10V/pnTcWcbBGcW6YtWxzU/1ItUiTg4WH0qd0ch68J+Pe98WBCj8DVHNmr 3 | -------------------------------------------------------------------------------- /tests/keys/ssh_host_ecdsa_key: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PRIVATE KEY----- 2 | MHcCAQEEIB9v2n1oaXvBECf0gDPxTibeUPvvkI1anNWDAIkNjs5JoAoGCCqGSM49 3 | AwEHoUQDQgAEqkTqNu7gRegPJRy0WiseJz9NAdBimzyNSzNwI5eAkEqv9D6Y95KL 4 | 7DBEnDQ2p08iOLw+vN1PKHsCM7b/ONbYVg== 5 | -----END EC PRIVATE KEY----- 6 | -------------------------------------------------------------------------------- /tests/keys/ssh_host_ecdsa_key.pub: -------------------------------------------------------------------------------- 1 | ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKpE6jbu4EXoDyUctForHic/TQHQYps8jUszcCOXgJBKr/Q+mPeSi+wwRJw0NqdPIji8PrzdTyh7AjO2/zjW2FY= asn@magrathea 2 | -------------------------------------------------------------------------------- /tests/keys/ssh_host_key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/libssh/a2e4e969cf160789abaf0100e85b1a6c342d5d7e/tests/keys/ssh_host_key -------------------------------------------------------------------------------- /tests/keys/ssh_host_key.pub: -------------------------------------------------------------------------------- 1 | 2048 65537 25221975523736997039149017470335977198642717886559395625730372192276493838727011206749822289920387480933533054627057418868711378045090730895752530916661328094497437687453813456961487210492465678475508526337829331199296553120728607984859224949182503917312492825658971738208505685553964707412720244524969161284321098487507924676797222812771309962906894332072854924265623785469343453142982185436565166155021228521252914913227554455102103918367844210755391318078654400527927267478149210805219779896806429660492177158822689909493046725157917529664436252598971135251689616517266344945600782273453037452082373553352939812279 asn@magrathea 2 | -------------------------------------------------------------------------------- /tests/keys/ssh_host_rsa_key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEowIBAAKCAQEAqzabeU0oKbHDwdlqindABvtzgWCvXdHJ+d2Ew6te2LXjkwju 3 | y7u6B7y63NZRy57ccrE4YSeWItVoZn+DWN+guU354Ss/tzQ9/thUmLrvtKNvJwuF 4 | F5Ch7Q4BsrXGsb2GSv+7W5tpx3yAqH1TvKQj/MmQVX+/9KtXEnh7/vpiCqoOXQAR 5 | zvIIQxoo1aUQBHAkRW7Yw0Ds7AjC9uV1ns4xdBXPQmDk23pWvCq7E+7rOEbKRrjj 6 | lApS4lJYy0oEXsFdqUPd+PtT1gG0nIElHFQtsTgUvwYQmJEzrBxv41odwRvxbMjg 7 | THPr4SLRRRSuPwICWyvxqPpa7EsfMBnbPEIUzQIDAQABAoIBAEUO15MLvgFjRDQy 8 | P7jt9JNcZPBwUQukjLUN1nkd7Dm407wAxGDErXplc3GTuJZK01wngzgcwX/3WA7P 9 | q+jy+l8DxqA904tPtRnPo/+elwTjTvgOu3YPzmBRX/n3O9eBPGOP1sBSZU4jN7m+ 10 | I0JZanKR0nfJ+WD0o0A9/LWRxG3MFIntBamtT6pgee8sAu44IvW0o7tHJabMq02J 11 | Z/ndrJmox34wq6SMFANax+N1x9sZa60bL7gEoDWQJNKOaMrbtOaIoTGFIc4hFqoA 12 | SzjNqcGsHPWs44cw0mNkUGq37jEvaCwzAp+U80ma1skBhXuJL9sQOxl1v5qW91c/ 13 | Cnm5WYECgYEA4DPvqbLt+VdyTtmCQ370yiCk4OPPMPzbM65IVKgQL/rN6HdNShTO 14 | uLF6P8XC8vNP2OSydJeFt+kMKd7E/4o5LfvEqUGXZJDkB7fLjrOjyZU3bxtIx95x 15 | qYGWRcWbd3sHzlBJGuFVSE7GREE+lqhkSu4ry4l/GAKxSymAXgGd/9ECgYEAw37L 16 | ppZIavcLE2rZgXHoqMiJzeGzsidJbkHss4k7ubLe8vyBMiv0HC2anxPa2+yNWuF2 17 | +pEr84bllh149VKeild24UEBAR2w/P41ggWqiUP7PKllh+huWzG4+KNFbfUP4dd0 18 | 4LkVgfsCz32qD8qxXNCxJCZ8H2fmjKsYw/oCID0CgYAiuSh3GdUtdtOnTpyUI4d5 19 | /pBKnD2skpzIZkehhN3s8GUPidqYjJxvkl0in1hQFErbhp/02rrE/vz5Rx0vjpLI 20 | gmO06wmtc5s9bsPB+CR3xfpt5MXi3pqv6/gAGli3qoBM/bY0yY1Rw5GFZK1y2+Wc 21 | jUKPJV5fs5sNzwGojYuQ4QKBgQCNNgqOo2Fd+mLCvNyt1wTy3iBEWfL+DcjJ3s7G 22 | hKtioKTQqbn87qjercZRf/sH/t/ANLpHlhNETj2KaHGV6v7f+PvDC7xY/QR6SnmG 23 | GOetTTCuCcJwIGGOd+UfnHgrS+gT/xjKtoalpBXMoP31eDkTTR+XeEESQm/TTkeO 24 | UAm3FQKBgD8Y7CLHpyZZ+eOnxRSPU4m4AWAEp7JOwHDRWWQeUornrXDYgD87d2M9 25 | iIAEuOzNggA56Nm3AzBOPRj4HkBh57ToVKPswHwB0oWvrtSjpLkkU6q8xRG3XuJD 26 | 2AskDaZONzIDoJGfZ3+W7YbKELK7DPtFXL15sOfBmpoEkI9RA5vM 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /tests/keys/ssh_host_rsa_key.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCrNpt5TSgpscPB2WqKd0AG+3OBYK9d0cn53YTDq17YteOTCO7Lu7oHvLrc1lHLntxysThhJ5Yi1Whmf4NY36C5TfnhKz+3ND3+2FSYuu+0o28nC4UXkKHtDgGytcaxvYZK/7tbm2nHfICofVO8pCP8yZBVf7/0q1cSeHv++mIKqg5dABHO8ghDGijVpRAEcCRFbtjDQOzsCML25XWezjF0Fc9CYOTbela8KrsT7us4RspGuOOUClLiUljLSgRewV2pQ934+1PWAbScgSUcVC2xOBS/BhCYkTOsHG/jWh3BG/FsyOBMc+vhItFFFK4/AgJbK/Go+lrsSx8wGds8QhTN asn@magrathea 2 | -------------------------------------------------------------------------------- /tests/keys/user_ca: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEowIBAAKCAQEApwNp+bx82W7Pxr0ZBpaCTVdQlxyEuV565tOR7rFCUlsj6tyN 3 | YgjB3WAO6Hsx2vRghWGyHp2mD8vhulEkEY2EM/ErwGaNOkhTXiUrGtZACKsc3T0/ 4 | ZAa0a2Ct/T2UD7GFX0T6mQXZnPo8K38/eyBRCclzCOOxaExpIBKu3rt89qcf7XSG 5 | d+COR6+QwwcYnGYuI5bskVCR30j6AccoRezpD1+G2JK3OvdY3iEA8bm5eudFmCx4 6 | BX2ndMU8wSBROl1G+eQ6eQIEXXr0qLKNT3tCChccTFaT+uuCwm2CtOi7+pHKLXxZ 7 | ab1LUdcsfI06BnEqKubEs08L10hwkEPWQNYbxQIDAQABAoIBACW2AaHgS5iVCtln 8 | LVVterKX+pyEVfu9N6cTMqpg4AbUiYGol0wBijTAUd1wo8s6zuiPLLb5BdwfPzLg 9 | y3IjMCzCUgy5mz4Dwr9JSThgFElgyb2y7LNbSDXOuLqrwtjgTqs6WhNfXMmzPw7b 10 | Rqw4mdPJ5u2k7BQO3NXfIhks4ISYzpzNAwj1a2NMphvkZyvfRnWiQ0pvEXQCxwuR 11 | 74iGpPFeyFjjku/O4TiHZllPmDdD3ERalkf8RIudQ5gcbL4fRoONTzfZHtmARWoP 12 | Jury4Zfr5b3VGSnkUDaGlzilXvBusAZOCaaU7chvOPVjXMbSAUEpFBmnRHk5dfrH 13 | fCXECcECgYEA0KMtV3IzwMToVdvzcMQc1ovDvKZAQPneLTxFgNpOeycOhzulzY9p 14 | 3fRi5QUOA/Ff+LcCL86APqwoEYe4bgam6mwGFFhv1usf4ulbLNk8ZeR51CG6emPt 15 | tLpg6PThxhMnNpu+StrBAOxeo9pZGd+Plt6d4vfoalOHVkPlSv7OC9kCgYEAzO1I 16 | HuZAQkVdKLGuZlf8E4VEaiMBKdl5+H+8w9peOOax6nqAIrwp2d0aZ52LDjwg7d3C 17 | eSmxu0U1jsbzexVVePr/NmdJOu3+gB0GvlzRjS1xT+MCZIye5a7Nxc7lBp5rFmgV 18 | dJTA6XXRoykinZIxz068SHqtNhNOzO4hUmPDN80CgYAlxOR4aBwmUX8dy+uOBnKS 19 | BEsy44XOPW2TEs4iPWLnuHJQ2ONzCvtHSu58NyYKYK/W/opOzTs6HUBDrCYfBOVC 20 | mrufA0N7zKTBFy2COPFOIMZNOK3haiWmCfdxNKOKj/0RTbBtLJyz5hZb4zMuE+KS 21 | lUpPxEE2vlhJrZDcurPiQQKBgQCIEqMKCX/vwVlLlTglsxSp7ZrxEw9Jt6O68y7n 22 | qc9Y3y6ScQc2iVUM2jkXRlA4goqnB9KDW8EthZY7mTXBq/fWXmwqtsi0faW5cgyx 23 | SLbIlL0h+63yEEHOZ5UxXOFM1NJszW45vDCglOBABCd9E79JVZHGWtc7CfUQNKsh 24 | pybQnQKBgHbPnITR7esVQYLq3PHSsdOdkFiiVf3D7wHiNZcXWjJvUqMF4tH5XAzY 25 | QafKqKk0FzO92ZOhQeB5xauFY5wzsa+Xl8cQkyvtWngFIKbWydEehZWVgXcedxEC 26 | xjbZWKmsYDqBYi3bw9Dxb0AvT+kDtq0Azi8QTDAvRwylvtkYj/V8 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /tests/pkd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(pkd C) 2 | 3 | if (WITH_SERVER AND UNIX AND NOT WIN32) 4 | 5 | include_directories(${libssh_SOURCE_DIR}/include 6 | ${libssh_BINARY_DIR}/include 7 | ${CMOCKA_INCLUDE_DIR} 8 | ${CMAKE_BINARY_DIR} 9 | ${libssh_SOURCE_DIR}/src 10 | ${CMAKE_CURRENT_SOURCE_DIR}) 11 | 12 | set(pkd_hello_src 13 | pkd_daemon.c 14 | pkd_hello.c 15 | pkd_keyutil.c 16 | pkd_util.c 17 | ) 18 | 19 | set(pkd_libs 20 | ${CMOCKA_LIBRARY} 21 | ssh::static 22 | ${ARGP_LIBRARIES} 23 | pthread 24 | ) 25 | 26 | add_executable(pkd_hello ${pkd_hello_src}) 27 | target_compile_options(pkd_hello PRIVATE ${DEFAULT_C_COMPILE_FLAGS}) 28 | target_link_libraries(pkd_hello PRIVATE ${pkd_libs}) 29 | if (WITH_COVERAGE) 30 | append_coverage_compiler_flags_to_target(pkd_hello) 31 | endif (WITH_COVERAGE) 32 | 33 | # 34 | # pkd_hello_i1 runs only one iteration per algorithm combination for 35 | # sake of speeding up overall test run time. More iterations can be 36 | # specified with `-i` and may be helpful for chasing down bugs that 37 | # are not 100% reproducible. 38 | # 39 | add_test(pkd_hello_i1 ${CMAKE_CURRENT_BINARY_DIR}/pkd_hello -e -o -i1 -w /tmp/pkd_socket_wrapper_XXXXXX -L pkd_scratch_XXXXXX) 40 | # 41 | # Configure environment for cwrap socket wrapper. 42 | # 43 | if (OSX) 44 | set(PKD_ENVIRONMENT "DYLD_FORCE_FLAT_NAMESPACE=1;DYLD_INSERT_LIBRARIES=${SOCKET_WRAPPER_LIBRARY}") 45 | else () 46 | set(PKD_ENVIRONMENT "LD_PRELOAD=${SOCKET_WRAPPER_LIBRARY};OPENSSL_ENABLE_SHA1_SIGNATURES=1") 47 | endif () 48 | message(STATUS "PKD_ENVIRONMENT=${PKD_ENVIRONMENT}") 49 | set_property(TEST pkd_hello_i1 PROPERTY ENVIRONMENT ${PKD_ENVIRONMENT}) 50 | 51 | # 52 | # pkd_hello_rekey is used to test server-side implementation of rekeying. 53 | # 54 | add_test(pkd_hello_rekey ${CMAKE_CURRENT_BINARY_DIR}/pkd_hello -t torture_pkd_openssh_rsa_rsa_default -i1 --rekey=16 -v -v -v -w /tmp/pkd_socket_wrapper_XXXXXX -L pkd_scratch_XXXXXX) 55 | set_property(TEST pkd_hello_rekey PROPERTY ENVIRONMENT OPENSSL_ENABLE_SHA1_SIGNATURES=1) 56 | 57 | endif (WITH_SERVER AND UNIX AND NOT WIN32) 58 | -------------------------------------------------------------------------------- /tests/pkd/pkd_daemon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pkd_daemon.h -- tests use this interface to start, stop pkd 3 | * instances and get results 4 | * 5 | * (c) 2014 Jon Simons 6 | */ 7 | 8 | #ifndef __PKD_DAEMON_H__ 9 | #define __PKD_DAEMON_H__ 10 | 11 | #include "config.h" 12 | 13 | enum pkd_hostkey_type_e { 14 | PKD_RSA, 15 | PKD_ED25519, 16 | PKD_ECDSA 17 | }; 18 | 19 | struct pkd_daemon_args { 20 | enum pkd_hostkey_type_e type; 21 | const char *hostkeypath; 22 | 23 | struct { 24 | const uint8_t *buf; 25 | size_t len; 26 | } payload; 27 | 28 | uint64_t rekey_data_limit; 29 | 30 | int original_dir_fd; 31 | 32 | struct { 33 | int list; 34 | 35 | int log_stdout; 36 | int log_stderr; 37 | int libssh_log_level; 38 | 39 | const char *testname; 40 | const char *testmatch; 41 | unsigned int iterations; 42 | 43 | struct { 44 | const char *argv_mkdtemp_str; 45 | char *mkdtemp_str; 46 | } socket_wrapper; 47 | 48 | struct { 49 | const char *argv_mkdtemp_str; 50 | char *mkdtemp_str; 51 | } temp_dir; 52 | } opts; 53 | }; 54 | 55 | struct pkd_result { 56 | int ok; 57 | }; 58 | 59 | int pkd_start(struct pkd_daemon_args *args); 60 | void pkd_stop(struct pkd_result *out); 61 | 62 | #endif /* __PKD_DAEMON_H__ */ 63 | -------------------------------------------------------------------------------- /tests/pkd/pkd_keyutil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pkd_keyutil.h -- 3 | * 4 | * (c) 2014 Jon Simons 5 | */ 6 | 7 | #ifndef __PKD_KEYUTIL_H__ 8 | #define __PKD_KEYUTIL_H__ 9 | 10 | #include "config.h" 11 | 12 | /* Server keys. */ 13 | #define LIBSSH_RSA_TESTKEY "libssh_testkey.id_rsa" 14 | #define LIBSSH_ED25519_TESTKEY "libssh_testkey.id_ed25519" 15 | #define LIBSSH_ECDSA_256_TESTKEY "libssh_testkey.id_ecdsa256" 16 | #define LIBSSH_ECDSA_384_TESTKEY "libssh_testkey.id_ecdsa384" 17 | #define LIBSSH_ECDSA_521_TESTKEY "libssh_testkey.id_ecdsa521" 18 | 19 | void setup_rsa_key(void); 20 | void setup_ed25519_key(void); 21 | void setup_ecdsa_keys(void); 22 | void cleanup_rsa_key(void); 23 | void cleanup_ed25519_key(void); 24 | void cleanup_ecdsa_keys(void); 25 | 26 | /* Client keys. */ 27 | #define OPENSSH_RSA_TESTKEY "openssh_testkey.id_rsa" 28 | #define OPENSSH_ECDSA256_TESTKEY "openssh_testkey.id_ecdsa256" 29 | #define OPENSSH_ECDSA384_TESTKEY "openssh_testkey.id_ecdsa384" 30 | #define OPENSSH_ECDSA521_TESTKEY "openssh_testkey.id_ecdsa521" 31 | #define OPENSSH_ED25519_TESTKEY "openssh_testkey.id_ed25519" 32 | #define OPENSSH_CA_TESTKEY "libssh_testkey.ca" 33 | 34 | #define DROPBEAR_RSA_TESTKEY "dropbear_testkey.id_rsa" 35 | 36 | void setup_openssh_client_keys(void); 37 | void cleanup_openssh_client_keys(void); 38 | 39 | void setup_dropbear_client_rsa_key(void); 40 | void cleanup_dropbear_client_rsa_key(void); 41 | 42 | #define cleanup_file(name) do {\ 43 | if (access((name), F_OK) != -1) {\ 44 | unlink((name));\ 45 | }} while (0) 46 | 47 | #define cleanup_key(name) do {\ 48 | cleanup_file((name));\ 49 | cleanup_file((name ".pub"));\ 50 | cleanup_file((name "-cert.pub"));\ 51 | } while (0) 52 | 53 | #endif /* __PKD_KEYUTIL_H__ */ 54 | -------------------------------------------------------------------------------- /tests/pkd/pkd_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pkd_keyutil.h -- 3 | * 4 | * (c) 2014 Jon Simons 5 | */ 6 | 7 | #ifndef __PKD_UTIL_H__ 8 | #define __PKD_UTIL_H__ 9 | 10 | int system_checked(const char *cmd); 11 | 12 | /* Is client 'X' enabled? */ 13 | int is_openssh_client_enabled(void); 14 | int is_dropbear_client_enabled(void); 15 | 16 | #endif /* __PKD_UTIL_H__ */ 17 | -------------------------------------------------------------------------------- /tests/server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(servertests C) 2 | 3 | if (WITH_SERVER AND UNIX AND NOT WIN32) 4 | 5 | find_package(socket_wrapper) 6 | 7 | add_subdirectory(test_server) 8 | 9 | set(LIBSSH_SERVER_TESTS 10 | torture_server_default 11 | torture_server_auth_kbdint 12 | torture_server_config 13 | torture_server_algorithms 14 | torture_sftpserver 15 | ) 16 | 17 | if (WITH_GSSAPI AND GSSAPI_FOUND AND GSSAPI_TESTING) 18 | set(LIBSSH_SERVER_TESTS 19 | ${LIBSSH_SERVER_TESTS} 20 | torture_gssapi_server_auth 21 | torture_gssapi_server_auth_cb 22 | torture_gssapi_server_delegation) 23 | endif() 24 | 25 | include_directories(${libssh_SOURCE_DIR}/include 26 | ${libssh_BINARY_DIR}/include 27 | ${libssh_BINARY_DIR} 28 | test_server) 29 | 30 | set(TORTURE_SERVER_ENVIRONMENT ${TORTURE_ENVIRONMENT}) 31 | list(APPEND TORTURE_SERVER_ENVIRONMENT NSS_WRAPPER_HOSTS=${CMAKE_BINARY_DIR}/tests/etc/hosts) 32 | 33 | if (ARGP_INCLUDE_DIR) 34 | include_directories(${ARGP_INCLUDE_DIR}) 35 | endif () 36 | 37 | foreach(_SRV_TEST ${LIBSSH_SERVER_TESTS}) 38 | add_cmocka_test(${_SRV_TEST} 39 | SOURCES ${_SRV_TEST}.c 40 | COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} 41 | LINK_LIBRARIES ${TORTURE_LIBRARY} testserver util 42 | ) 43 | 44 | if (OSX) 45 | set_property( 46 | TEST 47 | ${_SRV_TEST} 48 | PROPERTY 49 | ENVIRONMENT DYLD_FORCE_FLAT_NAMESPACE=1;DYLD_INSERT_LIBRARIES=${SOCKET_WRAPPER_LIBRARY}) 50 | else () 51 | set_property( 52 | TEST 53 | ${_SRV_TEST} 54 | PROPERTY 55 | ENVIRONMENT ${TORTURE_SERVER_ENVIRONMENT}) 56 | endif() 57 | endforeach() 58 | 59 | endif (WITH_SERVER AND UNIX AND NOT WIN32) 60 | -------------------------------------------------------------------------------- /tests/server/test_server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(test_server C) 2 | 3 | if (WITH_SERVER AND UNIX AND NOT WIN32) 4 | 5 | find_package(socket_wrapper) 6 | 7 | set(server_SRCS 8 | main.c 9 | ) 10 | 11 | add_library(testserver STATIC 12 | test_server.c 13 | default_cb.c 14 | sftpserver_cb.c) 15 | if (WITH_COVERAGE) 16 | append_coverage_compiler_flags_to_target(testserver) 17 | endif (WITH_COVERAGE) 18 | 19 | set(LIBSSH_SERVER_TESTS 20 | # torture_server_kbdint 21 | ) 22 | 23 | include_directories(${libssh_SOURCE_DIR}/include 24 | ${libssh_BINARY_DIR}/include 25 | ${libssh_BINARY_DIR}) 26 | 27 | if (ARGP_INCLUDE_DIR) 28 | include_directories(${ARGP_INCLUDE_DIR}) 29 | endif () 30 | 31 | if (UNIX AND NOT WIN32) 32 | add_executable(test_server ${server_SRCS}) 33 | target_compile_options(test_server PRIVATE ${DEFAULT_C_COMPILE_FLAGS}) 34 | target_link_libraries(test_server 35 | PRIVATE testserver ssh::ssh ${ARGP_LIBRARIES} util) 36 | if (WITH_COVERAGE) 37 | append_coverage_compiler_flags_to_target(test_server) 38 | endif (WITH_COVERAGE) 39 | endif () 40 | 41 | endif (WITH_SERVER AND UNIX AND NOT WIN32) 42 | -------------------------------------------------------------------------------- /tests/server/test_server/test_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SSH Library 3 | * 4 | * Copyright (c) 2018 by Red Hat, Inc. 5 | * 6 | * Author: Anderson Toshiyuki Sasaki 7 | * 8 | * The SSH Library is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation; either version 2.1 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * The SSH Library is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | * License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with the SSH Library; see the file COPYING. If not, write to 20 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 21 | * MA 02111-1307, USA. 22 | */ 23 | 24 | #include "config.h" 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | struct server_state_st { 34 | /* Arguments */ 35 | char *address; 36 | int port; 37 | 38 | char *ecdsa_key; 39 | char *ed25519_key; 40 | char *rsa_key; 41 | char *host_key; 42 | 43 | int verbosity; 44 | int auth_methods; 45 | bool with_pcap; 46 | 47 | char *pcap_file; 48 | 49 | char *expected_username; 50 | char *expected_password; 51 | 52 | char *config_file; 53 | bool parse_global_config; 54 | 55 | char *log_file; 56 | 57 | /* State */ 58 | int max_tries; 59 | int error; 60 | 61 | struct ssh_server_callbacks_struct *server_cb; 62 | struct ssh_channel_callbacks_struct *channel_cb; 63 | 64 | /* Callback to handle the session, should block until disconnected */ 65 | void (*handle_session)(ssh_event event, 66 | ssh_session session, 67 | struct server_state_st *state); 68 | }; 69 | 70 | /*TODO: Add documentation */ 71 | void free_server_state(struct server_state_st *state); 72 | 73 | /*TODO: Add documentation */ 74 | int run_server(struct server_state_st *state); 75 | 76 | /*TODO: Add documentation */ 77 | pid_t 78 | fork_run_server(struct server_state_st *state, 79 | void (*free_state) (void **userdata), 80 | void *userdata); 81 | -------------------------------------------------------------------------------- /tests/ssh_ping.c: -------------------------------------------------------------------------------- 1 | /* ssh_ping.c */ 2 | /* 3 | Copyright 2018 Red Hat, Inc 4 | 5 | Author: Jakub Jelen 6 | 7 | This file is part of the SSH Library 8 | 9 | You are free to copy this file, modify it in any way, consider it being public 10 | domain. This does not apply to the rest of the library though, but it is 11 | allowed to cut-and-paste working code from this file to any license of 12 | program. 13 | The goal is to show the API in action. It's not a reference on how terminal 14 | clients must be made or how a client should react. 15 | */ 16 | 17 | #include "config.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | int main(int argc, char **argv) 26 | { 27 | const char *banner = NULL; 28 | ssh_session session = NULL; 29 | const char *hostkeys = NULL; 30 | int rc = 1; 31 | 32 | bool process_config = false; 33 | 34 | if (argc < 1 || argv[1] == NULL) { 35 | fprintf(stderr, "Error: Need an argument (hostname)\n"); 36 | goto out; 37 | } 38 | 39 | ssh_init(); 40 | 41 | session = ssh_new(); 42 | if (session == NULL) { 43 | goto out; 44 | } 45 | 46 | rc = ssh_options_set(session, SSH_OPTIONS_HOST, argv[1]); 47 | if (rc < 0) { 48 | goto out; 49 | } 50 | 51 | /* The automatic username is not available under uid wrapper */ 52 | rc = ssh_options_set(session, SSH_OPTIONS_USER, "ping"); 53 | if (rc < 0) { 54 | goto out; 55 | } 56 | 57 | /* Ignore system-wide configurations when simply trying to reach host */ 58 | rc = ssh_options_set(session, SSH_OPTIONS_PROCESS_CONFIG, &process_config); 59 | if (rc < 0) { 60 | goto out; 61 | } 62 | 63 | /* Enable all supported algorithms */ 64 | hostkeys = ssh_kex_get_supported_method(SSH_HOSTKEYS); 65 | rc = ssh_options_set(session, SSH_OPTIONS_HOSTKEYS, hostkeys); 66 | if (rc < 0) { 67 | goto out; 68 | } 69 | 70 | rc = ssh_connect(session); 71 | if (rc != SSH_OK) { 72 | fprintf(stderr, "Connection failed : %s\n", ssh_get_error(session)); 73 | goto out; 74 | } 75 | 76 | banner = ssh_get_serverbanner(session); 77 | if (banner == NULL) { 78 | fprintf(stderr, "Did not receive SSH banner\n"); 79 | goto out; 80 | } 81 | 82 | printf("OK: %s\n", banner); 83 | rc = 0; 84 | 85 | out: 86 | ssh_free(session); 87 | ssh_finalize(); 88 | return rc; 89 | } 90 | 91 | -------------------------------------------------------------------------------- /tests/suppressions/lsan.supp: -------------------------------------------------------------------------------- 1 | leak:libcrypto.so 2 | -------------------------------------------------------------------------------- /tests/torture_cmocka.h: -------------------------------------------------------------------------------- 1 | /* 2 | * torture.c - torture library for testing libssh 3 | * 4 | * This file is part of the SSH Library 5 | * 6 | * Copyright (c) 2018 by Andreas Schneider 7 | * 8 | * The SSH Library is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation; either version 2.1 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * The SSH Library is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | * License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with the SSH Library; see the file COPYING. If not, write to 20 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 21 | * MA 02111-1307, USA. 22 | */ 23 | 24 | #ifndef _TORTURE_CMOCKA_H 25 | #define _TORTURE_CMOCKA_H 26 | 27 | #include "libssh/session.h" 28 | 29 | void _assert_ssh_return_code(ssh_session session, 30 | int rc, 31 | const char * const file, 32 | const int line); 33 | 34 | #define assert_ssh_return_code(session, rc) \ 35 | _assert_ssh_return_code((session), (rc), __FILE__, __LINE__) 36 | 37 | void _assert_ssh_return_code_equal(ssh_session session, 38 | int rc, 39 | int expected_rc, 40 | const char * const file, 41 | const int line); 42 | 43 | #define assert_ssh_return_code_equal(session, rc, expected_rc) \ 44 | _assert_ssh_return_code_equal((session), (rc), (expected_rc), __FILE__, __LINE__) 45 | 46 | void _assert_ssh_return_code_not_equal(ssh_session session, 47 | int rc, 48 | int expected_rc, 49 | const char * const file, 50 | const int line); 51 | 52 | #define assert_ssh_return_code_not_equal(session, rc, unexpected_rc) \ 53 | _assert_ssh_return_code_not_equal((session), (rc), (unexpected_rc), __FILE__, __LINE__) 54 | 55 | #endif /* _TORTURE_CMOCKA_H */ 56 | -------------------------------------------------------------------------------- /tests/torture_key.h: -------------------------------------------------------------------------------- 1 | /* 2 | * torture_key.h - torture library for testing libssh 3 | * 4 | * This file is part of the SSH Library 5 | * 6 | * Copyright (c) 2008-2009 by Andreas Schneider 7 | * 8 | * The SSH Library is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation; either version 2.1 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * The SSH Library is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | * License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with the SSH Library; see the file COPYING. If not, write to 20 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 21 | * MA 02111-1307, USA. 22 | */ 23 | 24 | #ifndef _TORTURE_KEY_H 25 | #define _TORTURE_KEY_H 26 | 27 | #include 28 | 29 | #define TORTURE_TESTKEY_PASSWORD "libssh-rocks" 30 | 31 | /* Return the encrypted private key in a new OpenSSH format */ 32 | const char *torture_get_openssh_testkey(enum ssh_keytypes_e type, 33 | bool with_passphrase); 34 | 35 | /* Return the private key in the legacy PEM format */ 36 | const char *torture_get_testkey(enum ssh_keytypes_e type, 37 | bool with_passphrase); 38 | const char *torture_get_testkey_passphrase(void); 39 | 40 | const char *torture_get_testkey_pub(enum ssh_keytypes_e type); 41 | 42 | const char *torture_get_testkey_pub_pem(enum ssh_keytypes_e type); 43 | 44 | #endif /* _TORTURE_KEY_H */ 45 | -------------------------------------------------------------------------------- /tests/torture_pki.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #ifdef HAVE_UNISTD_H 11 | #include 12 | #endif 13 | 14 | #include "torture_pki.h" 15 | #include 16 | 17 | char *torture_pki_read_file(const char *filename) 18 | { 19 | char *key; 20 | int fd; 21 | int size; 22 | int rc; 23 | struct stat sb; 24 | 25 | if (filename == NULL || filename[0] == '\0') { 26 | return NULL; 27 | } 28 | 29 | fd = open(filename, O_RDONLY); 30 | if (fd < 0) { 31 | return NULL; 32 | } 33 | 34 | rc = fstat(fd, &sb); 35 | if (rc != 0) { 36 | close(fd); 37 | return NULL; 38 | } 39 | 40 | key = malloc(sb.st_size + 1); 41 | if (key == NULL) { 42 | close(fd); 43 | return NULL; 44 | } 45 | 46 | size = read(fd, key, sb.st_size); 47 | close(fd); 48 | if (size != sb.st_size) { 49 | free(key); 50 | return NULL; 51 | } 52 | 53 | key[size] = '\0'; 54 | return key; 55 | } 56 | 57 | int torture_read_one_line(const char *filename, char *buffer, size_t len) 58 | { 59 | FILE *fp; 60 | size_t nmemb; 61 | 62 | fp = fopen(filename, "r"); 63 | if (fp == NULL) { 64 | return -1; 65 | } 66 | 67 | nmemb = fread(buffer, len - 2, 1, fp); 68 | if (nmemb != 0 || ferror(fp)) { 69 | fclose(fp); 70 | return -1; 71 | } 72 | buffer[len - 1] = '\0'; 73 | 74 | fclose(fp); 75 | 76 | return 0; 77 | } 78 | 79 | /** 80 | * @internal 81 | * 82 | * Returns the character len of a public key string, omitting the comment part 83 | */ 84 | size_t torture_pubkey_len(const char *pubkey) 85 | { 86 | const char *ptr; 87 | 88 | ptr = strchr(pubkey, ' '); 89 | if (ptr != NULL) { 90 | ptr = strchr(ptr + 1, ' '); 91 | if (ptr != NULL) { 92 | return ptr - pubkey; 93 | } 94 | } 95 | 96 | return 0; 97 | } 98 | -------------------------------------------------------------------------------- /tests/torture_pki.h: -------------------------------------------------------------------------------- 1 | char *torture_pki_read_file(const char *filename); 2 | int torture_read_one_line(const char *filename, char *buffer, size_t len); 3 | size_t torture_pubkey_len(const char *pubkey); 4 | -------------------------------------------------------------------------------- /tests/unittests/hello world.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | printf '%s' "$1" 2>&1 3 | -------------------------------------------------------------------------------- /tests/unittests/torture_channel.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #define LIBSSH_STATIC 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "torture.h" 11 | #include "channels.c" 12 | 13 | static void torture_channel_select(void **state) 14 | { 15 | fd_set readfds; 16 | int fd; 17 | int rc; 18 | int i; 19 | 20 | (void)state; /* unused */ 21 | 22 | ZERO_STRUCT(readfds); 23 | 24 | fd = open("/dev/null", 0); 25 | assert_true(fd > 2); 26 | 27 | FD_ZERO(&readfds); 28 | FD_SET(fd, &readfds); 29 | 30 | for (i = 0; i < 10; i++) { 31 | ssh_channel cin[1] = { NULL, }; 32 | ssh_channel cout[1] = { NULL, }; 33 | struct timeval tv = { .tv_sec = 0, .tv_usec = 1000 }; 34 | 35 | rc = ssh_select(cin, cout, fd + 1, &readfds, &tv); 36 | assert_int_equal(rc, SSH_OK); 37 | } 38 | 39 | close(fd); 40 | } 41 | 42 | int torture_run_tests(void) { 43 | int rc; 44 | struct CMUnitTest tests[] = { 45 | cmocka_unit_test(torture_channel_select), 46 | }; 47 | 48 | ssh_init(); 49 | torture_filter_tests(tests); 50 | rc = cmocka_run_group_tests(tests, NULL, NULL); 51 | ssh_finalize(); 52 | 53 | return rc; 54 | } 55 | -------------------------------------------------------------------------------- /tests/unittests/torture_init.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #define LIBSSH_STATIC 4 | 5 | #include 6 | #include "torture.h" 7 | #include "libssh/libssh.h" 8 | 9 | static void torture_ssh_init(void **state) { 10 | int rc; 11 | 12 | (void) state; 13 | 14 | rc = ssh_init(); 15 | assert_int_equal(rc, SSH_OK); 16 | rc = ssh_finalize(); 17 | assert_int_equal(rc, SSH_OK); 18 | } 19 | 20 | static void torture_ssh_init_after_finalize(void **state) { 21 | 22 | int rc; 23 | 24 | (void) state; 25 | 26 | rc = ssh_init(); 27 | assert_int_equal(rc, SSH_OK); 28 | rc = ssh_finalize(); 29 | assert_int_equal(rc, SSH_OK); 30 | rc = ssh_init(); 31 | assert_int_equal(rc, SSH_OK); 32 | rc = ssh_finalize(); 33 | assert_int_equal(rc, SSH_OK); 34 | } 35 | 36 | static void torture_is_ssh_initialized(UNUSED_PARAM(void **state)) { 37 | 38 | int rc; 39 | bool initialized = false; 40 | 41 | /* Make sure the library is not initialized */ 42 | while (is_ssh_initialized()) { 43 | rc = ssh_finalize(); 44 | assert_return_code(rc, errno); 45 | } 46 | 47 | rc = ssh_init(); 48 | assert_return_code(rc, errno); 49 | initialized = is_ssh_initialized(); 50 | assert_true(initialized); 51 | rc = ssh_finalize(); 52 | assert_return_code(rc, errno); 53 | initialized = is_ssh_initialized(); 54 | assert_false(initialized); 55 | } 56 | 57 | int torture_run_tests(void) { 58 | int rc; 59 | struct CMUnitTest tests[] = { 60 | cmocka_unit_test(torture_ssh_init), 61 | cmocka_unit_test(torture_ssh_init_after_finalize), 62 | cmocka_unit_test(torture_is_ssh_initialized), 63 | }; 64 | 65 | torture_filter_tests(tests); 66 | rc = cmocka_run_group_tests(tests, NULL, NULL); 67 | 68 | return rc; 69 | } 70 | -------------------------------------------------------------------------------- /tests/unittests/torture_isipaddr.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #define LIBSSH_STATIC 4 | 5 | #include "torture.h" 6 | 7 | #include "misc.c" 8 | #include "error.c" 9 | 10 | /* 11 | * Test the behavior of ssh_is_ipaddr() 12 | */ 13 | static void torture_ssh_is_ipaddr(void **state) 14 | { 15 | (void)state; 16 | 17 | assert_int_equal(ssh_is_ipaddr("127.0.0.1"),1); 18 | assert_int_equal(ssh_is_ipaddr("0.0.0.0"),1); 19 | assert_int_equal(ssh_is_ipaddr("1.1.1.1"),1); 20 | assert_int_equal(ssh_is_ipaddr("255.255.255.255"),1); 21 | assert_int_equal(ssh_is_ipaddr("128.128.128.128"),1); 22 | assert_int_equal(ssh_is_ipaddr("1.10.100.1"),1); 23 | assert_int_equal(ssh_is_ipaddr("0.1.10.100"),1); 24 | 25 | assert_int_equal(ssh_is_ipaddr("2001:0db8:85a3:0000:0000:8a2e:0370:7334"),1); 26 | assert_int_equal(ssh_is_ipaddr("fe80:0000:0000:0000:0202:b3ff:fe1e:8329"),1); 27 | assert_int_equal(ssh_is_ipaddr("fe80:0:0:0:202:b3ff:fe1e:8329"),1); 28 | assert_int_equal(ssh_is_ipaddr("fe80::202:b3ff:fe1e:8329"),1); 29 | assert_int_equal(ssh_is_ipaddr("::1"),1); 30 | 31 | assert_int_equal(ssh_is_ipaddr("::ffff:192.0.2.128"),1); 32 | 33 | assert_int_equal(ssh_is_ipaddr("0.0.0.0.0"),0); 34 | assert_int_equal(ssh_is_ipaddr("0.0.0.0.a"),0); 35 | assert_int_equal(ssh_is_ipaddr("a.0.0.0"),0); 36 | assert_int_equal(ssh_is_ipaddr("0a.0.0.0.0"),0); 37 | assert_int_equal(ssh_is_ipaddr(""),0); 38 | assert_int_equal(ssh_is_ipaddr("0.0.0."),0); 39 | assert_int_equal(ssh_is_ipaddr("0.0"),0); 40 | assert_int_equal(ssh_is_ipaddr("0"),0); 41 | 42 | /* 43 | * FIXME: Temporary workaround for Wine bug 44 | */ 45 | #ifndef _WIN32 46 | assert_int_equal(ssh_is_ipaddr("255.255.255"),0); 47 | #endif 48 | 49 | assert_int_equal(ssh_is_ipaddr("2001:0db8:85a3:0000:0000:8a2e:0370:7334:1002"), 0); 50 | assert_int_equal(ssh_is_ipaddr("fe80:x:202:b3ff:fe1e:8329"), 0); 51 | assert_int_equal(ssh_is_ipaddr("fe80:x:202:b3ff:fe1e:8329"), 0); 52 | assert_int_equal(ssh_is_ipaddr(":1"), 0); 53 | } 54 | 55 | int torture_run_tests(void) { 56 | int rc; 57 | struct CMUnitTest tests[] = { 58 | cmocka_unit_test(torture_ssh_is_ipaddr) 59 | }; 60 | 61 | ssh_init(); 62 | torture_filter_tests(tests); 63 | rc = cmocka_run_group_tests(tests, NULL, NULL); 64 | ssh_finalize(); 65 | return rc; 66 | } 67 | -------------------------------------------------------------------------------- /tests/unittests/torture_push_pop_dir.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #include "torture.h" 4 | #define LIBSSH_STATIC 5 | 6 | const char template[] = "temp_dir_XXXXXX"; 7 | 8 | static int setup(void **state) 9 | { 10 | char *temp_dir = NULL; 11 | 12 | temp_dir = torture_make_temp_dir(template); 13 | assert_non_null(temp_dir); 14 | 15 | *state = (void *)temp_dir; 16 | 17 | return 0; 18 | } 19 | 20 | static int teardown(void **state) 21 | { 22 | char *temp_dir = *((char **)state); 23 | 24 | torture_rmdirs((const char *)temp_dir); 25 | 26 | free(temp_dir); 27 | 28 | return 0; 29 | } 30 | 31 | static void torture_back_and_forth(void **state) 32 | { 33 | char *temp_dir = *((char **)state); 34 | char *cwd = NULL; 35 | char *after_change = NULL; 36 | char *after_changing_back = NULL; 37 | int rc = 0; 38 | 39 | cwd = torture_get_current_working_dir(); 40 | assert_non_null(cwd); 41 | 42 | printf("Current dir: %s\n", cwd); 43 | 44 | rc = torture_change_dir(temp_dir); 45 | assert_int_equal(rc, 0); 46 | 47 | after_change = torture_get_current_working_dir(); 48 | assert_non_null(after_change); 49 | 50 | printf("Current dir after change: %s\n", after_change); 51 | 52 | rc = torture_change_dir(cwd); 53 | assert_int_equal(rc, 0); 54 | 55 | after_changing_back = torture_get_current_working_dir(); 56 | assert_non_null(after_changing_back); 57 | 58 | printf("Back to dir: %s\n", after_changing_back); 59 | 60 | SAFE_FREE(cwd); 61 | SAFE_FREE(after_change); 62 | SAFE_FREE(after_changing_back); 63 | } 64 | 65 | int torture_run_tests(void) 66 | { 67 | int rc; 68 | struct CMUnitTest tests[] = { 69 | cmocka_unit_test_setup_teardown(torture_back_and_forth, 70 | setup, teardown), 71 | }; 72 | 73 | torture_filter_tests(tests); 74 | rc = cmocka_run_group_tests(tests, NULL, NULL); 75 | 76 | return rc; 77 | } 78 | 79 | -------------------------------------------------------------------------------- /tests/unittests/torture_rand.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #define LIBSSH_STATIC 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "torture.h" 9 | 10 | #ifdef HAVE_LIBGCRYPT 11 | #define NUM_LOOPS 1000 12 | #else 13 | /* openssl is much faster */ 14 | #define NUM_LOOPS 20000 15 | #endif 16 | #define NUM_THREADS 100 17 | 18 | static int setup(void **state) { 19 | int rc; 20 | 21 | (void) state; 22 | 23 | ssh_threads_set_callbacks(ssh_threads_get_pthread()); 24 | rc = ssh_init(); 25 | if (rc != SSH_OK) { 26 | return -1; 27 | } 28 | 29 | return 0; 30 | } 31 | 32 | static int teardown(void **state) { 33 | (void) state; 34 | 35 | ssh_finalize(); 36 | 37 | return 0; 38 | } 39 | 40 | static void *torture_rand_thread(void *threadid) { 41 | char buffer[12]; 42 | int i; 43 | int ok; 44 | 45 | (void) threadid; 46 | 47 | buffer[0] = buffer[1] = buffer[10] = buffer[11] = 'X'; 48 | for(i = 0; i < NUM_LOOPS; ++i) { 49 | ok = ssh_get_random(&buffer[2], i % 8 + 1, 0); 50 | assert_true(ok); 51 | } 52 | 53 | pthread_exit(NULL); 54 | } 55 | 56 | static void torture_rand_threading(void **state) { 57 | pthread_t threads[NUM_THREADS]; 58 | int i; 59 | int err; 60 | 61 | (void) state; 62 | 63 | for(i = 0; i < NUM_THREADS; ++i) { 64 | err = pthread_create(&threads[i], NULL, torture_rand_thread, NULL); 65 | assert_int_equal(err, 0); 66 | } 67 | for(i = 0; i < NUM_THREADS; ++i) { 68 | err=pthread_join(threads[i], NULL); 69 | assert_int_equal(err, 0); 70 | } 71 | } 72 | 73 | int torture_run_tests(void) { 74 | int rc; 75 | struct CMUnitTest tests[] = { 76 | cmocka_unit_test_setup_teardown(torture_rand_threading, setup, teardown), 77 | }; 78 | 79 | torture_filter_tests(tests); 80 | rc = cmocka_run_group_tests(tests, NULL, NULL); 81 | 82 | return rc; 83 | } 84 | -------------------------------------------------------------------------------- /tests/unittests/torture_temp_dir.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #include "torture.h" 4 | #define LIBSSH_STATIC 5 | 6 | const char template[] = "temp_dir_XXXXXX"; 7 | 8 | static int setup(void **state) 9 | { 10 | char *temp_dir = NULL; 11 | 12 | temp_dir = torture_make_temp_dir(template); 13 | assert_non_null(temp_dir); 14 | 15 | *state = (void *)temp_dir; 16 | 17 | return 0; 18 | } 19 | 20 | static int teardown(void **state) 21 | { 22 | char *temp_dir = *((char **)state); 23 | 24 | torture_rmdirs((const char *)temp_dir); 25 | 26 | free(temp_dir); 27 | 28 | return 0; 29 | } 30 | 31 | 32 | static void torture_create_temp_dir(void **state) 33 | { 34 | char *temp_dir = *((char **)state); 35 | 36 | printf("Created temp dir: %s\n", temp_dir); 37 | } 38 | 39 | int torture_run_tests(void) 40 | { 41 | int rc; 42 | struct CMUnitTest tests[] = { 43 | cmocka_unit_test_setup_teardown(torture_create_temp_dir, setup, teardown), 44 | }; 45 | 46 | torture_filter_tests(tests); 47 | rc = cmocka_run_group_tests(tests, NULL, NULL); 48 | 49 | return rc; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /tests/unittests/torture_temp_file.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #include "torture.h" 4 | #define LIBSSH_STATIC 5 | 6 | const char template[] = "temp_file_XXXXXX"; 7 | 8 | static int setup(void **state) 9 | { 10 | char *file_name = NULL; 11 | 12 | file_name = torture_create_temp_file(template); 13 | assert_non_null(file_name); 14 | 15 | *state = (void *)file_name; 16 | 17 | return 0; 18 | } 19 | 20 | static int teardown(void **state) 21 | { 22 | int rc; 23 | char *file_name = *((char **)state); 24 | 25 | assert_non_null(file_name); 26 | 27 | rc = unlink(file_name); 28 | assert_int_equal(rc, 0); 29 | 30 | SAFE_FREE(file_name); 31 | 32 | return 0; 33 | } 34 | 35 | 36 | static void torture_temp_file(void **state) 37 | { 38 | char *file_name = *((char **)state); 39 | FILE *fp = NULL; 40 | 41 | assert_non_null(file_name); 42 | 43 | fp = fopen(file_name, "r"); 44 | assert_non_null(fp); 45 | 46 | fclose(fp); 47 | 48 | printf("Created temp file: %s\n", file_name); 49 | } 50 | 51 | int torture_run_tests(void) 52 | { 53 | int rc; 54 | struct CMUnitTest tests[] = { 55 | cmocka_unit_test_setup_teardown(torture_temp_file, setup, teardown), 56 | }; 57 | 58 | torture_filter_tests(tests); 59 | rc = cmocka_run_group_tests(tests, NULL, NULL); 60 | 61 | return rc; 62 | } 63 | 64 | --------------------------------------------------------------------------------