Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnsupportedAlgorithm: X25519 is not supported by this version of OpenSSL. #8837

Closed
mocart2 opened this issue Apr 27, 2019 · 24 comments
Closed
Labels
triaged: question The issue contains a question

Comments

@mocart2
Copy link

mocart2 commented Apr 27, 2019

root@orangepiplus2e:/etc/ld.so.conf.d# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.6 LTS
Release:        16.04
Codename:       xenial

i get latest version openssl:
wget --no-check-certificate https://www.openssl.org/source/openssl-1.1.1b.tar.gz
unarchive it and configure:
./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib
then:
make && make test && make install
fixed links in os and cheked version:

openssl version -a
OpenSSL 1.1.1b  26 Feb 2019
built on: Sat Apr 27 14:42:16 2019 UTC
platform: linux-armv4
options:  bn(64,32) rc4(char) des(long) idea(int) blowfish(ptr)
compiler: gcc -fPIC -pthread  -march=armv7-a -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DAES_ASM -DBSAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DPOLY1305_ASM -DZLIB -DNDEBUG
OPENSSLDIR: "/usr/local/ssl"
ENGINESDIR: "/usr/local/ssl/lib/engines-1.1"
Seeding source: os-specific

and afterm i exec app (yowsup request):

...
  File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/x25519.py", line 42, in generate
    _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM
cryptography.exceptions.UnsupportedAlgorithm: X25519 is not supported by this version of OpenSSL.

i write about it yowsup developer, he says, upgrade openssl version 1.1.0+, i upgrade it, but it not works, may be i have mistake in configure proccess? can anybody help me please?

@kroeckx
Copy link
Member

kroeckx commented Apr 27, 2019 via email

@mocart2
Copy link
Author

mocart2 commented Apr 28, 2019

i get latest pythone 2.7 and recompile it for using system openssl:

root@orangepiplus2e:~# openssl version -v
OpenSSL 1.1.1b  26 Feb 2019
root@orangepiplus2e:~# python -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 1.1.1b  26 Feb 2019

but problem is not solved

Traceback (most recent call last):
  File "/usr/local/bin/yowsup-cli", line 518, in <module>
    if not parser.process():
  File "/usr/local/bin/yowsup-cli", line 340, in process
    self.handleRequestCode(self.args["requestcode"], config)
  File "/usr/local/bin/yowsup-cli", line 351, in handleRequestCode
    codeReq = WACodeRequest(method, config)
  File "/usr/local/lib/python2.7/dist-packages/yowsup/registration/coderequest.py", line 15, in __init__
    super(WACodeRequest,self).__init__(config)
  File "/usr/local/lib/python2.7/dist-packages/yowsup/common/http/warequest.py", line 71, in __init__
    config.client_static_keypair = WATools.generateKeyPair()
  File "/usr/local/lib/python2.7/dist-packages/yowsup/common/tools.py", line 70, in generateKeyPair
    return KeyPair.generate()
  File "/usr/local/lib/python2.7/dist-packages/consonance/structs/keypair.py", line 36, in generate
    keypair = X25519DH().generate_keypair()
  File "/usr/local/lib/python2.7/dist-packages/dissononce/dh/x25519/x25519.py", line 28, in generate_keypair
    private = x25519.X25519PrivateKey.generate()
  File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/x25519.py", line 42, in generate
    _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM
cryptography.exceptions.UnsupportedAlgorithm: X25519 is not supported by this version of OpenSSL.

@mocart2 mocart2 closed this as completed Apr 28, 2019
@mocart2 mocart2 reopened this Apr 28, 2019
@kroeckx
Copy link
Member

kroeckx commented Apr 28, 2019 via email

@1seven
Copy link

1seven commented May 20, 2019

I had the same problem on gentoo. Solved it by rebuilding dev-python/cryptography

@levitte
Copy link
Member

levitte commented May 20, 2019

If @mocart2 can confirm what @1seven wrote, then it's time to close this

@mocart2
Copy link
Author

mocart2 commented May 22, 2019

i install latest version(by pip install/upgrade) of packages devops-tools and cryptography:

root@orangepiplus2e:~# pip show cryptography
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Name: cryptography
Version: 2.6.1
Summary: cryptography is a package which provides cryptographic recipes and primitives to Python developers.
Home-page: https://github.com/pyca/cryptography
Author: The cryptography developers
Author-email: cryptography-dev@python.org
License: BSD or Apache License, Version 2.0
Location: /usr/local/lib/python2.7/site-packages
Requires: enum34, cffi, six, asn1crypto, ipaddress
Required-by:

and

