t_crl.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stdio.h>
  10. #include "internal/cryptlib.h"
  11. #include <openssl/buffer.h>
  12. #include <openssl/bn.h>
  13. #include <openssl/objects.h>
  14. #include <openssl/x509.h>
  15. #include <openssl/x509v3.h>
  16. DEFINE_STACK_OF(X509_REVOKED)
  17. #ifndef OPENSSL_NO_STDIO
  18. int X509_CRL_print_fp(FILE *fp, X509_CRL *x)
  19. {
  20. BIO *b;
  21. int ret;
  22. if ((b = BIO_new(BIO_s_file())) == NULL) {
  23. X509err(X509_F_X509_CRL_PRINT_FP, ERR_R_BUF_LIB);
  24. return 0;
  25. }
  26. BIO_set_fp(b, fp, BIO_NOCLOSE);
  27. ret = X509_CRL_print(b, x);
  28. BIO_free(b);
  29. return ret;
  30. }
  31. #endif
  32. int X509_CRL_print(BIO *out, X509_CRL *x)
  33. {
  34. return X509_CRL_print_ex(out, x, XN_FLAG_COMPAT);
  35. }
  36. int X509_CRL_print_ex(BIO *out, X509_CRL *x, unsigned long nmflag)
  37. {
  38. STACK_OF(X509_REVOKED) *rev;
  39. X509_REVOKED *r;
  40. const X509_ALGOR *sig_alg;
  41. const ASN1_BIT_STRING *sig;
  42. long l;
  43. int i;
  44. BIO_printf(out, "Certificate Revocation List (CRL):\n");
  45. l = X509_CRL_get_version(x);
  46. if (l >= 0 && l <= 1)
  47. BIO_printf(out, "%8sVersion %ld (0x%lx)\n", "", l + 1, (unsigned long)l);
  48. else
  49. BIO_printf(out, "%8sVersion unknown (%ld)\n", "", l);
  50. X509_CRL_get0_signature(x, &sig, &sig_alg);
  51. BIO_puts(out, " ");
  52. X509_signature_print(out, sig_alg, NULL);
  53. BIO_printf(out, "%8sIssuer: ", "");
  54. X509_NAME_print_ex(out, X509_CRL_get_issuer(x), 0, nmflag);
  55. BIO_puts(out, "\n");
  56. BIO_printf(out, "%8sLast Update: ", "");
  57. ASN1_TIME_print(out, X509_CRL_get0_lastUpdate(x));
  58. BIO_printf(out, "\n%8sNext Update: ", "");
  59. if (X509_CRL_get0_nextUpdate(x))
  60. ASN1_TIME_print(out, X509_CRL_get0_nextUpdate(x));
  61. else
  62. BIO_printf(out, "NONE");
  63. BIO_printf(out, "\n");
  64. X509V3_extensions_print(out, "CRL extensions",
  65. X509_CRL_get0_extensions(x), 0, 8);
  66. rev = X509_CRL_get_REVOKED(x);
  67. if (sk_X509_REVOKED_num(rev) > 0)
  68. BIO_printf(out, "Revoked Certificates:\n");
  69. else
  70. BIO_printf(out, "No Revoked Certificates.\n");
  71. for (i = 0; i < sk_X509_REVOKED_num(rev); i++) {
  72. r = sk_X509_REVOKED_value(rev, i);
  73. BIO_printf(out, " Serial Number: ");
  74. i2a_ASN1_INTEGER(out, X509_REVOKED_get0_serialNumber(r));
  75. BIO_printf(out, "\n Revocation Date: ");
  76. ASN1_TIME_print(out, X509_REVOKED_get0_revocationDate(r));
  77. BIO_printf(out, "\n");
  78. X509V3_extensions_print(out, "CRL entry extensions",
  79. X509_REVOKED_get0_extensions(r), 0, 8);
  80. }
  81. X509_signature_print(out, sig_alg, sig);
  82. return 1;
  83. }