Skip to content

mbedtls: require 3.1.0 (2.x no longer supported upstream) - #1727

Closed
vszakats wants to merge 16 commits into
libssh2:masterfrom
vszakats:mbed2
Closed

vszakats wants to merge 16 commits into
libssh2:masterfrom
vszakats:mbed2

Conversation

@vszakats

@vszakats vszakats commented Oct 16, 2025 •

Copy link
Copy Markdown
Member

The mbedTLS API is not one API but distinctly incompatible APIs
depending on its version. 2.x is largely incompatible with 3.x, and 4.x
is largely incompatible with 3.x, also dropping certain legacy crypto
primitives.

Following the release of 3.x in 2021, libssh2 added support for 3.x in
2022. 4.x was released in October 2025, and it makes using the PSA
Crypto API mandatory, after adding it in 3.x.

Supporting 2.x while also supporting the PSA Crypto API would mean
supporting 3 different crypto backends meshed together in a single
source file, with various overlapping and per-version parts, with
different features and separate needs to test.

2.x is also no longer maintained, supported, or security patched, as
written in its latest, and final, release notes on 2025-03-24:
https://github.com/Mbed-TLS/mbedtls/releases/tag/mbedtls-2.28.10
The mbedTLS project recommends upgrading to an upper major version.

To allow adding support for the PSA Crypto API and the 4.x series, and
to avoid an unmaintained 2.x major version, this patch drops support for
mbedTLS 2.x.

Also:

  • GHA: update CI jobs to either use Linuxbrew mbedtls 3.x, or build from
    source and cache it.
  • Require 3.1.0 minimum (instead of 3.0.0), because libssh2 never built
    with 3.0.0 due the use of API mbedtls_cipher_info_get_key_bitlen().
    Nobody complained since the initial commit introducing it.

Refs:
https://github.com/Mbed-TLS/TF-PSA-Crypto/blob/tf-psa-crypto-1.0.0/docs/1.0-migration-guide.md
https://github.com/Mbed-TLS/TF-PSA-Crypto/blob/tf-psa-crypto-1.0.0/docs/psa-transition.md#asymmetric-cryptography


w/o sp: https://github.com/libssh2/libssh2/pull/1727/files?w=1

mbedTLS 4.0.0 was released yesterday with a new round of breaking changes.
Drop support for 2.x to give room for the upcoming complexity.

@vszakats
vszakats marked this pull request as draft October 16, 2025 20:25
@KuzinAndrey

Copy link
Copy Markdown

You want drop all backward compatibility (2.x)? Due to support complexity? You jokes? Somewhere i use 18.04 ubuntu and what ? If stable base LTS distib version 24.04 support only 2.x you can't broke that in important library.

@vszakats

Copy link
Copy Markdown
Member Author

mbedTLS breaks compatibility in big ways on each major release,
and it did it again with 4.x. If you have a patch adding support
for 4.x while keeping support for 2.x, we're happy to review the PR.

@KuzinAndrey

Copy link
Copy Markdown

May be try to add support 4.x with next layer of preprocessing directives:

#if MBEDTLS_VERSION_NUMBER >= 0x04000000
...
#elif MBEDTLS_VERSION_NUMBER >= 0x03000000
...
#else
...
#endif

Your commit simply drop all previous work in trash can without any explanations. After that all tries of backporting bug fixes to old LTS versions be more difficult for maintainers.

@vszakats

Copy link
Copy Markdown
Member Author

Everything is possible, but it means to build the patch, maintain and
test 3 distinct, incompatible, major versions within this single codebase
which is all additional, continuous, work.

mbedTLS 3.x has been released in 2021, 4+ years ago, and it's possible
to build from source for anyone. I've added support for it to libssh2 in
2022 (048a6b4).

We've also dropped support for mbedTLS 2.x in curl.

You should talk to distros and mbedTLS to provide updates and/or
not break all codebases on major/minor upgrades. It's not feasible to
push all the work to unpaid maintainers to keep a codebase afloat.

