radiator-software / p5-net-ssleay

Net-SSLeay: Perl bindings for OpenSSL and LibreSSL
https://metacpan.org/release/Net-SSLeay
Artistic License 2.0
31 stars 43 forks source link

Net::SSLeay assumes all libssl/libcrypto constants are doubles #315

Open chrisnovakovic opened 2 years ago

chrisnovakovic commented 2 years ago

Raised by @h-vn in a comment in #313, but it deserves its own issue.

helper_script/regen_openssl_constants.pl (and, when #313 is merged, helper_script/update-exported-constants) generates C code that returns the values of libssl and libcrypto constants as doubles:

https://github.com/radiator-software/p5-net-ssleay/blob/4d9f7eaeeeb982ca3a92d469a0a6771d8031734c/constants.c#L3-L4

This assumes that the values of constants will never be greater than 253. This appears to be the case for all constants we currently export for all versions of OpenSSL and LibreSSL we currently support, although this isn't guaranteed to be true in future.

h-vn commented 2 years ago

What if we start with a partial solution: switch to an unsigned 64bit integer with Perls that support 64bit integer?

h-vn commented 2 years ago

Pull request #344 implements the partial solution.

However, https://metacpan.org/pod/Math::Int64#C-API looks like a better option. If we change to it, parts of the pull request can still be used. It would also be usable with API functions that use 64 bit integers. None are exposed yet, but when they are needed, we'd have the support correctly available.

h-vn commented 2 years ago

After a closer look at Math::Int64, it appears that use of it would create a dependency which would also affect 64bit integer Perl environments. I guess there's no possibility to have a dependency that would only apply with 32bit integer Perls. This optional dependency would also require a number of ifdefs in the code, possibly two typemap files and would otherwise be ugly. I would stay with pull request #344 for now to cover most of the target Perls.

h-vn commented 2 years ago

Changes in pull request GH-344 fix this for Perls that use 64bit integers.

Perls with 32bit integers continue to use double and long with OpenSSL 3.0 and later. This needs to be addressed later while also keeping in mind that starting with OpenSSL 1.1.0, a number of APIs are now using 64bit types. These are typically new APIs with SSL_CTX_get_options() family of functions being an exception that changed from long to uint64_t in OpenSSL 3.0.0-alpha17.

h-vn commented 2 years ago

Stable release 1.92 includes the changes described above. Constants use type uint64_t when OpenSSL is 3.0 and Perl has 64bit integers.