1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-01-27 00:18:12 +03:00
Commit Graph

3010 Commits

Author SHA1 Message Date
Viktor Szakats
ba53142e0e cmake: detect WinCNG last
This gives a chance to auto-detect mbedTLS on Windows with CMake.
2023-04-01 19:31:25 +02:00
Viktor Szakats
62235989e8 NMakefile: rename config variables, default to WinCNG [ci skip]
- replace `OPENSSLINC` and `OPENSSLLIB` with `OPENSSL_PATH`.
  Assume `include` and `lib` subdirs for headers and libs.

- replace `WITH_ZLIB`, `ZLIBINC` and `ZLIBLIB` with `ZLIB_PATH`.
  Assume `include` and `lib` subdirs for header and lib.

- make WinCNG the default if `WITH_OPENSSL` is not set.
2023-04-01 17:28:23 +00:00
Viktor Szakats
f058f7eacc win32/GNUmakefile: rename object dir and update .gitignore [ci skip]
From `<triplet>-{release|debug}` to `{release|debug}-<triplet>`.

Follow-up to 68fd02fba0
2023-04-01 16:39:48 +00:00
Viktor Szakats
5bcd25c4c9 win32/GNUmakefile: add libgcrypt support [ci skip]
In the previous commit 969487113a,
the commit message should read `win32/GNUmakefile: ` instead of
`libssh2-gnumake.sh: `. Sorry for the mixup.
2023-04-01 16:20:30 +00:00
Viktor Szakats
969487113a libssh2-gnumake.sh: make variable names platform-agnostic [ci skip]
Also more consistent. Refer to DLL/SO/shared as 'dyn'.

Also add comment on how to find customizable environment variables.
2023-04-01 15:51:13 +00:00
Viktor Szakats
68fd02fba0 win32/GNUmakefile: make it support non-Windows builds [ci skip]
With 20-ish extra lines, make this Makefile support all GCC-like
toolchains.

The temporary directory becomes `<triplet>-{release|debug}` from
the former `{release|debug}`.

Also change the lib directory name in the `dist` package from
`win32` to `lib`, to match other packages and build tools.
2023-04-01 15:41:15 +00:00
Viktor Szakats
82644b649a win32/GNUmakefile: default to WinCNG [ci skip]
Also check for wolfSSL before mbedTLS to match CMake.
2023-04-01 15:24:40 +00:00
Viktor Szakats
618c0e68ac win32/GNUmakefile: fixups to previous commit [ci skip]
- `-lws2_32` is necessary when building examples.

- drop a temporary variable.

Follow-up to d245c66cc0
2023-04-01 11:53:55 +00:00
Viktor Szakats
b66d7317ca delete redundant HAVE_WS2TCPIP_H
It was used once in `src/libssh2_priv.h`, but without any effect.
The header included `ws2tcpip.h` twice, once guarded by
`HAVE_WS2TCPIP_H` and another time by `HAVE_WINSOCK2_H`.

Dedupe these to not use `HAVE_WS2TCPIP_H`. Then delete detection
of this feature from all build methods.

TODO: Replace `HAVE_WINSOCK2_H` with `_WIN32`/`WIN32`.
2023-04-01 13:15:55 +02:00
Viktor Szakats
0d1ef8a7cb win32/libssh2_config.h: set HAVE_LONGLONG & HAVE_STDLIB_H [ci skip]
- enable `HAVE_LONGLONG` for MinGW and MSVC versions supporting it.

  Necessary for `GNUmakefile`/`NMakefile` builds to create the same
  binaries as CMake/autotools ones do.

- enable `HAVE_STDLIB_H`. It has been universally available on
  Windows for a long time.

  Fixes these clang-cl warnings:
  ```
  src\wincng.c(444,5) :  warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration]
      free(buf);
      ^
  src\wincng.c(491,20) :  warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long long)' [-Wimplicit-function-declaration]
      pbHashObject = malloc(dwHashObject);
                     ^
  src\wincng.c(491,20) :  note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
  src\wincng.c(2106,14) :  warning: implicitly declaring library function 'realloc' with type 'void *(void *, unsigned long long)' [-Wimplicit-function-declaration]
      bignum = realloc(bn->bignum, length);
               ^
  src\wincng.c(2106,14) :  note: include the header <stdlib.h> or explicitly provide a declaration for 'realloc'
  3 warnings generated.
  ```
2023-04-01 01:52:22 +00:00
Viktor Szakats
d245c66cc0 example: make x11 exclusion build-tool-agnostic
Whether to build the `x11` example or not was decided by each build
tool. CMake didn't build it even on supported platforms. GNUMakefile
used a specific blocklist for it, while autotools enabled it based on
feature-detection.