@KuzinAndrey

Copy link
Copy Markdown

You can drop anything you want, but i want aware you from wrong decisions. You wrote what LTS Ubuntu 24.04 shipped with 2.x version, this mean what you doing this too early. You can watch https://ubuntu.com/about/release-cycle, this version has security support up to 5 year and full EOL only in 2036 !

@dfandrich

dfandrich commented Oct 17, 2025 via email

Copy link
Copy Markdown
Contributor

@vszakats

vszakats commented Oct 17, 2025 •

Copy link
Copy Markdown
Member Author

You can drop anything you want, but i want aware you from wrong decisions. You wrote what LTS Ubuntu 24.04 shipped with 2.x version, this mean what you doing this too early. You can watch https://ubuntu.com/about/release-cycle, this version has security support up to 5 year and full EOL only in 2036 !

LTS distros ship with a compatible libssh2 release, which will continue
to work with the pre-built mbedtls there.

Besides the above option, you are free to build a supported mbedTLS
from source, if you want to use libssh2 master or a version not compatible
with your LTS of choice. You're also welcome to contribute with patches
to keep maintaining the exact combination of versions you need.

Saying we are supposed to use more #ifs, doesn't help anyone.

@vszakats vszakats changed the title mbedcrypto: require 3.0.0 (was: 2.x) mbedcrypto: require 3.0.0 (was: 2.x, no longer supported upstream) Oct 18, 2025
@vszakats vszakats changed the title mbedcrypto: require 3.0.0 (was: 2.x, no longer supported upstream) mbedcrypto: require 3.0.0 (2.x no longer supported upstream) Oct 18, 2025
@vszakats vszakats changed the title mbedcrypto: require 3.0.0 (2.x no longer supported upstream) mbedcrypto: require 3.1.0 (2.x no longer supported upstream) Oct 18, 2025
vszakats added a commit to vszakats/libssh2 that referenced this pull request Oct 18, 2025
In `_libssh2_mbedtls_pub_priv_key()` on a NON-error code path, a stack
variable was checked without initializing it first.

I found it interesting that clang-tidy did not find this when building
against the system mbedtls (2.x) with 2.x compatibility code still it.
Then it did find it when using a manual build of mbedtls 3.1.0 with
2.x compatibility code deleted from libssh2. Being such a trivial error
I wonder why no compiler ever detected it as a regular warning.

linux (clang-tidy, amd64, mbedTLS-prev [3.1.0], cmake, ON):
```
/home/runner/work/libssh2/libssh2/src/mbedtls.c:744:8: error: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch,-warnings-as-errors]
  744 |     if(ret) {
      |        ^
```
Ref: https://github.com/libssh2/libssh2/actions/runs/18620615649/job/53091295760#step:22:44

Follow-up to 186f1a2 libssh2#132
Cherry-picked from libssh2#1727
@vszakats
vszakats marked this pull request as ready for review October 18, 2025 21:57
@vszakats vszakats changed the title mbedcrypto: require 3.1.0 (2.x no longer supported upstream) mbedtls: require 3.1.0 (2.x no longer supported upstream) Oct 18, 2025
vszakats added a commit that referenced this pull request Oct 18, 2025
In `_libssh2_mbedtls_pub_priv_key()` on a NON-error code path, a stack
variable was checked without initializing it first.

I found it interesting that clang-tidy did not find this when building
against the system mbedtls (2.x) with 2.x compatibility code still in.
Then it did find it when using a manual build of mbedtls 3.1.0 with
2.x compatibility code deleted from libssh2. Being such a trivial error
I wonder why no compiler ever detected it as a regular warning.

linux (clang-tidy, amd64, mbedTLS-prev [3.1.0], cmake, ON):
```
src/mbedtls.c:744:8: error: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch,-warnings-as-errors]
  744 |     if(ret) {
      |        ^
```
Ref: https://github.com/libssh2/libssh2/actions/runs/18620615649/job/53091295760#step:22:44

