Skip to content

Conversation

@Aaronontheweb
Copy link
Member

Summary

This PR integrates the new CertificateValidationCallback feature from Akka.NET v1.5.55 into Akka.Remote.Hosting, allowing users to provide custom certificate validation logic for SSL/TLS connections.

Changes

  • Updated Akka.NET to v1.5.55 - Required to access the new SSL/TLS features
  • Added CustomValidator property to SslOptions - Allows users to provide a CertificateValidationCallback delegate
  • Enhanced RemoteOptions.Build method - Now intelligently selects the appropriate DotNettySslSetup constructor:
    • 5-parameter constructor when CustomValidator is provided (v1.5.55+)
    • 4-parameter constructor when RequireMutualAuthentication or ValidateCertificateHostname is set
    • 2-parameter constructor for legacy scenarios (full backward compatibility)
  • Added test coverage - New test verifies custom validators are properly configured
  • Updated API approval tests - Reflects the new public API surface

Key Features

This enhancement enables advanced SSL/TLS scenarios including:

  • Certificate pinning (whitelist known cert thumbprints)
  • Subject/issuer matching (organizational CA validation)
  • Custom business validation rules
  • Advanced mTLS scenarios

Example Usage

services.AddAkka("RemoteSys", (builder, provider) =>
{
    builder.WithRemoting(new RemoteOptions
    {
        Port = 2552,
        EnableSsl = true,
        Ssl = new SslOptions
        {
            X509Certificate = myCert,
            CustomValidator = (cert, chain, peer, errors, log) =>
            {
                // Custom validation logic
                return IsValidCertificate(cert, peer);
            }
        }
    });
});

Backward Compatibility

100% backward compatible - All existing code continues to work unchanged. The new CustomValidator property is optional and the implementation maintains the existing constructor selection logic when it's not provided.

Testing

  • All existing tests pass (16/16 in Akka.Remote.Hosting.Tests)
  • New test specifically validates CustomValidator configuration
  • API approval tests updated and passing
  • No SSL/TLS functional testing added (we rely on Akka.Remote's comprehensive test coverage)

Notes

  • As noted in Akka.NET v1.5.55 release notes, programmatic DotNettySslSetup configuration now correctly takes precedence over HOCON defaults, ensuring our settings are effective
  • We use DotNettySslSetup for SSL configuration when a certificate object is provided, which guarantees the settings are applied

Resolves the need to support custom certificate validation scenarios as introduced in Akka.NET v1.5.55.

… from Akka.NET v1.5.55

- Updated Akka.NET from v1.5.53 to v1.5.55 to access new SSL/TLS features
- Added CustomValidator property to SslOptions to support CertificateValidationCallback
- Updated RemoteOptions.Build to use appropriate DotNettySslSetup constructor based on settings:
  - 5-parameter constructor when CustomValidator is provided (v1.5.55+)
  - 4-parameter constructor when RequireMutualAuthentication or ValidateCertificateHostname is set
  - 2-parameter constructor for legacy scenarios (backward compatibility)
- Added comprehensive test coverage for CustomValidator configuration
- Updated API approval tests to reflect new public API surface

This enhancement allows users to implement custom certificate validation logic such as:
- Certificate pinning
- Subject/issuer matching
- Business-specific validation rules
- Advanced mTLS scenarios

The implementation maintains full backward compatibility while providing access to the powerful
new CertificateValidation features introduced in Akka.NET v1.5.55.
Copy link
Member Author

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

LGTM

Fixed bug where both HOCON SSL configuration and DotNettySslSetup were being emitted simultaneously. DotNettySslSetup ALWAYS takes precedence when present, making HOCON SSL settings ineffective and potentially confusing.

Changes:
- Modified RemoteOptions.Build to only emit HOCON SSL config when X509Certificate is null
- Added comprehensive comments explaining SSL configuration strategy with link to Akka.NET issue #7914
- Updated tests to use CertificateOptions instead of X509Certificate when testing HOCON SSL configuration
- Both WithRemotingNewSslSettingsHoconTest and WithRemotingConfiguratorNewSslSettingsTest now properly test HOCON config

This ensures users understand that:
1. X509Certificate object → DotNettySslSetup (programmatic, takes precedence)
2. X509Certificate null + SSL settings → HOCON configuration only

Related to: akkadotnet/akka.net#7914
@Aaronontheweb Aaronontheweb enabled auto-merge (squash) October 26, 2025 21:21
Added detailed SSL/TLS configuration documentation to Akka.Remote.Hosting README including:
- Basic SSL configuration with certificate file (HOCON-based)
- SSL configuration with X509Certificate2 object (programmatic)
- Advanced custom certificate validation example (certificate pinning)
- Examples using all CertificateValidation helper methods from Akka.NET v1.5.55:
  * ValidateChain() - Standard chain validation
  * ValidateHostname() - Hostname validation
  * PinnedCertificate() - Certificate pinning
  * ValidateSubject() - Subject pattern matching
  * ValidateIssuer() - Issuer validation
  * Combine() - Combining multiple validators
- Complete SSL configuration options reference
- Important note about DotNettySslSetup vs HOCON precedence

This helps users understand how to use the new CustomValidator feature for enhanced security scenarios.
@Aaronontheweb Aaronontheweb enabled auto-merge (squash) October 26, 2025 21:35
@Aaronontheweb Aaronontheweb merged commit efca03b into akkadotnet:dev Oct 26, 2025
2 checks passed
@Aaronontheweb Aaronontheweb deleted the feature/ssl-custom-validator branch October 26, 2025 22:36
Aaronontheweb added a commit that referenced this pull request Oct 26, 2025
Added documentation for PR #686 which integrates custom certificate validation callbacks from Akka.NET v1.5.55.
Aaronontheweb added a commit that referenced this pull request Oct 26, 2025
* Prepare for 1.5.55 stable release

- Updated RELEASE_NOTES.md with stable release entry
- Updated version metadata from 1.5.55-beta1 to 1.5.55

* Add SSL custom certificate validation to 1.5.55 release notes

Added documentation for PR #686 which integrates custom certificate validation callbacks from Akka.NET v1.5.55.
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.

1 participant