1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-01-06 14:21:57 +03:00
Commit Graph

2765 Commits

Author SHA1 Message Date
Viktor Szakats
8715c3d51b cmake: add integration tests
Add a small project to test dependent/downstream CMake build using
libssh2. Also added to the GHA CI, and you can also run it locally with
`tests/cmake/test.sh`.

Test three methods of integrating libssh2 into a project:
- via `find_package()`:
  https://cmake.org/cmake/help/latest/command/find_package.html
- via `add_subdirectory()`:
  https://cmake.org/cmake/help/latest/command/add_subdirectory.html
- via `FetchContent`:
  https://cmake.org/cmake/help/latest/module/FetchContent.html

Closes #1170
2023-08-17 09:01:08 +00:00
Viktor Szakats
4ff64ae3ca cmake: (re-)add aliases for add_subdirectory() builds
Add internal libssh2 library aliases to make these available for
downstream/dependent projects building libssh2 via `add_subdirectory()`:

- `libssh2:libssh2_static`
- `libssh2:libssh2_shared`
- `libssh2:libssh2` (shared, or static when not building shared)
- `libssh2` (shared, or static when not building shared)

Of these, `libssh2` was present in v1.10.0 and earlier releases, but
missing from v1.11.0.

Closes #1169
2023-08-16 07:10:51 +00:00
Viktor Szakats
8eade0c9b7 cmake: delete empty line [ci skip]
Follow-up to 3fa5282d62
2023-08-16 06:36:16 +00:00
Viktor Szakats
6eda1ee433 cmake: reflect minimum version in docs [ci skip]
Follow-up to 9cd18f4578
2023-08-15 21:58:56 +00:00
Viktor Szakats
3fa5282d62 cmake: style tidy up
- quote text literals to improve readability.
  (exceptions: `FILES` items, `add_subdirectory` names, `find_package`
  names, literal target names, version numbers, 0/1, built-in CMake
  values and CMake keywords, list items in `cmake/max_warnings.cmake`)
- quote standalone variables that could break syntax on empty values.
- replace `libssh2_SOURCE_DIR` with `PROJECT_SOURCE_DIR`.
- add missing mode to `message()` call.
- `TRUE`/`FALSE` → `ON`/`OFF`.
- add missing default value `OFF` to `option()` for clarity.
- unfold some lines.
- `INSTALL_CMAKE.md` fixes and updates. Show defaults.

Closes #1166
2023-08-15 15:08:30 +00:00
Viktor Szakats
186c1d6394 wincng: prefer ULONG/DWORD over unsigned long
To match with the types used by the `Crypt*()` (uses `DWORD`) and
`BCrypt*()` (uses `ULONG`) Windows APIs.

This patch doesn't change data width or signedness.

Closes #1165
2023-08-15 10:42:00 +00:00
Viktor Szakats
7bb669b52a wincng: tidy-ups
- make `_libssh2_wincng_key_sha_verify` static.

- prefer `unsigned long` over `size_t` in two static functions.

- prefer `ULONG` over `DWORD` to match `BCryptImportKeyPair()`
  and `BCryptGenerateKeyPair()`.

- add a newline.

Closes #1164
2023-08-15 01:31:19 +00:00
Viktor Szakats
d43b8d9b0b ci: add MSYS builds (autotools and cmake)
Use existing MSYS2 section and extend it with builds for the MSYS
environment with both autotools and cmake.

MSYS builds resemble Cygwin ones: The env is Unixy, where Windows
headers are all available but we don't use them.

Also:

- extend existing autotools logic for Cygwin to skip detecting
  `windows.h` for MSYS targets too.

- require `windows.h` for the WinCNG backend in autotools. Before this
  patch, autotools allowed selecting WinCNG on the Cygwin and MSYS
  platforms, but the builds then fell apart due to the resulting mixed
  Unixy + Windowsy environment. The general expectation for Cygwin/MSYS
  builds is not to use the Windows API directly in them.

- stop manually selecting the `MSYS Makefiles` CMake generator for
  MSYS2-based GHA CI builds. mingw-w64 builds work fine without it, but
  it broke MSYS build which use `Unix Makefiles`. Deleting this setting
  fixes all build flavours.

Closes #1162
2023-08-14 23:10:15 +00:00
Viktor Szakats
84912e2ed8 ci: cygwin job tidy-ups
`CMAKE_C_COMPILER=gcc` not necessary, delete it.

