tests: Work around pyopenssl API change

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>
This commit is contained in:
Jouni Malinen 2017-02-28 11:48:16 +02:00 committed by Jouni Malinen
parent 5118319831
commit 33a6da6908

View file

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