wolfssl_extras.inl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Additional defines for WolfSSL, see
  2. * https://github.com/civetweb/civetweb/issues/583 */
  3. /* Required for WOLFSSL_X509 */
  4. #include <openssl/../internal.h>
  5. #define i2d_X509 cw_i2d_X509
  6. #define EVP_Digest cw_EVP_Digest
  7. /* i2d_X509 has no valid implementation in wolfssl
  8. *
  9. * The letters i and d in for example i2d_X509 stand for "internal" (that is an
  10. *internal C structure)
  11. * and " DER ". So that i2d_X509 converts from internal to DER.
  12. *
  13. * For OpenSSL 0.9.7 and later if *out is NULL memory will be allocated for a
  14. *buffer and the encoded
  15. * data written to it. In this case *out is not incremented and it points to the
  16. *start of the data
  17. * just written.
  18. */
  19. int
  20. cw_i2d_X509(struct WOLFSSL_X509 *x, unsigned char **out)
  21. {
  22. if (!x || !x->derCert) {
  23. return -1;
  24. }
  25. const int ret = (int)x->derCert->length;
  26. if (out && (ret > 0)) {
  27. if (*out == NULL) {
  28. *out = mg_malloc(ret);
  29. }
  30. if (*out != NULL) {
  31. memcpy(*out, x->derCert->buffer, ret);
  32. }
  33. }
  34. return ret;
  35. }
  36. /* EVP_Digest not in wolfssl */
  37. int
  38. cw_EVP_Digest(const void *data,
  39. size_t count,
  40. unsigned char *md,
  41. unsigned int *size,
  42. const EVP_MD *type,
  43. ENGINE *impl)
  44. {
  45. EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  46. int ret;
  47. if (ctx == NULL)
  48. return 0;
  49. /* EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_ONESHOT); */
  50. ret = EVP_DigestInit_ex(ctx, type, impl)
  51. && EVP_DigestUpdate(ctx, data, count)
  52. && EVP_DigestFinal_ex(ctx, md, size);
  53. EVP_MD_CTX_free(ctx);
  54. return ret;
  55. }
  56. /*
  57. * the variable SSL_OP_NO_TLSv1_1 is not defined within the context of
  58. * wolfssl but since the methods using the value are all stubs, we can
  59. * define it arbitrarily and it will not have any consequences
  60. */
  61. #define SSL_OP_NO_TLSv1_1 (0x10000000L)