v3_rolespec.c 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_SEQUENCE(OSSL_ROLE_SPEC_CERT_ID) = {
  14. ASN1_EXP(OSSL_ROLE_SPEC_CERT_ID, roleName, GENERAL_NAME, 0),
  15. ASN1_EXP(OSSL_ROLE_SPEC_CERT_ID, roleCertIssuer, GENERAL_NAME, 1),
  16. ASN1_IMP_OPT(OSSL_ROLE_SPEC_CERT_ID, roleCertSerialNumber, ASN1_INTEGER, 2),
  17. ASN1_IMP_SEQUENCE_OF_OPT(OSSL_ROLE_SPEC_CERT_ID, roleCertLocator, GENERAL_NAME, 3),
  18. } ASN1_SEQUENCE_END(OSSL_ROLE_SPEC_CERT_ID)
  19. IMPLEMENT_ASN1_FUNCTIONS(OSSL_ROLE_SPEC_CERT_ID)
  20. ASN1_ITEM_TEMPLATE(OSSL_ROLE_SPEC_CERT_ID_SYNTAX) =
  21. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF,
  22. 0, OSSL_ROLE_SPEC_CERT_ID_SYNTAX, OSSL_ROLE_SPEC_CERT_ID)
  23. ASN1_ITEM_TEMPLATE_END(OSSL_ROLE_SPEC_CERT_ID_SYNTAX)
  24. IMPLEMENT_ASN1_FUNCTIONS(OSSL_ROLE_SPEC_CERT_ID_SYNTAX)
  25. static int i2r_OSSL_ROLE_SPEC_CERT_ID(X509V3_EXT_METHOD *method,
  26. OSSL_ROLE_SPEC_CERT_ID *rscid,
  27. BIO *out, int indent)
  28. {
  29. if (BIO_printf(out, "%*sRole Name: ", indent, "") <= 0)
  30. return 0;
  31. if (GENERAL_NAME_print(out, rscid->roleName) <= 0)
  32. return 0;
  33. if (BIO_puts(out, "\n") <= 0)
  34. return 0;
  35. if (BIO_printf(out, "%*sRole Certificate Issuer: ", indent, "") <= 0)
  36. return 0;
  37. if (GENERAL_NAME_print(out, rscid->roleCertIssuer) <= 0)
  38. return 0;
  39. if (rscid->roleCertSerialNumber != NULL) {
  40. if (BIO_puts(out, "\n") <= 0)
  41. return 0;
  42. if (BIO_printf(out, "%*sRole Certificate Serial Number:", indent, "") <= 0)
  43. return 0;
  44. if (ossl_serial_number_print(out, rscid->roleCertSerialNumber, indent) != 0)
  45. return 0;
  46. }
  47. if (rscid->roleCertLocator != NULL) {
  48. if (BIO_puts(out, "\n") <= 0)
  49. return 0;
  50. if (BIO_printf(out, "%*sRole Certificate Locator:\n", indent, "") <= 0)
  51. return 0;
  52. if (OSSL_GENERAL_NAMES_print(out, rscid->roleCertLocator, indent) <= 0)
  53. return 0;
  54. }
  55. return BIO_puts(out, "\n");
  56. }
  57. static int i2r_OSSL_ROLE_SPEC_CERT_ID_SYNTAX(X509V3_EXT_METHOD *method,
  58. OSSL_ROLE_SPEC_CERT_ID_SYNTAX *rscids,
  59. BIO *out, int indent)
  60. {
  61. OSSL_ROLE_SPEC_CERT_ID *rscid;
  62. int i;
  63. for (i = 0; i < sk_OSSL_ROLE_SPEC_CERT_ID_num(rscids); i++) {
  64. if (i > 0 && BIO_puts(out, "\n") <= 0)
  65. return 0;
  66. if (BIO_printf(out,
  67. "%*sRole Specification Certificate Identifier #%d:\n",
  68. indent, "", i + 1) <= 0)
  69. return 0;
  70. rscid = sk_OSSL_ROLE_SPEC_CERT_ID_value(rscids, i);
  71. if (i2r_OSSL_ROLE_SPEC_CERT_ID(method, rscid, out, indent + 4) != 1)
  72. return 0;
  73. }
  74. return 1;
  75. }
  76. const X509V3_EXT_METHOD ossl_v3_role_spec_cert_identifier = {
  77. NID_role_spec_cert_identifier, X509V3_EXT_MULTILINE,
  78. ASN1_ITEM_ref(OSSL_ROLE_SPEC_CERT_ID_SYNTAX),
  79. 0, 0, 0, 0,
  80. 0, 0,
  81. 0,
  82. 0,
  83. (X509V3_EXT_I2R)i2r_OSSL_ROLE_SPEC_CERT_ID_SYNTAX,
  84. NULL,
  85. NULL
  86. };