Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve make_optional_func_list and make renegotiation functions optional. #23

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/wolfssl/_build_ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,19 @@ def make_optional_func_list(libwolfssl_path, funcs):
except AttributeError as _:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this isn't part of the PR but can we just change this to except AttributeError:? The as _ isn't necessary if all we care about is exception type.

pass
# Can't discover functions in a static library with ctypes. Need to fall
# back to running nm as a subprocess.
# back to running nm, if available, as a subprocess.
else:
nm_cmd = "nm --defined-only {}".format(libwolfssl_path)
result = subprocess.run(shlex.split(nm_cmd), capture_output=True)
nm_stdout = result.stdout.decode()
defined = [func for func in funcs if func.name in nm_stdout]
which_cmd = "which nm"
result = subprocess.run(shlex.split(which_cmd))
if result.returncode == 0:
nm_cmd = "nm --defined-only {}".format(libwolfssl_path)
result = subprocess.run(shlex.split(nm_cmd), capture_output=True)
nm_stdout = result.stdout.decode()
defined = [func for func in funcs if func.name in nm_stdout]
else:
print(("WARNING: Can't determine available libwolfssl functions."
" Assuming all optional functions are available."))
defined = funcs
Comment on lines +56 to +58
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would be better to throw an exception here and allow the user to skip the exception (and assume all optional funcs are available) through a command line parameter? This would make error detection and debugging easier.


return defined

Expand All @@ -63,6 +70,9 @@ def make_optional_func_list(libwolfssl_path, funcs):
# Depending on how wolfSSL was configured, the functions below may or may not be
# defined.
optional_funcs = [
WolfFunction("wolfSSL_Rehandshake",
"int wolfSSL_Rehandshake(WOLFSSL*)",
"int SSL_renegotiate(SSL*)"),
WolfFunction("wolfSSL_ERR_func_error_string",
"const char* wolfSSL_ERR_func_error_string(unsigned long)",
"const char* ERR_func_error_string(unsigned long)"),
Expand Down
1 change: 0 additions & 1 deletion src/wolfssl/_openssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ def construct_cdef(optional_funcs):
X509* SSL_get_peer_certificate(SSL*);
const char* SSL_alert_type_string_long(int);
const char* SSL_alert_desc_string_long(int);
int SSL_renegotiate(SSL*);
void SSL_get0_next_proto_negotiated(const SSL*,
const unsigned char**, unsigned*);
const char* SSL_get_servername(SSL*, unsigned char);
Expand Down