From baeba53527b0a78c8045938fa4190e5dfb71e74c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moise=CC=81s=20Guimara=CC=83es?= Date: Tue, 6 Dec 2016 00:10:05 -0300 Subject: [PATCH] adds wrap_socket to the context --- wrapper/python/wolfssl/wolfssl/_context.py | 31 ++++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/wrapper/python/wolfssl/wolfssl/_context.py b/wrapper/python/wolfssl/wolfssl/_context.py index 17d150a58..edce885b1 100644 --- a/wrapper/python/wolfssl/wolfssl/_context.py +++ b/wrapper/python/wolfssl/wolfssl/_context.py @@ -26,6 +26,7 @@ except ImportError: pass from wolfssl._methods import WolfSSLMethod +from wolfssl._socket import SSLSocket from wolfssl._exceptions import SSLError from wolfssl.utils import t2b @@ -92,17 +93,25 @@ class SSLContext(object): _ffi.NULL) -# def wrap_socket(self, sock, server_side=False, -# do_handshake_on_connect=True, -# suppress_ragged_eofs=True, -# server_hostname=None): -# return SSLSocket(sock=sock, server_side=server_side, -# do_handshake_on_connect=do_handshake_on_connect, -# suppress_ragged_eofs=suppress_ragged_eofs, -# server_hostname=server_hostname, -# _context=self) -# -# + def wrap_socket(self, sock, server_side=False, + do_handshake_on_connect=True, + suppress_ragged_eofs=True, + server_hostname=None): + """ + Wrap an existing Python socket sock and return an SSLSocket object. + sock must be a SOCK_STREAM socket; other socket types are unsupported. + + The returned SSL socket is tied to the context, its settings and + certificates. The parameters server_side, do_handshake_on_connect and + suppress_ragged_eofs have the same meaning as in the top-level + wrap_socket() function. + """ + return SSLSocket(sock=sock, server_side=server_side, + do_handshake_on_connect=do_handshake_on_connect, + suppress_ragged_eofs=suppress_ragged_eofs, + server_hostname=server_hostname, + _context=self) + def set_ciphers(self, ciphers): """