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

Add configure option and code to disable OpenSSL engines #781

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

bukka
Copy link
Contributor

@bukka bukka commented Jan 21, 2025

This is to disable OpenSSL engines that are deprecated and in some setups inconvenient - especially the rdrand default usage which has priority over providers and disallows overwriting random generator using custom providers.

Summary by CodeRabbit

  • New Features

    • Added configuration option to disable OpenSSL engines
    • Enhanced control over cryptographic engine initialization
  • Bug Fixes

    • Improved error handling for cryptographic engine loading
    • Prevented potential null pointer dereferences during engine cleanup
  • Refactor

    • Modularized OpenSSL engine support with conditional compilation
    • Updated initialization and cleanup processes for cryptographic engines

@bukka bukka marked this pull request as ready for review January 28, 2025 14:37
@bukka bukka requested a review from a team as a code owner January 28, 2025 14:37
Copy link

coderabbitai bot commented Jan 28, 2025

Walkthrough

The pull request introduces configuration options for OpenSSL engines in a cryptographic library. A new configuration argument --disable-openssl-engines is added to allow users to control OpenSSL engine support. The changes modify build configuration macros and source code to conditionally compile and initialize cryptographic engines like RDRAND and GOST. The modifications enhance the library's flexibility by providing more granular control over cryptographic backend features.

Changes

File Change Summary
m4/acx_crypto_backend.m4 Added new configuration option --disable-openssl-engines with default "yes"
m4/acx_openssl_engines.m4 Introduced ACX_OPENSSL_ENGINES macro to check OpenSSL engines support
src/lib/crypto/OSSLCryptoFactory.h Added WITH_ENGINES preprocessor directive, declared rdrand_engine member
src/lib/crypto/OSSLCryptoFactory.cpp Added conditional compilation for RDRAND and GOST engine initialization

Sequence Diagram

sequenceDiagram
    participant User as User
    participant Configure as Configure Script
    participant Compiler as Compiler
    participant CryptoFactory as Crypto Factory

    User->>Configure: Run with --disable-openssl-engines
    Configure->>Compiler: Set compilation flags
    Compiler->>CryptoFactory: Conditionally compile engine support
    CryptoFactory-->>Compiler: Compile with/without engines
Loading

Poem

🐰 Engines of crypto, now under control,
With flags and macros, we've reached our goal!
Disable or enable, the choice is now clear,
OpenSSL's power, we hold ever so dear!
A rabbit's delight, in configuration's embrace 🔒

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
src/lib/crypto/OSSLCryptoFactory.cpp (1)

Line range hint 144-165: Improve RDRAND engine error handling and cleanup.

The current implementation has potential issues:

  1. No cleanup if ENGINE_init succeeds but ENGINE_set_default fails
  2. Warning messages could be more descriptive
 	if (rdrand_engine != NULL)
 	{
 		// Initialize RDRAND engine
 		if (!ENGINE_init(rdrand_engine))
 		{
-			WARNING_MSG("ENGINE_init returned %lu\n", ERR_get_error());
+			WARNING_MSG("Failed to initialize RDRAND engine: %lu\n", ERR_get_error());
+			ENGINE_free(rdrand_engine);
+			rdrand_engine = NULL;
 		}
 		// Set RDRAND engine as the default for RAND_ methods
 		else if (!ENGINE_set_default(rdrand_engine, ENGINE_METHOD_RAND))
 		{
-			WARNING_MSG("ENGINE_set_default returned %lu\n", ERR_get_error());
+			WARNING_MSG("Failed to set RDRAND as default engine: %lu\n", ERR_get_error());
+			ENGINE_finish(rdrand_engine);
+			ENGINE_free(rdrand_engine);
+			rdrand_engine = NULL;
 		}
 	}
🧹 Nitpick comments (2)
m4/acx_openssl_engines.m4 (1)

1-35: LGTM! Consider improving the error message.

The macro implementation follows autoconf best practices with proper environment handling and result caching.

Consider improving the error message in the test program:

-                #error "Engines are disabled"
+                #error "OpenSSL engines are not available (OPENSSL_NO_ENGINE is defined)"
m4/acx_crypto_backend.m4 (1)

54-60: Enhance the help string for the openssl-engines option.

The current help string could be more descriptive about the implications of disabling engines.

-			[Disable OpenSSL engines usage]
+			[Disable OpenSSL engines usage (prevents usage of hardware-based random number generation and GOST)]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0053e2b and a393bf8.

📒 Files selected for processing (4)
  • m4/acx_crypto_backend.m4 (2 hunks)
  • m4/acx_openssl_engines.m4 (1 hunks)
  • src/lib/crypto/OSSLCryptoFactory.cpp (5 hunks)
  • src/lib/crypto/OSSLCryptoFactory.h (2 hunks)
🔇 Additional comments (4)
src/lib/crypto/OSSLCryptoFactory.h (2)

45-48: LGTM! Clean conditional compilation setup.

The WITH_ENGINES macro is properly defined based on OpenSSL configuration.


110-119: LGTM! Good encapsulation of engine-related members.

Engine member variables are properly wrapped in WITH_ENGINES conditional.

m4/acx_crypto_backend.m4 (1)

118-132: LGTM! Clean integration with crypto backend selection.

The OpenSSL engines support check is properly integrated with the existing crypto backend selection logic.

src/lib/crypto/OSSLCryptoFactory.cpp (1)

Line range hint 233-263: Verify OpenSSL version-specific cleanup logic.

The cleanup code uses version-specific paths that need verification.

✅ Verification successful

OpenSSL version-specific cleanup logic is correctly implemented

The cleanup code properly handles different OpenSSL versions and LibreSSL, with consistent version checks across the codebase and appropriate safeguards against use-after-free issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check OpenSSL version compatibility for cleanup logic

# Test: Check OpenSSL version and LibreSSL definitions
rg -A 5 "OPENSSL_VERSION|LIBRESSL" --type cpp

Length of output: 6812

@abbra
Copy link
Contributor

abbra commented Jan 29, 2025

LGTM

@jschlyter jschlyter merged commit 7081d3b into softhsm:develop Jan 29, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants