t_crl.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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. #ifndef OPENSSL_NO_STDIO
  17. int X509_CRL_print_fp(FILE *fp, X509_CRL *x)
  18. {
  19. BIO *b;
  20. int ret;
  21. if ((b = BIO_new(BIO_s_file())) == NULL) {
  22. X509err(X509_F_X509_CRL_PRINT_FP, ERR_R_BUF_LIB);
  23. return 0;
  24. }
  25. BIO_set_fp(b, fp, BIO_NOCLOSE);
  26. ret = X509_CRL_print(b, x);
  27. BIO_free(b);
  28. return ret;
  29. }
  30. #endif
  31. int X509_CRL_print(BIO *out, X509_CRL *x)
  32. {
  33. return X509_CRL_print_ex(out, x, XN_FLAG_COMPAT);
  34. }
  35. int X509_CRL_print_ex(BIO *out, X509_CRL *x, unsigned long nmflag)
  36. {
  37. STACK_OF(X509_REVOKED) *rev;
  38. X509_REVOKED *r;
  39. const X509_ALGOR *sig_alg;
  40. const ASN1_BIT_STRING *sig;
  41. long l;
  42. int i;
  43. BIO_printf(out, "Certificate Revocation List (CRL):\n");
  44. l = X509_CRL_get_version(x);
  45. if (l >= 0 && l <= 1)
  46. BIO_printf(out, "%8sVersion %ld (0x%lx)\n", "", l + 1, (unsigned long)l);
  47. else
  48. BIO_printf(out, "%8sVersion unknown (%ld)\n", "", l);
  49. X509_CRL_get0_signature(x, &sig, &sig_alg);
  50. BIO_puts(out, " ");
  51. X509_signature_print(out, sig_alg, NULL);
  52. BIO_printf(out, "%8sIssuer: ", "");
  53. X509_NAME_print_ex(out, X509_CRL_get_issuer(x), 0, nmflag);
  54. BIO_puts(out, "\n");
  55. BIO_printf(out, "%8sLast Update: ", "");
  56. ASN1_TIME_print(out, X509_CRL_get0_lastUpdate(x));
  57. BIO_printf(out, "\n%8sNext Update: ", "");
  58. if (X509_CRL_get0_nextUpdate(x))
  59. ASN1_TIME_print(out, X509_CRL_get0_nextUpdate(x));
  60. else
  61. BIO_printf(out, "NONE");
  62. BIO_printf(out, "\n");
  63. X509V3_extensions_print(out, "CRL extensions",
  64. X509_CRL_get0_extensions(x), 0, 8);
  65. rev = X509_CRL_get_REVOKED(x);
  66. if (sk_X509_REVOKED_num(rev) > 0)
  67. BIO_printf(out, "Revoked Certificates:\n");
  68. else
  69. BIO_printf(out, "No Revoked Certificates.\n");
  70. for (i = 0; i < sk_X509_REVOKED_num(rev); i++) {
  71. r = sk_X509_REVOKED_value(rev, i);
  72. BIO_printf(out, " Serial Number: ");
  73. i2a_ASN1_INTEGER(out, X509_REVOKED_get0_serialNumber(r));
  74. BIO_printf(out, "\n Revocation Date: ");
  75. ASN1_TIME_print(out, X509_REVOKED_get0_revocationDate(r));
  76. BIO_printf(out, "\n");
  77. X509V3_extensions_print(out, "CRL entry extensions",
  78. X509_REVOKED_get0_extensions(r), 0, 8);
  79. }
  80. X509_signature_print(out, sig_alg, sig);
  81. return 1;
  82. }