Skip to content

Commit e6fb25f

Browse files
authored
Merge pull request #15 from okfn/fix-pysaml2-version
Fix pysaml2 dependency.
2 parents e16ecca + 4c06f8d commit e6fb25f

4 files changed

Lines changed: 47 additions & 29 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
strategy:
2828
fail-fast: false
2929
matrix:
30-
python-version: ['3.9', '3.10'] # TODO '3.11'
30+
python-version: ['3.10', '3.11']
3131
ckan-version: ["2.10", "2.11"]
3232
name: Python ${{ matrix.python-version }} CKAN ${{ matrix.ckan-version }} extension test
3333

ckanext/saml2auth/tests/test_blueprint_get_request.py

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -227,43 +227,59 @@ def _load_base(
227227
}
228228

229229
def _generate_cert(self):
230-
from saml2.cert import OpenSSLWrapper
231-
232-
cert_info_ca = {
233-
"cn": "localhost.ca",
234-
"country_code": "se",
235-
"state": "ac",
236-
"city": "umea",
237-
"organization": "Test University",
238-
"organization_unit": "Deca"
239-
}
240-
241-
osw = OpenSSLWrapper()
242-
ca_cert, ca_key = osw.create_certificate(
243-
cert_info_ca,
244-
request=False,
245-
write_to_file=False
230+
# Mint a throwaway RSA keypair / self-signed certificate for the SP
231+
# using the `cryptography` library directly. We deliberately avoid
232+
# pysaml2's saml2.cert.OpenSSLWrapper, which relies on
233+
# OpenSSL.crypto.X509Req -- deprecated in pyOpenSSL 24.2.0 and removed
234+
# in 26.3.0 (which the fork's pyopenssl>=25.3.0 resolves to). The
235+
# extension never generates certificates at runtime, so this keeps
236+
# the test compatible with current pyOpenSSL / cryptography releases.
237+
import datetime
238+
from cryptography import x509
239+
from cryptography.x509.oid import NameOID
240+
from cryptography.hazmat.primitives import hashes, serialization
241+
from cryptography.hazmat.primitives.asymmetric import rsa
242+
243+
key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
244+
245+
name = x509.Name([
246+
x509.NameAttribute(NameOID.COUNTRY_NAME, u"SE"),
247+
x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, u"ac"),
248+
x509.NameAttribute(NameOID.LOCALITY_NAME, u"umea"),
249+
x509.NameAttribute(NameOID.ORGANIZATION_NAME, u"Test University"),
250+
x509.NameAttribute(NameOID.ORGANIZATIONAL_UNIT_NAME, u"Deca"),
251+
x509.NameAttribute(NameOID.COMMON_NAME, u"localhost"),
252+
])
253+
254+
now = datetime.datetime.now(datetime.timezone.utc)
255+
cert = (
256+
x509.CertificateBuilder()
257+
.subject_name(name)
258+
.issuer_name(name)
259+
.public_key(key.public_key())
260+
.serial_number(x509.random_serial_number())
261+
.not_valid_before(now - datetime.timedelta(days=1))
262+
.not_valid_after(now + datetime.timedelta(days=3650))
263+
.sign(key, hashes.SHA256())
246264
)
247265

248-
cert_str, key_str = osw.create_certificate(cert_info_ca, request=True)
249-
re_cert_str = osw.create_cert_signed_certificate(
250-
ca_cert,
251-
ca_key,
252-
cert_str,
253-
valid_from=0,
254-
valid_to=1
266+
key_str = key.private_bytes(
267+
encoding=serialization.Encoding.PEM,
268+
format=serialization.PrivateFormat.TraditionalOpenSSL,
269+
encryption_algorithm=serialization.NoEncryption(),
255270
)
271+
cert_str = cert.public_bytes(serialization.Encoding.PEM).decode('ascii')
256272

257273
f = open(os.path.join(extras_folder, 'provider1', 'mycert.pem'), 'w')
258-
f.write(re_cert_str)
274+
f.write(cert_str)
259275
f.close()
260276

261277
f = open(os.path.join(extras_folder, 'provider1', 'mykey.pem'), 'wb')
262278
f.write(key_str)
263279
f.close()
264280

265281
self.key_str = key_str
266-
self.cert_str = re_cert_str
282+
self.cert_str = cert_str
267283

268284
@pytest.mark.ckan_config(u'ckanext.saml2auth.entity_id', u'urn:gov:gsa:SAML:2.0.profiles:sp:sso:test:entity')
269285
@pytest.mark.ckan_config(u'ckanext.saml2auth.idp_metadata.location', u'local')

dev-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
flake8 # for the CI build
2-
pysaml2
32
packaging>=22.0

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@
7878
packages=find_packages(exclude=['contrib', 'docs', 'tests*']),
7979
namespace_packages=['ckanext'],
8080

81-
# pysaml2 7.4 requires python 3.9
81+
# See pysaml2 dependency
82+
# https://github.com/IdentityPython/pysaml2/pull/1021
83+
# https://github.com/IdentityPython/pysaml2/pull/1021#issuecomment-4075874429
8284
install_requires=[
83-
'pysaml2>=7.4',
85+
'pysaml2 @ git+https://github.com/peppelinux/pysaml2@pplnx-v7.5.4-1',
86+
8487
],
8588

8689
# If there are data files included in your packages that need to be

0 commit comments

Comments
 (0)