1616using NuGet . Jobs ;
1717using NuGet . Jobs . Configuration ;
1818using NuGet . Jobs . Validation . Common ;
19+ using NuGet . Jobs . Validation . PackageSigning . Messages ;
20+ using NuGet . Jobs . Validation . PackageSigning . Storage ;
1921using NuGet . Services . Configuration ;
2022using NuGet . Services . KeyVault ;
2123using NuGet . Services . ServiceBus ;
24+ using NuGet . Services . Validation . PackageCertificates ;
25+ using NuGet . Services . Validation . PackageSigning ;
2226using NuGet . Services . Validation . Vcs ;
2327
2428namespace NuGet . Services . Validation . Orchestrator
@@ -30,12 +34,17 @@ public class Job : JobBase
3034
3135 private const string ConfigurationSectionName = "Configuration" ;
3236 private const string VcsSectionName = "Vcs" ;
37+ private const string PackageSigningSectionName = "PackageSigning" ;
38+ private const string PackageCertificatesSectionName = "PackageCertificates" ;
3339 private const string RunnerConfigurationSectionName = "RunnerConfiguration" ;
3440 private const string GalleryDbConfigurationSectionName = "GalleryDb" ;
3541 private const string ValidationDbConfigurationSectionName = "ValidationDb" ;
3642 private const string ServiceBusConfigurationSectionName = "ServiceBus" ;
3743
3844 private const string VcsBindingKey = VcsSectionName ;
45+ private const string PackageVerificationTopicClientBindingKey = "PackageVerificationTopicClient" ;
46+ private const string PackageSigningBindingKey = PackageSigningSectionName ;
47+ private const string PackageCertificatesBindingKey = PackageCertificatesSectionName ;
3948 private const string ValidationStorageBindingKey = "ValidationStorage" ;
4049 private const string OrchestratorBindingKey = "Orchestrator" ;
4150
@@ -123,6 +132,8 @@ private void ConfigureJobServices(IServiceCollection services, IConfigurationRoo
123132 {
124133 services . Configure < ValidationConfiguration > ( configurationRoot . GetSection ( ConfigurationSectionName ) ) ;
125134 services . Configure < VcsConfiguration > ( configurationRoot . GetSection ( VcsSectionName ) ) ;
135+ services . Configure < PackageSigningConfiguration > ( configurationRoot . GetSection ( PackageSigningSectionName ) ) ;
136+ services . Configure < PackageCertificatesConfiguration > ( configurationRoot . GetSection ( PackageCertificatesSectionName ) ) ;
126137 services . Configure < OrchestrationRunnerConfiguration > ( configurationRoot . GetSection ( RunnerConfigurationSectionName ) ) ;
127138 services . Configure < GalleryDbConfiguration > ( configurationRoot . GetSection ( GalleryDbConfigurationSectionName ) ) ;
128139 services . Configure < ValidationDbConfiguration > ( configurationRoot . GetSection ( ValidationDbConfigurationSectionName ) ) ;
@@ -138,6 +149,8 @@ private void ConfigureJobServices(IServiceCollection services, IConfigurationRoo
138149 services . AddScoped ( serviceProvider =>
139150 new ValidationEntitiesContext (
140151 serviceProvider . GetRequiredService < IOptionsSnapshot < ValidationDbConfiguration > > ( ) . Value . ConnectionString ) ) ;
152+ services . AddScoped < IValidationEntitiesContext > ( serviceProvider =>
153+ serviceProvider . GetRequiredService < ValidationEntitiesContext > ( ) ) ;
141154 services . AddScoped < IValidationStorageService , ValidationStorageService > ( ) ;
142155 services . Add ( ServiceDescriptor . Transient ( typeof ( NuGetGallery . IEntityRepository < > ) , typeof ( NuGetGallery . EntityRepository < > ) ) ) ;
143156 services . AddTransient < NuGetGallery . ICorePackageService , NuGetGallery . CorePackageService > ( ) ;
@@ -159,6 +172,10 @@ private void ConfigureJobServices(IServiceCollection services, IConfigurationRoo
159172 services . AddTransient < IBrokeredMessageSerializer < PackageValidationMessageData > , PackageValidationMessageDataSerializationAdapter > ( ) ;
160173 services . AddTransient < IPackageCriteriaEvaluator , PackageCriteriaEvaluator > ( ) ;
161174 services . AddTransient < VcsValidator > ( ) ;
175+ services . AddTransient < IPackageSignatureVerificationEnqueuer , PackageSignatureVerificationEnqueuer > ( ) ;
176+ services . AddTransient < IBrokeredMessageSerializer < SignatureValidationMessage > , SignatureValidationMessageSerializer > ( ) ;
177+ services . AddTransient < IValidatorStateService , ValidatorStateService > ( ) ;
178+ services . AddTransient < PackageSigningValidator > ( ) ;
162179 }
163180
164181 private static IServiceProvider CreateProvider ( IServiceCollection services )
@@ -177,6 +194,14 @@ private static IServiceProvider CreateProvider(IServiceCollection services)
177194 return cloudStorageAccount ;
178195 } )
179196 . Keyed < CloudStorageAccount > ( VcsBindingKey ) ;
197+ containerBuilder
198+ . Register ( c =>
199+ {
200+ var serviceBusConfiguration = c . Resolve < IOptionsSnapshot < ServiceBusConfiguration > > ( ) ;
201+ var topicClient = new TopicClientWrapper ( serviceBusConfiguration . Value . ConnectionString , serviceBusConfiguration . Value . TopicPath ) ;
202+ return topicClient ;
203+ } )
204+ . Keyed < TopicClientWrapper > ( PackageVerificationTopicClientBindingKey ) ;
180205
181206 containerBuilder
182207 . RegisterType < PackageValidationService > ( )
@@ -194,6 +219,17 @@ private static IServiceProvider CreateProvider(IServiceCollection services)
194219 ( pi , ctx ) => ctx . Resolve < IOptionsSnapshot < VcsConfiguration > > ( ) . Value . ContainerName ) )
195220 . As < IPackageValidationAuditor > ( ) ;
196221
222+ containerBuilder
223+ . RegisterType < PackageSignatureVerificationEnqueuer > ( )
224+ . WithParameter ( new ResolvedParameter (
225+ ( pi , ctx ) => pi . ParameterType == typeof ( ITopicClient ) ,
226+ ( pi , ctx ) => ctx . ResolveKeyed < TopicClientWrapper > ( PackageVerificationTopicClientBindingKey ) ) )
227+ . WithParameter ( new ResolvedParameter (
228+ ( pi , ctx ) => pi . ParameterType == typeof ( IBrokeredMessageSerializer < SignatureValidationMessage > ) ,
229+ ( pi , ctx ) => ctx . Resolve < SignatureValidationMessageSerializer > ( )
230+ ) )
231+ . As < IPackageSignatureVerificationEnqueuer > ( ) ;
232+
197233 containerBuilder
198234 . Register ( c =>
199235 {
@@ -235,9 +271,79 @@ private static IServiceProvider CreateProvider(IServiceCollection services)
235271 IMessageHandler < PackageValidationMessageData > > (
236272 OrchestratorBindingKey ) ;
237273
274+ ConfigurePackageSigningValidator ( containerBuilder ) ;
275+ ConfigurePackageCertificatesValidator ( containerBuilder ) ;
276+
238277 return new AutofacServiceProvider ( containerBuilder . Build ( ) ) ;
239278 }
240279
280+ private static void ConfigurePackageSigningValidator ( ContainerBuilder builder )
281+ {
282+ // Configure the validator state service for the package certificates validator.
283+ builder
284+ . RegisterType < ValidatorStateService > ( )
285+ . WithParameter (
286+ ( pi , ctx ) => pi . ParameterType == typeof ( Type ) ,
287+ ( pi , ctx ) => typeof ( PackageSigningValidator ) )
288+ . Keyed < IValidatorStateService > ( PackageSigningBindingKey ) ;
289+
290+ // Configure the package signature verification enqueuer.
291+ builder
292+ . Register ( c =>
293+ {
294+ var configuration = c . Resolve < IOptionsSnapshot < PackageSigningConfiguration > > ( ) . Value . ServiceBus ;
295+
296+ return new TopicClientWrapper ( configuration . ConnectionString , configuration . TopicPath ) ;
297+ } )
298+ . Keyed < ITopicClient > ( PackageSigningBindingKey ) ;
299+
300+ builder
301+ . RegisterType < PackageSignatureVerificationEnqueuer > ( )
302+ . WithKeyedParameter ( typeof ( ITopicClient ) , PackageSigningBindingKey )
303+ . As < IPackageSignatureVerificationEnqueuer > ( ) ;
304+
305+ // Configure the package signing validator.
306+ builder
307+ . RegisterType < PackageSigningValidator > ( )
308+ . WithKeyedParameter ( typeof ( IValidatorStateService ) , PackageSigningBindingKey )
309+ . As < PackageSigningValidator > ( ) ;
310+ }
311+
312+ private static void ConfigurePackageCertificatesValidator ( ContainerBuilder builder )
313+ {
314+ // Configure the validator state service for the package certificates validator.
315+ builder
316+ . RegisterType < ValidatorStateService > ( )
317+ . WithParameter (
318+ ( pi , ctx ) => pi . ParameterType == typeof ( Type ) ,
319+ ( pi , ctx ) => typeof ( PackageCertificatesValidator ) )
320+ . Keyed < IValidatorStateService > ( PackageCertificatesBindingKey ) ;
321+
322+ // Configure the certificate verification enqueuer.
323+ builder
324+ . Register ( c =>
325+ {
326+ var configuration = c . Resolve < IOptionsSnapshot < PackageCertificatesConfiguration > > ( ) . Value . ServiceBus ;
327+
328+ return new TopicClientWrapper ( configuration . ConnectionString , configuration . TopicPath ) ;
329+ } )
330+ . Keyed < ITopicClient > ( PackageCertificatesBindingKey ) ;
331+
332+ builder
333+ . RegisterType < CertificateVerificationEnqueuer > ( )
334+ . WithKeyedParameter ( typeof ( ITopicClient ) , PackageCertificatesBindingKey )
335+ . As < ICertificateVerificationEnqueuer > ( ) ;
336+
337+ // Configure the certificates validator.
338+ builder
339+ . RegisterType < PackageCertificatesValidator > ( )
340+ . WithKeyedParameter ( typeof ( IValidatorStateService ) , PackageCertificatesBindingKey )
341+ . WithParameter (
342+ ( pi , ctx ) => pi . ParameterType == typeof ( TimeSpan ? ) ,
343+ ( pi , ctx ) => ctx . Resolve < IOptionsSnapshot < PackageCertificatesConfiguration > > ( ) . Value . CertificateRevalidationThreshold )
344+ . As < PackageCertificatesValidator > ( ) ;
345+ }
346+
241347 private T GetRequiredService < T > ( )
242348 {
243349 return _serviceProvider . GetRequiredService < T > ( ) ;
0 commit comments