Follow-up to f1e96e733f

Cherry-picked from #1163
Closes #1163
2023-08-14 23:09:54 +00:00
Viktor Szakats
f1e96e733f ci: add Cygwin builds (autotools and cmake)
To avoid builds picking up non-Cygwin components coming by default with
the CI machine, I used the solution recommended by Cygwin [1] and set
`PATH` manually. To avoid repeating this for each step, I merged steps
into a single one. Let us know if there is a more elegant way.

Cygwin's Github Action uses cleartext HTTP. We upgrade this to HTTPS.

autotools build seemed to take slightly longer than other jobs. To save
turnaround time I disabled building tests.

Cygwin package search: https://cygwin.com/cgi-bin2/package-grep.cgi

[1] https://github.com/cygwin/cygwin-install-action/tree/v4#path

Closes #1161
2023-08-14 21:54:43 +00:00
Viktor Szakats
5453fc8035 cmake: add LIB_NAME variable
It holds the name `libssh2`. Mainly to document its uses, and also
syncing up with the same variable in libcurl.

Closes #1159
2023-08-13 10:20:57 +00:00
Viktor Szakats
c705ff3f37 cmake: add one missed PROJECT_NAME variable
Follow-up to 72fd25958a

Closes #1158
2023-08-11 23:09:52 +00:00
Viktor Szakats
ae7d51085e cmake: tidy-up concatenation in CMAKE_MODULE_PATH
Former solution was appending an empty element to the array if
`CMAKE_MODULE_PATH` was originally empty. The new syntax doesn't have
this side-effect.

There is no known issue caused by this. Fixing it for good measure.

Closes #1157
2023-08-11 20:10:23 +00:00
Viktor Szakats
1215aa5f46 ci: add mingw-w64 UWP build
Add a CI test for Windows UWP builds using mingw-w64. Before this patch
we had UWP builds tested with MSVC only.

Alike existing UWP jobs, it's not possible to run the binaries due to
the missing UWP runtime DLL:
https://github.com/libssh2/libssh2/actions/runs/5821297010/job/15783475118#step:11:42

We could install `winstorecompat-git` in the setup-msys2 step, but opted
to do it manually to avoid the overhead for every matrix job.

All this would work smoother with llvm-mingw, which features an UWP
toolchain prefix and provides all necessary implibs by default.

This also hit a CMake bug (with v3.26.4), where CMake gets confused and
sets up `windres.exe` to use the MSVC rc.exe-style command-line:
https://github.com/libssh2/libssh2/actions/runs/5819232677/job/15777236773#step:9:126

Notice that MS "sunset" UWP in 2021:
https://github.com/microsoft/WindowsAppSDK/discussions/1615

If this particular CI job turns out to be not worth the maintenance
burden or CPU time, or too much of a hack, feel free to delete it.

Ref: https://github.com/libssh2/libssh2/pull/1147#issuecomment-1670850890
Closes #1155
2023-08-10 22:56:47 +00:00
Viktor Szakats
72fd25958a cmake: replace libssh2 literals with PROJECT_NAME variable
Where applicable.

This also makes it more obvious which `libssh2` uses were referring
to the project itself.

Closes #1152
2023-08-09 15:47:49 +00:00
Viktor Szakats
42d3bf1348 cmake: fix STREQUAL check in error branch
This caused a CMake error instead of our custom error when manually
selecting the `WinCNG` crypto-backend for a non-Windows target.

Also cleanup `STREQUAL` checks to use variable name without `${}` on
the left side and quoted string literals on the right.

Closes #1151
2023-08-09 15:47:49 +00:00
Viktor Szakats
74e742887c misc: flatten _libssh2_explicit_zero if tree
Closes #1149
2023-08-09 15:47:49 +00:00
Viktor Szakats
1f0174d0df src: drop a redundant #include
We include `misc.h` via `libssh2_priv.h` already.

Closes #1153
2023-08-09 15:47:49 +00:00
Viktor Szakats
d79047c938 openssl: use automatic initialization with LibreSSL 2.7.0+
Stop calling `OpenSSL_add_all_*()` for LibreSSL 2.7.0 and later.

LibreSSL 2.7.0 (2018-03-21) introduced automatic initialization and
deprecated these functions. Stop calling these functions manually for
LibreSSL version that no longer need them.

