@@ -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' )
0 commit comments