streamlined file loading labels
[strongswan.git] / src / pluto / crl.c
1 /* Support of X.509 certificate revocation lists (CRLs)
2 * Copyright (C) 2000-2009 Andreas Steffen
3 *
4 * HSR Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include <stdlib.h>
18 #include <stdio.h>
19 #include <string.h>
20 #include <unistd.h>
21 #include <dirent.h>
22 #include <time.h>
23 #include <sys/types.h>
24
25 #include <freeswan.h>
26
27 #include <asn1/asn1.h>
28 #include <asn1/asn1_parser.h>
29 #include <asn1/oid.h>
30 #include <crypto/hashers/hasher.h>
31 #include <credentials/certificates/certificate.h>
32
33 #include "constants.h"
34 #include "defs.h"
35 #include "log.h"
36 #include "x509.h"
37 #include "crl.h"
38 #include "ca.h"
39 #include "certs.h"
40 #include "keys.h"
41 #include "whack.h"
42 #include "fetch.h"
43 #include "builder.h"
44
45
46 /* chained lists of X.509 crls */
47
48 static x509crl_t *x509crls = NULL;
49
50 /**
51 * ASN.1 definition of an X.509 certificate revocation list
52 */
53 static const asn1Object_t crlObjects[] = {
54 { 0, "certificateList", ASN1_SEQUENCE, ASN1_OBJ }, /* 0 */
55 { 1, "tbsCertList", ASN1_SEQUENCE, ASN1_OBJ }, /* 1 */
56 { 2, "version", ASN1_INTEGER, ASN1_OPT |
57 ASN1_BODY }, /* 2 */
58 { 2, "end opt", ASN1_EOC, ASN1_END }, /* 3 */
59 { 2, "signature", ASN1_EOC, ASN1_RAW }, /* 4 */
60 { 2, "issuer", ASN1_SEQUENCE, ASN1_OBJ }, /* 5 */
61 { 2, "thisUpdate", ASN1_EOC, ASN1_RAW }, /* 6 */
62 { 2, "nextUpdate", ASN1_EOC, ASN1_RAW }, /* 7 */
63 { 2, "revokedCertificates", ASN1_SEQUENCE, ASN1_OPT |
64 ASN1_LOOP }, /* 8 */
65 { 3, "certList", ASN1_SEQUENCE, ASN1_NONE }, /* 9 */
66 { 4, "userCertificate", ASN1_INTEGER, ASN1_BODY }, /* 10 */
67 { 4, "revocationDate", ASN1_EOC, ASN1_RAW }, /* 11 */
68 { 4, "crlEntryExtensions", ASN1_SEQUENCE, ASN1_OPT |
69 ASN1_LOOP }, /* 12 */
70 { 5, "extension", ASN1_SEQUENCE, ASN1_NONE }, /* 13 */
71 { 6, "extnID", ASN1_OID, ASN1_BODY }, /* 14 */
72 { 6, "critical", ASN1_BOOLEAN, ASN1_DEF |
73 ASN1_BODY }, /* 15 */
74 { 6, "extnValue", ASN1_OCTET_STRING, ASN1_BODY }, /* 16 */
75 { 4, "end opt or loop", ASN1_EOC, ASN1_END }, /* 17 */
76 { 2, "end opt or loop", ASN1_EOC, ASN1_END }, /* 18 */
77 { 2, "optional extensions", ASN1_CONTEXT_C_0, ASN1_OPT }, /* 19 */
78 { 3, "crlExtensions", ASN1_SEQUENCE, ASN1_LOOP }, /* 20 */
79 { 4, "extension", ASN1_SEQUENCE, ASN1_NONE }, /* 21 */
80 { 5, "extnID", ASN1_OID, ASN1_BODY }, /* 22 */
81 { 5, "critical", ASN1_BOOLEAN, ASN1_DEF |
82 ASN1_BODY }, /* 23 */
83 { 5, "extnValue", ASN1_OCTET_STRING, ASN1_BODY }, /* 24 */
84 { 3, "end loop", ASN1_EOC, ASN1_END }, /* 25 */
85 { 2, "end opt", ASN1_EOC, ASN1_END }, /* 26 */
86 { 1, "signatureAlgorithm", ASN1_EOC, ASN1_RAW }, /* 27 */
87 { 1, "signatureValue", ASN1_BIT_STRING, ASN1_BODY }, /* 28 */
88 { 0, "exit", ASN1_EOC, ASN1_EXIT }
89 };
90
91 #define CRL_OBJ_CERTIFICATE_LIST 0
92 #define CRL_OBJ_TBS_CERT_LIST 1
93 #define CRL_OBJ_VERSION 2
94 #define CRL_OBJ_SIG_ALG 4
95 #define CRL_OBJ_ISSUER 5
96 #define CRL_OBJ_THIS_UPDATE 6
97 #define CRL_OBJ_NEXT_UPDATE 7
98 #define CRL_OBJ_USER_CERTIFICATE 10
99 #define CRL_OBJ_REVOCATION_DATE 11
100 #define CRL_OBJ_CRL_ENTRY_EXTN_ID 14
101 #define CRL_OBJ_CRL_ENTRY_CRITICAL 15
102 #define CRL_OBJ_CRL_ENTRY_EXTN_VALUE 16
103 #define CRL_OBJ_EXTN_ID 22
104 #define CRL_OBJ_CRITICAL 23
105 #define CRL_OBJ_EXTN_VALUE 24
106 #define CRL_OBJ_ALGORITHM 27
107 #define CRL_OBJ_SIGNATURE 28
108
109 const x509crl_t empty_x509crl = {
110 NULL , /* *next */
111 UNDEFINED_TIME, /* installed */
112 NULL , /* distributionPoints */
113 { NULL, 0 } , /* certificateList */
114 { NULL, 0 } , /* tbsCertList */
115 1 , /* version */
116 OID_UNKNOWN , /* sigAlg */
117 { NULL, 0 } , /* issuer */
118 UNDEFINED_TIME, /* thisUpdate */
119 UNDEFINED_TIME, /* nextUpdate */
120 NULL , /* revokedCertificates */
121 /* crlExtensions */
122 /* extension */
123 /* extnID */
124 /* critical */
125 /* extnValue */
126 { NULL, 0 } , /* authKeyID */
127 { NULL, 0 } , /* authKeySerialNumber */
128 { NULL, 0 } , /* crlNumber */
129 OID_UNKNOWN , /* algorithm */
130 { NULL, 0 } /* signature */
131 };
132
133 /**
134 * Get the X.509 CRL with a given issuer
135 */
136 static x509crl_t* get_x509crl(chunk_t issuer, chunk_t serial, chunk_t keyid)
137 {
138 x509crl_t *crl = x509crls;
139 x509crl_t *prev_crl = NULL;
140
141 while (crl != NULL)
142 {
143 if ((keyid.ptr != NULL && crl->authKeyID.ptr != NULL)
144 ? same_keyid(keyid, crl->authKeyID)
145 : (same_dn(crl->issuer, issuer) && same_serial(serial, crl->authKeySerialNumber)))
146 {
147 if (crl != x509crls)
148 {
149 /* bring the CRL up front */
150 prev_crl->next = crl->next;
151 crl->next = x509crls;
152 x509crls = crl;
153 }
154 return crl;
155 }
156 prev_crl = crl;
157 crl = crl->next;
158 }
159 return NULL;
160 }
161
162 /**
163 * Free the dynamic memory used to store revoked certificates
164 */
165 static void free_revoked_certs(revokedCert_t* revokedCerts)
166 {
167 while (revokedCerts != NULL)
168 {
169 revokedCert_t * revokedCert = revokedCerts;
170 revokedCerts = revokedCert->next;
171 free(revokedCert);
172 }
173 }
174
175 /**
176 * Free the dynamic memory used to store CRLs
177 */
178 void free_crl(x509crl_t *crl)
179 {
180 free_revoked_certs(crl->revokedCertificates);
181 free_generalNames(crl->distributionPoints, TRUE);
182 free(crl->certificateList.ptr);
183 free(crl);
184 }
185
186 static void free_first_crl(void)
187 {
188 x509crl_t *crl = x509crls;
189
190 x509crls = crl->next;
191 free_crl(crl);
192 }
193
194 void free_crls(void)
195 {
196 lock_crl_list("free_crls");
197
198 while (x509crls != NULL)
199 free_first_crl();
200
201 unlock_crl_list("free_crls");
202 }
203
204 /**
205 * Insert X.509 CRL into chained list
206 */
207 bool insert_crl(x509crl_t *crl, chunk_t crl_uri, bool cache_crl)
208 {
209 x509cert_t *issuer_cert;
210 x509crl_t *oldcrl;
211 bool valid_sig;
212 generalName_t *gn;
213
214 /* add distribution point */
215 gn = malloc_thing(generalName_t);
216 gn->kind = GN_URI;
217 gn->name = crl_uri;
218 gn->next = crl->distributionPoints;
219 crl->distributionPoints = gn;
220
221 lock_authcert_list("insert_crl");
222 /* get the issuer cacert */
223 issuer_cert = get_authcert(crl->issuer, crl->authKeySerialNumber,
224 crl->authKeyID, AUTH_CA);
225 if (issuer_cert == NULL)
226 {
227 plog("crl issuer cacert not found");
228 free_crl(crl);
229 unlock_authcert_list("insert_crl");
230 return FALSE;
231 }
232 DBG(DBG_CONTROL,
233 DBG_log("crl issuer cacert found")
234 )
235
236 /* check the issuer's signature of the crl */
237 valid_sig = x509_check_signature(crl->tbsCertList, crl->signature,
238 crl->algorithm, issuer_cert);
239 unlock_authcert_list("insert_crl");
240
241 if (!valid_sig)
242 {
243 free_crl(crl);
244 return FALSE;
245 }
246 DBG(DBG_CONTROL,
247 DBG_log("crl signature is valid")
248 )
249
250 lock_crl_list("insert_crl");
251 oldcrl = get_x509crl(crl->issuer, crl->authKeySerialNumber
252 , crl->authKeyID);
253
254 if (oldcrl != NULL)
255 {
256 if (crl->thisUpdate > oldcrl->thisUpdate)
257 {
258 /* keep any known CRL distribution points */
259 add_distribution_points(oldcrl->distributionPoints
260 , &crl->distributionPoints);
261
262 /* now delete the old CRL */
263 free_first_crl();
264 DBG(DBG_CONTROL,
265 DBG_log("thisUpdate is newer - existing crl deleted")
266 )
267 }
268 else
269 {
270 unlock_crl_list("insert_crls");
271 DBG(DBG_CONTROL,
272 DBG_log("thisUpdate is not newer - existing crl not replaced");
273 )
274 free_crl(crl);
275 return oldcrl->nextUpdate - time(NULL) > 2*crl_check_interval;
276 }
277 }
278
279 /* insert new CRL */
280 crl->next = x509crls;
281 x509crls = crl;
282
283 unlock_crl_list("insert_crl");
284
285 /* If crl caching is enabled then the crl is saved locally.
286 * Only http or ldap URIs are cached but not local file URIs.
287 * The issuer's subjectKeyID is used as a unique filename
288 */
289 if (cache_crl && strncasecmp(crl_uri.ptr, "file", 4) != 0)
290 {
291 char path[BUF_LEN], buf[BUF_LEN];
292 char digest_buf[HASH_SIZE_SHA1];
293 chunk_t subjectKeyID = chunk_from_buf(digest_buf);
294 bool has_keyID;
295
296 if (issuer_cert->subjectKeyID.ptr == NULL)
297 {
298 has_keyID = compute_subjectKeyID(issuer_cert, subjectKeyID);
299 }
300 else
301 {
302 subjectKeyID = issuer_cert->subjectKeyID;
303 has_keyID = TRUE;
304 }
305 if (has_keyID)
306 {
307 datatot(subjectKeyID.ptr, subjectKeyID.len, 16, buf, BUF_LEN);
308 snprintf(path, BUF_LEN, "%s/%s.crl", CRL_PATH, buf);
309 chunk_write(crl->certificateList, path, "crl", 0022, TRUE);
310 }
311 }
312
313 /* is the fetched crl valid? */
314 return crl->nextUpdate - time(NULL) > 2*crl_check_interval;
315 }
316
317 /**
318 * Loads CRLs
319 */
320 void load_crls(void)
321 {
322 struct dirent **filelist;
323 u_char buf[BUF_LEN];
324 u_char *save_dir;
325 int n;
326
327 /* change directory to specified path */
328 save_dir = getcwd(buf, BUF_LEN);
329 if (chdir(CRL_PATH))
330 {
331 plog("Could not change to directory '%s'", CRL_PATH);
332 }
333 else
334 {
335 plog("Changing to directory '%s'", CRL_PATH);
336 n = scandir(CRL_PATH, &filelist, file_select, alphasort);
337
338 if (n < 0)
339 plog(" scandir() error");
340 else
341 {
342 while (n--)
343 {
344 char *filename = filelist[n]->d_name;
345 x509crl_t *crl;
346
347 crl = lib->creds->create(lib->creds, CRED_CERTIFICATE,
348 CERT_PLUTO_CRL, BUILD_FROM_FILE, filename, BUILD_END);
349 if (crl)
350 {
351 chunk_t crl_uri;
352
353 plog(" loaded crl from '%s'", filename);
354 crl_uri.len = 7 + sizeof(CRL_PATH) + strlen(filename);
355 crl_uri.ptr = malloc(crl_uri.len + 1);
356
357 /* build CRL file URI */
358 snprintf(crl_uri.ptr, crl_uri.len + 1, "file://%s/%s"
359 , CRL_PATH, filename);
360
361 insert_crl(crl, crl_uri, FALSE);
362 }
363 free(filelist[n]);
364 }
365 free(filelist);
366 }
367 }
368 /* restore directory path */
369 ignore_result(chdir(save_dir));
370 }
371
372 /**
373 * Parses a CRL revocation reason code
374 */
375 static crl_reason_t parse_crl_reasonCode(chunk_t object)
376 {
377 crl_reason_t reason = REASON_UNSPECIFIED;
378
379 if (*object.ptr == ASN1_ENUMERATED
380 && asn1_length(&object) == 1)
381 {
382 reason = *object.ptr;
383 }
384
385 DBG(DBG_PARSING,
386 DBG_log(" '%N'", crl_reason_names, reason)
387 )
388 return reason;
389 }
390
391 /*
392 * Parses an X.509 CRL
393 */
394 bool parse_x509crl(chunk_t blob, u_int level0, x509crl_t *crl)
395 {
396 u_char buf[BUF_LEN];
397 asn1_parser_t *parser;
398 chunk_t extnID;
399 chunk_t userCertificate = chunk_empty;
400 chunk_t object;
401 int objectID;
402 bool success = FALSE;
403 bool critical;
404
405 parser = asn1_parser_create(crlObjects, blob);
406
407 while (parser->iterate(parser, &objectID, &object))
408 {
409 u_int level = parser->get_level(parser)+1;
410
411 switch (objectID) {
412 case CRL_OBJ_CERTIFICATE_LIST:
413 crl->certificateList = object;
414 break;
415 case CRL_OBJ_TBS_CERT_LIST:
416 crl->tbsCertList = object;
417 break;
418 case CRL_OBJ_VERSION:
419 crl->version = (object.len) ? (1+(u_int)*object.ptr) : 1;
420 DBG(DBG_PARSING,
421 DBG_log(" v%d", crl->version);
422 )
423 break;
424 case CRL_OBJ_SIG_ALG:
425 crl->sigAlg = asn1_parse_algorithmIdentifier(object, level, NULL);
426 break;
427 case CRL_OBJ_ISSUER:
428 crl->issuer = object;
429 DBG(DBG_PARSING,
430 dntoa(buf, BUF_LEN, object);
431 DBG_log(" '%s'",buf)
432 )
433 break;
434 case CRL_OBJ_THIS_UPDATE:
435 crl->thisUpdate = asn1_parse_time(object, level);
436 break;
437 case CRL_OBJ_NEXT_UPDATE:
438 crl->nextUpdate = asn1_parse_time(object, level);
439 break;
440 case CRL_OBJ_USER_CERTIFICATE:
441 userCertificate = object;
442 break;
443 case CRL_OBJ_REVOCATION_DATE:
444 {
445 /* put all the serial numbers and the revocation date in a chained list
446 with revocedCertificates pointing to the first revoked certificate */
447
448 revokedCert_t *revokedCert = malloc_thing(revokedCert_t);
449 revokedCert->userCertificate = userCertificate;
450 revokedCert->revocationDate = asn1_parse_time(object, level);
451 revokedCert->revocationReason = REASON_UNSPECIFIED;
452 revokedCert->next = crl->revokedCertificates;
453 crl->revokedCertificates = revokedCert;
454 }
455 break;
456 case CRL_OBJ_CRL_ENTRY_EXTN_ID:
457 case CRL_OBJ_EXTN_ID:
458 extnID = object;
459 break;
460 case CRL_OBJ_CRL_ENTRY_CRITICAL:
461 case CRL_OBJ_CRITICAL:
462 critical = object.len && *object.ptr;
463 DBG(DBG_PARSING,
464 DBG_log(" %s",(critical)?"TRUE":"FALSE");
465 )
466 break;
467 case CRL_OBJ_CRL_ENTRY_EXTN_VALUE:
468 case CRL_OBJ_EXTN_VALUE:
469 {
470 u_int extn_oid = asn1_known_oid(extnID);
471
472 if (extn_oid == OID_CRL_REASON_CODE)
473 {
474 crl->revokedCertificates->revocationReason =
475 parse_crl_reasonCode(object);
476 }
477 else if (extn_oid == OID_AUTHORITY_KEY_ID)
478 {
479 parse_authorityKeyIdentifier(object, level
480 , &crl->authKeyID, &crl->authKeySerialNumber);
481 }
482 else if (extn_oid == OID_CRL_NUMBER)
483 {
484 if (!asn1_parse_simple_object(&object, ASN1_INTEGER,
485 level, "crlNumber"))
486 {
487 goto end;
488 }
489 crl->crlNumber = object;
490 }
491 }
492 break;
493 case CRL_OBJ_ALGORITHM:
494 crl->algorithm = asn1_parse_algorithmIdentifier(object, level, NULL);
495 break;
496 case CRL_OBJ_SIGNATURE:
497 crl->signature = object;
498 break;
499 default:
500 break;
501 }
502 }
503 success = parser->success(parser);
504 time(&crl->installed);
505
506 end:
507 parser->destroy(parser);
508 return success;
509 }
510
511 /* Checks if the current certificate is revoked. It goes through the
512 * list of revoked certificates of the corresponding crl. Either the
513 * status CERT_GOOD or CERT_REVOKED is returned
514 */
515 static cert_status_t
516 check_revocation(const x509crl_t *crl, chunk_t serial
517 , time_t *revocationDate, crl_reason_t * revocationReason)
518 {
519 revokedCert_t *revokedCert = crl->revokedCertificates;
520
521 *revocationDate = UNDEFINED_TIME;
522 *revocationReason = REASON_UNSPECIFIED;
523
524 DBG(DBG_CONTROL,
525 DBG_dump_chunk("serial number:", serial)
526 )
527
528 while(revokedCert != NULL)
529 {
530 /* compare serial numbers */
531 if (revokedCert->userCertificate.len == serial.len &&
532 memeq(revokedCert->userCertificate.ptr, serial.ptr, serial.len))
533 {
534 *revocationDate = revokedCert->revocationDate;
535 *revocationReason = revokedCert->revocationReason;
536 return CERT_REVOKED;
537 }
538 revokedCert = revokedCert->next;
539 }
540 return CERT_GOOD;
541 }
542
543 /*
544 * check if any crls are about to expire
545 */
546 void
547 check_crls(void)
548 {
549 x509crl_t *crl;
550
551 lock_crl_list("check_crls");
552 crl = x509crls;
553
554 while (crl != NULL)
555 {
556 time_t time_left = crl->nextUpdate - time(NULL);
557 u_char buf[BUF_LEN];
558
559 DBG(DBG_CONTROL,
560 dntoa(buf, BUF_LEN, crl->issuer);
561 DBG_log("issuer: '%s'",buf);
562 if (crl->authKeyID.ptr != NULL)
563 {
564 datatot(crl->authKeyID.ptr, crl->authKeyID.len, ':'
565 , buf, BUF_LEN);
566 DBG_log("authkey: %s", buf);
567 }
568 DBG_log("%ld seconds left", time_left)
569 )
570 if (time_left < 2*crl_check_interval)
571 {
572 fetch_req_t *req = build_crl_fetch_request(crl->issuer
573 , crl->authKeySerialNumber
574 , crl->authKeyID, crl->distributionPoints);
575 add_crl_fetch_request(req);
576 }
577 crl = crl->next;
578 }
579 unlock_crl_list("check_crls");
580 }
581
582 /*
583 * verify if a cert hasn't been revoked by a crl
584 */
585 cert_status_t
586 verify_by_crl(const x509cert_t *cert, time_t *until, time_t *revocationDate
587 , crl_reason_t *revocationReason)
588 {
589 x509crl_t *crl;
590
591 ca_info_t *ca = get_ca_info(cert->issuer, cert->authKeySerialNumber
592 , cert->authKeyID);
593
594 generalName_t *crluri = (ca == NULL)? NULL : ca->crluri;
595
596 *revocationDate = UNDEFINED_TIME;
597 *revocationReason = REASON_UNSPECIFIED;
598
599 lock_crl_list("verify_by_crl");
600 crl = get_x509crl(cert->issuer, cert->authKeySerialNumber, cert->authKeyID);
601
602 if (crl == NULL)
603 {
604 unlock_crl_list("verify_by_crl");
605 plog("crl not found");
606
607 if (cert->crlDistributionPoints != NULL)
608 {
609 fetch_req_t *req = build_crl_fetch_request(cert->issuer
610 , cert->authKeySerialNumber
611 , cert->authKeyID, cert->crlDistributionPoints);
612 add_crl_fetch_request(req);
613 }
614
615 if (crluri != NULL)
616 {
617 fetch_req_t *req = build_crl_fetch_request(cert->issuer
618 , cert->authKeySerialNumber
619 , cert->authKeyID, crluri);
620 add_crl_fetch_request(req);
621 }
622
623 if (cert->crlDistributionPoints != 0 || crluri != NULL)
624 {
625 wake_fetch_thread("verify_by_crl");
626 return CERT_UNKNOWN;
627 }
628 else
629 return CERT_UNDEFINED;
630 }
631 else
632 {
633 x509cert_t *issuer_cert;
634 bool valid;
635
636 DBG(DBG_CONTROL,
637 DBG_log("crl found")
638 )
639
640 add_distribution_points(cert->crlDistributionPoints
641 , &crl->distributionPoints);
642
643 add_distribution_points(crluri
644 , &crl->distributionPoints);
645
646 lock_authcert_list("verify_by_crl");
647
648 issuer_cert = get_authcert(crl->issuer, crl->authKeySerialNumber
649 , crl->authKeyID, AUTH_CA);
650 valid = x509_check_signature(crl->tbsCertList, crl->signature,
651 crl->algorithm, issuer_cert);
652
653 unlock_authcert_list("verify_by_crl");
654
655 if (valid)
656 {
657 cert_status_t status;
658
659 DBG(DBG_CONTROL,
660 DBG_log("crl signature is valid")
661 )
662 /* return the expiration date */
663 *until = crl->nextUpdate;
664
665 /* has the certificate been revoked? */
666 status = check_revocation(crl, cert->serialNumber, revocationDate
667 , revocationReason);
668
669 if (*until < time(NULL))
670 {
671 fetch_req_t *req;
672
673 plog("crl update is overdue since %T", until, TRUE);
674
675 /* try to fetch a crl update */
676 req = build_crl_fetch_request(crl->issuer
677 , crl->authKeySerialNumber
678 , crl->authKeyID, crl->distributionPoints);
679 unlock_crl_list("verify_by_crl");
680
681 add_crl_fetch_request(req);
682 wake_fetch_thread("verify_by_crl");
683 }
684 else
685 {
686 unlock_crl_list("verify_by_crl");
687 DBG(DBG_CONTROL,
688 DBG_log("crl is valid")
689 )
690 }
691 return status;
692 }
693 else
694 {
695 unlock_crl_list("verify_by_crl");
696 plog("crl signature is invalid");
697 return CERT_UNKNOWN;
698 }
699 }
700 }
701
702 /*
703 * list all X.509 crls in the chained list
704 */
705 void
706 list_crls(bool utc, bool strict)
707 {
708 x509crl_t *crl;
709
710 lock_crl_list("list_crls");
711 crl = x509crls;
712
713 if (crl != NULL)
714 {
715 whack_log(RC_COMMENT, " ");
716 whack_log(RC_COMMENT, "List of X.509 CRLs:");
717 whack_log(RC_COMMENT, " ");
718 }
719
720 while (crl != NULL)
721 {
722 u_char buf[BUF_LEN];
723 u_int revoked = 0;
724 revokedCert_t *revokedCert = crl->revokedCertificates;
725
726 /* count number of revoked certificates in CRL */
727 while (revokedCert != NULL)
728 {
729 revoked++;
730 revokedCert = revokedCert->next;
731 }
732
733 whack_log(RC_COMMENT, "%T, revoked certs: %d",
734 &crl->installed, utc, revoked);
735 dntoa(buf, BUF_LEN, crl->issuer);
736 whack_log(RC_COMMENT, " issuer: '%s'", buf);
737 if (crl->crlNumber.ptr != NULL)
738 {
739 datatot(crl->crlNumber.ptr, crl->crlNumber.len, ':'
740 , buf, BUF_LEN);
741 whack_log(RC_COMMENT, " crlnumber: %s", buf);
742 }
743 list_distribution_points(crl->distributionPoints);
744
745 whack_log(RC_COMMENT, " updates: this %T",
746 &crl->thisUpdate, utc);
747 whack_log(RC_COMMENT, " next %T %s",
748 &crl->nextUpdate, utc,
749 check_expiry(crl->nextUpdate, CRL_WARNING_INTERVAL, strict));
750 if (crl->authKeyID.ptr != NULL)
751 {
752 datatot(crl->authKeyID.ptr, crl->authKeyID.len, ':'
753 , buf, BUF_LEN);
754 whack_log(RC_COMMENT, " authkey: %s", buf);
755 }
756 if (crl->authKeySerialNumber.ptr != NULL)
757 {
758 datatot(crl->authKeySerialNumber.ptr, crl->authKeySerialNumber.len, ':'
759 , buf, BUF_LEN);
760 whack_log(RC_COMMENT, " aserial: %s", buf);
761 }
762
763 crl = crl->next;
764 }
765 unlock_crl_list("list_crls");
766 }
767