Ref: https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.7.0-relnotes.txt
Ref: 46f29f1197
Ref: https://github.com/libssh2/libssh2/issues/302

Also stop calling `ENGINE_*()` functions when initialization is
automatic with LibreSSL 2.7.0+ and OpenSSL 1.1.0+. Engines are also
initializated automatically with these.

Closes #1146
2023-08-07 20:44:09 +00:00
Viktor Szakats
36748270f9 gha: restore curly braces in if
Without curly braces it was less obvious which string is a GHA expression.

Also fix an `if` expression that always missed its curly braces.

Reverts cab3db5887

Closes #1145
2023-08-06 11:46:20 +00:00
Viktor Szakats
82b0c89e29 ci: bump mbedtls 2023-08-04 01:01:31 +02:00
renmingshuai
63b4c20eb0 Add a new structure to separate memory read and file read.
We use different APIs when we read one private key from memory,
so it is improper to store the private key information in the
structure that stores the private key file information.

Fixes https://github.com/libssh2/libssh2/issues/773
Reported-by: mike-jumper
2023-08-03 13:10:32 +02:00
Viktor Szakats
1a99a86a29 tests: replace FIXME with comments
`key_dsa_wrong` is the same kind of (valid) key as `key_dsa`, both with
an empty passphrase. Named "wrong" because it's intentionally not added
to our `openssh_server/authorized_keys` file.
2023-08-03 01:12:21 +00:00
Viktor Szakats
76307435b8 tidy-up: delete duplicate word from comment 2023-08-02 23:04:43 +00:00
Viktor Szakats
11a03690e1 cmake: cache more config values on Windows
Set two cases of non-detection to save the time dynamically detecting
these on each build init. Affects old MSVC versions.

Before:
https://ci.appveyor.com/project/libssh2org/libssh2/builds/47668870/job/i17e0e9yx8rgpv4i

After:
https://ci.appveyor.com/project/libssh2org/libssh2/builds/47674950/job/ysa1jq0pxtyhui3f

Closes #1142
2023-07-31 09:52:35 +00:00
Viktor Szakats
481be044e0 revert: build: respect autotools DLL_EXPORT in libssh2.h
Revert fb1195cf88 #917

On a second look this change did not improve anything with autotools
builds. autotools seems to handle the dll export matter without it.

This patch also broke (e.g.) curl-for-win autotools builds, where the
curl build defines `DLL_EXPORT` while building libcurl DLL. `libssh2.h`
picks it up, resulting in unresolved symbols while trying to link a
static libssh2 on Windows. The best fix seems to be to revert this,
instead of adding extra tweaks to dependents.

Fixes:
https://ci.appveyor.com/project/curlorg/curl-for-win/builds/47667412#L11035
```
ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_block_directions
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_do)
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_connect)
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_multi_statemach)
>>> referenced 8 more times

ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_init_ex
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_connect)

ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_set_read_timeout
[...]
```

Closes #1141
2023-07-29 23:52:33 +00:00
Viktor Szakats
cab3db5887 gha: simplify if strings
Closes #1140
2023-07-28 10:03:57 +00:00
Viktor Szakats
57e9d18e38 test_read: make it run without Docker
Apply an existing fix to `test_read`, so that it falls back to use
the current username instead of the hardcoded `libssh2` when run
outside Docker.

This allows to run algo tests with this command:
```shell
cd tests
./test_sshd.test ./test_read_algos.test
```

Closes #1139
2023-07-27 10:49:42 +00:00
Viktor Szakats
f58f77b5c8 cmake: streamline invocation
Stop specifiying the current directory.
Simplify build instructions.

Closes #1138
2023-07-27 10:49:00 +00:00
Viktor Szakats
c515eed398 NMakefile: delete
This make file was for long time unmaintained (last updated in 2014).
Despite best efforts to keep it working in the recent round of major
overhauls, it appears to be broken now. There is also no way to test it
without an actual MSVC env and it's also missing from our CI. Based on
our Issue tracker, it's also not widely used.

