diff options
-rw-r--r-- | src/lib/tls/asio/asio_stream.h | 7 | ||||
-rw-r--r-- | src/tests/unit_asio_stream.cpp | 20 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/lib/tls/asio/asio_stream.h b/src/lib/tls/asio/asio_stream.h index 4d2de0967..37f031571 100644 --- a/src/lib/tls/asio/asio_stream.h +++ b/src/lib/tls/asio/asio_stream.h @@ -113,7 +113,12 @@ class Stream lowest_layer_type& lowest_layer() { return m_nextLayer.lowest_layer(); } const lowest_layer_type& lowest_layer() const { return m_nextLayer.lowest_layer(); } - native_handle_type native_handle() { return m_native_handle.get(); } + native_handle_type native_handle() + { + if(m_native_handle == nullptr) + { throw Invalid_State("Invalid handshake state"); } + return m_native_handle.get(); + } //! @} //! \name configuration and callback setters diff --git a/src/tests/unit_asio_stream.cpp b/src/tests/unit_asio_stream.cpp index 5621a9ddd..aa65b145f 100644 --- a/src/tests/unit_asio_stream.cpp +++ b/src/tests/unit_asio_stream.cpp @@ -558,6 +558,24 @@ class Asio_Stream_Tests final : public Test results.push_back(result); } + void test_sync_no_handshake(std::vector<Test::Result>& results) + { + net::io_context ioc; + TestStream remote{ioc}; + + auto ctx = get_context(); + Botan::TLS::Stream<TestStream> ssl(ctx, ioc); // Note that we're not using MockChannel here + ssl.next_layer().connect(remote); + error_code ec; + + net::write(ssl, net::const_buffer(TEST_DATA, TEST_DATA_SIZE), ec); + + Test::Result result("sync write_some without handshake fails gracefully"); + result.confirm("reports an error", ec.failed()); + + results.push_back(result); + } + void test_sync_write_some_buffer_sequence(std::vector<Test::Result>& results) { net::io_context ioc; @@ -755,6 +773,8 @@ class Asio_Stream_Tests final : public Test { std::vector<Test::Result> results; + test_sync_no_handshake(results); + test_sync_handshake(results); test_sync_handshake_error(results); test_sync_handshake_throw(results); |