stream_peer_ssl.cpp 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**************************************************************************/
  2. /* stream_peer_ssl.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "stream_peer_ssl.h"
  31. #include "core/engine.h"
  32. StreamPeerSSL *(*StreamPeerSSL::_create)() = nullptr;
  33. StreamPeerSSL *StreamPeerSSL::create() {
  34. if (_create) {
  35. return _create();
  36. }
  37. return nullptr;
  38. }
  39. bool StreamPeerSSL::available = false;
  40. bool StreamPeerSSL::is_available() {
  41. return available;
  42. }
  43. void StreamPeerSSL::set_blocking_handshake_enabled(bool p_enabled) {
  44. blocking_handshake = p_enabled;
  45. }
  46. bool StreamPeerSSL::is_blocking_handshake_enabled() const {
  47. return blocking_handshake;
  48. }
  49. void StreamPeerSSL::_bind_methods() {
  50. ClassDB::bind_method(D_METHOD("poll"), &StreamPeerSSL::poll);
  51. ClassDB::bind_method(D_METHOD("accept_stream", "stream", "private_key", "certificate", "chain"), &StreamPeerSSL::accept_stream, DEFVAL(Ref<X509Certificate>()));
  52. ClassDB::bind_method(D_METHOD("connect_to_stream", "stream", "validate_certs", "for_hostname", "valid_certificate"), &StreamPeerSSL::connect_to_stream, DEFVAL(false), DEFVAL(String()), DEFVAL(Ref<X509Certificate>()));
  53. ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerSSL::get_status);
  54. ClassDB::bind_method(D_METHOD("disconnect_from_stream"), &StreamPeerSSL::disconnect_from_stream);
  55. ClassDB::bind_method(D_METHOD("set_blocking_handshake_enabled", "enabled"), &StreamPeerSSL::set_blocking_handshake_enabled);
  56. ClassDB::bind_method(D_METHOD("is_blocking_handshake_enabled"), &StreamPeerSSL::is_blocking_handshake_enabled);
  57. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "blocking_handshake"), "set_blocking_handshake_enabled", "is_blocking_handshake_enabled");
  58. BIND_ENUM_CONSTANT(STATUS_DISCONNECTED);
  59. BIND_ENUM_CONSTANT(STATUS_HANDSHAKING);
  60. BIND_ENUM_CONSTANT(STATUS_CONNECTED);
  61. BIND_ENUM_CONSTANT(STATUS_ERROR);
  62. BIND_ENUM_CONSTANT(STATUS_ERROR_HOSTNAME_MISMATCH);
  63. }
  64. StreamPeerSSL::StreamPeerSSL() {
  65. blocking_handshake = true;
  66. }