@@ -43,19 +43,15 @@ public CertificateValidationService(
4343
4444 public Task < EndCertificateValidation > FindCertificateValidationAsync ( CertificateValidationMessage message )
4545 {
46+ // Fetch the validation, the end certificate that this validation is for, and all of the parent
47+ // certificates that the end certificate depends on.
4648 return _context
4749 . CertificateValidations
4850 . Where ( v => v . ValidationId == message . ValidationId && v . EndCertificateKey == message . CertificateKey )
49- . Include ( v => v . EndCertificate )
51+ . Include ( v => v . EndCertificate . CertificateChainLinks . Select ( l => l . ParentCertificate ) )
5052 . FirstOrDefaultAsync ( ) ;
5153 }
5254
53- public Task < CertificateVerificationResult > VerifyAsync ( X509Certificate2 certificate )
54- {
55- // TODO: This will be implemented in a separate change!
56- throw new NotImplementedException ( ) ;
57- }
58-
5955 public async Task < bool > TrySaveResultAsync ( EndCertificateValidation validation , CertificateVerificationResult result )
6056 {
6157 if ( validation . EndCertificate . Status == EndCertificateStatus . Revoked && result . Status != EndCertificateStatus . Revoked )
@@ -171,6 +167,7 @@ void InvalidateCertificate()
171167
172168 return ProcessDependentSignaturesAsync (
173169 validation . EndCertificate ,
170+ result ,
174171 invalidationDecider ,
175172 onAllSignaturesHandled : InvalidateCertificate ) ;
176173 }
@@ -193,6 +190,7 @@ void RevokeCertificate()
193190
194191 return ProcessDependentSignaturesAsync (
195192 validation . EndCertificate ,
193+ result ,
196194 invalidationDecider ,
197195 onAllSignaturesHandled : RevokeCertificate ) ;
198196 }
@@ -201,11 +199,13 @@ void RevokeCertificate()
201199 /// The helper that processes how a certificate's status change affects its dependent signatures.
202200 /// </summary>
203201 /// <param name="certificate">The certificate whose dependent signatures should be processed.</param>
202+ /// <param name="certificateVerificationResult">The result of the certificate's verification.</param>
204203 /// <param name="signatureDecider">The delegate that decides how a dependent signature should be handled.</param>
205204 /// <param name="onAllSignaturesHandled">The action that will be called once all dependent signatures have been processed.</param>
206205 /// <returns></returns>
207206 private async Task ProcessDependentSignaturesAsync (
208207 EndCertificate certificate ,
208+ CertificateVerificationResult certificateVerificationResult ,
209209 SignatureDecider signatureDecider ,
210210 Action onAllSignaturesHandled )
211211 {
@@ -246,7 +246,7 @@ private async Task ProcessDependentSignaturesAsync(
246246 {
247247 var decision = signatureDecider ( signature ) ;
248248
249- HandleSignatureDecision ( signature , decision ) ;
249+ HandleSignatureDecision ( signature , decision , certificate , certificateVerificationResult ) ;
250250 }
251251 }
252252 while ( signatures . Count == MaxSignatureUpdatesPerTransaction ) ;
@@ -294,7 +294,7 @@ private Task<List<PackageSignature>> FindSignaturesAsync(EndCertificate certific
294294 }
295295
296296 return packageSignatures
297- . Include ( s => s . TrustedTimestamps )
297+ . Include ( s => s . TrustedTimestamps . Select ( t => t . EndCertificate ) )
298298 . Include ( s => s . PackageSigningState )
299299 . OrderBy ( s => s . Key )
300300 . Skip ( page * MaxSignatureUpdatesPerTransaction )
@@ -307,33 +307,72 @@ private Task<List<PackageSignature>> FindSignaturesAsync(EndCertificate certific
307307 /// Handle the decision on how to update the signature.
308308 /// </summary>
309309 /// <param name="signature">The signature that should be updated.</param>
310- /// <param name="decision"></param>
310+ /// <param name="decision">How the signature should be updated.</param>
311+ /// <param name="certificate">The certificate that signature depends on that changed the signature's state.</param>
312+ /// <param name="certificateVerificationResult">The certificate verification that changed the signature's state.</param>
311313 private void HandleSignatureDecision (
312314 PackageSignature signature ,
313- SignatureDecision decision )
315+ SignatureDecision decision ,
316+ EndCertificate certificate ,
317+ CertificateVerificationResult certificateVerificationResult )
314318 {
315- // TODO: Log all the necessary information to investigate the signature decision.
316319 switch ( decision )
317320 {
318321 case SignatureDecision . Ignore :
322+ _logger . LogInformation (
323+ "Signature {SignatureKey} is not affected by certificate verification result: {CertificateVerificationResult}" ,
324+ signature . Key ,
325+ certificateVerificationResult ) ;
319326 break ;
320327
321328 case SignatureDecision . Warn :
322- signature . Status = PackageSignatureStatus . Invalid ;
323- signature . PackageSigningState . SigningStatus = PackageSigningStatus . Invalid ;
329+ _logger . LogWarning (
330+ "Invalidating signature {SignatureKey} due to certificate verification result: {CertificateVerificationResult}" ,
331+ signature . Key ,
332+ certificateVerificationResult ) ;
333+
334+ InvalidateSignature ( signature , certificate ) ;
324335
325336 _telemetryService . TrackPackageSignatureMayBeInvalidatedEvent ( signature ) ;
337+
326338 break ;
327339
328340 case SignatureDecision . Reject :
329- signature . Status = PackageSignatureStatus . Invalid ;
330- signature . PackageSigningState . SigningStatus = PackageSigningStatus . Invalid ;
341+ _logger . LogWarning (
342+ "Rejecting signature {SignatureKey} due to certificate verification result: {CertificateVerificationResult}" ,
343+ signature . Key ,
344+ certificateVerificationResult ) ;
345+
346+ InvalidateSignature ( signature , certificate ) ;
331347
332348 _telemetryService . TrackPackageSignatureShouldBeInvalidatedEvent ( signature ) ;
333349 break ;
334350
335351 default :
336- throw new InvalidOperationException ( $ "Unknown signature decision: { decision } ") ;
352+ throw new InvalidOperationException (
353+ $ "Unknown signature decision '{ decision } ' for certificate verification result: { certificateVerificationResult } ") ;
354+ }
355+ }
356+
357+ private void InvalidateSignature ( PackageSignature signature , EndCertificate certificate )
358+ {
359+ signature . Status = PackageSignatureStatus . Invalid ;
360+ signature . PackageSigningState . SigningStatus = PackageSigningStatus . Invalid ;
361+
362+ if ( certificate . Use == EndCertificateUse . Timestamping )
363+ {
364+ var affectedTimestamps = signature . TrustedTimestamps
365+ . Where ( t => t . EndCertificate . Thumbprint == certificate . Thumbprint ) ;
366+
367+ foreach ( var timestamp in affectedTimestamps )
368+ {
369+ _logger . LogWarning (
370+ "Invalidating timestamp {TimestampKey} due to invalid certificate {CertificateKey}" ,
371+ signature . Key ,
372+ certificate . Key ) ;
373+
374+ timestamp . Status = TrustedTimestampStatus . Invalid ;
375+ }
337376 }
338377 }
339378 }
0 commit comments