summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-05-21 00:35:19 +0430
committerAndreas Kling <kling@serenityos.org>2020-05-21 01:21:39 +0200
commit7d76299ca9e0a4590a5c0ff8c45e1ec15a21b8bb (patch)
treedf98d3459ce37cfc47157591243df769abcc046e /Libraries
parentef49309807a43294fd2d730919921f9ef4100131 (diff)
downloadserenity-7d76299ca9e0a4590a5c0ff8c45e1ec15a21b8bb.zip
LibTLS: Do not call on_tls_finished until the client has read app data
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibTLS/Socket.cpp32
-rw-r--r--Libraries/LibTLS/TLSv12.h1
2 files changed, 22 insertions, 11 deletions
diff --git a/Libraries/LibTLS/Socket.cpp b/Libraries/LibTLS/Socket.cpp
index 95790fa412..05839ff1d2 100644
--- a/Libraries/LibTLS/Socket.cpp
+++ b/Libraries/LibTLS/Socket.cpp
@@ -113,13 +113,7 @@ bool TLSv12::common_connect(const struct sockaddr* saddr, socklen_t length)
Core::Socket::on_connected = [this] {
Core::Socket::on_ready_to_read = [this] {
- if (!check_connection_state(true))
- return;
- flush();
- consume(Core::Socket::read(4096));
- if (is_established() && m_context.application_buffer.size())
- if (on_tls_ready_to_read)
- on_tls_ready_to_read(*this);
+ read_from_socket();
};
write_into_socket();
if (on_tls_connected)
@@ -132,6 +126,20 @@ bool TLSv12::common_connect(const struct sockaddr* saddr, socklen_t length)
return true;
}
+void TLSv12::read_from_socket()
+{
+ if (m_context.application_buffer.size() > 0) {
+ deferred_invoke([&](auto&) { read_from_socket(); });
+ if (on_tls_ready_to_read)
+ on_tls_ready_to_read(*this);
+ }
+
+ if (!check_connection_state(true))
+ return;
+ flush();
+ consume(Core::Socket::read(4096));
+}
+
void TLSv12::write_into_socket()
{
#ifdef TLS_DEBUG
@@ -161,16 +169,18 @@ bool TLSv12::check_connection_state(bool read)
m_context.connection_finished = true;
}
if (m_context.critical_error) {
- dbg() << "WRITE CRITICAL ERROR " << m_context.critical_error << " :(";
+ dbg() << "CRITICAL ERROR " << m_context.critical_error << " :(";
if (on_tls_error)
on_tls_error((AlertDescription)m_context.critical_error);
return false;
}
if (((read && m_context.application_buffer.size() == 0) || !read) && m_context.connection_finished) {
- if (on_tls_finished)
- on_tls_finished();
+ if (m_context.application_buffer.size() == 0) {
+ if (on_tls_finished)
+ on_tls_finished();
+ }
if (m_context.tls_buffer.size()) {
- dbg() << "connection closed without finishing data transfer, " << m_context.tls_buffer.size() << " bytes still in buffer";
+ dbg() << "connection closed without finishing data transfer, " << m_context.tls_buffer.size() << " bytes still in buffer & " << m_context.application_buffer.size() << " bytes in application buffer";
} else {
m_context.connection_finished = false;
dbg() << "FINISHED";
diff --git a/Libraries/LibTLS/TLSv12.h b/Libraries/LibTLS/TLSv12.h
index efd1394389..74e310f473 100644
--- a/Libraries/LibTLS/TLSv12.h
+++ b/Libraries/LibTLS/TLSv12.h
@@ -376,6 +376,7 @@ private:
bool flush();
void write_into_socket();
+ void read_from_socket();
bool check_connection_state(bool read);