@@ -40,6 +40,7 @@ This file is part of the iText (R) project.
40
40
import com .itextpdf .signatures .validation .v1 .context .ValidatorContext ;
41
41
import com .itextpdf .signatures .validation .v1 .extensions .BasicConstraintsExtension ;
42
42
import com .itextpdf .signatures .validation .v1 .report .CertificateReportItem ;
43
+ import com .itextpdf .signatures .validation .v1 .report .ReportItem ;
43
44
import com .itextpdf .signatures .validation .v1 .report .ReportItem .ReportItemStatus ;
44
45
import com .itextpdf .signatures .validation .v1 .report .ValidationReport ;
45
46
@@ -54,8 +55,6 @@ This file is part of the iText (R) project.
54
55
import java .util .HashMap ;
55
56
import java .util .Map ;
56
57
57
- import static com .itextpdf .signatures .validation .v1 .RevocationDataValidator .SELF_SIGNED_CERTIFICATE ;
58
-
59
58
/**
60
59
* Class that allows you to validate a certificate against a Certificate Revocation List (CRL) Response.
61
60
*/
@@ -79,8 +78,6 @@ public class CRLValidator {
79
78
"not all reason codes are covered by the current CRL." ;
80
79
static final String SAME_REASONS_CHECK = "CRLs that cover the same reason codes were already verified." ;
81
80
static final String UPDATE_DATE_BEFORE_CHECK_DATE = "nextUpdate: {0} of CRLResponse is before validation date {1}." ;
82
- static final String NEXT_UPDATE_VALIDATION = "Using crl nextUpdate date as validation date." ;
83
- static final String THIS_UPDATE_VALIDATION = "Using crl thisUpdate date as validation date." ;
84
81
85
82
// All reasons without unspecified.
86
83
static final int ALL_REASONS = 32895 ;
@@ -111,18 +108,36 @@ protected CRLValidator(ValidatorChainBuilder builder) {
111
108
* @param certificate the certificate to check against CRL response
112
109
* @param crl the crl response to be validated
113
110
* @param validationDate validation date to check for
111
+ *
112
+ * @deprecated starting from 8.0.5. TODO DEVSIX-8398 To be removed.
114
113
*/
114
+ @ Deprecated
115
115
public void validate (ValidationReport report , ValidationContext context , X509Certificate certificate , X509CRL crl ,
116
116
Date validationDate ) {
117
+ validate (report , context , certificate , crl , validationDate , DateTimeUtil .getCurrentTimeDate ());
118
+ }
119
+
120
+ /**
121
+ * Validates a certificate against Certificate Revocation List (CRL) Responses.
122
+ *
123
+ * @param report to store all the chain verification results
124
+ * @param context the context in which to perform the validation
125
+ * @param certificate the certificate to check against CRL response
126
+ * @param crl the crl response to be validated
127
+ * @param validationDate validation date to check for
128
+ * @param responseGenerationDate trusted date at which response is generated
129
+ */
130
+ public void validate (ValidationReport report , ValidationContext context , X509Certificate certificate , X509CRL crl ,
131
+ Date validationDate , Date responseGenerationDate ) {
117
132
ValidationContext localContext = context .setValidatorContext (ValidatorContext .CRL_VALIDATOR );
118
133
if (CertificateUtil .isSelfSigned (certificate )) {
119
- report .addReportItem (new CertificateReportItem (certificate , CRL_CHECK , SELF_SIGNED_CERTIFICATE ,
120
- ReportItemStatus .INFO ));
134
+ report .addReportItem (new CertificateReportItem (certificate , CRL_CHECK ,
135
+ RevocationDataValidator . SELF_SIGNED_CERTIFICATE , ReportItemStatus .INFO ));
121
136
return ;
122
137
}
123
- // Check that thisUpdate >= (validationDate - freshness).
124
138
Duration freshness = properties .getFreshness (localContext );
125
- if (crl .getThisUpdate ().before (DateTimeUtil .addMillisToDate (validationDate , -(long ) freshness .toMillis ()))) {
139
+ // Check that thisUpdate + freshness < validation.
140
+ if (DateTimeUtil .addMillisToDate (crl .getThisUpdate (), (long ) freshness .toMillis ()).before (validationDate )) {
126
141
report .addReportItem (new CertificateReportItem (certificate , CRL_CHECK ,
127
142
MessageFormatUtil .format (FRESHNESS_CHECK , crl .getThisUpdate (), validationDate , freshness ),
128
143
ReportItemStatus .INDETERMINATE ));
@@ -175,16 +190,10 @@ public void validate(ValidationReport report, ValidationContext context, X509Cer
175
190
Integer reasonsMask = checkedReasonsMask .get (certificate );
176
191
if (reasonsMask != null ) {
177
192
interimReasonsMask |= (int ) reasonsMask ;
178
-
179
- // Verify that interim_reasons_mask includes one or more reasons that are not included in the reasons_mask.
180
- if (interimReasonsMask == reasonsMask ) {
181
- report .addReportItem (
182
- new CertificateReportItem (certificate , CRL_CHECK , SAME_REASONS_CHECK , ReportItemStatus .INFO ));
183
- }
184
193
}
185
194
186
195
// Verify the CRL issuer.
187
- verifyCrlIntegrity (report , localContext , certificate , crl );
196
+ verifyCrlIntegrity (report , localContext , certificate , crl , responseGenerationDate );
188
197
189
198
// Check the status of the certificate.
190
199
verifyRevocation (report , certificate , validationDate , crl );
@@ -272,7 +281,7 @@ private static int computeInterimReasonsMask(IIssuingDistributionPoint issuingDi
272
281
}
273
282
274
283
private void verifyCrlIntegrity (ValidationReport report , ValidationContext context , X509Certificate certificate ,
275
- X509CRL crl ) {
284
+ X509CRL crl , Date responseGenerationDate ) {
276
285
Certificate [] certs = certificateRetriever .getCrlIssuerCertificates (crl );
277
286
if (certs .length == 0 ) {
278
287
report .addReportItem (new CertificateReportItem (certificate , CRL_CHECK , CRL_ISSUER_NOT_FOUND ,
@@ -285,6 +294,7 @@ private void verifyCrlIntegrity(ValidationReport report, ValidationContext conte
285
294
if (!crlIssuerRoot .equals (subjectRoot )) {
286
295
report .addReportItem (new CertificateReportItem (certificate , CRL_CHECK , CRL_ISSUER_NO_COMMON_ROOT ,
287
296
ReportItemStatus .INDETERMINATE ));
297
+ return ;
288
298
}
289
299
try {
290
300
crl .verify (crlIssuer .getPublicKey ());
@@ -293,25 +303,23 @@ private void verifyCrlIntegrity(ValidationReport report, ValidationContext conte
293
303
ReportItemStatus .INDETERMINATE ));
294
304
return ;
295
305
}
296
- // Ideally this date should be the date this response was retrieved from the server.
297
- Date crlIssuerDate ;
298
- if (TimestampConstants .UNDEFINED_TIMESTAMP_DATE != crl .getNextUpdate ()) {
299
- crlIssuerDate = crl .getNextUpdate ();
300
- report .addReportItem (new CertificateReportItem ((X509Certificate ) crlIssuer , CRL_CHECK ,
301
- NEXT_UPDATE_VALIDATION , ReportItemStatus .INFO ));
302
- } else {
303
- crlIssuerDate = crl .getThisUpdate ();
304
- report .addReportItem (new CertificateReportItem ((X509Certificate ) crlIssuer , CRL_CHECK ,
305
- THIS_UPDATE_VALIDATION , ReportItemStatus .INFO ));
306
- }
307
306
308
- builder .getCertificateChainValidator ().validate (report ,
307
+ ValidationReport responderReport = new ValidationReport ();
308
+ builder .getCertificateChainValidator ().validate (responderReport ,
309
309
context .setCertificateSource (CertificateSource .CRL_ISSUER ),
310
- (X509Certificate ) crlIssuer , crlIssuerDate );
310
+ (X509Certificate ) crlIssuer , responseGenerationDate );
311
+ addResponderValidationReport (report , responderReport );
311
312
}
312
313
313
314
private Certificate getRoot (Certificate cert ) {
314
315
Certificate [] chain = certificateRetriever .retrieveMissingCertificates (new Certificate [] {cert });
315
316
return chain [chain .length - 1 ];
316
317
}
318
+
319
+ private static void addResponderValidationReport (ValidationReport report , ValidationReport responderReport ) {
320
+ for (ReportItem reportItem : responderReport .getLogs ()) {
321
+ report .addReportItem (ReportItemStatus .INVALID == reportItem .getStatus () ?
322
+ reportItem .setStatus (ReportItemStatus .INDETERMINATE ) : reportItem );
323
+ }
324
+ }
317
325
}
0 commit comments