1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-01 11:01:40 +03:00
Commit Graph

313 Commits

Author SHA1 Message Date
a751d578be tidy-up: replace exit() with return
In examples and the manual page for `libssh2_version()`.

Closes #1541
2025-02-13 13:51:49 +01:00
cf3aac1aba libssh2_base64_decode: add deprecation warning
Cherry-picked from #1484
2025-01-31 02:04:59 +01:00
7027604505 libssh2_scp_send, libssh2_scp_send_ex: add deprecation warning
Also:
- switch to non-deprecated alternative in examples.
- add pointers and deprecation warning to libssh2_scp_send man page.

Cherry-picked from #1484
2025-01-31 02:04:59 +01:00
90a686ef3a gitignore: compress rules
Cherry-picked from #1484
2025-01-31 02:00:28 +01:00
7495084b1c libssh2_trace.3: Update prototype
Return value is int, not void.

Reported-by: pyscripter on github
Bug: https://github.com/libssh2/libssh2/issues/1517#issuecomment-2608628918
Closes #1518
2025-01-29 02:55:02 +01:00
114923f1ac tidy-up: unsigned const char -> const unsigned char
For consistency with rest of the code.

Closes #1487
2024-11-02 00:37:59 +01:00
b7ab0faa70 disable DSA by default
Also:
- add `LIBSSH2_DSA_ENABLE` to enable it explicitly.
- test the above option in CI.
- say 'deprecated' in docs and public header.
- disable DSA in the CI server config.
  (OpenSSH 9.8 no longer builds with it by default)
  https://www.openssh.com/txt/release-9.8
  Patch-by: Jose Quaresma
- disable more DSA code when not enabled.

