v3_sda.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 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 <crypto/x509.h>
  12. #include "ext_dat.h"
  13. ASN1_ITEM_TEMPLATE(OSSL_ATTRIBUTES_SYNTAX) =
  14. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Attributes, X509_ATTRIBUTE)
  15. ASN1_ITEM_TEMPLATE_END(OSSL_ATTRIBUTES_SYNTAX)
  16. IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTES_SYNTAX)
  17. static int i2r_ATTRIBUTES_SYNTAX(X509V3_EXT_METHOD *method,
  18. OSSL_ATTRIBUTES_SYNTAX *attrlst,
  19. BIO *out, int indent)
  20. {
  21. X509_ATTRIBUTE *attr;
  22. ASN1_TYPE *av;
  23. int i, j, attr_nid;
  24. if (!attrlst) {
  25. if (BIO_printf(out, "<No Attributes>\n") <= 0)
  26. return 0;
  27. return 1;
  28. }
  29. if (!sk_X509_ATTRIBUTE_num(attrlst)) {
  30. if (BIO_printf(out, "<Empty Attributes>\n") <= 0)
  31. return 0;
  32. return 1;
  33. }
  34. for (i = 0; i < sk_X509_ATTRIBUTE_num(attrlst); i++) {
  35. ASN1_OBJECT *attr_obj;
  36. attr = sk_X509_ATTRIBUTE_value(attrlst, i);
  37. attr_obj = X509_ATTRIBUTE_get0_object(attr);
  38. attr_nid = OBJ_obj2nid(attr_obj);
  39. if (indent && BIO_printf(out, "%*s", indent, "") <= 0)
  40. return 0;
  41. if (attr_nid == NID_undef) {
  42. if (i2a_ASN1_OBJECT(out, attr_obj) <= 0)
  43. return 0;
  44. if (BIO_puts(out, ":\n") <= 0)
  45. return 0;
  46. } else if (BIO_printf(out, "%s:\n", OBJ_nid2ln(attr_nid)) <= 0) {
  47. return 0;
  48. }
  49. if (X509_ATTRIBUTE_count(attr)) {
  50. for (j = 0; j < X509_ATTRIBUTE_count(attr); j++)
  51. {
  52. av = X509_ATTRIBUTE_get0_type(attr, j);
  53. if (ossl_print_attribute_value(out, attr_nid, av, indent + 4) <= 0)
  54. return 0;
  55. if (BIO_puts(out, "\n") <= 0)
  56. return 0;
  57. }
  58. } else if (BIO_printf(out, "%*s<No Values>\n", indent + 4, "") <= 0) {
  59. return 0;
  60. }
  61. }
  62. return 1;
  63. }
  64. const X509V3_EXT_METHOD ossl_v3_subj_dir_attrs = {
  65. NID_subject_directory_attributes, X509V3_EXT_MULTILINE,
  66. ASN1_ITEM_ref(OSSL_ATTRIBUTES_SYNTAX),
  67. 0, 0, 0, 0,
  68. 0, 0, 0, 0,
  69. (X509V3_EXT_I2R)i2r_ATTRIBUTES_SYNTAX,
  70. 0,
  71. NULL
  72. };
  73. const X509V3_EXT_METHOD ossl_v3_associated_info = {
  74. NID_associated_information, X509V3_EXT_MULTILINE,
  75. ASN1_ITEM_ref(OSSL_ATTRIBUTES_SYNTAX),
  76. 0, 0, 0, 0,
  77. 0, 0, 0, 0,
  78. (X509V3_EXT_I2R)i2r_ATTRIBUTES_SYNTAX,
  79. 0,
  80. NULL
  81. };