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

Exported constant management process is cumbersome #313

Closed
chrisnovakovic opened this issue Oct 1, 2021 · 2 comments
Closed

Exported constant management process is cumbersome #313

chrisnovakovic opened this issue Oct 1, 2021 · 2 comments
Assignees
Labels
tech-debt Technical debt

Comments

@chrisnovakovic
Copy link
Collaborator

Since 2012, the list of libssl/libcrypto constants exported by Net::SSLeay has been managed using helper_script/regen_openssl_constants.pl. There are numerous problems with this approach:

  • The script isn't well-documented. There are mistakes in the instructions for adding a constant to be exported; e.g., the suggested invocation of the script with the -gen-t option involves writing the generated test to t/local/20_autoload.t, which historically didn't exhaustively test constant loading and has since been overwritten (this presumably directly led to t/local/20_autoload.t doesn't perform any unique autoloading tests #311).
  • It's written in an unclear style, making it hard to maintain (e.g., I'd like to be able to switch to a two-column format for the constants list destined for the Pod, but it's not straightforward to rework const_list_3columns to get it to do this).
  • Its output is messy, and naturally leads to larger and unintelligible Git commits. For example, a three-column layout for @EXPORT_OK in lib/Net/SSLeay.pm makes it almost impossible to tell which constants have been added or removed in a commit, because every line changes. It also leads to an overall larger file size for lib/Net/SSLeay.pm than having one constant per line, because formatting each constant requires on average more than the 5 bytes it would take to indent each constant individually.
  • Even with this script, multiple manual and error-prone processes need to be performed to add or remove an exported constant: multiple invocations are necessary to generate constants.c, the test file and the list of constants for lib/Net/SSLeay.pod, and the script prompts the user to manually edit @EXPORT_OK in lib/Net/SSLeay.pm (which also contains non-constant exports). This has led to inconsistencies between the four files because of the lack of clarity in the instructions; e.g., in lib/Net/SSLeay.pm the OCSP constants are listed separately from the rest of the constants for no apparent reason.

We'd benefit from a script that does for constant management what helper_script/generate-test-pki does for the PKI used by the test suite: something that consumes an exported constants list from a separate file, and automatically generates or updates all files in the repository that need to be changed as a result of that file changing. The Net::SSLeay code and documentation will be clearer, the purpose of commits will be more obvious, and there'll be fewer opportunities to make mistakes when adding or removing constants.

@chrisnovakovic chrisnovakovic added the tech-debt Technical debt label Oct 1, 2021
@chrisnovakovic chrisnovakovic self-assigned this Oct 1, 2021
@h-vn
Copy link
Contributor

h-vn commented Oct 1, 2021

There's also additional requirement introduced by OpenSSL 3.0.0: the return values of SSL_CTX_set_options family of functions now return an uint64_t whereas earlier they returned a long.

The help script now uses static double for constant return value. Doesn't this break things when the functions start returning values that have high bits set?

chrisnovakovic added a commit to chrisnovakovic/p5-net-ssleay that referenced this issue Oct 6, 2021
Exported libssl/libcrypto constants are currently managed using
helper_script/regen_openssl_constants.pl, which still involves following
a lot of cumbersome and error-prone manual steps. See radiator-software#313 for a
detailed discussion of the problems with this script.

Fully automate the constant management process with a new script,
helper_script/update-exported-constants, which reads a list of
libssl/libcrypto constants from constants.txt and automatically
generates or updates the necessary files in the repository. Make the
following changes to accommodate the new script:

* Remove invocations of regen_openssl_constants.pl from the Makefile,
  but don't replace them with invocations of update-exported-constants:
  the new script is intended to be run as part of a commit that adds or
  removes constants, and should not need to be run by end users of the
  module.
* In lib/Net/SSLeay.pm, split the list of exportable symbols into two
  categories, defined in separate arrays: one for constants (which is
  automatically updated when update-exported-constants runs), and one
  for functions (which will continue to be managed manually).
* In lib/Net/SSLeay.pod, signpost the location of the code block
  containing the constants list by surrounding it with Pod comments; the
  Pod between these comments is automatically updated when
  update-exported-constants runs.

Closes radiator-software#313.
@chrisnovakovic
Copy link
Collaborator Author

There's also additional requirement introduced by OpenSSL 3.0.0: the return values of SSL_CTX_set_options family of functions now return an uint64_t whereas earlier they returned a long.

The help script now uses static double for constant return value. Doesn't this break things when the functions start returning values that have high bits set?

This is definitely something we need to think about. Since we won't be in a worse position than we already are by having a helper script that assumes all constants are doubles, I've opened another issue (#315) so we can fix this separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tech-debt Technical debt
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants