x509v3.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* x509v3.h
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* x509v3.h for openSSL */
  22. #ifndef WOLFSSL_x509v3_H
  23. #define WOLFSSL_x509v3_H
  24. #include <wolfssl/wolfcrypt/types.h>
  25. #include <wolfssl/openssl/compat_types.h>
  26. #include <wolfssl/openssl/conf.h>
  27. #include <wolfssl/openssl/bio.h>
  28. #include <wolfssl/openssl/ssl.h>
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  33. #define EXFLAG_KUSAGE 0x2
  34. #define EXFLAG_XKUSAGE 0x4
  35. #define KU_DIGITAL_SIGNATURE KEYUSE_DIGITAL_SIG
  36. #define KU_NON_REPUDIATION KEYUSE_CONTENT_COMMIT
  37. #define KU_KEY_ENCIPHERMENT KEYUSE_KEY_ENCIPHER
  38. #define KU_DATA_ENCIPHERMENT KEYUSE_DATA_ENCIPHER
  39. #define KU_KEY_AGREEMENT KEYUSE_KEY_AGREE
  40. #define KU_KEY_CERT_SIGN KEYUSE_KEY_CERT_SIGN
  41. #define KU_CRL_SIGN KEYUSE_CRL_SIGN
  42. #define KU_ENCIPHER_ONLY KEYUSE_ENCIPHER_ONLY
  43. #define KU_DECIPHER_ONLY KEYUSE_DECIPHER_ONLY
  44. #define XKU_SSL_SERVER 0x1
  45. #define XKU_SSL_CLIENT 0x2
  46. #define XKU_SMIME 0x4
  47. #define XKU_CODE_SIGN 0x8
  48. #define XKU_SGC 0x10
  49. #define XKU_OCSP_SIGN 0x20
  50. #define XKU_TIMESTAMP 0x40
  51. #define XKU_DVCS 0x80
  52. #define XKU_ANYEKU 0x100
  53. #define X509_PURPOSE_SSL_CLIENT 0
  54. #define X509_PURPOSE_SSL_SERVER 1
  55. #define NS_SSL_CLIENT WC_NS_SSL_CLIENT
  56. #define NS_SSL_SERVER WC_NS_SSL_SERVER
  57. /* Forward reference */
  58. #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x0090801fL
  59. typedef void *(*X509V3_EXT_D2I)(void *, const unsigned char **, long);
  60. #else
  61. typedef void *(*X509V3_EXT_D2I)(void *, unsigned char **, long);
  62. #endif
  63. typedef int (*X509V3_EXT_I2D) (void *, unsigned char **);
  64. typedef STACK_OF(CONF_VALUE) *(*X509V3_EXT_I2V) (
  65. struct WOLFSSL_v3_ext_method *method,
  66. void *ext, STACK_OF(CONF_VALUE) *extlist);
  67. typedef char *(*X509V3_EXT_I2S)(struct WOLFSSL_v3_ext_method *method, void *ext);
  68. typedef int (*X509V3_EXT_I2R) (struct WOLFSSL_v3_ext_method *method,
  69. void *ext, BIO *out, int indent);
  70. typedef struct WOLFSSL_v3_ext_method X509V3_EXT_METHOD;
  71. struct WOLFSSL_v3_ext_method {
  72. int ext_nid;
  73. int ext_flags;
  74. void *usr_data;
  75. X509V3_EXT_D2I d2i;
  76. X509V3_EXT_I2D i2d;
  77. X509V3_EXT_I2V i2v;
  78. X509V3_EXT_I2S i2s;
  79. X509V3_EXT_I2R i2r;
  80. };
  81. struct WOLFSSL_X509_EXTENSION {
  82. WOLFSSL_ASN1_OBJECT *obj;
  83. WOLFSSL_ASN1_BOOLEAN crit;
  84. ASN1_OCTET_STRING value; /* DER format of extension */
  85. WOLFSSL_v3_ext_method ext_method;
  86. WOLFSSL_STACK* ext_sk; /* For extension specific data */
  87. };
  88. #define WOLFSSL_ASN1_BOOLEAN int
  89. #define GEN_OTHERNAME 0
  90. #define GEN_EMAIL 1
  91. #define GEN_DNS 2
  92. #define GEN_X400 3
  93. #define GEN_DIRNAME 4
  94. #define GEN_EDIPARTY 5
  95. #define GEN_URI 6
  96. #define GEN_IPADD 7
  97. #define GEN_RID 8
  98. #define GEN_IA5 9
  99. #define GENERAL_NAME WOLFSSL_GENERAL_NAME
  100. #define X509V3_CTX WOLFSSL_X509V3_CTX
  101. #define CTX_TEST 0x1
  102. typedef struct WOLFSSL_AUTHORITY_KEYID AUTHORITY_KEYID;
  103. typedef struct WOLFSSL_BASIC_CONSTRAINTS BASIC_CONSTRAINTS;
  104. typedef struct WOLFSSL_ACCESS_DESCRIPTION ACCESS_DESCRIPTION;
  105. typedef WOLF_STACK_OF(WOLFSSL_ACCESS_DESCRIPTION) WOLFSSL_AUTHORITY_INFO_ACCESS;
  106. WOLFSSL_API WOLFSSL_BASIC_CONSTRAINTS* wolfSSL_BASIC_CONSTRAINTS_new(void);
  107. WOLFSSL_API void wolfSSL_BASIC_CONSTRAINTS_free(WOLFSSL_BASIC_CONSTRAINTS *bc);
  108. WOLFSSL_API WOLFSSL_AUTHORITY_KEYID* wolfSSL_AUTHORITY_KEYID_new(void);
  109. WOLFSSL_API void wolfSSL_AUTHORITY_KEYID_free(WOLFSSL_AUTHORITY_KEYID *id);
  110. #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  111. WOLFSSL_API const WOLFSSL_v3_ext_method* wolfSSL_X509V3_EXT_get(
  112. WOLFSSL_X509_EXTENSION* ex);
  113. #else
  114. WOLFSSL_API WOLFSSL_v3_ext_method* wolfSSL_X509V3_EXT_get(
  115. WOLFSSL_X509_EXTENSION* ex);
  116. #endif
  117. WOLFSSL_API void* wolfSSL_X509V3_EXT_d2i(WOLFSSL_X509_EXTENSION* ex);
  118. WOLFSSL_API char* wolfSSL_i2s_ASN1_STRING(WOLFSSL_v3_ext_method *method,
  119. const WOLFSSL_ASN1_STRING *s);
  120. WOLFSSL_API int wolfSSL_X509V3_EXT_print(WOLFSSL_BIO *out,
  121. WOLFSSL_X509_EXTENSION *ext, unsigned long flag, int indent);
  122. WOLFSSL_API int wolfSSL_X509V3_EXT_add_nconf(WOLFSSL_CONF *conf, WOLFSSL_X509V3_CTX *ctx,
  123. const char *section, WOLFSSL_X509 *cert);
  124. WOLFSSL_API WOLFSSL_ASN1_STRING* wolfSSL_a2i_IPADDRESS(const char* ipa);
  125. #define BASIC_CONSTRAINTS_free wolfSSL_BASIC_CONSTRAINTS_free
  126. #define AUTHORITY_KEYID_free wolfSSL_AUTHORITY_KEYID_free
  127. #define SSL_CTX_get_cert_store(x) wolfSSL_CTX_get_cert_store ((WOLFSSL_CTX*) (x))
  128. #define ASN1_INTEGER WOLFSSL_ASN1_INTEGER
  129. #define ASN1_OCTET_STRING WOLFSSL_ASN1_STRING
  130. #define X509V3_EXT_get wolfSSL_X509V3_EXT_get
  131. #define X509V3_EXT_d2i wolfSSL_X509V3_EXT_d2i
  132. #define X509V3_EXT_add_nconf wolfSSL_X509V3_EXT_add_nconf
  133. #ifndef NO_WOLFSSL_STUB
  134. #define X509V3_parse_list(...) NULL
  135. #endif
  136. #define i2s_ASN1_OCTET_STRING wolfSSL_i2s_ASN1_STRING
  137. #define a2i_IPADDRESS wolfSSL_a2i_IPADDRESS
  138. #define X509V3_EXT_print wolfSSL_X509V3_EXT_print
  139. #define X509V3_EXT_conf_nid wolfSSL_X509V3_EXT_conf_nid
  140. #define X509V3_set_ctx wolfSSL_X509V3_set_ctx
  141. #ifndef NO_WOLFSSL_STUB
  142. #define X509V3_set_nconf(...) WC_DO_NOTHING
  143. #define X509V3_EXT_cleanup(...) WC_DO_NOTHING
  144. #endif
  145. #define X509V3_set_ctx_test(ctx) wolfSSL_X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, CTX_TEST)
  146. #define X509V3_set_ctx_nodb wolfSSL_X509V3_set_ctx_nodb
  147. #define X509v3_get_ext_count wolfSSL_sk_num
  148. #endif /* OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL */
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152. #endif