Since its addition in 2005, libssh2 got support for CMake in 2014.
CMake should be able to generate NMake makefiles with the option
`-G "NMake Makefiles"`. (I haven't tested this.)

Ref: https://github.com/libssh2/libssh2/discussions/1129
Closes #1134
2023-07-26 09:38:02 +00:00
Viktor Szakats
802336cf95 tests: add aes256-gcm encrypted key test
Follow-up to #1133

Also update `tests/gen_keys.sh` to set `aes256-ctr` encryption method
for `key_ed25519_encrypted' explicitly.

Closes #1135
2023-07-26 07:17:29 +00:00
Jakob Egger
e87bdefac6 Fix private keys encrypted with aes-gcm methods (#1133)
libssh2 1.11.0 fails to decrypt private keys encrypted with
aes128-gcm@openssh.com and aes256-gcm@openssh.com ciphers.

To reproduce the issue, you can create a test key with a command like
the following:

```bash                                                        
ssh-keygen -Z aes256-gcm@openssh.com -f id_aes256-gcm          
```                                                            
                                                               
If you attempt to use this key for authentication, libssh2 returns the
not-so-helpful error message "Wrong passphrase or invalid/unrecognized
private key file format".                                      
                                                               
The problem is that OpenSSH encrypts keys differently than packets. It
does not include the length as AAD, and the 16 byte authentication tag
is appended after the encrypted key. The length of the authentication
tag is not included in the encrypted key length.               
                                                               
I have not found any documentation for this behaviour -- I discovered it
by looking at the OpenSSH source. See the `private2_decrypt` function in
<https://github.com/openssh/openssh-portable/blob/master/sshkey.c>.

This patch fixes the code for reading OpenSSH private keys encrypted
with AES-GCM methods.
2023-07-26 09:15:20 +02:00
Viktor Szakats
6265ffdb70 ci: add missing timeout to 'autotools distcheck' step 2023-07-26 00:05:00 +00:00
Viktor Szakats
a909100705 cmake: merge set_target_properties() calls
Also rename variable `LIBSSH2_VERSION` to `LIBSSH2_LIBVERSION` in
context of lib versioning to avoid collision with another use.

Closes #1132
2023-07-25 11:17:02 +00:00
Viktor Szakats
2fdc10ba04 cmake: formatting [ci skip] 2023-07-25 08:38:54 +00:00
Viktor Szakats
6464301820 cmake: (re-)add zlib to Libs.private in libssh2.pc
We mistakently added transitive zlib to `Requires.private` before, then
removed it. This patch re-adds zlib, but this time to `Libs.private`,
which is listing raw libs and should include transitive libs as well.

Also add zlib when used as a direct dependency when zlib compression
support is enabled.

Follow-up to ef538069a6

Closes #1131
2023-07-23 19:27:22 +00:00
Viktor Szakats
83910b724c cmake: formatting [ci skip] 2023-07-23 14:44:22 +00:00
Viktor Szakats
c5ec6c4945 cmake: use wolfssl/options.h for detection, like autotools
Closes #1130
2023-07-21 14:21:50 +00:00
Viktor Szakats
c84745e34e build: stop requiring libssl from openssl
libssh2 does not use or need the TLS/SSL library of OpenSSL.
It only needs libcrypto.

Closes #1128
2023-07-21 12:21:54 +00:00
Viktor Szakats
5cfa59d391 cmake: add openssl libs to Libs.private in libssh2.pc
Also to sync up with autotools-generated `libssh2.pc`, that
already added them.

Closes #1127
2023-07-20 16:47:17 +00:00
Viktor Szakats
75ed30917d Makefile.mk: stop linking unused mbedtls libs
Stop linking libmbedtls and libmbedx509 (similarly to autotools).
Only libmbedcrypto is necessary for libssh2.
2023-07-20 12:52:44 +00:00
Viktor Szakats
9cd18f4578 cmake: bump minimum CMake version to v3.7.0
Fixes the warning below, which appeared in CMake v3.27.0:
```
CMake Deprecation Warning at CMakeLists.txt:39 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.
```

Bump straight up to v3.7.0 to sync up with the curl project:
2900c29218/CMakeLists.txt (L64)

CMake release dates:
v3.7.0 2016-11-11
v3.5.0 2016-03-08
v3.1.0 2014-12-17

Closes #1126
2023-07-20 12:45:50 +00:00
Viktor Szakats
5720dd9fe0 build: tidy-up libssh2.pc.in variable names
- prefix with `LIBSSH2_PC_`

- match with the names of `pkg-config` values.

- use the same names in autotools and CMake scripts.

- use `LIBSSH2_VERSION` for the version number in autotools scripts,
  to match the name used in CMake.

Closes #1125
2023-07-18 20:45:14 +00:00
Viktor Szakats
624abe275f libssh2.pc: re-add & extend support for static-only libssh2 builds
Adapted for libssh2 from the curl commit message by James Le Cuirot:

"A project built entirely statically will call `pkg-config` with
`--static`, which utilises the `Libs.private:` field. Conversely it will
not use `--static` when not being built entirely statically, even if
there is only a static build of libssh2 available. This will most
likely cause the build to fail due to underlinking unless we merge the
`Libs:` fields.

Consider that this is what the Meson build system does when it generates
`pkg-config` files."

This patch extends the above to `Requires:`, to mirror `Libs:` with
`pkg-config` package names.

Follow-up to 1209c16d93 #1114

Ref: https://github.com/libssh2/libssh2/pull/1114#issuecomment-1634334809
Ref: 98e5904165
Ref: https://github.com/curl/curl/pull/5373
Closes #1119
2023-07-18 15:18:50 +00:00
Nursan Valeyev
0f396aa926 cmake: CMAKE_SOURCE_DIR -> PROJECT_SOURCE_DIR (#1121)
Fixes compiling as dependency with FetchContent

Co-authored-by: Viktor Szakats
2023-07-14 23:25:05 +02:00
Viktor Szakats
7f83de14a0 autotools: use comma separator in Requires.private of libssh2.pc
In `Requires*:`, the documented name separator is comma. We already used
it in the CMake-generated `libssh2.pc`. Adjust the autotools-generated
one to use it too, instead of spaces.

Ref: https://linux.die.net/man/1/pkg-config
Ref: d97db4fae4/pkg-config.1

Closes #1124
2023-07-14 21:08:44 +00:00
Viktor Szakats
ef538069a6 build: add/fix Requires.private packages in libssh2.pc
- autotools was using `libwolfssl`. CMake left it empty. wolfSSL
  provides `wolfssl.pc`. This patch sets `Requires.private: wolfssl`
  with both build tools.

- add `libgcrypt` to `Requires.private` with both autotools and CMake.
  Ref:
    e76e88eef7/src/libgcrypt.pc.in
  Present since 2005-04-22:
    32bf3f13e8
  Released in v1.3.0 2007-05-04:
    https://github.com/gpg/libgcrypt/releases/tag/libgcrypt-1.3.0

- also stop adding transitive `zlib` deps to `Requires.private`.
  The referenced crypto package is adding it as nedded.
  This makes deduplication of the list redundant, so stop doing it.
  Follow-up to 2fc3679007

(`libssh2.pc` not tested as a project dependency.)

Closes #1123
2023-07-14 18:36:25 +00:00
Viktor Szakats
2fc3679007 cmake: tidy-ups
- dedupe `Requires.private` in `libssh2.pc`.
  `zlib` could appear on the list twice:
  ```
  Requires.private: libssl,libcrypto,zlib,zlib
  ```
  According to CMake docs `list(REMOVE_DUPLICATES ...)`, is supported by
  our minimum required CMake version (and by   earlier ones even):
  https://cmake.org/cmake/help/v3.1/command/list.html#remove-duplicates

- move `cmake_minimum_required()` to the top.

- move `set(CMAKE_MODULE_PATH)` to the top.

- delete duplicate `set(CMAKE_MODULE_PATH)`.

- replace `CMAKE_CURRENT_SOURCE_DIR` with `PROJECT_SOURCE_DIR` in root
  `CMakeLists.txt` for robustness.

- replace `gcovr` option with long-form for readability/consistency.

- rename `GCOV_OPTIONS` to `GCOV_CFLAGS`. These are C options we enable
  when using gcov, not gcov tooling options.

Closes #1122
2023-07-14 12:36:02 +00:00
Viktor Szakats
4a42f42e40 openssl: add missing check for LIBRESSL_VERSION_NUMBER before use
Fixes:
```
openssl.h:101:5: warning: "LIBRESSL_VERSION_NUMBER" is not defined [-Wundef]
     LIBRESSL_VERSION_NUMBER >= 0x3050000fL
     ^
```

Ref: https://github.com/libssh2/libssh2/issues/1115#issuecomment-1631845640
Closes #1117
2023-07-12 10:56:30 +00:00
Harmen Stoppels
1209c16d93 Don't put @LIBS@ in pc file 2023-07-11 12:02:46 +02:00