Fixes #1433
Closes #1435
2024-07-30 22:59:02 +02:00
c905bfd27c tidy-up: link updates (#1434) 2024-07-30 19:35:38 +02:00
fb6527468c sftp: implement posix-rename@openssh.com
Add a new function `libssh2_sftp_posix_rename_ex()` and
`libssh2_sftp_posix_rename()`, which implement
the posix-rename@openssh.com extension.

If the server does not support this extension, the function returns
`LIBSSH2_FX_OP_UNSUPPORTED` and it's up to the user to recover, possibly
by calling `libssh2_sftp_rename()`.

Co-authored-by: Viktor Szakats (bump to size_t)
Closes #1386
2024-06-26 19:31:34 +02:00
581b72aab7 docs: improve libssh2_userauth_publickey_from* manpages
Reported-by: Lyndon Brown
Assisted-by: Ryan Kelley
Fixes #652
Closes #1308
Closes #xxxx
2024-04-03 11:16:08 +00:00
2f0efde37a docs: update INSTALL_AUTOTOOLS (#1316)
corrected --with-libmbedtls-prefix to current option --with-libmbedcrypto-prefix
2024-03-28 23:27:52 +01:00
4718ede4e0 src: check hash update/final success
Also:
- delete unused internal macro `libssh2_md5()` where defined.
- prefix `libssh2_os400qc3_hash*()` function names with underscore.
  These are public/visible, but internal.
- add FIXMEs to OS/400 code to verify update/final calls; some OS API,
  some internal.

Ref: https://github.com/libssh2/libssh2/pull/1301#discussion_r1446861650
Reviewed-by: Michael Buckley
Reviewed-by: Patrick Monnerat
Closes #1303
2024-01-18 23:54:29 +00:00
ba27bbe7c9 HACKING-CRYPTO: more fixups [ci skip]
Follow-up to f64885b6ab #1297
2024-01-12 01:11:58 +00:00
cf5364f303 HACKING-CRYPTO: fixups [ci skip]
Follow-up to f64885b6ab #1297
2024-01-12 01:00:53 +00:00
f64885b6ab mac: handle low-level errors
- update low-level hmac functions from macros to functions.
- libgcrypt: propagate low-level hmac errors.
- libgcrypt: add error checks for hmac calls.
- os400qc3: add error checks, propagate them.
  Assisted-by: Patrick Monnerat
- mbedtls: fix propagating low-level hmac errors.
- wincng: fix propagating low-level hmac errors.
- mac: verify success of low-level hmac functions.
- knownhost: verify success of low-level hmac functions.
- transport: verify success of MAC hash call.
- minor type cleanup in wincng.
- delete unused ripemd wrapper in wincng.
- delete unused SHA384 wrapper in mbedtls.

Reported-by: Paul Howarth
Reviewed-by: Michael Buckley
Closes #1297
2024-01-10 16:32:22 +00:00
c0f69548be session: add libssh2_session_callback_set2()
Add new `libssh2_session_callback_set2()` API that deprecates
`libssh2_session_callback_set()`.

The new implementation offers the same functionality, but accepts and
returns a generic function pointer (of type `libssh2_cb_generic *`), as
opposed to the old function that used data pointers (`void *`). The new
solution thus avoids data to function (and vice versa) pointer
conversions, which has undefined behaviour in standard C.

About the name: It seems the `*2` suffix was used in the past for
replacement functions for deprecated ones. Let's stick with that.
`*_ex` was preferred for new functions that extend existing ones with
new features.

Closes #1285
2023-12-18 15:02:17 +00:00
9839ebe5e9 libssh2.h: add deprecated function warnings
With deprecated-at versions and suggested replacement function.

It's possible to silence them by defining `LIBSSH2_DISABLE_DEPRECATION`.

Also add depcreated-at versions to documentation, and unify wording.

Ref: https://github.com/libssh2/libssh2/pull/1260#issuecomment-1837017987
Closes #1289
2023-12-16 17:43:02 +00:00
afa6b86560 build: enable missing OpenSSF-recommended warnings, with fixes
Ref:
https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html
(2023-11-29)

Enable new warnings:

- replace `-Wno-sign-conversion` with `-Wsign-conversion`.

  Fix them in example, tests and wincng. There remain about 360 of these
  warnings in `src`. Add a TODO item for those and disable `-Werror` for
  this particular warning.

- enable `-Wformat=2` for clang (in both cmake and autotools).

- enable `__attribute__((format))` for `_libssh2_debug()`,
  `_libssh2_snprintf()` and in tests for `run_command()`.

  `LIBSSH2_PRINTF()` copied from `CURL_TEMP_PRINTF()` in curl.

- enable `-Wimplicit-fallthrough`.

- enable `-Wtrampolines`.

Fix them:

- src: replace obsolete fall-through-comments with
  `__attribute__((fallthrough))`.

- wincng: fix `-Wsign-conversion` warnings.

- tests: fix `-Wsign-conversion` warnings.

- example: fix `-Wsign-conversion` warnings.

- src: fix `-Wformat` issues in trace calls.

  Also, where necessary fix `int` and `unsigned char` casts to
  `unsigned int` and adjust printf format strings. These were not
  causing compiler warnings.

  Cast large types to `long` to avoid dealing with printf masks for
  `size_t` and other C99 types. Existing code often used `int` for this.
  I'll update them to `long` in an upcoming commit.

- tests: fix `-Wformat` warning.

- silence `-Wformat-nonliteral` warnings.

- mbedtls: silence `-Wsign-conversion`/`-Warith-conversion`
  in external header.

Closes #1257
2023-12-03 01:32:20 +00:00
b136c37998 tidy-up: unsigned -> unsigned int
In the `interval` argument of public `libssh2_keepalive_config()`.

Tested via #1257
2023-12-02 09:53:56 +00:00
0b4bdc856f TODO: disable or drop weak algos [ci skip]
Closes #1261
2023-12-02 08:29:49 +00:00
4348557960 Makefile.mk: delete Windows-focused raw GNU Make build
We recommend using CMake instead. Especially in unity mode, it's faster
and probably more familiar for most. It's also easily portable.

(`Makefile.mk` was also portable, but in practice only usable for
Windows. Other platforms required a manual config header.)

Also:
- migrate `LIBSSH2_NO_*` option CI tests to CMake.
- make MSYS2 CMake builds verbose to show compilation options.

Closes #1204
2023-11-06 21:41:12 +00:00
bfa00f1bd5 tidy-up: around stdint.h
- os400: delete unused `HAVE_STDINT_H`.

- fuzz: delete redundant `stdint.h` use.
  `inttypes.h` is already included via `testinput.h`.

- docs/TODO: adjust type in planned function.

Closes #1212
2023-11-06 15:00:08 +00:00
a3ffc4221d man: fix double spaces and dash escaping
- `-  ` -> `- `
- `.  ` -> `. `
- `\- ` -> `- `
- `-1` -> `\-1`
- fold long lines along the way

This makes the minus sign come out as a Unicode minus sign
(0x2212), and title separator dashes as Unicode hyphen (0x2010),
with `groff -Tutf8` v1.23.0.

Ref: https://lwn.net/Articles/947941/

Closes #1210
2023-11-03 19:57:56 +00:00
67e39091b2 libssh2_session_get_blocking.3: Add description (#1185) 2023-09-24 01:00:14 +02:00
6e3e883994 drop www. from www.libssh2.org
<https://www.libssh2.org/*> is now a 301 permanent redirect to
<https://libssh2.org/*>.

Update all references to point directly to the new destination.

Ref: ccf4a7de7f

Closes #1172
2023-08-18 11:20:58 +00:00
6eda1ee433 cmake: reflect minimum version in docs [ci skip]
Follow-up to 9cd18f4578
2023-08-15 21:58:56 +00:00
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
f58f77b5c8 cmake: streamline invocation
Stop specifiying the current directory.
Simplify build instructions.

Closes #1138
2023-07-27 10:49:00 +00:00
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
766bde9fb9 docs: replace SHA1 with SHA256 in CMake example 2023-06-23 16:31:16 +00:00
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
f6aa31f48f provide SPDX identifiers
- All files have prominent copyright and SPDX identifier
- If not embedded in the file, in the .reuse/dep5 file
- All used licenses are in LICENSES/ (not shipped in tarballs)
- A new REUSE CI job verify that all files are OK

Assisted-by: Viktor Szakats

Closes #1084
2023-06-07 08:18:55 +02:00
187d89bb07 copyright: remove years from copyright headers
Also:
- uppercase `(C)`.
- add missing 'All rights reserved.' lines.
- drop duplicate 'Author' lines.
- add copyright headers where missing.
- enable copyright header check in checksrc.

Reasons for deleting years (copied as-is from curl):
- they are mostly pointless in all major jurisdictions
- many big corporations and projects already don't use them
- saves us from pointless churn
- git keeps history for us
- the year range is kept in COPYING

Closes #1082
2023-06-04 19:19:16 +00:00
003fb454c3 tidy-up: avoid exclamations, prefer single quotes, in outputs
Closes #1079
2023-06-03 12:51:56 +00:00
e7a542da6a add copyright/credits
Closes #1050
2023-05-29 17:07:11 +00:00
dee8ec9270 docs: delete two stray characters
Cherry-picked from #1017
2023-05-03 01:35:16 +00:00
5ee6d0ffbc tidy-up: avoid expression 'of course'
Cherry-picked from #1017
2023-05-03 01:35:10 +00:00
31851511bf tidy-up: avoid word 'just'
Cherry-picked from #1017
2023-05-03 01:35:05 +00:00
081c04571b tidy-up: avoid word 'simply'
Cherry-picked from #1017
2023-05-03 01:34:58 +00:00
d67aaaffc4 tidy-up: text nits, English contractions [ci skip]
In input/output text and docs mostly.
2023-04-27 14:19:03 +00:00
592e2b37fa docs: simplify .TH header & other cleanups [ci skip]
- simplify `.TH` headers.
- delete empty lines before sections.
- update template with an `AVAILABILITY` section.

Left libssh2 version number in the `.TH` header for entries without an
`AVAILABILITY` section, or where there was a different version number
there.
2023-04-26 17:55:51 +00:00
d7bec41df3 tidy-up: formatting nits [ci skip] 2023-04-26 17:55:51 +00:00
bc4e619e76 Agent forwarding implementation (#752)
This PR contains a series of patches that date back many years and I
believe were discussed on the mailing list, but never merged. We have
been using these in our local copy of libssh2 without issue since 2015,
if not earlier. I believe this is the full set of changes, as we tried
to use comments to mark where our copy of libssh2 differs from the
canonical version.

This also contains changes I made earlier this year, but which were not
discussed on the mailing list, to support certificates and FIDO2 keys
with agent forwarding.

Note that this is not a complete implementation of agent forwarding, as
that is outside the scope of libssh2. Clients still need to provide
their own implementation that parses ssh-agent methods after calling
libssh2_channel_read() and calls the appropriate callback messages in
libssh2. See the man page changes in this PR for more details.

Integration-patches-by: Viktor Szakats

* prefer size_t
* prefer unsigned int over u_int in public function
* add const
* docs, indent, checksrc, debug call, compiler warning fixes
2023-04-22 10:54:20 +02:00
6812985e60 docs: fix typo in argument name [ci skip] 2023-04-20 23:04:26 +00:00
a4544c0117 channel: add support for "signal" message
Can send specific signals to remote process. Allows for slightly
improved remote process management, if the server supports it.

Integration-patches-by: Viktor Szakats

* doc updates
* change `signame_len` to `size_t`
* variable scopes
* fix checksrc warnings

Closes #672
Closes #991
2023-04-20 21:51:29 +00:00
3c953c05d6 Add support for AES-GCM crypto protocols (#797)
Add support for aes256-gcm@openssh.com and aes128-gcm@openssh.com
ciphers, which are the OpenSSH implementations of AES-GCM cryptography.
It is similar to RFC5647 but has changes to the MAC protocol
negotiation.  These are implemented for recent versions of OpenSSL only.

The ciphers work differently than most previous ones in two big areas:
the cipher includes its own integrated MAC, and the packet length field
in the SSH frame is left unencrypted.  The code changes necessary are
gated by flags in the LIBSSH2_CRYPT_METHOD configuration structure.

These differences mean that both the first and last parts of a block
require special handling during encryption. The first part is where the
packet length field is, which must be kept out of the encryption path
but in the authenticated part (as AAD).  The last part is where the
Authentication Tag is found, which is calculated and appended during
encryption or removed and validated on decryption. As encryption/
decryption is performed on each packet in a loop, one block at a time,
flags indicating when the first and last blocks are being processed are
passed down to the encryption layers.

The strict block-by-block encryption that occurs with other protocols is
inappropriate for AES-GCM, since the packet length shifts the first
encrypted byte 4 bytes into the block. Additionally, the final part of
the block must contain the AES-GCM's Authentication Tag, so it must be
presented to the lower encryption layer whole. These requirements mean
added code to consolidate blocks as they are passed down.

When AES-GCM is negotiated as the cipher, its built-in MAC is
automatically used as the SSH MAC so further MAC negotiation is not
necessary.  The SSH negotiation is skipped when _libssh2_mac_override()
indicates that such a cipher is in use.  The virtual MAC configuration
block mac_method_hmac_aesgcm is then used as the MAC placeholder.

This work was sponsored by Anders Borum.

Integration-patches-by: Viktor Szakats

* fix checksrc errors
* fix openssl.c warning
* fix transport.c warnings
* switch to `LIBSSH2_MIN/MAX()` from `MIN()`/`MAX()`
* fix indent
* fix libgcrypt unused warning
* fix mbedtls unused warning
* fix wincng unused warning
* fix old openssl unused variable warnings
* delete blank lines
* updates to help merging with the ETM patch
2023-04-20 15:46:44 +02:00
e4d827479c HACKING-CRYPTO: fix stray whitespace 2023-04-19 18:24:12 +00:00
17801d2064 tidy-up: fix more nits
- fix indentation errors.
- reformat `cmake/FindmbedTLS.cmake`
- replace a macro with a variable in `example/sftp_RW_nonblock.c`.
- delete macOS macro `_DARWIN_USE_64_BIT_INODE` from the
  OS/400 config header, `os400/libssh2_config.h`.
- fix other minor nits.

Closes #983
2023-04-18 08:41:20 +00:00
6dc42e9d62 Make OS/400 implementation work again (#953)
* os400: support QADRT development files in a non-standard directory

This enables the possibility to compile libssh2 even if the ascii
runtime development files are not installed system-wide.

* userauth_kbd_packet: fix a pointer target type mismatch.

A temporary variable matching the parameter type is used before copying
to the real target and checking for overflow (that should not occur!).

* os400qc3: move and fix big number procedures

A bug added by a previous code style cleaning is fixed.
_libssh2_random() now checks and return the success status.

* os400qc3: fix cipher definition block lengths

They were wrongly set to the key size.

* Diffie-Hellman min/max modulus sizes are dependent of crypto-backend

In particular, os400qc3 limits the maximum group size to 2048-bits.
Move definitions of these parameters to crypto backend header files.

* kex: return an error if Diffie-Hellman key pair generation fails

* os400: add an ascii assert.h header file

* os400qc3: implement RSA SHA2 256/512
2023-04-13 14:08:12 +02:00
bf85faaa92 sftp: add open functions with custom attribute support
Before this patch, libssh2 sent hardcoded `LIBSSH2_SFTP_ATTRIBUTES`
struct on handle open. This can be problematic on some special OS,
where the file size should be known on new file creation. I added
two new functions to resolve this issue.

Patch-by: @vajdaakos on github via #506

Changes compared to #506:
- drop attr size fixup in favour of #946.
- move `memcpy()` under the state where we need it.
- bump filename length type to `size_t`.
- fix filenames in documentation and other nits.

Closes #506
Closes #947
2023-04-13 11:35:21 +00:00