1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-11-18 15:20:56 +03:00
Commit Graph

271 Commits

Author SHA1 Message Date
Viktor Szakats
819573f94e tests: restore debian:bullseye in Dockerfile
Follow-up to 78cb64a859
2023-04-16 17:08:16 +00:00
Viktor Szakats
c9160bf89c tests: try debian:testing for Dockerfile
Follow-up to 78cb64a859
2023-04-16 16:16:18 +00:00
Viktor Szakats
78cb64a859 tests: switch Dockerfile to debian:testing-slim
From debian:bullseye

- doesn't need manual bumps.
- is ahead of stable and should be stable enough for our purpose.
- slim is saving resources.

Closes #971
2023-04-16 15:43:43 +00:00
Viktor Szakats
bf3b44ca18 cmake: use a single build rule for all tests
- use the complete filename of test sources in the input list.

- build all tests with the ability to access libssh2 internals.

  This is necessary for `test_keyboard_interactive_auth_info_request`
  now and might be necessary for others in the future, e.g. to avoid
  the depreacted public base64 decoding API.

- move `test_keyboard_interactive_auth_info_request` into the main
  test build loop.

- move `simple` into the main test build loop too.

- build `ssh2` also in static mode.

- cleanup the way we detect and enable gcov.

- fix indentation.

Closes #967
2023-04-15 02:50:41 +00:00
Viktor Szakats
5d399233d8 checksrc: fix EQUALSNULL warnings
`s/([a-z0-9._>*-]+) == NULL/!\1/g`

Closes #964
2023-04-15 02:46:09 +00:00
Viktor Szakats
2efdb6747a tidy-up: example, tests continued
- fix skip auth if `userauthlist` is NULL.
  Closes #836 (Reported-by: @sudipm-mukherjee on github)
- fix most silenced `checksrc` warnings.
- sync examples/tests code between each other.
  (output messages, error handling, declaration order, comments)
- stop including unnecessary headers.
- always deinitialize in case of error.
- drop some redundant variables.
- add error handling where missing.
- show more error codes.
- switch `perror()` to `fprintf()`.
- fix some `printf()`s to be `fprintf()`.
- formatting.

Closes #960
2023-04-14 11:07:53 +00:00
Viktor Szakats
ec0feae792 build: speed up and extend picky compiler options
Implement picky warnings with clang in autotools. Extend picky gcc
warnings, sync them between build tools and compilers and greatly
speed up detection in CMake.

- autotools: enable clang compiler warnings with `--enable-debug`.

- autotools: enable more gcc compiler warnings with `--enable-debug`.

- autotools/cmake: sync compiler warning options between gcc and clang.

- sync compiler warning options between autotools and cmake.

- cmake: reduce option-checks to speed up the detection phase.
  Bring them down to 3 (from 35). Leaving some checks to keep the
  CMake logic alive and for an easy way to add new options.

  clang 3.0 (2011-11-29) and gcc 2.95 (1999-07-31) now required.

- autotools logic copied from curl, with these differences:

  - delete `-Wimplicit-fallthrough=4` due to a false positive.

  - reduce `-Wformat-truncation=2` to `1` due to a false positive.

  - simplify MinGW detection for `-Wno-pedantic-ms-format`.

- cmake: show enabled picky compiler options (like autotools).

- cmake: do compile `tests/simple.c` and `tests/ssh2.c`.

- fix new compiler warnings.

- `tests/CMakeLists.txt`: fix indentation.

Original source of autotools logic:
- a8fbdb461c/acinclude.m4
- a8fbdb461c/m4/curl-compilers.m4

Notice that the autotools implementation considers Apple clang as
legacy clang 3.7. CMake detection works more accurately, at the same
time more error-prone and difficult to update due to the sparsely
documented nature of Apple clang option evolution.

Closes #952
2023-04-13 11:12:22 +00:00
Viktor Szakats
fb9f888308 tidy-up: example, tests
- drop unnecessary `WIN32`-specific branches.

- add `static`.

- sync header inclusion order.

- sync some common code between examples/tests.

- fix formatting/indentation.

- fix some `checksrc` errors not caught by `checksrc`.

Closes #936
2023-04-08 22:26:10 +00:00
Viktor Szakats
7e4855926e tests/mansyntax.sh: avoid if ! for portability
Ref: https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Limitations-of-Builtins.html#Limitations-of-Builtins

