stream_peer_ssl.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*************************************************************************/
  2. /* stream_peer_ssl.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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. #ifndef STREAM_PEER_SSL_H
  31. #define STREAM_PEER_SSL_H
  32. #include "core/io/stream_peer.h"
  33. class StreamPeerSSL : public StreamPeer {
  34. GDCLASS(StreamPeerSSL, StreamPeer);
  35. public:
  36. typedef void (*LoadCertsFromMemory)(const PoolByteArray &p_certs);
  37. protected:
  38. static StreamPeerSSL *(*_create)();
  39. static void _bind_methods();
  40. static LoadCertsFromMemory load_certs_func;
  41. static bool available;
  42. bool blocking_handshake;
  43. public:
  44. enum Status {
  45. STATUS_DISCONNECTED,
  46. STATUS_HANDSHAKING,
  47. STATUS_CONNECTED,
  48. STATUS_ERROR,
  49. STATUS_ERROR_HOSTNAME_MISMATCH
  50. };
  51. void set_blocking_handshake_enabled(bool p_enabled);
  52. bool is_blocking_handshake_enabled() const;
  53. virtual void poll() = 0;
  54. virtual Error accept_stream(Ref<StreamPeer> p_base) = 0;
  55. virtual Error connect_to_stream(Ref<StreamPeer> p_base, bool p_validate_certs = false, const String &p_for_hostname = String()) = 0;
  56. virtual Status get_status() const = 0;
  57. virtual void disconnect_from_stream() = 0;
  58. static StreamPeerSSL *create();
  59. static PoolByteArray get_cert_file_as_array(String p_path);
  60. static PoolByteArray get_project_cert_array();
  61. static void load_certs_from_file(String p_path);
  62. static void load_certs_from_memory(const PoolByteArray &p_memory);
  63. static bool is_available();
  64. StreamPeerSSL();
  65. };
  66. VARIANT_ENUM_CAST(StreamPeerSSL::Status);
  67. #endif // STREAM_PEER_SSL_H