@@ -50,94 +50,99 @@ public CertificateValidationMessageHandler(
5050 /// <returns>Whether the validation completed. If false, the validation should be retried later.</returns>
5151 public async Task < bool > HandleAsync ( CertificateValidationMessage message )
5252 {
53- var validation = await _certificateValidationService . FindCertificateValidationAsync ( message ) ;
54-
55- if ( validation == null )
53+ using ( _logger . BeginScope ( "Handling validate certificate message {CertificateKey} {ValidationId}" ,
54+ message . CertificateKey ,
55+ message . ValidationId ) )
5656 {
57- _logger . LogInformation (
58- "Could not find a certificate validation entity, failing (certificate: {CertificateKey} validation: {ValidationId})" ,
59- message . CertificateKey ,
60- message . ValidationId ) ;
61-
62- return false ;
63- }
57+ var validation = await _certificateValidationService . FindCertificateValidationAsync ( message ) ;
6458
65- if ( validation . Status != null )
66- {
67- // A certificate validation should be queued with a Status of null, and once the certificate validation
68- // completes, the Status should be updated to a non-null value. Hence, the Status here SHOULD be null.
69- // A non-null Status may indicate message duplication.
70- _logger . LogWarning (
71- "Invalid certificate validation entity's status, dropping message (certificate: {CertificateThumbprint} validation: {ValidationId})" ,
72- validation . EndCertificate . Thumbprint ,
73- validation . ValidationId ) ;
59+ if ( validation == null )
60+ {
61+ _logger . LogInformation (
62+ "Could not find a certificate validation entity, failing (certificate: {CertificateKey} validation: {ValidationId})" ,
63+ message . CertificateKey ,
64+ message . ValidationId ) ;
7465
75- return true ;
76- }
66+ return false ;
67+ }
7768
78- if ( validation . EndCertificate . Status == EndCertificateStatus . Revoked )
79- {
80- if ( message . RevalidateRevokedCertificate )
69+ if ( validation . Status != null )
8170 {
71+ // A certificate validation should be queued with a Status of null, and once the certificate validation
72+ // completes, the Status should be updated to a non-null value. Hence, the Status here SHOULD be null.
73+ // A non-null Status may indicate message duplication.
8274 _logger . LogWarning (
83- "Revalidating certificate that is known to be revoked " +
84- "(certificate: {CertificateThumbprint} validation: {ValidationId})" ,
85- validation . EndCertificate . Thumbprint ,
86- validation . ValidationId ) ;
87- }
88- else
89- {
90- // Do NOT revalidate a certificate that is known to be revoked unless explicitly told to!
91- // Certificate Authorities are not required to keep a certificate's revocation information
92- // forever, therefore, revoked certificates should only be revalidated in special cases.
93- _logger . LogError (
94- "Certificate known to be revoked MUST be validated with the " +
95- $ "{ nameof ( CertificateValidationMessage . RevalidateRevokedCertificate ) } flag enabled " +
96- "(certificate: {CertificateThumbprint} validation: {ValidationId})" ,
75+ "Invalid certificate validation entity's status, dropping message (certificate: {CertificateThumbprint} validation: {ValidationId})" ,
9776 validation . EndCertificate . Thumbprint ,
9877 validation . ValidationId ) ;
9978
10079 return true ;
10180 }
102- }
10381
104- CertificateVerificationResult result ;
82+ if ( validation . EndCertificate . Status == EndCertificateStatus . Revoked )
83+ {
84+ if ( message . RevalidateRevokedCertificate )
85+ {
86+ _logger . LogWarning (
87+ "Revalidating certificate that is known to be revoked " +
88+ "(certificate: {CertificateThumbprint} validation: {ValidationId})" ,
89+ validation . EndCertificate . Thumbprint ,
90+ validation . ValidationId ) ;
91+ }
92+ else
93+ {
94+ // Do NOT revalidate a certificate that is known to be revoked unless explicitly told to!
95+ // Certificate Authorities are not required to keep a certificate's revocation information
96+ // forever, therefore, revoked certificates should only be revalidated in special cases.
97+ _logger . LogError (
98+ "Certificate known to be revoked MUST be validated with the " +
99+ $ "{ nameof ( CertificateValidationMessage . RevalidateRevokedCertificate ) } flag enabled " +
100+ "(certificate: {CertificateThumbprint} validation: {ValidationId})" ,
101+ validation . EndCertificate . Thumbprint ,
102+ validation . ValidationId ) ;
103+
104+ return true ;
105+ }
106+ }
105107
106- using ( var certificates = await LoadCertificatesAsync ( validation ) )
107- {
108- switch ( validation . EndCertificate . Use )
108+ CertificateVerificationResult result ;
109+
110+ using ( var certificates = await LoadCertificatesAsync ( validation ) )
109111 {
110- case EndCertificateUse . CodeSigning :
111- result = _certificateVerifier . VerifyCodeSigningCertificate (
112- certificates . EndCertificate ,
113- certificates . AncestorCertificates ) ;
114- break ;
115-
116- case EndCertificateUse . Timestamping :
117- result = _certificateVerifier . VerifyTimestampingCertificate (
118- certificates . EndCertificate ,
119- certificates . AncestorCertificates ) ;
120- break ;
121-
122- default :
123- throw new InvalidOperationException ( $ "Unknown { nameof ( EndCertificateUse ) } : { validation . EndCertificate . Use } ") ;
112+ switch ( validation . EndCertificate . Use )
113+ {
114+ case EndCertificateUse . CodeSigning :
115+ result = _certificateVerifier . VerifyCodeSigningCertificate (
116+ certificates . EndCertificate ,
117+ certificates . AncestorCertificates ) ;
118+ break ;
119+
120+ case EndCertificateUse . Timestamping :
121+ result = _certificateVerifier . VerifyTimestampingCertificate (
122+ certificates . EndCertificate ,
123+ certificates . AncestorCertificates ) ;
124+ break ;
125+
126+ default :
127+ throw new InvalidOperationException ( $ "Unknown { nameof ( EndCertificateUse ) } : { validation . EndCertificate . Use } ") ;
128+ }
124129 }
125- }
126130
127- // Save the result. This may alert if packages are invalidated.
128- if ( ! await _certificateValidationService . TrySaveResultAsync ( validation , result ) )
129- {
130- _logger . LogWarning (
131- "Failed to save certificate validation result " +
132- "(certificate: {CertificateThumbprint} validation: {ValidationId}), " +
133- "failing validation" ,
134- validation . EndCertificate . Thumbprint ,
135- validation . ValidationId ) ;
136-
137- return false ;
138- }
131+ // Save the result. This may alert if packages are invalidated.
132+ if ( ! await _certificateValidationService . TrySaveResultAsync ( validation , result ) )
133+ {
134+ _logger . LogWarning (
135+ "Failed to save certificate validation result " +
136+ "(certificate: {CertificateThumbprint} validation: {ValidationId}), " +
137+ "failing validation" ,
138+ validation . EndCertificate . Thumbprint ,
139+ validation . ValidationId ) ;
139140
140- return HasValidationCompleted ( validation , result ) ;
141+ return false ;
142+ }
143+
144+ return HasValidationCompleted ( validation , result ) ;
145+ }
141146 }
142147
143148 private bool HasValidationCompleted ( EndCertificateValidation validation , CertificateVerificationResult result )
0 commit comments