Fixes #704
Closes #935
2023-04-08 22:25:46 +00:00
Viktor Szakats
dfb086bfe2 tidy-up: indentation in guarded #includes [ci skip] 2023-04-08 10:56:14 +00:00
Viktor Szakats
59666e03f0 build: hand-crafted config rework & header tidy-up
- introduce the concept of a project level setup header
  `src/libssh2_setup.h`, that is used by `src`, `example` and `tests`
  alike. Move there all common platform/compiler configuration from
  `src/libssh2_priv.h`, individual sources and `CMakeFiles.txt` files.
  Also move there our hand-crafted (= not auto-generated by CMake or
  autotools) configuration `win32/libssh2-config.h`.

- `win32` directory is empty now, delete it.

- `Makefile.mk`: adapt to the above. Build-directory is the target
  triplet, or any custom name set via `BLD_DIR`.

- sync header path order between build systems:
  build/src -> source/src -> source/include

- delete redundant references to `windows.h`, `winsock2.h`,
  `ws2tcpip.h`.

- delete unnecessary #includes, update order (`libssh2_setup.h` first,
  `winsock2.h` first), simplify where possible.

  This makes the code warning-free without `WIN32_LEAN_AND_MEAN`.
  At the same time this patch applies this macro globally, to avoid
  header bloat.

- example: add missing *nix header guards.

- example: fix misindented `HAVE_UNISTD_H` `#ifdef`s.

- set `WIN32` with all build-tools.

- set `HAVE_SYS_PARAM_H` in the hand-crafted config for MinGW.
  To match auto-detection.

- move a source-specific macro to `misc.c` from `libssh2_priv.h`.

See the PR's individual commits for step-by-step updates.

Closes #932
2023-04-07 23:44:43 +00:00
Viktor Szakats
72cd241239 test_warmup: re-implement as test()
Instead of overriding `main()`. To align with the other tests.

Overriding `main()` can cause duplicate symbols without using a lib for
the `runner` code.

Follow-up to 40ac6b230a

Closes #934
2023-04-07 15:43:26 +00:00
Viktor Szakats
202a4f3f7a build: MSVS warning suppression option tidy-up
- in `win32/libssh2_config.h` replace `_CRT_SECURE_NO_DEPRECATE` with
  `_CRT_SECURE_NO_WARNINGS`, to use the official macro for this, like
  in CMake.

  Also, it's now safe to move it back under `_MSC_VER`.

  Suppressing:

  `warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead.`
  `warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead.`

- move `_CRT_NONSTDC_NO_DEPRECATE` to `example` and `tests`.
  Not needed for `src`.

  Suppressing:

  `warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup.`
  `warning C4996: 'write': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _write.`

- move `_WINSOCK_DEPRECATED_NO_WARNINGS` from source files to
  CMake files, in `example` and `tests`. Also limit this to MSVC.

  Suppressing:

  `warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead`

TODO: try fixing these instead of suppressing.

Closes #929
2023-04-04 00:03:33 +00:00
Viktor Szakats
eb236329c4 delete redundant HAVE_WINSOCK2_H
`libssh2.h` required `winsock2.h` for `_WIN32` since
81d53de4dc (2011-06-04).

Apply that to the whole codebase. This makes it unnecessary to detect
`HAVE_WINSOCK2_H` and allows to drop all its uses.

Completes TODO from b66d7317ca

TODO: Straighten out the use a mixture of `HAVE_WINDOWS_H`,
      `WIN32`, `_WIN32` to detect Windows.
2023-04-01 19:32:08 +02:00
Viktor Szakats
ce26743b4e cmake: dedupe and merge config detection
Before this patch CMake did feature detections in three files:
`src/CMakefiles.txt`, `examples/CMakefiles.txt` and
`tests/CMakefiles.txt`.

Merge and move them to the root `CMakefiles.txt`.

After this patch we end up with a single `src/libssh2_config.h`. This
brings CMake in sync with autotools builds, which already worked with
a single config header.

This also prevents mistakes where feature detection went out of sync
between `src` & `tests` (see ae90a35d15).
`tests` do compile sources from `src` directly, so these should always
be in sync.

