@@ -452,24 +452,8 @@ def create_ssl_nonblocking_connection(
452452 Returns the raw sockets, the SSL Connection objects
453453 and the actual send/receive buffer sizes.
454454 """
455- chain = _create_certificate_chain ()
456-
457- # Extract the server's key and certificate from the chain ---
458- # The chain is [ (root_key, root_cert),
459- # (intermediate_key, intermediate_cert), (server_key, server_cert) ]
460- server_key , server_cert = chain [
461- 2
462- ] # Index 2 gets the last tuple: (skey, scert)
463-
464- # Set up the server's SSL context ---
465- server_ctx = Context (SSLv23_METHOD )
466- server_ctx .use_privatekey (server_key ) # Use the server_key from the chain
467- server_ctx .use_certificate (
468- server_cert
469- ) # Use the server_cert from the chain
470- server_ctx .add_extra_chain_cert (
471- chain [1 ][1 ]
472- ) # Add the intermediate cert to the server's extra chain
455+
456+ client_socket , server_socket = socket_pair ()
473457
474458 # Set up client context
475459 client_ctx = Context (SSLv23_METHOD )
@@ -487,29 +471,9 @@ def create_ssl_nonblocking_connection(
487471 # Set the new mode to the requested value
488472 client_ctx .set_mode (mode )
489473
490- # Get the certificate store from the context
491- cert_store = client_ctx .get_cert_store ()
492-
493- # Assert that cert_store is not None to satisfy mypy
494- assert cert_store is not None , (
495- "Expected X509Store, but got None from get_cert_store()"
496- )
497-
498- # Add the Root CA certificate to the store
499- cert_store .add_cert (
500- chain [0 ][1 ]
501- ) # chain[0][1] is the pyOpenSSL X509 object for the root CA
502- # Enable peer verification so the client actually checks the server's cert
503- client_ctx .set_verify (
504- SSL .VERIFY_PEER , lambda conn , cert , errnum , depth , ok : bool (ok )
505- )
506-
507- # Create connections with real sockets
508- client_socket , server_socket = socket_pair ()
509-
510- # Create Connection objects from the sockets
474+ # create the SSL connections
511475 client = Connection (client_ctx , client_socket )
512- server = Connection ( server_ctx , server_socket )
476+ server = loopback_server_factory ( server_socket )
513477
514478 # Allow caller to request small buffer sizes so they can be easily filled.
515479 # Note the OS may not respect the requested values.
@@ -533,7 +497,7 @@ def create_ssl_nonblocking_connection(
533497
534498 # set the connection state
535499 client .set_connect_state ()
536- server . set_accept_state ()
500+ # loopback_server_factory already sets the accept state on the server
537501
538502 handshake (client , server )
539503
0 commit comments