v3_usernotice.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 1999-2024 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 <openssl/asn1t.h>
  10. #include <openssl/x509v3.h>
  11. #include "ext_dat.h"
  12. ASN1_ITEM_TEMPLATE(OSSL_USER_NOTICE_SYNTAX) =
  13. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_USER_NOTICE_SYNTAX, USERNOTICE)
  14. ASN1_ITEM_TEMPLATE_END(OSSL_USER_NOTICE_SYNTAX)
  15. IMPLEMENT_ASN1_FUNCTIONS(OSSL_USER_NOTICE_SYNTAX)
  16. static int print_notice(BIO *out, USERNOTICE *notice, int indent)
  17. {
  18. int i;
  19. ASN1_INTEGER *num;
  20. char *tmp;
  21. if (notice->noticeref) {
  22. NOTICEREF *ref;
  23. ref = notice->noticeref;
  24. if (BIO_printf(out, "%*sOrganization: %.*s\n", indent, "",
  25. ref->organization->length,
  26. ref->organization->data) <= 0)
  27. return 0;
  28. if (BIO_printf(out, "%*sNumber%s: ", indent, "",
  29. sk_ASN1_INTEGER_num(ref->noticenos) > 1 ? "s" : "") <= 0)
  30. return 0;
  31. for (i = 0; i < sk_ASN1_INTEGER_num(ref->noticenos); i++) {
  32. num = sk_ASN1_INTEGER_value(ref->noticenos, i);
  33. if (i && BIO_puts(out, ", ") <= 0)
  34. return 0;
  35. if (num == NULL && BIO_puts(out, "(null)") <= 0)
  36. return 0;
  37. else {
  38. tmp = i2s_ASN1_INTEGER(NULL, num);
  39. if (tmp == NULL)
  40. return 0;
  41. if (BIO_puts(out, tmp) <= 0) {
  42. OPENSSL_free(tmp);
  43. return 0;
  44. }
  45. OPENSSL_free(tmp);
  46. }
  47. }
  48. if (notice->exptext && BIO_puts(out, "\n") <= 0)
  49. return 0;
  50. }
  51. if (notice->exptext == NULL)
  52. return 1;
  53. return BIO_printf(out, "%*sExplicit Text: %.*s", indent, "",
  54. notice->exptext->length,
  55. notice->exptext->data) >= 0;
  56. }
  57. static int i2r_USER_NOTICE_SYNTAX(X509V3_EXT_METHOD *method,
  58. OSSL_USER_NOTICE_SYNTAX *uns,
  59. BIO *out, int indent)
  60. {
  61. int i;
  62. USERNOTICE *unotice;
  63. if (BIO_printf(out, "%*sUser Notices:\n", indent, "") <= 0)
  64. return 0;
  65. for (i = 0; i < sk_USERNOTICE_num(uns); i++) {
  66. unotice = sk_USERNOTICE_value(uns, i);
  67. if (!print_notice(out, unotice, indent + 4))
  68. return 0;
  69. if (BIO_puts(out, "\n\n") <= 0)
  70. return 0;
  71. }
  72. return 1;
  73. }
  74. const X509V3_EXT_METHOD ossl_v3_user_notice = {
  75. NID_user_notice, 0,
  76. ASN1_ITEM_ref(OSSL_USER_NOTICE_SYNTAX),
  77. 0, 0, 0, 0,
  78. 0,
  79. 0,
  80. 0, 0,
  81. (X509V3_EXT_I2R)i2r_USER_NOTICE_SYNTAX,
  82. 0,
  83. NULL
  84. };