1010using Keyfactor . PKI . Enums . EJBCA ;
1111using Microsoft . Extensions . Logging ;
1212using Newtonsoft . Json ;
13- using Org . BouncyCastle . Asn1 ;
1413using Org . BouncyCastle . Asn1 . Pkcs ;
1514using Org . BouncyCastle . Asn1 . X509 ;
1615using Org . BouncyCastle . Pkcs ;
2221using System . Text . RegularExpressions ;
2322using System . Threading ;
2423using System . Threading . Tasks ;
25- using static Org . BouncyCastle . Math . EC . ECCurve ;
2624
2725namespace Keyfactor . Extensions . CAPlugin . Acme
2826{
@@ -73,19 +71,13 @@ public class AcmeCaPlugin : IAnyCAPlugin
7371 private const string USER_AGENT = "KeyfactorAcmePlugin/1.0" ;
7472
7573 /// <summary>
76- /// Default constructor for backward compatibility
74+ /// Constructor requires domain validator factory for plugin-based DNS providers
7775 /// </summary>
78- public AcmeCaPlugin ( ) : this ( null )
79- {
80- }
81-
82- /// <summary>
83- /// Constructor with dependency injection support for domain validator factory
84- /// </summary>
85- /// <param name="validatorFactory">Factory to resolve domain validators from plugins</param>
76+ /// <param name="validatorFactory">Factory to resolve domain validators from plugins (Required)</param>
8677 public AcmeCaPlugin ( IDomainValidatorFactory validatorFactory )
8778 {
88- _validatorFactory = validatorFactory ;
79+ _validatorFactory = validatorFactory ?? throw new ArgumentNullException ( nameof ( validatorFactory ) ,
80+ "IDomainValidatorFactory is required. DNS providers are now externalized as plugins." ) ;
8981 }
9082
9183 /// <summary>
@@ -96,43 +88,54 @@ public void Initialize(IAnyCAPluginConfigProvider configProvider, ICertificateDa
9688 _logger . MethodEntry ( ) ;
9789 Config = configProvider ?? throw new ArgumentNullException ( nameof ( configProvider ) ) ;
9890
99- // Try to use plugin-based domain validator if factory is available
100- if ( _validatorFactory ! = null )
91+ // Factory is now required - all DNS providers are externalized as plugins
92+ if ( _validatorFactory = = null )
10193 {
102- _logger . LogInformation ( "Using plugin-based domain validator resolution" ) ;
103- try
104- {
105- // Resolve domain validator from plugin system
106- _domainValidator = _validatorFactory . ResolveDomainValidator (
107- domain : "www.keyfactortestb.com" , // Wildcard - let the factory choose the right provider
108- validationType : DNS_CHALLENGE_TYPE
109- ) ;
110-
111- if ( _domainValidator != null )
112- {
113- //_domainValidator.Initialize(new DomainValidatorConfigProvider(configProvider.CAConnectionData));
114- _logger . LogInformation ( "Successfully initialized domain validator from plugin: {ValidatorType}" ,
115- _domainValidator . GetType ( ) . FullName ) ;
116- }
117- }
118- catch ( Exception ex )
119- {
120- _logger . LogWarning ( ex , "Failed to resolve domain validator from plugin factory, falling back to embedded validator" ) ;
121- _domainValidator = null ;
122- }
94+ var errorMsg = "IDomainValidatorFactory is required. DNS providers are now loaded as external plugins. " +
95+ "Ensure the Keyfactor platform is configured to inject the factory." ;
96+ _logger . LogError ( errorMsg ) ;
97+ throw new InvalidOperationException ( errorMsg ) ;
12398 }
12499
125- // Fallback to embedded validator for backward compatibility
100+ _logger . LogInformation ( "Resolving domain validator from plugin system" ) ;
101+
102+ // Resolve domain validator from plugin system
103+ _domainValidator = _validatorFactory . ResolveDomainValidator (
104+ domain : "*" , // Wildcard - let the factory choose based on configuration
105+ validationType : DNS_CHALLENGE_TYPE
106+ ) ;
107+
126108 if ( _domainValidator == null )
127109 {
128- _logger . LogInformation ( "Using embedded Dns01DomainValidator (legacy mode)" ) ;
129- _domainValidator = new Dns01DomainValidator ( ) ;
130- _domainValidator . Initialize ( new DomainValidatorConfigProvider ( configProvider . CAConnectionData ) ) ;
110+ var errorMsg = $ "Failed to resolve domain validator for type '{ DNS_CHALLENGE_TYPE } '. " +
111+ "Ensure the appropriate DNS provider plugin is deployed and configured." ;
112+ _logger . LogError ( errorMsg ) ;
113+ throw new InvalidOperationException ( errorMsg ) ;
131114 }
132115
116+ // Initialize the validator with configuration
117+ var domainValidatorConfig = new DomainValidatorConfigProvider ( configProvider . CAConnectionData ) ;
118+ _domainValidator . Initialize ( domainValidatorConfig ) ;
119+
120+ _logger . LogInformation ( "Successfully initialized domain validator from plugin: {ValidatorType}" ,
121+ _domainValidator . GetType ( ) . FullName ) ;
122+
133123 _logger . MethodExit ( ) ;
134124 }
135125
126+ /// <summary>
127+ /// Simple implementation of IDomainValidatorConfigProvider to pass configuration to plugins
128+ /// </summary>
129+ private class DomainValidatorConfigProvider : IDomainValidatorConfigProvider
130+ {
131+ public Dictionary < string , object > DomainValidationConfiguration { get ; }
132+
133+ public DomainValidatorConfigProvider ( Dictionary < string , object > config )
134+ {
135+ DomainValidationConfiguration = config ?? new Dictionary < string , object > ( ) ;
136+ }
137+ }
138+
136139 /// <summary>
137140 /// Health check method - currently no-op for ACME
138141 /// </summary>
0 commit comments