Migrate the enabler logic to an #ifdef in source and build `x11`
unconditionally with all build tools.

On unsupported platforms (=Windows) this program now displays a short
message stating that fact.

Also:

- fix `x11.c` warnings uncovered after CMake started building it.

- use `libssh2_socket_t` type for portability in `x11.c` too.

- use detected header guards in `x11.c`.

- delete a duplicate reference to `-lws2_32` from `win32/GNUmakefile`
  while there.

Closes #909
2023-04-01 01:36:54 +00:00
Viktor Szakats
91af53851d .gitignore updates [ci skip] 2023-03-31 23:45:36 +00:00
Viktor Szakats
9aa1964dfb tidy-up: whitespace, sorting, comment and naming fixups 2023-03-31 23:46:06 +02:00
Viktor Szakats
ccfeac87da cmake: add missing man pages 2023-03-31 23:44:00 +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
3da46f17ad cmake: add missing #cmakedefines to src
- `HAVE_MEMSET_S` missing since
  0309229259 (2018-08-02)

- `HAVE_EXPLICIT_BZERO` and `HAVE_EXPLICIT_MEMSET` missing since
  00005682f7 (2023-03-28)
2023-03-31 12:12:41 +02:00
Viktor Szakats
bcb5eda096 tidy-up: NMakefile (#903) 2023-03-31 00:17:46 +02:00
Viktor Szakats
e195aeeff3 GNUmakefile: adjust win32/.gitignore [ci skip] 2023-03-30 19:08:27 +00:00
Viktor Szakats
46f233fd7d build: delete references to deleted NMake files [ci skip]
Follow-up to 057522bb0f
2023-03-30 19:05:27 +00:00
Viktor Szakats
057522bb0f NMakefile: merge them into a single file [ci skip] (#902)
Also:

- allow to override `AR` and `ARFLAGS`.

- The extra `src` subdir in the target directory is no longer, to
  simplify things.

- gone the dynamically generated `objects.mk`. Now replaced with some
  tricky logic to do that inline.

- add necessary `LIBS` for WinCNG. (untested)

Lightly tested via clang-cl.
2023-03-30 21:01:01 +02: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
d23133b5a3 ci: flatten AppVeyor jobs, add debug builds (#900)
This results in better job names (now including CPU), avoiding the
complex exception rules, and fine-tuning the order and variation of
these tests.

Enable `LIBSSH2DEBUG` for two of the existing jobs.
2023-03-29 22:53:59 +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
08354e0abb src: fix compiler warning on Darwin (#898)
```
src/session.c:675:52: warning: implicit conversion loses integer precision: 'long' to '__darwin_suseconds_t' (aka 'int') [-Wshorten-64-to-32]
        tv.tv_usec = (ms_to_next - tv.tv_sec*1000) * 1000;
                   ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
```
2023-03-29 10:07:57 +02:00
Viktor Szakats
0b61317e6f tidy-up: tabs to spaces in Makefile.am [ci skip]
Follow-up to 2f16d8105c
2023-03-29 00:35:40 +00:00
Viktor Szakats
84f5cb9f23 netware: delete support (#888)
Last related commit happened 15 years ago.
NetWare had it last release in 2009.

All links referenced from the make file are inaccessible.
2023-03-29 02:09:30 +02:00
Viktor Szakats
da0584534f wolfssl: add workaround for HMAC_Update() len arg difference (#897)
It's `int` in wolfSSL. `size_t` in OpenSSL/quictls/LibreSSL/BoringSSL.

Ref: ba47562d18/wolfssl/openssl/hmac.h (L60-L61)

/cc @wolfSSL
2023-03-28 23:46:58 +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
00005682f7 detect and use explicit_bzero() and explicit_memset() (#895)
Also skip detecting these and `memset_s()` for Windows targets in CMake,
to save detection time. On Windows we always use `SecureZeroMemory()`.
2023-03-28 17:49:38 +02:00
Viktor Szakats
9e99a80ebf ci: bump mbedtls (#894) 2023-03-28 17:47:34 +02:00
Viktor Szakats
9cfb5816df GNUmakefile: minor fix for DYN mode [ci skip] (#893)
Follow-up to b8762c1003
2023-03-28 17:22:40 +02:00
Viktor Szakats
243e7a82f7 build: delete MS Dev Studio build files (#891)
Last updated in 2007.

Also delete `VCPROJ` target remains (necessary files seem to have
been missing from the repo all along) for Visual Studio 2008.
2023-03-28 14:58:07 +02:00
Viktor Szakats
4e0f0ceeb3 checksrc: fix reference in Makefile.am, update options [ci skip] 2023-03-28 07:59:24 +00:00
Viktor Szakats
b35381e446 build: delete native Watcom wmake support with Win32 (#889)
CMake supports generating Watcom wmake files:
https://cmake.org/cmake/help/v3.1/generator/Watcom%20WMake.html
2023-03-28 09:40:51 +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
480965e2d9 tidy-up: fix/update URLs (#887) 2023-03-27 19:48:41 +02:00
Viktor Szakats
1d9af00609 tidy-up: fix typos (#886)
detected by codespell 2.2.4.
2023-03-27 19:26:58 +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
0d08974633 ci: drop cmake --parallel (#884)
`--parallel 2` did not seem to make builds faster. Neither did 4 or 6.

Delete this option from both GHA and AppVeyor jobs.

On AppVeyor, with VS, it uses MSBuild under the hood where apparently
`--parallel` doesn't do much [1]. The suggested MSBuild-specific option
`/p:CL_MPcount=2` did not improve build times either.

CMake spends significant time (comparable to building the project
itself) on feature detection, it'd be nice to execute those in parallel,
but I found not such CMake option.

[1] https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964

Partial revert of 7a039d9a7a
2023-03-27 16:29:00 +02:00
Viktor Szakats
50c9bf868e rework how to enable insecure null-cipher/null-MAC (#873)
Null-cipher and null-MAC are security footguns we want to avoid.

Existing option names to toggle these were ambiguous and gave room for
misinterpretation. Some projects may have had these options enabled by
accident.

This patch aims to make it more difficult to enable them, and making
sure that existing methods require an update to stay enabled.

- delete CMake/autotools settings to enable the "none" cipher and MAC.

- rename existing C macros that can enable them.

  To use them, pass them as custom `CPPFLAGS` to the build.

- enable them only if `LIBSSH2DEBUG` is also enabled.

Best would be to delete them, though they may have some use while
developing libssh2 itself, or debugging.
2023-03-27 11:34:54 +02:00
Viktor Szakats
38177f18dd delete old gex (SSH2_MSG_KEX_DH_GEX_REQUEST_OLD) build option (#872)
libssh2 supports an "old" style KEX message
`SSH2_MSG_KEX_DH_GEX_REQUEST_OLD`, as an off-by-default build option.

OpenSSH deprecated/disabled this feature in v6.9 (2015-07-01):
https://www.openssh.com/releasenotes.html#6.9

This patch deletes this obsolete feature from libssh2, with no option
to enable it.

Added to libssh2 in: cf8ca63ea0 (2004-12-31)
RFC: https://datatracker.ietf.org/doc/html/rfc4419 (2006-03)
2023-03-27 11:28:51 +02:00
Viktor Szakats
4f28eec947 src: more tolerant snprintf() local override (#881)
`#undef snprintf` before redefining it, when `HAVE_SNPRINTF` is not
defined, even though `snprintf` is available and it should have been.
Possibly with 3rd party builds.

Downside is that cases of missing `HAVE_SNPRINTF` are less trivially
detected at compile-time.
2023-03-27 11:27:59 +02:00
Viktor Szakats
a3d42f41d0 ci: fix cmake warning with AppVeyor WinCNG builds (#883)
```
CMake Warning:
  Manually-specified variables were not used by the project:

    OPENSSL_ROOT_DIR
```

Follow-up to 0834b9bcc8
2023-03-27 11:27:05 +02:00
Viktor Szakats
71cae949d5 ci: cmake ENABLE_WERROR -> ON (#877)
Consider warnings as errors for CMake jobs in CI.
2023-03-27 01:23:55 +02:00
Viktor Szakats
2934790572 src: silence compiler warnings 4 (alignment in WinCNG)
Silence alignment warnings in WinCNG, by reworking the code.

Also add two unrelated casts to avoid gcc compiler warnings
in surrounding code.

`increases required alignment from 1 to 4 [-Wcast-align]`
`increases required alignment from 1 to 8 [-Wcast-align]`

See warning details in the PR's individual commits.

Reviewed-by: Marc Hörsken in <https://github.com/libssh2/libssh2/pull/846#pullrequestreview-1350253621>
Cherry-picked from #846
Closes #880
2023-03-26 22:50:14 +00:00
Viktor Szakats
5a96f494ee src: silence compiler warnings 3 (change types)
Apply type changes to avoid casts and warnings. In most cases this
means changing to a larger type, usually `size_t` or `ssize_t`.

Change signedness in a few places.

Also introduce new variables to avoid reusing them for multiple
purposes, to avoid casts and warnings.

- add FIXME for public `libssh2_sftp_readdir_ex()` return type.

- fix `_libssh2_mbedtls_rsa_sha2_verify()` to verify if `sig_len`
  is large enough.

- fix `_libssh2_dh_key_pair()` in `wincng.c` to return error if
  `group_order` input is negative.

  Maybe we should also reject zero?

- bump `_libssh2_random()` size type `int` -> `size_t`. Add checks
  for WinCNG and OpenSSL to return error if requested more than they
  support (`ULONG_MAX`, `INT_MAX` respectively).

- change `_libssh2_ntohu32()` return value `unsigned int` -> `uint32_t`.

- fix `_libssh2_mbedtls_bignum_random()` to check for a negative `top`
  input.

- size down `_libssh2_wincng_key_sha_verify()` `hashlen` to match
  Windows'.

- fix `session_disconnect()` to limit length of `lang_len`
  (to 256 bytes).

- fix bad syntax in an `assert()`.

- add a few `const` to casts.

- `while(1)` -> `for(;;)`.

- add casts that didn't fit into #876.

- update `docs/HACKING-CRYPTO` with new sizes.

May need review for OS400QC3: /cc @monnerat @jonrumsey

See warning details in the PR's individual commits.

Cherry-picked from #846
Closes #879
2023-03-26 22:42:04 +00:00
Viktor Szakats
463449fb9e src: silence compiler warnings 2 (ZLIB interface)
Silence warnings in the ZLIB interface by adding casts and changing
types.

See PR for individual commits.

Cherry-picked from #846
Closes #878
2023-03-26 09:37:05 +00:00
Viktor Szakats
02f2700a61 src: silence compiler warnings 1
Most of the changes aim to silence warnings by adding casts.

An assortment of other issues, mainly compiler warnings, resolved:

- unreachable code fixed by using `goto` in
  `publickey_response_success()` in `publickey.c`.

- potentially uninitialized variable in `sftp_open()`.

- MSVS-specific bogus warnings with `nid_type` in `kex.c`.

- check result of `kex_session_ecdh_curve_type()`.

- add missing function declarations.

- type changes to fit values without casts:
  - `cmd_len` in `scp_recv()` and `scp_send()`: `int` -> `size_t`
  - `Blowfish_expandstate()`, `Blowfish_expand0state()` loop counters:
    `uint16_t` -> `int`
  - `RECV_SEND_ALL()`: `int` -> `ssize_t`
  - `shell_quotearg()` -> `unsigned` -> `size_t`
  - `sig_len` in `_libssh2_mbedtls_rsa_sha2_sign()`:
    `unsigned` -> `size_t`
  - `prefs_len` in `libssh2_session_method_pref()`: `int` -> `size_t`
  - `firstsec` in `_libssh2_debug_low()`: `int` -> `long`
  - `method_len` in `libssh2_session_method_pref()`: `int` -> `size_t`

- simplify `_libssh2_ntohu64()`.

- fix `LIBSSH2_INT64_T_FORMAT` for MinGW.

- fix gcc warning by not using a bit field for
  `burn_optimistic_kexinit`.

- fix unused variable warning in `_libssh2_cipher_crypt()` in
  `libgcrypt.c`.

- fix unused variables with `HAVE_DISABLED_NONBLOCKING`.

- avoid const stripping with `BIO_new_mem_buf()` and OpenSSL 1.0.2 and
  newer.

- add a missing const in `wincng.h`.

- FIXME added for public:
  - `libssh2_channel_window_read_ex()` `read_avail` argument type.
  - `libssh2_base64_decode()` `datalen` argument type.

- fix possible overflow in `sftp_read()`.

  Ref: 4552c73cd5

- formatting in `wincng.h`.

See warning details in the PR's individual commits.

Cherry-picked from #846
Closes #876
2023-03-26 09:34:26 +00:00
Viktor Szakats
bd078e12bd cmake: automatic exports macro tidy-up (#875)
In a recent CMake update I left the original CMake EXPORTS macro
unchanged (`libssh2_EXPORTS`) for compatibility.

However, that macro was also recently added [1] and not present in an
official release yet, so we might as well just use the new native one
instead (`libssh2_shared_EXPORTS`), defined by CMake automatically.
This way we don't need to define the old macro manually.

CMake forms this macro from the lib's internal name as defined in
`add_library()` by appending `_EXPORTS`. That target name changed from
`libssh2` to `libssh2_shared` after introducing dual shared + static
builds in the recent update.

If we're here, add a new, stable, build-tool agnostic macro with the
same effect, for non-CMake use: `LIBSSH2_EXPORTS`

[1] 1f0fe7443a (2021-10-26)

Follow-up to 4e2580628d
2023-03-24 03:29:46 +01:00