ssl_x509.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _SSL_X509_H_
  14. #define _SSL_X509_H_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "ssl_types.h"
  19. #include "ssl_stack.h"
  20. DEFINE_STACK_OF(X509_NAME)
  21. /**
  22. * @brief create a X509 certification object according to input X509 certification
  23. *
  24. * @param ix - input X509 certification point
  25. *
  26. * @return new X509 certification object point
  27. */
  28. X509* __X509_new(X509 *ix);
  29. /**
  30. * @brief create a X509 certification object
  31. *
  32. * @param none
  33. *
  34. * @return X509 certification object point
  35. */
  36. X509* X509_new(void);
  37. /**
  38. * @brief load a character certification context into system context. If '*cert' is pointed to the
  39. * certification, then load certification into it. Or create a new X509 certification object
  40. *
  41. * @param cert - a point pointed to X509 certification
  42. * @param buffer - a point pointed to the certification context memory point
  43. * @param length - certification bytes
  44. *
  45. * @return X509 certification object point
  46. */
  47. X509* d2i_X509(X509 **cert, const unsigned char *buffer, long len);
  48. /**
  49. * @brief free a X509 certification object
  50. *
  51. * @param x - X509 certification object point
  52. *
  53. * @return none
  54. */
  55. void X509_free(X509 *x);
  56. /**
  57. * @brief set SSL context client CA certification
  58. *
  59. * @param ctx - SSL context point
  60. * @param x - X509 certification point
  61. *
  62. * @return result
  63. * 0 : failed
  64. * 1 : OK
  65. */
  66. int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x);
  67. /**
  68. * @brief add CA client certification into the SSL
  69. *
  70. * @param ssl - SSL point
  71. * @param x - X509 certification point
  72. *
  73. * @return result
  74. * 0 : failed
  75. * 1 : OK
  76. */
  77. int SSL_add_client_CA(SSL *ssl, X509 *x);
  78. /**
  79. * @brief load certification into the SSL
  80. *
  81. * @param ssl - SSL point
  82. * @param len - data bytes
  83. * @param d - data point
  84. *
  85. * @return result
  86. * 0 : failed
  87. * 1 : OK
  88. *
  89. */
  90. int SSL_use_certificate_ASN1(SSL *ssl, int len, const unsigned char *d);
  91. /**
  92. * @brief set SSL context client CA certification
  93. *
  94. * @param store - pointer to X509_STORE
  95. * @param x - pointer to X509 certification point
  96. *
  97. * @return result
  98. * 0 : failed
  99. * 1 : OK
  100. */
  101. int X509_STORE_add_cert(X509_STORE *store, X509 *x);
  102. /**
  103. * @brief load data in BIO
  104. *
  105. * Normally BIO_write should append data but that doesn't happen here, and
  106. * 'data' cannot be freed after the function is called, it should remain valid
  107. * until BIO object is in use.
  108. *
  109. * @param b - pointer to BIO
  110. * @param data - pointer to data
  111. * @param dlen - data bytes
  112. *
  113. * @return result
  114. * 0 : failed
  115. * 1 : OK
  116. */
  117. int BIO_write(BIO *b, const void *data, int dlen);
  118. /**
  119. * @brief load a character certification context into system context.
  120. *
  121. * If '*cert' is pointed to the certification, then load certification
  122. * into it, or create a new X509 certification object.
  123. *
  124. * @param bp - pointer to BIO
  125. * @param buffer - pointer to the certification context memory
  126. * @param cb - pointer to a callback which queries pass phrase used
  127. for encrypted PEM structure
  128. * @param u - pointer to arbitary data passed by application to callback
  129. *
  130. * @return X509 certification object point
  131. */
  132. X509 * PEM_read_bio_X509(BIO *bp, X509 **x, void *cb, void *u);
  133. /**
  134. * @brief create a BIO object
  135. *
  136. * @param method - pointer to BIO_METHOD
  137. *
  138. * @return pointer to BIO object
  139. */
  140. BIO *BIO_new(void * method);
  141. /**
  142. * @brief get the memory BIO method function
  143. */
  144. void *BIO_s_mem(void);
  145. /**
  146. * @brief free a BIO object
  147. *
  148. * @param x - pointer to BIO object
  149. */
  150. void BIO_free(BIO *b);
  151. #ifdef __cplusplus
  152. }
  153. #endif
  154. #endif