root@orangepiplus2e:~# pip show devops-tools
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Name: devops-tools
Version: 0.1
Summary: Devops Tools
Home-page: UNKNOWN
Author: Pablo Venegas
Author-email: pablo.venegas@gmail.com
License: MIT
Location: /usr/local/lib/python2.7/site-packages
Requires: dockerpty, docker-py, PyYAML
Required-by:

but problem is not solved...

@1seven
Copy link

1seven commented May 22, 2019

I use the following combination:

python 3.6.5
cryptography 2.6.1
openssl 1.1.0j-r1

Keep in mind, that cryptography has to be compiled against the new openssl version. Depending on your pip version you just might have reinstalled the cryptography binary.

@gabyokal
Copy link

Hi, @mocart2 Are you solved it?, i have the same problem :(

@easyyu
Copy link

easyyu commented Oct 4, 2019

Me too..
Anyone with some solution?

@mattcaswell mattcaswell added triaged: question The issue contains a question unresolved labels Nov 19, 2019
@mattcaswell
Copy link
Member

This does not appear to be an OpenSSL issue. Please ask about this on a python forum. Closing.

@ghost
Copy link

ghost commented May 6, 2020

@mattcaswell

I'm not entirely sure it is "just a Python issue" since:

marisa@odroidhc1:~$ openssl ecparam -list_curves
  secp112r1 : SECG/WTLS curve over a 112 bit prime field
  secp112r2 : SECG curve over a 112 bit prime field
  secp128r1 : SECG curve over a 128 bit prime field
  secp128r2 : SECG curve over a 128 bit prime field
  secp160k1 : SECG curve over a 160 bit prime field
  secp160r1 : SECG curve over a 160 bit prime field
  secp160r2 : SECG/WTLS curve over a 160 bit prime field
  secp192k1 : SECG curve over a 192 bit prime field
  secp224k1 : SECG curve over a 224 bit prime field
  secp224r1 : NIST/SECG curve over a 224 bit prime field
  secp256k1 : SECG curve over a 256 bit prime field
  secp384r1 : NIST/SECG curve over a 384 bit prime field
  secp521r1 : NIST/SECG curve over a 521 bit prime field
  prime192v1: NIST/X9.62/SECG curve over a 192 bit prime field
  prime192v2: X9.62 curve over a 192 bit prime field
  prime192v3: X9.62 curve over a 192 bit prime field
  prime239v1: X9.62 curve over a 239 bit prime field
  prime239v2: X9.62 curve over a 239 bit prime field
  prime239v3: X9.62 curve over a 239 bit prime field
  prime256v1: X9.62/SECG curve over a 256 bit prime field
  sect113r1 : SECG curve over a 113 bit binary field
  sect113r2 : SECG curve over a 113 bit binary field
  sect131r1 : SECG/WTLS curve over a 131 bit binary field
  sect131r2 : SECG curve over a 131 bit binary field
  sect163k1 : NIST/SECG/WTLS curve over a 163 bit binary field
  sect163r1 : SECG curve over a 163 bit binary field
  sect163r2 : NIST/SECG curve over a 163 bit binary field
  sect193r1 : SECG curve over a 193 bit binary field
  sect193r2 : SECG curve over a 193 bit binary field
  sect233k1 : NIST/SECG/WTLS curve over a 233 bit binary field
  sect233r1 : NIST/SECG/WTLS curve over a 233 bit binary field
  sect239k1 : SECG curve over a 239 bit binary field
  sect283k1 : NIST/SECG curve over a 283 bit binary field
  sect283r1 : NIST/SECG curve over a 283 bit binary field
  sect409k1 : NIST/SECG curve over a 409 bit binary field
  sect409r1 : NIST/SECG curve over a 409 bit binary field
  sect571k1 : NIST/SECG curve over a 571 bit binary field
  sect571r1 : NIST/SECG curve over a 571 bit binary field
  c2pnb163v1: X9.62 curve over a 163 bit binary field
  c2pnb163v2: X9.62 curve over a 163 bit binary field
  c2pnb163v3: X9.62 curve over a 163 bit binary field
  c2pnb176v1: X9.62 curve over a 176 bit binary field
  c2tnb191v1: X9.62 curve over a 191 bit binary field
  c2tnb191v2: X9.62 curve over a 191 bit binary field
  c2tnb191v3: X9.62 curve over a 191 bit binary field
  c2pnb208w1: X9.62 curve over a 208 bit binary field
  c2tnb239v1: X9.62 curve over a 239 bit binary field
  c2tnb239v2: X9.62 curve over a 239 bit binary field
  c2tnb239v3: X9.62 curve over a 239 bit binary field
  c2pnb272w1: X9.62 curve over a 272 bit binary field
  c2pnb304w1: X9.62 curve over a 304 bit binary field
  c2tnb359v1: X9.62 curve over a 359 bit binary field
  c2pnb368w1: X9.62 curve over a 368 bit binary field
  c2tnb431r1: X9.62 curve over a 431 bit binary field
  wap-wsg-idm-ecid-wtls1: WTLS curve over a 113 bit binary field
  wap-wsg-idm-ecid-wtls3: NIST/SECG/WTLS curve over a 163 bit binary field
  wap-wsg-idm-ecid-wtls4: SECG curve over a 113 bit binary field
  wap-wsg-idm-ecid-wtls5: X9.62 curve over a 163 bit binary field
  wap-wsg-idm-ecid-wtls6: SECG/WTLS curve over a 112 bit prime field
  wap-wsg-idm-ecid-wtls7: SECG/WTLS curve over a 160 bit prime field
  wap-wsg-idm-ecid-wtls8: WTLS curve over a 112 bit prime field
  wap-wsg-idm-ecid-wtls9: WTLS curve over a 160 bit prime field
  wap-wsg-idm-ecid-wtls10: NIST/SECG/WTLS curve over a 233 bit binary field
  wap-wsg-idm-ecid-wtls11: NIST/SECG/WTLS curve over a 233 bit binary field
  wap-wsg-idm-ecid-wtls12: WTLS curve over a 224 bit prime field
  Oakley-EC2N-3:
        IPSec/IKE/Oakley curve #3 over a 155 bit binary field.
        Not suitable for ECDSA.
        Questionable extension field!
  Oakley-EC2N-4:
        IPSec/IKE/Oakley curve #4 over a 185 bit binary field.
        Not suitable for ECDSA.
        Questionable extension field!
  brainpoolP160r1: RFC 5639 curve over a 160 bit prime field
  brainpoolP160t1: RFC 5639 curve over a 160 bit prime field
  brainpoolP192r1: RFC 5639 curve over a 192 bit prime field
  brainpoolP192t1: RFC 5639 curve over a 192 bit prime field
  brainpoolP224r1: RFC 5639 curve over a 224 bit prime field
  brainpoolP224t1: RFC 5639 curve over a 224 bit prime field
  brainpoolP256r1: RFC 5639 curve over a 256 bit prime field
  brainpoolP256t1: RFC 5639 curve over a 256 bit prime field
  brainpoolP320r1: RFC 5639 curve over a 320 bit prime field
  brainpoolP320t1: RFC 5639 curve over a 320 bit prime field
  brainpoolP384r1: RFC 5639 curve over a 384 bit prime field
  brainpoolP384t1: RFC 5639 curve over a 384 bit prime field
  brainpoolP512r1: RFC 5639 curve over a 512 bit prime field
  brainpoolP512t1: RFC 5639 curve over a 512 bit prime field
  SM2       : SM2 curve over a 256 bit prime field
marisa@odroidhc1:~$ openssl
OpenSSL> version
OpenSSL 1.1.1d  10 Sep 2019
marisa@odroidhc1:~$ python -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 1.1.1d  10 Sep 2019
marisa@odroidhc1:~$ python3 -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 1.1.1d  10 Sep 2019

Since the OP is an SBC user as well, but on orangepiplus2e, I assume it is a Debian flavour just like my armbian system.

Are perhaps the Debian packages itself lacking X25519 support?
I see it nowhere in the output of OpenSSL itself.

Oddly enough keys can be created though:

marisa@odroidhc1:~$ openssl genpkey -algorithm X25519
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VuBCIEIED+ev9oOe8xKgPZRW1tv1wY8MS893lwL3Smrlq+s8J/
-----END PRIVATE KEY-----

So since most people here want to likely use it for TLS key exchange (Firefox supports x25519 for this), I just want to ask if OpenSSL is broken on Debian as well, or why this curve cannot be accessed anywhere from within OpenSSL itself and Python's modules, once it comes to key exchange.

Forgive me my thread necroing, I will not reply again unless you want me to, perhaps it is okay picking up on this issue. It cannot be just Python for the reasons above, or I made a mistake listing the supported curves.

@mattcaswell
Copy link
Member

openssl ecparam -list_curves lists all the curves supported for ECDSA and ECDH use. Cuurve25519 is a different type of curve for use in X25519 which is very similar to, but different from ECDH. It is handled entirely separately in OpenSSL and hence does not appear in the -list_curves output.

@ghost
Copy link

ghost commented May 6, 2020

@mattcaswell

openssl ecparam -list_curves lists all the curves supported for ECDSA and ECDH use

ECDH is what TLS servers use and what I need, so basically the correct use of listing confirmed?

Cuurve25519 is a different type of curve for use in X25519 which is very similar to, but different from ECDH

Sorry but I never mentioned Curve25519 itself? Always referred solely to the need to use X25519.

grafik

The screenshot is just to illustrate the use on a server with nginx. However I need these in OpenSSL on a Debian based SBC, in particular in Python. Currently I only have secp384r1 which is also listed correctly in the -list_curves command.

I'm not forcing you into a discussion, but I feel like you misread my initial post.
Why is secp384r1 working fine in TLS and -list_curves, but X25519 is inexistent in both pure OpenSSL itself, absent from the list of ECDH supporting curves and Python2/3 on several different Debian based systems? I see an issue here that reaches way outside of Python if something is not listed in OpenSSL itself.

Why am I writing you this? Basically once you confirm me something is broken on Debian, I will contact the package maintainer. If this is an issue with me understanding something, please try to explain if you have a minute.

PS: The previous creation of keys was merely an illustration. It's still all about X25519 for TLS.

@mattcaswell
Copy link
Member

ECDH is what TLS servers use and what I need, so basically the correct use of listing confirmed?

ECDH is a key agreement scheme used in the TLS protocol to agree secrets between a client and a server. X25519 is another key agreement scheme which is very similar to ECDH but slightly different - and can also be used in TLS. Sometimes people will use the term ECDH to refer to both things - but strictly speaking they are separate (different standards involved).

Sorry but I never mentioned Curve25519 itself? Always referred solely to the need to use X25519.

No - but you are looking at the output of openssl ecparam -list_curves and wondering why X25519 is not mentioned. X25519 is not a curve, it is a key agreement scheme which uses Curve25519. However that command lists the curves that may be used for ECDH or ECDSA. Curve25519 can't be used for that and therefore isn't listed. It does not mean that OpenSSL does not support X25519.

Typically you don't need to worry about X25519 at all. You don't need to configure it, create keys for it, or parameters, or anything. These are created on-the-fly, and it will be offered by an OpenSSL client, and used by an OpenSSL server if offered by the client unless explicitly configured not to do so. All versions of OpenSSL that support TLSv1.3 also support X25519. For clients it is the default key agreement scheme in TLSv1.3.

Currently I only have secp384r1

What does this mean? How do you know you are only using this curve?

@ghost
Copy link

ghost commented May 6, 2020

@mattcaswell

or why this curve cannot be accessed anywhere from within OpenSSL ['s key agreement schemes]

listing the supported curves [of the key agreement schemes].

Sorry but I never mentioned Curve25519 itself? Always referred solely to the need to use X25519 [, since I need it for this key agreement scheme i desire in my server].

There, I fixed my old posts? Sorry my exclusion angered you, but I really wanted to just skip the textbook basics and pretend to just get info on why these are inaccessible.

Every attempt to get any reply why this [key agreement scheme] is excluded for me to select inside OpenSSL itself, rather than just Python was dodged by focusing on my petty wording.

Yes yes I can run A+ SSL-Labs rated servers:
#7562 (comment)

Sorry for trying to have some fun and wanting to add extra support for a different [key agreement scheme] because NIST curves vs Curve25519 is a loaded issue which you prefer.

What does this mean? How do you know you are only using this curve?

Because my servers run TLS1.2 and 1.3 to the highest recommended specs in industry standards?
Because I manually selected it in my code?

global tlsctx
tlsctx = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH)
tlsctx.options |= ssl.OP_NO_TLSv1
tlsctx.options |= ssl.OP_NO_TLSv1_1
tlsctx.set_ciphers("ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305")
tlsctx.set_ecdh_curve("secp384r1")
tlsctx.load_cert_chain(MYSERV_FULLCHAIN, MYSERV_PRIVKEY)

Instead of forcing me to brag, you should grant me the benefit of doubt that I'm no random git.

grafik
Seems to work on a friends gentoo nginx, so why are BOTH the Debian packages for OpenSSL itself and Python not?

I try again:

Why am I writing you this? Basically once you confirm me something is broken on Debian, I will contact the package maintainer.

@t8m
Copy link
Member

t8m commented May 6, 2020

Would tlsctx.set_ecdh_curve("x25519:secp384r1") help?

@mattcaswell
Copy link
Member

There, I fixed my old posts? Sorry my exclusion angered you, but I really wanted to just skip the textbook basics and pretend to just get info on why these are inaccessible.

I'm not angry - and I'm sorry if it came across that way. I'm simply trying to explain why X25519 doesn't appear in the output from openssl ecparam -list_curves even though it is supported by OpenSSL.

Instead of forcing me to brag, you should grant me the benefit of doubt that I'm no random git.

I'm not trying to force you to brag. Nor do I consider you a "random git". I'm trying to understand your context so I can provide better answers.

tlsctx.set_ecdh_curve("secp384r1")

I'm not a python guy, and I'm not familiar with the python bindings - but my best guess (possibly wrong) is that this is a wrapper around our macro SSL_CTX_set_tmp_ecdh which takes a single ECDH curve name (emphasis means this excludes X25519, because X25519 is not ECDH). That API is soon to be deprecated in the forthcoming OpenSSL 3.0 in favour of the more flexible function SSL_CTX_set1_groups() which can take a list of group names (including X25519).

I wonder if there is a python wrapper for that function instead?

@kroeckx
Copy link
Member

kroeckx commented May 6, 2020 via email

@mattcaswell
Copy link
Member

I suspect set_ecdh_curve is a hold over from earlier versions of OpenSSL. There's a bit of history here. OpenSSL 1.0.0 introduced ECDH support and you had to call SSL_CTX_set_tmp_ecdh() in order to enable it by specifying a single ECDH curve. OpenSSL 1.0.2 additionally introduced SSL_CTX_set_ecdh_auto() which you still had to call explicitly but you didn't have to specify a single ECDH curve - it used a built in default set. OpenSSL 1.1.0 made SSL_CTX_set_ecdh_auto() a no-op (deprecating it at the same time), and "auto" ecdh config was enabled by default. Probably SSL_CTX_set_tmp_ecdh() should have been deprecated at the same time - but this has only relatively recently occurred (will be the case for 3.0).

In the meantime X25519/X448 support has also been added (which is strictly speaking not ECDH and can't be controlled by the legacy SSL_CTX_set_tmp_ecdh() function). The new method of configuring these things (if you don't want the default) is to use SSL_CTX_set1_groups().

Most applications don't need to worry about this stuff. They just get the default set of supported groups without calling anything specific (and that includes X25519).

It's possible that python defaults to some specific ECDH curve using the old functions if you don't call set_ecdh_curve explicitly - which is why you get this problem. If it doesn't then it could be that a fix is as simple as removing the call to set_ecdh_curve to go back to getting the OpenSSL defaults. If not, and if there is no way to call SSL_CTX_set1_groups() then the python bindings will need to be changed in order to enable this in some way.

@nick2525
Copy link

UnsupportedAlgorithm: ed25519 is not supported by this version of OpenSSL

doesn't work on OpenSSL 1.1.1f, cryptography-3.3.1, python 3.9 ubuntu 20.04, I tried manual install of openssl, edit ldconfig, move libraries, edit /etc/ld.so.conf.d/libc.conf, did't worked for me

home-assistant/core#45363
#11227
postlund/pyatv#831

@romen
Copy link
Member

romen commented Jan 25, 2021

@nick2525 I would recommend opening a separate issue: they are not the same problem, as ed25519 is not a key exchange algorithm but just deals with signatures.

In the new issue you might also want to include more details about what you are trying to do exactly when the error occurs.

As a sidenote, it seems very likely that this is an issue in the python binding rather than in OpenSSL, so you might consider opening an issue in that project to receive the best support for your problem!

@t8m
Copy link
Member

t8m commented Jan 25, 2021 via email

@nick2525
Copy link

@t8m
Python 3.9.0 (default, Oct 28 2020, 23:50:03)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

from cryptography.hazmat.backends import default_backend
default_backend().openssl_version_text()
'OpenSSL 1.1.1f 31 Mar 2020'
=======================================================================
and also

from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
Ed25519PrivateKey.generate()
Traceback (most recent call last):
File "", line 1, in
File "/home/nick252/homeassistant/lib/python3.9/site-packages/cryptography/hazmat/primitives/asymmetric/ed25519.py", line 52, in generate
raise UnsupportedAlgorithm(
cryptography.exceptions.UnsupportedAlgorithm: ed25519 is not supported by this version of OpenSSL.

@nick2525
Copy link

remove python cache ./.cache/pip/wheels/ and reinstall cryptography fixes it

rmculpepper added a commit to rmculpepper/racket that referenced this issue Aug 25, 2022
Since v1.1.0, ECDH is always enabled with auto curve selection,
and customizing curves is rarely needed or advisable.
For v1.0.2, set auto-selection in server context construction.

See openssl/openssl#8837 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged: question The issue contains a question
Projects
None yet
Development

No branches or pull requests

10 participants