1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-08-07 08:02:56 +03:00
Commit Graph

2997 Commits

Author SHA1 Message Date
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
Viktor Szakats
573e4ed0c9 misc: delete redundant NULL check and assignment
Follow-up to 724effcb47 #1109

Ref: https://github.com/libssh2/libssh2/pull/1109#discussion_r1246613274
Closes #1111
2023-07-02 09:18:40 +00:00
renmingshuai
bec57c409d We should check whether *key_method is a NULL pointer instead of key_method
Signed-off-by: renmingshuai <renmingshuai@huawei.com>
2023-07-01 18:51:08 +02:00
ren mingshuai
724effcb47 Add NULL pointer check for outlen before use (#1109)
Before assigning a value to the outlen, we need to check whether it is NULL.

Credit: Ren Mingshuai <renmingshuai@huawei.com>
2023-06-30 10:34:44 -07:00
Viktor Szakats
2da13c13e1 cmake: re-add Libssh2:libssh2 for compatibiliy + lowercase namespace
- add `libssh2:libssh2` target that selects the shared lib if built,
  otherwise the static one.

- re-add `Libssh2:libssh2` target for compatibility with v1.10.0 and
  earlier. This is an alias for `libssh2:libssh2`.

- keep `libssh2:libssh2_shared` and `libssh2_libssh2_static` targets.

- allow using `find_package(libssh2)` in dependents as an alternative
  to `find_package(Libssh2)`.

Co-authored-by: Radek Brich
Suggested-by: Haowei Hsu

Fixes #1103
Fixes #731
Closes #1104
2023-06-25 19:14:18 +00:00
Viktor Szakats
279a2e57e5 example: fix regression in ssh2_exec.c
Regression from b13936bd6a #861 #846.
Update a variable name missed above.

Reported-by: PewPewPew
Fixes #1105
Closes #1106
2023-06-25 16:48:49 +00:00
Viktor Szakats
766bde9fb9 docs: replace SHA1 with SHA256 in CMake example 2023-06-23 16:31:16 +00:00
Viktor Szakats
3d309f9b8d checksrc: modernise perl file open
Use regular variables and separate file open modes from filenames.

Suggested by perlcritic

Copied from 7f669aa0f1
Copied from https://github.com/curl/trurl/commit/f2784a9240f47ee28a845
2023-06-23 16:30:41 +00:00
Viktor Szakats
fe6239a11f reuse: comply with 3.1 spec and 2.0.0 checker
The checker tool was upgraded upstream to 2.0.0 and the REUSE
Specification to version 3.1 (from 3.0), causing these new errors:
```
reuse.project - WARNING - Copyright and licensing information for 'docs/INSTALL_AUTOTOOLS' have been found in 'docs/INSTALL_AUTOTOOLS' and the DEP5 file located at '.reuse/dep5'. The information in the DEP5 file has been overridden. Please ensure that this is correct.
reuse.project - WARNING - Copyright and licensing information for 'tests/openssh_server/Dockerfile' have been found in 'tests/openssh_server/Dockerfile' and the DEP5 file located at '.reuse/dep5'. The information in the DEP5 file has been overridden. Please ensure that this is correct.

The following files have no licensing information:
* docs/INSTALL_AUTOTOOLS
* tests/openssh_server/Dockerfile
```
Via: https://github.com/libssh2/libssh2/actions/runs/5333572682/jobs/9664211341?pr=1098#step:4:4

Ref: https://github.com/fsfe/reuse-tool/releases/tag/v2.0.0
Ref: https://git.fsfe.org/reuse/docs/src/branch/stable/CHANGELOG.md#3-1-2023-06-21

Original discovery: https://github.com/libssh2/libssh2/pull/1098#issuecomment-1600719575

Fixes #1101
Closes #1102
2023-06-21 17:43:42 +00:00
Viktor Szakats
b2916b286b tests: trap signals in scripts
Closes #1098
2023-06-21 12:50:26 +00:00
Viktor Szakats
ad7188456f test_sshd.test: fixup to distcheck failure
Fixes:
```
ERROR: test_sshd.test - missing test plan
ERROR: test_sshd.test - exited with status 1
```
Ref: https://github.com/libssh2/libssh2/actions/runs/5322354271/jobs/9638694218#step:10:532

Caused by trying to create the log file in a read-only directory.

Follow-up to 299c204062
Closes #1099
2023-06-21 11:08:44 +00:00
Viktor Szakats
299c204062 test_sshd.test: show sshd and test connect logs on harness failure (#1097) 2023-06-21 10:09:45 +02:00
Joel Depooter
2388a3aa49 Fix incorrect byte offset in debug message (#1096)
Fixes debug log message

Credit:
Joel Depooter
2023-06-16 13:55:28 -07:00
Viktor Szakats
9218d37798 tidy-up: delete whitespace at EOL [ci skip] 2023-06-16 11:34:17 +00:00
Viktor Szakats
9d7bc25306 mbedtls: include version.h for MBEDTLS_VERSION_NUMBER
Older (2021 or earlier?) mbedTLS releases require this.

Reported-by: rahmanih on Github
Fixes #1094
Closes #1095
2023-06-16 11:22:43 +00:00
Viktor Szakats
82d1b8ff47 hostkey: do not advertise ssh-rsa when SHA1 is disabled
Before this patch OpenSSL, mbedTLS, WinCNG and OS/400 advertised both
SHA2 and SHA1 host key algos, even when SHA1 was not supported by the
crypto backend or when forcefully disabled via `LIBSSH2_NO_RSA_SHA1`.

Reported-by: João M. S. Silva
Fixes #1092
Closes #1093
2023-06-14 20:41:17 +00:00
Viktor Szakats
12ae9645ff openssl.h: whitespace tidy-up [ci skip] 2023-06-14 12:34:18 +00:00
Dan Fandrich
e8cabdcf2c test_sshd.test: set a safe PID directory (#1089)
The compiled in default to sshd can be a non-writable location since it
expects to be run as root.
2023-06-14 00:09:48 +02:00
Viktor Szakats
36c1e1d1f2 mingw: fix printf mask for 64-bit integers
Before 02f2700a61 #846 #876, we used
`%I64d'. That patch changed this to `%lld`. This patch uses `PRId64`
(defined in `inttypes.h`).

Fixes #1090
Closes #1091
2023-06-13 17:47:47 +00:00