It also allows to better integrate hand-crafted, platform-specific
config headers into the builds, like the one currently residing in
the `win32` directory (and also in `vms` and `os400`). Subject to an
upcoming PR.

Also fix a warning revealed after this patch made CMake correctly
enable `HAVE_GETTIMEOFDAY` for `example` programs.

Closes #906
2023-03-31 18:11:27 +00:00
Viktor Szakats
67ac735ad0 cmake: dedupe crypto-backend detection
Before this patch CMake did crypto-backend detection in both
`src/CMakefiles.txt` and `tests/CMakefiles.txt`.

Merge them and move it to the root `CMakefiles.txt`.

While here, also add zlib for OpenSSL. Necessary when using OpenSSL
builds with zlib enabled.

Closes #905
2023-03-31 13:39:11 +00:00
Viktor Szakats
5012442850 maketgz: tidy-up [ci skip] (#901)
- fix shellcheck warnings:
  - use quotes
  - use `$()`
- use `printf` (instead of calling perl).
- indent.
- copy/adapt header comment from curl to `maketgz`.
2023-03-30 20:59:47 +02:00
Viktor Szakats
97417ad37f ci: add VS2022 builds (incl. ARM64) to AppVeyor (#899)
- add MSVS 2022 WinCNG builds for x64 and ARM64,
  replacing MSVS 2013 WinCNG builds for x64 and x86.

- add MSVS 2022 OpenSSL builds for x64.

- fix a compiler warning uncovered by the new ARM64 build:

  ```
  tests\openssh_fixture.c(393,17): warning C4477: 'fprintf' : format string '%d' requires an argument of type 'int', but variadic argument 1 has type 'libssh2_socket_t'
  tests\openssh_fixture.c(393,17): message : consider using '%lld' in the format string
  tests\openssh_fixture.c(393,17): message : consider using '%Id' in the format string
  tests\openssh_fixture.c(393,17): message : consider using '%I64d' in the format string
  ```

- echo the actual CMake command-line.

- cmake: echo the DLL filenames found by the OpenSSL DLL-finder
  heuristics.

- cmake: delete `libcrypto.dll` and `libssl.dll` names from the above
  logic.

  I've added these in 19884e5055. That
  resulted in CMake picking up a rogue `libcrypto.dll` (with no
  `libssl.dll` pair) from `C:\Windows\System32\` on the
  `Visual Studio 2022` image, breaking tests.

  Turns out, OpenSSL v1.0.2 uses the "EAY" names, but let's not re-add
  those either, because CMake mis-picks those up from
  `C:/OpenSSL-Win64/bin/`, even while pointing `OPENSSL_ROOT_DIR` to a
  v1.1.1 installation.

- cmake: set `NO_DEFAULT_PATH` for OpenSSL DLL lookup to avoid picking
  up all kinds of wrong DLLs. CMake considers not the first, but the
  _last_ hit the valid one. This happened to be
  `C:/Program Files/Meson/lib*-1_1.dll` when using the
  `Visual Studio 2022` image.

  Ref: https://cmake.org/cmake/help/latest/command/find_file.html

- cmake: leave two commented debug lines that will be useful next time
  the DLL detection lookup goes wrong.

  Ref: https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_DEBUG_MODE.html

- on error, also dump `CMakeFiles/CMakeConfigureLog.yaml` if it exists
  (requires CMake 3.26 and newer)
2023-03-29 20:23:25 +02:00
Viktor Szakats
5a4d532ce5 cmake: introduce variables for lib target names (#896)
Make our CMake config more self-documenting by introducing variables
for the shared and static lib target names. Without this, it might be
non-trivial to find out which line is referring to a target name vs
libname, export name or other occurrences of `libssh2`.

This allows to rename back the shared lib target name to the value used
before 4e2580628d:
`libssh2_shared` -> `libssh2`, if necessary for compatibility. Notice:
before that patch, `libssh2` name referred to either the static or
shared lib, depending on build settings.
2023-03-28 19:13:28 +02:00
Viktor Szakats
4b800182c5 checksrc: update and fix warnings (#890)
Update from:
5fec927374/scripts/checksrc.pl

- suppress these new checks:

  - EQUALSNULL: 320 warnings
  - NOTEQUALSZERO: 142 warnings
  - TYPEDEFSTRUCT: 16 warnings

  We can enabled them in the future.

- fix all other new ones.

- also fix whitespace in two `NMakefile` files.
2023-03-28 09:37:46 +02:00
Viktor Szakats
2f16d8105c tidy-up: replace tabs and other whitespace (#885)
There are a few non-whitespace changes, see them here:
https://github.com/libssh2/libssh2/pull/885/files?w=1
2023-03-27 18:28:27 +02:00
Viktor Szakats
4e2580628d cmake: allow building static + shared libs in a single pass
- `BUILD_SHARED_LIBS=ON` no longer disables building static lib.

  When set, we build the static lib with PIC enabled.

  For shared lib only, set `BUILD_STATIC_LIBS=OFF`. For static lib
  without PIC, leave this option disabled.

- new setting: `BUILD_STATIC_LIBS`. `ON` by default.

  Force-enabled when building examples or tests (we build those in
  static mode always.)

- fix to exclude Windows Resource from the static lib.

- fix to not overwrite static lib with shared implib on Windows
  platforms using identical suffix for them (MSVS). By using
  `libssh2_imp<.ext>` implib filename.

- add support for `STATIC_LIB_SUFFIX` setting to set an optional suffix
  (e.g. `_static`) for the static lib. (experimental, not documented).
  Overrides the above when set.

- fix to set `dllexport` when building shared lib.

- set `TrackFileAccess=false` for MSVS.

  For faster builds, shorter verbose logs.

- tests: new test linking against shared libssh2: `test_warmup_shared`

- tests: simplify 'runner' lib by merging 3 libs into a single one.

- tests: drop hack from `test_keyboard_interactive_auth_info_request`
  build.

  We no longer need to compile `src/misc.c` because we always link
  libssh2 statically.

- tests: limit `FIXTURE_WORKDIR=` to the `runner` target.

TL;DR: Default behavior unchanged: static (no-PIC), no shared.
       Enabling shared unchanged, but now also builds a static (PIC)
       lib by default.

Based-on: b60dca8b64 #547 by berney on github
Fixes: #547
Fixes: #675
Closes: #863
2023-03-22 02:47:58 +00:00
Viktor Szakats
b13936bd6a example, tests: address compiler warnings
Fix or silence all C compiler warnings discovered with (or without)
`PICKY_COMPILER=ON` (in CMake). This means all warnings showing up in
CI (gcc, clang, MSVS 2013/2015), in local tests on macOS (clang 14) and
Windows cross-builds using gcc (12) and llvm/clang (14/15).

Also fix the expression `nread -= nread` in `sftp_RW_nonblock.c`.

Cherry-picked from: #846
Closes #861
2023-03-20 15:49:37 +00:00
Viktor Szakats
de91e22081 build: improve a test build workaround with bcrypt
- cmake: extend workaround for linking a test with shared libssh2.

  One of the tests uses internal libssh2 functions, and with CMake it
  compiles `src/misc.c` directly for this. `misc.c` references bcrypt /
  blowfish code. This needs a workaround for build configs where libssh2
  doesn't export these.

  Before this patch, we enabled this workaround for MSVC.

  In the patch we extend this to all Windows. There is no CI test for
  this, but gcc and llvm/clang + mingw64 builds also need it. This may
  well apply to other configurations (it should, as shared libs are not
  supposed to export internal functions), so also make it easy to enable
  it at a single point.

  [ autotools builds force-link this one test against static libssh2. ]

- make `misc.c` not depend on bcrypt.

  By moving out our `bcrypt_pbkdf()` wrapper into `bcrypt_pbkdf.c`
  itself.

  This allows to compile `misc.c` into tests without pulling in bcrypt /
  blowfish functions, and simplify the above workaround.

  Source code uses `HAVE_BCRYPT_PBKDF`, a leftover from original bcrypt
  source. We never define this inside libssh2. Defining it breaks the
  build, and this patch doesn't change that.

- make `bcrypt_pbkdf()` static.

  While here, make the low-level `bcrypt_pbkdf()` function static to
  avoid namespace pollution.

Closes #855
2023-03-19 15:51:52 +00:00
Viktor Szakats
f0b729f791 cmake: drop unnecessary exception for warmup build (#835) 2023-03-10 11:08:57 +01:00
Viktor Szakats
adac94af31 cmake: add wolfSSL support to tests (#833)
wolfSSL supports building with zlib as a dependency, that's the reason
for the ZLIB logic in the patch.

Also add it to `docs/INSTALL_CMAKE.md` and to the help text in
`src/CMakeLists.txt`.

Running tests not actually tested.

Follow-up to 9f217a17f6

Ref: #817
2023-03-10 00:55:37 +01:00
Viktor Szakats
40ac6b230a tests: workaround for intermittent first test failures (#832)
Flakiness got continously worse these last days. It didn't seem related
to recent commits. Flakiness also picked up in GitHub CI runs, something
rarely seen before. Manual restart consistently fixed them.

The repeating pattern was the _first_ test (`test_hostkey`) failing,
with `libssh2_session_handshake failed (-13): Failed getting banner`.
Failures came after a lengthy wait, suggesting a timeout.

I then reversed the order of the first two tests, and it turned out that
the _first_ test failed again (`test_hostkey_hash`). Also pointing to a
timeout issue.

Then I added a dummy test to "warm up" whatever needs warming up in the
layers of CI + Docker + ssh server and their interconnects. This helped,
and GitHub CI tests run without failure right for the first time.
AppVeyor CI also improved a little.

This patch adds a new first test called `test_warmup`, that creates a
new libssh2 session, and exits with success even if that attempt failed.

A stop-gap solution at best, and there is no guarantee it will continue
to fix this or similar future issues, but it's also untenable to have
almost every CI run fail for intermittent reasons.

In some [1] cases [2] it's not the first test failing intermittently.
That's a different issue, and this patch doesn't fix it.

[1] #804
[2] https://ci.appveyor.com/project/libssh2org/libssh2/builds/46440828/job/8rej6cq6itg7vc4w#L500
2023-03-10 00:53:55 +01:00
Viktor Szakats
ae90a35d15 cmake: detect HAVE_SNPRINTF for tests (#830)
Turns out `test_keyboard_interactive_auth_info_request.c` requires
`src/libssh2_priv.h`, which in turn requires a correctly set
`HAVE_SNPRINTF`.

Follow-up to 4cdf785cd3.
2023-03-09 19:49:20 +01:00
Viktor Szakats
33b6d5f89d cmake: reposition ws2_32 to make binutils ld work again (#827)
This restores socket libs to their pre-regression positions.

Without this, `ld` doesn't find `ws2_32` symbols when referenced
from TLS libs.

Regression from 31fb8860db
2023-03-09 00:41:48 +01:00
Viktor Szakats
31fb8860db build: more fixes and tidy-up (mostly for Windows)
- cmake: always link `ws2_32` on Windows. Also add it to `libssh2.pc`.

   Fixes #745

- agent: fix gcc compiler warning:
   `src/agent.c:296:35: warning: 'snprintf' output truncated before the last format character [-Wformat-truncation=]`

- autotools: fix `EVP_aes_128_ctr` detection with binutils `ld`

   The prerequisite for a successful detection is setting
   `LIBS=-lbcrypt` if the chosen openssl-compatible library requires
   it, e.g. libressl, or quictls/openssl built with
   `-DUSE_BCRYPTGENRANDOM`.

   With llvm `lld`, detection works out of the box. With binutils `ld`,
   it does not. The reason is `ld`s world-famous pickiness with lib
   order.

   To fix it, we pass all custom libs before and after the TLS libs.
   This ugly hack makes `ld` happy and detection succeed.

- agent: fix Windows-specific warning:
  `src/agent.c:318:10: warning: implicit conversion loses integer precision: 'LRESULT' (aka 'long long') to 'int' [-Wshorten-64-to-32]`

- src: fix llvm/clang compiler warning:
  `src/libssh2_priv.h:987:28: warning: variadic macros are a C99 feature [-Wvariadic-macros]`

- src: support `inline` with `__GNUC__` (llvm/clang and gcc), fixing:
  ```
  src/libssh2_priv.h:990:8: warning: extension used [-Wlanguage-extension-token]
  static inline void
         ^
  ```

- blowfish: support `inline` keyword with MSVC.

   Also switch to `__inline__` (from `__inline`) for `__GNUC__`:
     https://gcc.gnu.org/onlinedocs/gcc/Inline.html
     https://clang.llvm.org/docs/UsersManual.html#differences-between-various-standard-modes

- example/test: fix MSVC compiler warnings:

  - `example\direct_tcpip.c(209): warning C4244: 'function': conversion from 'unsigned int' to 'u_short', possible loss of data`
  - `tests\session_fixture.c(96): warning C4013: 'getcwd' undefined; assuming extern returning int`
  - `tests\session_fixture.c(100): warning C4013: 'chdir' undefined; assuming extern returning int`

- delete unused macros:
  - `HAVE_SOCKET`
  - `HAVE_INET_ADDR`
  - `NEED_LIB_NSL`
  - `NEED_LIB_SOCKET`
  - `HAVE_NTSTATUS_H`
  - `HAVE_NTDEF_H`

- build: delete stale zlib/openssl version numbers from path defaults.

- cmake: convert tabs to spaces, add newline at EOFs.

Closes #811
2023-03-07 15:14:22 +00:00
Viktor Szakats
23a21aa86c cmake: make test_read runs cross-build-friendly
Improve tests added in 7487dcf4b4 by
running `test_read` commands directly. This makes external shell/batch
files unnecessary, and is friendlier with cross-builds and when run
from non-default shells, like MSYS2.

Also extend CRYPT/MAC test error messages with the CRYPT/MAC name.

External runner shell scripts kept for future use.

Closes #814
2023-03-07 14:29:05 +00:00
Viktor Szakats
4cdf785cd3 snprintf: unify fallback logic
Before this patch, the `snprintf()` fallback logic for envs not
supporting this function (i.e. Visual Studio 2013 and older) varied
depending on build tool, and used different techniques in examples,
tests and libssh2 itself.

This patch aims to apply a common logic to libssh2 and examples/tests.

- libssh2: use local `snprintf()` fallback with all build tools.

  We already had a local implementation, but only with CMake. Move that
  to the library as `_libssh2_snprintf()`, and map `snprintf()` to it
  when `HAVE_SNPRINTF` is not set.

  Also change the length type from `int` to `size_t`, and fix
  formatting.

- set or detect `HAVE_SNPRINTF` in non-CMake builds.

  Detect in autotools. Keep existing logic in `win32/libssh2_config.h`.
  Always set for OS/400, NetWare and VMS, keeping existing behaviour.
  (OS/400 builds use a different local implementation)

- examples/tests: drop the CMake-specific fallback logic and map
  `snprintf()` to `_snprintf()` for old MSVC versions, like we did
  before with other build tools. This is unsafe, but should be fine for
  these uses.

- `win32/libssh2_config.h`: make it easier to read.

Closes #812
2023-03-07 14:08:12 +00:00
Viktor Szakats
2addafb77b build fixes and improvements (mostly for Windows)
- in `hostkey.c` check the result of `libssh2_sha256_init()` and
  `libssh2_sha512_init()` calls. This avoid the warning that we're
  ignoring the return values.

- fix code using `int` (or `SOCKET`) for sockets. Use libssh2's
  dedicated `libssh2_socket_t` and `LIBSSH2_INVALID_SOCKET` instead.

- fix compiler warnings due to `STATUS_*` macro redefinitions between
  `ntstatus.h` / `winnt.h`. Solve it by manually defining the single
  `STATUS` value we need from `ntstatus.h` and stop including the whole
  header.
  Fixes #733

- improve Windows UWP/WinRT builds by detecting it with code copied
  from the curl project. Then excluding problematic libssh2 parts
  according to PR by Dmitry Kostjučenko.
  Fixes #734

- always use `SecureZeroMemory()` on Windows.

  We can tweak this if not found or not inlined by a C compiler which
  we otherwise support. Same if it causes issues with UWP apps.

  Ref: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/aa366877(v=vs.85)
  Ref: https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-rtlsecurezeromemory

- always enable `LIBSSH2_CLEAR_MEMORY` on Windows. CMake and
  curl-for-win builds already did that. Delete `SecureZeroMemory()`
  detection from autotools' WinCNG backend logic, that this
  setting used to depend on.

  TODO: Enable it for all platforms in a separate PR.
  TODO: For clearing buffers in WinCNG, call `_libssh2_explicit_zero()`,
        insead of a local function or explicit `SecureZeroMemory()`.

- Makefile.inc: move `os400qc3.h` to `HEADERS`. This fixes
  compilation on non-unixy platforms. Recent regression.

- `libssh2.rc`: replace copyright with plain ASCII, as in curl.

  Ref: curl/curl@1ca62bb
  Ref: curl/curl#7765
  Ref: curl/curl#7776

- CMake fixes and improvements:

  - enable warnings with llvm/clang.
  - enable more comprehensive warnings with gcc and llvm/clang.
    Logic copied from curl:
    233810bb5f/CMakeLists.txt (L131-L148)
  - fix `Policy CMP0080` CMake warning by deleting that reference.
  - add `ENABLE_WERROR` (default: `OFF`) option. Ported from curl.
  - add `PICKY_COMPILER` (default: `ON`) option, as known from curl.

    It controls both the newly added picky warnings for llvm/clang and
    gcc, and also the pre-existing ones for MSVC.

- `win32/GNUmakefile` fixes and improvements:

  - delete `_AMD64_` and add missing `-m64` for x64 builds under test.
  - add support for `ARCH=custom`.
    It disables hardcoded Intel 64-bit and Intel 32-bit options,
    allowing ARM64 builds.
  - add support for `LIBSSH2_RCFLAG_EXTRAS`.
    To pass custom options to windres, e.g. in ARM64 builds.
  - add support for `LIBSSH2_RC`. To override `windres`.
  - delete support for Metrowerks C. Last released in 2004.

- `win32/libssh2_config.h`: delete unnecessary socket #includes

  `src/libssh2_priv.h` includes `winsock2.h` and `ws2tcpip.h` further
   down the line, triggered by `HAVE_WINSOCK2_H`.

  `mswsock.h` does not seem to be necessary anymore.

  Double-including these (before `windows.h`) caused compiler failures
  when building against BoringSSL and warnings with LibreSSL. We could
  work this around by passing `-DNOCRYPT`. Deleting the duplicates
  fixes these issues.

  Timeline:
  2013: c910cd382d deleted `mswsock.h` from `src/libssh2_priv.h`
  2008: 8c43bc52b1 added `winsock2.h` and `ws2tcpip.h` to `src/libssh2_priv.h`
  2005: dc4bb1af96 added the now deleted #includes

- delete or replace `LIBSSH2_WIN32` with `WIN32`.

- replace hand-rolled `HAVE_WINDOWS_H` macro with `WIN32`. Also delete
  its detections/definitions.

- delete unused `LIBSSH2_DARWIN` macro.

- delete unused `writev()` Windows implementation

  There is no reference to `writev()` since 2007-02-02, commit
  9d55db6501.

- fix a bunch of MSVC / llvm/clang / gcc compiler warnings:

  - `warning C4100: '...': unreferenced formal parameter`
  - using value of undefined PP macro `LIBSSH2DEBUG`
  - missing void from function definition
  - `if()` block missing in non-debug builds
  - unreferenced variable in non-debug builds
  - `warning: must specify at least one argument for '...' parameter of variadic macro [-Wgnu-zero-variadic-macro-arguments]`
    in `_libssh2_debug()`
  - `warning C4295: 'ciphertext' : array is too small to include a terminating null character`
  - `warning C4706: assignment within conditional expression`
  - `warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead or
      define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings`
    By suppressning it. Would be best to use inet_pton() as suggested.
    On Windows this needs Vista though.
  - `warning C4152: nonstandard extension, function/data pointer conversion in expression`
    (silenced locally)
  - `warning C4068: unknown pragma`

  Ref: https://ci.appveyor.com/project/libssh2org/libssh2/builds/46354480/job/j7d0m34qgq8rag5w

Closes #808
2023-03-03 13:30:03 +00:00
Dan Fandrich
7487dcf4b4 Add tests to check individual crypt & HMAC methods
One specific crypt or hmac method is requested to be negotiated, then
several MB of data is transferred.
2023-03-01 11:21:39 -08:00
Dan Fandrich
5f88efdddc Add test to read lots of data over a channel
Connects to the ssh server then downloads several MB of data.  This
tests the data transfer path as well as boundary cases in packet
handling as data is split into smaller SSH blocks.
2023-03-01 11:21:39 -08:00
Dan Fandrich
d8220ddbff Fix a couple of warnings of errors in MSVC builds
Two warnings (in tests & examples) in particular would cause problems:
bad format causing invalid data output or a bad chdir due to out of
scope buffer use.
2023-02-24 09:26:02 -08:00
Dan Fandrich
4c9ed51f96 tests: Support running tests in out-of-tree builds
Various files are found by referencing the srcdir environment variable
in that case.

Closes #801
2023-02-24 09:25:50 -08:00
Dan Fandrich
16619a8edd Add missing files to automake makefiles & build tests
Many files have been added to the cmake build files but not the automake
ones in recent years. Missing ones have been added so automake "make
dist" will now create a usable tar ball.

The integration tests using Docker are now built with automake as well
(with "make check").  They are not run yet since they aren't working yet
on Linux.
2023-01-06 10:47:32 -08:00
Dan Fandrich
e3ce906caf tests: Fix gcc compile warnings
These were mostly due to missing and non-ANSI prototypes.
2023-01-06 10:47:32 -08:00
Viktor Szakats
f6694beb21 tests: add option to run tests without docker (#762)
via `export OPENSSH_NO_DOCKER=1`.

SSH server host can be set via:
  `export OPENSSH_SERVER_HOST=127.0.0.1`

SSH server port via existing:
  `export OPENSSH_SERVER_PORT=4711`

This requires more work to be usable out of the box. The necessery sshd
config is (partly) embedded into `tests/openssh_server/Dockerfile`.

After this patch, it is possible to run tests in envs where docker is
not installed or not available, by running a preconfigured,
non-containerized sshd.
2022-11-12 12:40:40 +01:00
Viktor Szakats
e9561dd66e tests: add option to enable all trace messages in fixture
via `export FIXTURE_TRACE_ALL=1`.
2022-10-24 11:54:15 +02:00
Michael Buckley
ed439a29bb Support for sk-ecdsa-sha2-nistp256 and sk-ssh-ed25519 keys, FIDO (#698)
Notes:
Add support for sk-ecdsa-sha2-nistp256@openssh.com and sk-ssh-ed25519@openssh.com key exchange for FIDO auth using the OpenSSL backend. Stub API for other backends.

Credit:
Michael Buckley
2022-09-29 09:05:34 -07:00
zhaochongliu
09f0ffd9fb Support building with gcc < version 8
Files: CMakeLists.txt

Notes: don't use gcc arguments that don't exist in gcc versions lower than 8 if building with older gcc.

Credit:
zhaochongliu
2022-09-07 10:54:25 -07:00
Sandeep Bansal
4b21e49d9d Support RSA certificate authentication (#710)
* Adding support for signed RSA keys and unit test

Credit:
Sandeep Bansal
2022-07-28 08:57:34 -07:00
Will Cosgrove
dd0b5b2d2b Changed NULL check to avoid logic change 2022-04-11 09:49:00 -07:00
Will Cosgrove
3489ee9a6f NULL check before calling session_handshake 2022-04-11 09:46:52 -07:00
Marc Hoersken
c2c877b70b tests/openssh_fixture.c: print command after variable expansion 2022-03-16 22:54:33 +01:00
Marc Hoersken
87d208c95d CI: store and reuse OpenSSH Server docker image used for tests
Supersedes #588
Fixes #665
Closes #685
2022-03-16 22:37:07 +01:00
xalopp
83853f8aea Use modern API in userauth_keyboard_interactive() (#663)
Files: userauth_kbd_packet.c, userauth_kbd_packet.h, test_keyboard_interactive_auth_info_request.c, userauth.c

Notes:
This refactors `SSH_MSG_USERAUTH_INFO_REQUEST` processing in `userauth_keyboard_interactive()` in order to improve robustness, correctness and readability or the code.

* Refactor userauth_keyboard_interactive to use new api for packet parsing
* add unit test for userauth_keyboard_interactive_parse_response()
* add _libssh2_get_boolean() and _libssh2_get_byte() utility functions

Credit:
xalopp
2022-02-19 15:46:40 -08:00
Laurent Stacul
7daee037d1 openssh_fixture.c: Fix openssh_server build not working (#616) (#620)
File: openssh_fixture.c

Notes:
fixes too long of output lines building docker image

Credit:
Laurent Stacul
2021-09-02 13:17:35 -07:00