diff options
Diffstat (limited to 'modules/mbedtls/stream_peer_mbedtls.cpp')
-rw-r--r--[-rwxr-xr-x] | modules/mbedtls/stream_peer_mbedtls.cpp | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/modules/mbedtls/stream_peer_mbedtls.cpp b/modules/mbedtls/stream_peer_mbedtls.cpp index 983095c536..e9a610b7ee 100755..100644 --- a/modules/mbedtls/stream_peer_mbedtls.cpp +++ b/modules/mbedtls/stream_peer_mbedtls.cpp @@ -34,8 +34,9 @@ #include "core/os/file_access.h" int StreamPeerMbedTLS::bio_send(void *ctx, const unsigned char *buf, size_t len) { - - if (buf == nullptr || len <= 0) return 0; + if (buf == nullptr || len <= 0) { + return 0; + } StreamPeerMbedTLS *sp = (StreamPeerMbedTLS *)ctx; @@ -53,8 +54,9 @@ int StreamPeerMbedTLS::bio_send(void *ctx, const unsigned char *buf, size_t len) } int StreamPeerMbedTLS::bio_recv(void *ctx, unsigned char *buf, size_t len) { - - if (buf == nullptr || len <= 0) return 0; + if (buf == nullptr || len <= 0) { + return 0; + } StreamPeerMbedTLS *sp = (StreamPeerMbedTLS *)ctx; @@ -72,7 +74,6 @@ int StreamPeerMbedTLS::bio_recv(void *ctx, unsigned char *buf, size_t len) { } void StreamPeerMbedTLS::_cleanup() { - ssl_ctx->clear(); base = Ref<StreamPeer>(); status = STATUS_DISCONNECTED; @@ -102,7 +103,6 @@ Error StreamPeerMbedTLS::_do_handshake() { } Error StreamPeerMbedTLS::connect_to_stream(Ref<StreamPeer> p_base, bool p_validate_certs, const String &p_for_hostname, Ref<X509Certificate> p_ca_certs) { - ERR_FAIL_COND_V(p_base.is_null(), ERR_INVALID_PARAMETER); base = p_base; @@ -125,7 +125,6 @@ Error StreamPeerMbedTLS::connect_to_stream(Ref<StreamPeer> p_base, bool p_valida } Error StreamPeerMbedTLS::accept_stream(Ref<StreamPeer> p_base, Ref<CryptoKey> p_key, Ref<X509Certificate> p_cert, Ref<X509Certificate> p_ca_chain) { - ERR_FAIL_COND_V(p_base.is_null(), ERR_INVALID_PARAMETER); Error err = ssl_ctx->init_server(MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_VERIFY_NONE, p_key, p_cert); @@ -144,8 +143,8 @@ Error StreamPeerMbedTLS::accept_stream(Ref<StreamPeer> p_base, Ref<CryptoKey> p_ status = STATUS_CONNECTED; return OK; } -Error StreamPeerMbedTLS::put_data(const uint8_t *p_data, int p_bytes) { +Error StreamPeerMbedTLS::put_data(const uint8_t *p_data, int p_bytes) { ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_UNCONFIGURED); Error err; @@ -166,13 +165,13 @@ Error StreamPeerMbedTLS::put_data(const uint8_t *p_data, int p_bytes) { } Error StreamPeerMbedTLS::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) { - ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_UNCONFIGURED); r_sent = 0; - if (p_bytes == 0) + if (p_bytes == 0) { return OK; + } int ret = mbedtls_ssl_write(ssl_ctx->get_context(), p_data, p_bytes); if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) { @@ -193,14 +192,12 @@ Error StreamPeerMbedTLS::put_partial_data(const uint8_t *p_data, int p_bytes, in } Error StreamPeerMbedTLS::get_data(uint8_t *p_buffer, int p_bytes) { - ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_UNCONFIGURED); Error err; int got = 0; while (p_bytes > 0) { - err = get_partial_data(p_buffer, p_bytes, got); if (err != OK) { @@ -215,7 +212,6 @@ Error StreamPeerMbedTLS::get_data(uint8_t *p_buffer, int p_bytes) { } Error StreamPeerMbedTLS::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) { - ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_UNCONFIGURED); r_received = 0; @@ -238,7 +234,6 @@ Error StreamPeerMbedTLS::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r } void StreamPeerMbedTLS::poll() { - ERR_FAIL_COND(status != STATUS_CONNECTED && status != STATUS_HANDSHAKING); ERR_FAIL_COND(!base.is_valid()); @@ -272,13 +267,12 @@ void StreamPeerMbedTLS::poll() { } int StreamPeerMbedTLS::get_available_bytes() const { - ERR_FAIL_COND_V(status != STATUS_CONNECTED, 0); return mbedtls_ssl_get_bytes_avail(&(ssl_ctx->ssl)); } -StreamPeerMbedTLS::StreamPeerMbedTLS() { +StreamPeerMbedTLS::StreamPeerMbedTLS() { ssl_ctx.instance(); status = STATUS_DISCONNECTED; } @@ -288,9 +282,9 @@ StreamPeerMbedTLS::~StreamPeerMbedTLS() { } void StreamPeerMbedTLS::disconnect_from_stream() { - - if (status != STATUS_CONNECTED && status != STATUS_HANDSHAKING) + if (status != STATUS_CONNECTED && status != STATUS_HANDSHAKING) { return; + } Ref<StreamPeerTCP> tcp = base; if (tcp.is_valid() && tcp->get_status() == StreamPeerTCP::STATUS_CONNECTED) { @@ -302,23 +296,19 @@ void StreamPeerMbedTLS::disconnect_from_stream() { } StreamPeerMbedTLS::Status StreamPeerMbedTLS::get_status() const { - return status; } StreamPeerSSL *StreamPeerMbedTLS::_create_func() { - return memnew(StreamPeerMbedTLS); } void StreamPeerMbedTLS::initialize_ssl() { - _create = _create_func; available = true; } void StreamPeerMbedTLS::finalize_ssl() { - available = false; _create = nullptr; } |