]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Work around pyopenssl API change
authorJouni Malinen <jouni@qca.qualcomm.com>
Tue, 28 Feb 2017 09:48:16 +0000 (11:48 +0200)
committerJouni Malinen <j@w1.fi>
Tue, 28 Feb 2017 22:20:29 +0000 (00:20 +0200)
OpenSSL.SSL.Connection.state_string() was replaced with
get_state_string() in pyopenssl. Add workaround code to be able to use
either of these names.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
tests/hwsim/test_eap_proto.py

index 14509f2565aabcd97435e0fe40f23c1fce697283..cef72903739ac91dcbbefe341191a32c3e793978 100644 (file)
@@ -8029,6 +8029,14 @@ def run_eap_fast_phase2(dev, test_payload, test_failure=True):
     def ssl_info_callback(conn, where, ret):
         logger.debug("SSL: info where=%d ret=%d" % (where, ret))
 
+    def log_conn_state(conn):
+        try:
+            state = conn.state_string()
+        except AttributeError:
+            state = conn.get_state_string()
+        if state:
+            logger.info("State: " + state)
+
     def process_clienthello(ctx, payload):
         logger.info("Process ClientHello")
         ctx['sslctx'] = OpenSSL.SSL.Context(OpenSSL.SSL.TLSv1_METHOD)
@@ -8037,43 +8045,31 @@ def run_eap_fast_phase2(dev, test_payload, test_failure=True):
         ctx['sslctx'].set_cipher_list("ADH-AES128-SHA")
         ctx['conn'] = OpenSSL.SSL.Connection(ctx['sslctx'], None)
         ctx['conn'].set_accept_state()
-        state = ctx['conn'].state_string()
-        if state:
-            logger.info("State: " + state)
+        log_conn_state(ctx['conn'])
         ctx['conn'].bio_write(payload)
         try:
             ctx['conn'].do_handshake()
         except OpenSSL.SSL.WantReadError:
             pass
-        state = ctx['conn'].state_string()
-        if state:
-            logger.info("State: " + state)
+        log_conn_state(ctx['conn'])
         data = ctx['conn'].bio_read(4096)
-        state = ctx['conn'].state_string()
-        if state:
-            logger.info("State: " + state)
+        log_conn_state(ctx['conn'])
         return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
                            4 + 1 + 1 + len(data),
                            EAP_TYPE_FAST, 0x01) + data
 
     def process_clientkeyexchange(ctx, payload, appl_data):
         logger.info("Process ClientKeyExchange")
-        state = ctx['conn'].state_string()
-        if state:
-            logger.info("State: " + state)
+        log_conn_state(ctx['conn'])
         ctx['conn'].bio_write(payload)
         try:
             ctx['conn'].do_handshake()
         except OpenSSL.SSL.WantReadError:
             pass
         ctx['conn'].send(appl_data)
-        state = ctx['conn'].state_string()
-        if state:
-            logger.info("State: " + state)
+        log_conn_state(ctx['conn'])
         data = ctx['conn'].bio_read(4096)
-        state = ctx['conn'].state_string()
-        if state:
-            logger.info("State: " + state)
+        log_conn_state(ctx['conn'])
         return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
                            4 + 1 + 1 + len(data),
                            EAP_TYPE_FAST, 0x01) + data