Skip to content

Commit dcb7bd2

Browse files
committed
Address PR review feedback
1 parent 2c4ba3c commit dcb7bd2

4 files changed

Lines changed: 31 additions & 3 deletions

File tree

examples/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ def main():
140140
context = wolfssl.SSLContext(get_SSLmethod(args.v))
141141

142142
# enable debug, if native wolfSSL has been compiled with '--enable-debug'
143-
wolfssl.WolfSSL.enable_debug()
143+
try:
144+
wolfssl.WolfSSL.enable_debug()
145+
except RuntimeError:
146+
pass
144147

145148
context.load_cert_chain(args.c, args.k)
146149

examples/server.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ def main():
136136
print("Server listening on port", bind_socket.getsockname()[1])
137137

138138
# enable debug, if native wolfSSL has been compiled with '--enable-debug'
139-
wolfssl.WolfSSL.enable_debug()
139+
try:
140+
wolfssl.WolfSSL.enable_debug()
141+
except RuntimeError:
142+
pass
140143

141144
context.load_cert_chain(args.c, args.k)
142145

@@ -170,6 +173,9 @@ def main():
170173
finally:
171174
if secure_socket:
172175
secure_socket.shutdown(socket.SHUT_RDWR)
176+
# Don't close for DTLS - secure_socket wraps the
177+
# shared bind_socket which is needed for
178+
# subsequent connections
173179
if not args.u:
174180
secure_socket.close()
175181

tests/test_context.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,21 @@ def test_check_hostname_requires_cert_required(ssl_provider, ssl_context):
8888
def test_wrap_socket_server_side_mismatch(ssl_context, tcp_socket):
8989
with pytest.raises(ValueError):
9090
ssl_context.wrap_socket(tcp_socket, server_side=True)
91+
92+
93+
def test_close_without_handshake(ssl_context, tcp_socket):
94+
sock = ssl_context.wrap_socket(tcp_socket)
95+
sock.close()
96+
97+
98+
def test_close_releases_native_object(ssl_context, tcp_socket):
99+
sock = ssl_context.wrap_socket(tcp_socket)
100+
sock.close()
101+
sock.close()
102+
103+
104+
def test_operations_after_close_raise(ssl_context, tcp_socket):
105+
sock = ssl_context.wrap_socket(tcp_socket)
106+
sock.close()
107+
with pytest.raises(ValueError):
108+
sock.read()

wolfssl/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,8 @@ def version(self):
912912
# API and are provided here for compatibility.
913913
def close(self):
914914
if self.native_object != _ffi.NULL:
915-
_lib.wolfSSL_shutdown(self.native_object)
915+
if self._connected:
916+
_lib.wolfSSL_shutdown(self.native_object)
916917
self._release_native_object()
917918
self._sock.close()
918919

0 commit comments

Comments
 (0)