Skip to content

[BUG] - Paramiko 5.1.0 import fails under FIPS during ML-KEM availability detection #2712

In review

Description

@seth-tines

Are you using paramiko as a client or server?

Exception handling

What feature(s) aren't working right?

Something else

What version(s) of paramiko are you using?

5.0.1; 5.1.0 is where the issue arises and only in FIPS mode.

What version(s) of Python are you using?

3.13.17

What operating system and version are you using?

Wolfi Linux in a Docker container (linux/arm64), based on cgr.dev/chainguard/wolfi-base.

If you're connecting as a client, which SSH server are you connecting to?

No response

If you're using paramiko as part of another tool, which tool/version?

No response

Expected/desired behavior

Import should succeed when an optional key-exchange algorithm is unavailable in the configured provider. The unavailable algorithm should be excluded from supported/preferred key exchanges.

Environment

  • Python: 3.13.17
  • Paramiko: 5.1.0
  • cryptography: 50.0.2
  • OpenSSL used by cryptography: 4.0.3
  • FIPS provider: OpenSSL 3.4.0, built from source
  • Platform: Chainguard/Wolfi Linux container, arm64
  • Active providers: base and fips
  • Default properties: fips=yes
  • backend._fips_enabled: True

Actual behavior

Paramiko 5.1.0 fails on import paramiko when the configured FIPS provider does not implement ML-KEM. This happens before any SSH connection is attempted.

KexMLKEM768X25519.is_available() attempts ML-KEM key generation and catches UnsupportedAlgorithm. In this environment, the unsupported algorithm instead produces cryptography.exceptions.InternalError, which escapes and aborts the import.

The import fails through this call chain:

Transport class initialization
-> KexMLKEM768X25519.is_available()
-> mlkem.MLKEM768PrivateKey.generate()
-> cryptography.exceptions.InternalError

The OpenSSL error identifies the unsupported algorithm:

error:0308010C:digital envelope routines:inner_evp_generic_fetch:unsupported:
crypto/evp/evp_fetch.c:376:Global default library context,
Algorithm (ML-KEM-768 : 0), Properties (<null>)

How to reproduce

Using this Dockerfile

FROM cgr.dev/chainguard/wolfi-base:latest@sha256:88a20e2d017bd20cdc0cb3910de603e7bea9512a6c351a8dd3c9df212ab03d73

RUN apk add --no-cache \
    openssl-4.0=4.0.3-r8 py3.13-cryptography=50.0.2-r4 py3.13-pip \
    curl gcc glibc-dev make perl
RUN python3.13 -m pip install --break-system-packages --no-cache-dir paramiko==5.1.0

WORKDIR /repro
RUN curl --proto '=https' --tlsv1.2 -fsSL \
      https://github.com/openssl/openssl/releases/download/openssl-3.4.0/openssl-3.4.0.tar.gz \
      -o openssl.tar.gz \
    && echo 'e15dda82fe2fe8139dc2ac21a36d4ca01d5313c75f99f46c4e8a27709b7294bf  openssl.tar.gz' | sha256sum -c - \
    && tar -xf openssl.tar.gz \
    && cd openssl-3.4.0 \
    && ./Configure enable-fips \
    && make -s -j4 build_generated \
    && make -s -j4 providers/fips.so \
    && cp providers/fips.so /repro/fips.so \
    && openssl fipsinstall -module /repro/fips.so -out /repro/fipsmodule.cnf

COPY <<EOF /repro/openssl.cnf
config_diagnostics = 1
openssl_conf = openssl_init
.include /repro/fipsmodule.cnf
[openssl_init]
providers = providers
alg_section = algorithms
[providers]
base = base
fips = fips_sect
[base]
activate = 1
[fips_sect]
module = /repro/fips.so
[algorithms]
default_properties = fips=yes
EOF

ENV OPENSSL_CONF=/repro/openssl.cnf CRYPTOGRAPHY_OPENSSL_NO_LEGACY=1
CMD ["python3.13", "-c", "import paramiko"]

Run:

docker build -t paramiko-fips-repro .
docker run --rm --network none paramiko-fips-repro

When tested with the same cryptography and OpenSSL versions here are the results:

Paramiko FIPS active Import result
4.0.0 Yes Succeeds
5.0.0 Yes Succeeds
5.0.1 Yes Succeeds
5.1.0 Yes Fails
5.1.0 No Succeeds

Anything else?

#2442 and #2443 describe a similar FIPS import failure in the X25519 availability check. This report concerns the ML-KEM check introduced by #2668.

Activity

  1. hamarshehmhmd commented on Oct 30, 2026

    @hamarshehmhmd

    (Drafted with an AI assistant, reviewed by me.)

    I could reproduce the same failure without a FIPS module build. With cryptography 50.0.2 (OpenSSL 4.0.3) I used an OPENSSL_CONF that loads only the default provider and sets default_properties = fips=yes, so every fetch fails inside OpenSSL. Under that config, X25519PrivateKey.generate() raises UnsupportedAlgorithm, which KexCurve25519.is_available() already catches. MLKEM768PrivateKey.generate() raises cryptography.exceptions.InternalError instead, and KexMLKEM768X25519.is_available() only catches UnsupportedAlgorithm. Because Transport calls is_available() in its class body, the error is raised while import paramiko is still running.

    My config isn't your exact setup. In mine the fetch that fails is the DRBG, not ML-KEM-768. But the exception type and the path through paramiko are the same.

    Treating InternalError as "not available" in that check fixes it:

    --- a/paramiko/kex_mlkem.py
    +++ b/paramiko/kex_mlkem.py
    @@ -15,7 +15,7 @@
     import hashlib
     from typing import TYPE_CHECKING
     
    -from cryptography.exceptions import UnsupportedAlgorithm
    +from cryptography.exceptions import InternalError, UnsupportedAlgorithm
     from cryptography.hazmat.primitives import constant_time
     from cryptography.hazmat.primitives.asymmetric.x25519 import (
         X25519PrivateKey,
    @@ -74,7 +74,9 @@
             try:
                 mlkem.MLKEM768PrivateKey.generate()
                 X25519PrivateKey.generate()
    -        except UnsupportedAlgorithm:
    +        except (UnsupportedAlgorithm, InternalError):
    +            # Some providers (e.g. a FIPS provider without ML-KEM) fail the
    +            # fetch inside OpenSSL, which cryptography reports as InternalError.
                 return False
             return True

    Output from paramiko 5.1.0 with that config, before and after the patch, and then with the patch under the normal config:

    == before (stock paramiko 5.1.0) ==
    import paramiko FAILED: cryptography.exceptions.InternalError
    == after (fix.diff applied) ==
    paramiko 5.1.0 cryptography 50.0.2 -> import OK
      mlkem in _preferred_kex: False
      curve25519 in _preferred_kex: False
    == after, normal OpenSSL config (no OPENSSL_CONF) ==
    mlkem in _preferred_kex: True
    

    So with the patch, ML-KEM is simply dropped when the provider can't do it, and nothing changes when it can. I don't know of a user-side monkeypatch here, because the check runs while paramiko itself is being imported. Until this is fixed, pinning paramiko<5.1 (5.0.1 in your table) is the simplest workaround.

  2. seth-tines commented on Oct 30, 2026

    @seth-tines
    Author

    ah, thanks for looking into this - will be following along for the patch to land.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions