tls.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * Copyright (c) 2019-2020 Paul-Louis Ageneau
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef RTC_TLS_H
  19. #define RTC_TLS_H
  20. #include "common.hpp"
  21. #if USE_GNUTLS
  22. #include <gnutls/gnutls.h>
  23. #include <gnutls/crypto.h>
  24. #include <gnutls/dtls.h>
  25. #include <gnutls/x509.h>
  26. namespace rtc::gnutls {
  27. bool check(int ret, const string &message = "GnuTLS error");
  28. gnutls_certificate_credentials_t *new_credentials();
  29. void free_credentials(gnutls_certificate_credentials_t *creds);
  30. gnutls_x509_crt_t *new_crt();
  31. void free_crt(gnutls_x509_crt_t *crt);
  32. gnutls_x509_privkey_t *new_privkey();
  33. void free_privkey(gnutls_x509_privkey_t *privkey);
  34. gnutls_datum_t make_datum(char *data, size_t size);
  35. } // namespace rtc::gnutls
  36. #else // USE_GNUTLS==0
  37. #ifdef _WIN32
  38. // Include winsock2.h header first since OpenSSL may include winsock.h
  39. #include <winsock2.h>
  40. #endif
  41. #include <openssl/ssl.h>
  42. #include <openssl/bio.h>
  43. #include <openssl/bn.h>
  44. #include <openssl/ec.h>
  45. #include <openssl/err.h>
  46. #include <openssl/pem.h>
  47. #include <openssl/rsa.h>
  48. #include <openssl/x509.h>
  49. #ifndef BIO_EOF
  50. #define BIO_EOF -1
  51. #endif
  52. namespace rtc::openssl {
  53. void init();
  54. string error_string(unsigned long err);
  55. bool check(int success, const string &message = "OpenSSL error");
  56. bool check(SSL *ssl, int ret, const string &message = "OpenSSL error");
  57. } // namespace rtc::openssl
  58. #endif
  59. #endif