Skip to content

Commit 2a66c9c

Browse files
committed
Remove usage of OpenSSL.crypto.sign
This method has been removed in PyOpenSSL 24.3.0. This change replaces it with equivalent functions from python's cryptography library. In this way, the pyvim module can be used with recent versions of PyOpenSSL. This needed in particular due to CVE-2026-27459, which requires upgrading PyOpenSSL to 26.0.0. Changes in this commit: - Update the signing logic inside pyVim/sso.py's _sign helper to leverage Python's cryptography package primitives, replacing the legacy OpenSSL.crypto.sign wrapper. - Remove the constraint on pyOpenSSL in pyproject.toml. The whole repository is not using any other deprecated or removed feature in puOpenSSL. Resolves: #1112
1 parent e6cc09f commit 2a66c9c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pyVim/sso.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from cgi import escape
2121
#Third-party imports.
2222
from lxml import etree
23+
from cryptography.hazmat.primitives import hashes
24+
from cryptography.hazmat.primitives.asymmetric import padding
2325
from OpenSSL import crypto
2426
import ssl
2527

@@ -790,7 +792,20 @@ def _sign(private_key, data, digest=SHA256):
790792
# Convert private key in arbitrary format into DER (DER is binary format
791793
# so we get rid of \n / \r\n differences, and line breaks in PEM).
792794
pkey = _load_private_key(_extract_certificate(private_key))
793-
return base64.b64encode(crypto.sign(pkey, data.encode(UTF_8), digest))
795+
crypto_key = pkey.to_cryptography_key()
796+
if digest == SHA256:
797+
hash_alg = hashes.SHA256()
798+
elif digest == SHA512:
799+
hash_alg = hashes.SHA512()
800+
else:
801+
raise ValueError("Unsupported digest algorithm: %s" % digest)
802+
803+
signed = crypto_key.sign(
804+
data.encode(UTF_8),
805+
padding.PKCS1v15(),
806+
hash_alg
807+
)
808+
return base64.b64encode(signed)
794809

795810

796811
def _canonicalize(xml_string):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ classifiers = [
3838

3939
[project.optional-dependencies]
4040
sso = [
41-
"pyOpenSSL<24.3.0",
41+
"pyOpenSSL",
4242
"lxml",
4343
]
4444

0 commit comments

Comments
 (0)