Follow-up to 186f1a2 #132
Cherry-picked from #1727
Closes #1729
@vszakats
vszakats force-pushed the mbed2 branch 3 times, most recently from fd814f0 to 97949d3 Compare October 20, 2025 13:07
vszakats added 10 commits April 8, 2026 05:15
```
/home/runner/work/libssh2/libssh2/src/mbedtls.c: In function ‘_libssh2_mbedtls_cipher_init’:
/home/runner/work/libssh2/libssh2/src/mbedtls.c:129:24: error: implicit declaration of function ‘mbedtls_cipher_info_get_key_bitlen’; did you mean ‘mbedtls_cipher_get_key_bitlen’? [-Wimplicit-function-declaration]
  129 |                   (int)mbedtls_cipher_info_get_key_bitlen(cipher_info),
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                        mbedtls_cipher_get_key_bitlen
/home/runner/work/libssh2/libssh2/src/mbedtls.c:129:24: error: nested extern declaration of ‘mbedtls_cipher_info_get_key_bitlen’ [-Werror=nested-externs]
/home/runner/work/libssh2/libssh2/src/mbedtls.c:134:19: error: implicit declaration of function ‘mbedtls_cipher_info_get_iv_size’; did you mean ‘mbedtls_cipher_get_iv_size’? [-Wimplicit-function-declaration]
  134 |                   mbedtls_cipher_info_get_iv_size(cipher_info));
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                   mbedtls_cipher_get_iv_size
/home/runner/work/libssh2/libssh2/src/mbedtls.c:134:19: error: nested extern declaration of ‘mbedtls_cipher_info_get_iv_size’ [-Werror=nested-externs]
```
https://github.com/libssh2/libssh2/actions/runs/18620223849/job/53090381294?pr=1727#step:22:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR drops mbedTLS 2.x compatibility and raises the minimum supported mbedTLS version to 3.1.0 to simplify the backend and unblock future PSA/4.x-related work, while updating CI to install mbedTLS 3.x reliably on runners where distro packages are still 2.x.

Changes:

  • Enforce mbedTLS >= 3.1.0 at compile time and in CMake configuration.
  • Remove mbedTLS 2.x compatibility branches in the mbedTLS crypto backend implementation.
  • Update GitHub Actions workflows to avoid distro libmbedtls-dev (2.x) and install/build/cache mbedTLS 3.x instead.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/mbedtls.c Adds a hard compile-time minimum version check and removes 2.x compatibility code paths.
CMakeLists.txt Adds a CMake-time version gate for mbedTLS >= 3.1.0.
cmake/FindMbedTLS.cmake Simplifies version detection to only the 3.x+ header layout.
.github/workflows/codeql.yml Switches Ubuntu CodeQL job to use Homebrew for mbedTLS instead of apt.
.github/workflows/ci.yml Updates CI matrix and adds “prev” (3.1.0) mbedTLS-from-source install + cache logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/mbedtls.c Resolved
Comment thread CMakeLists.txt Resolved
Comment thread .github/workflows/codeql.yml Resolved
Comment thread .github/workflows/codeql.yml Resolved
@vszakats vszakats closed this in f63f68b Apr 10, 2026
@vszakats
vszakats deleted the mbed2 branch April 10, 2026 20:00
vszakats added a commit that referenced this pull request Jun 10, 2026
The check for version 3+ is redundant after bumping the minimum to 3.1.

Follow-up to f63f68b #1727
Follow-up to 7419595 #1822

Closes #2009
vszakats added a commit that referenced this pull request Jul 12, 2026
RC4 and Blowfish not supported by mbedTLS 3+.
3DES not supported by mbedTLS 4+.

Follow-up to f63f68b #1727

Closes #2277
vszakats added a commit that referenced this pull request Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants