Skip to content

Commit

Permalink
Merge pull request #99 from tasleson/replace_wrap_socket
Browse files Browse the repository at this point in the history
Replace ssl.wrap_socket
  • Loading branch information
tasleson authored Dec 11, 2023
2 parents a4df809 + 4b3c270 commit 9fc83fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion targetd/backends/zfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
pools_fs = dict()
zfs_cmd = ""
zfs_enable_copy = False
ALLOWED_DATASET_NAMES = re.compile("^[A-Za-z0-9][A-Za-z0-9_.\-]*$")
ALLOWED_DATASET_NAMES = re.compile("^[A-Za-z0-9][A-Za-z0-9_.-]*$")


class VolInfo(object):
Expand Down
20 changes: 9 additions & 11 deletions targetd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,6 @@ class HTTPService(ThreadingMixIn, HTTPServer, object):
class TLSHTTPService(HTTPService):
"""Also use TLS to encrypt the connection"""

def finish_request(self, sock, addr):
sockssl = ssl.wrap_socket(
sock,
server_side=True,
keyfile=config["ssl_key"],
certfile=config["ssl_cert"],
ciphers="HIGH:-aNULL:-eNULL:-PSK",
suppress_ragged_eofs=True,
)
return self.RequestHandlerClass(sockssl, addr, self)

@staticmethod
def _verify_ssl_file(f):
rc = False
Expand Down Expand Up @@ -319,6 +308,14 @@ def handler(signum, frame):
RUN = False


def wrap_socket(s):
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.check_hostname = False
context.load_cert_chain(config["ssl_cert"], config["ssl_key"])
context.set_ciphers("HIGH:-aNULL:-eNULL:-PSK")
wrapped = context.wrap_socket(s, server_side=True)
return wrapped

def main():

signal.signal(signal.SIGINT, handler)
Expand Down Expand Up @@ -349,6 +346,7 @@ def main():
note = "(TLS no)"

server = server_class(("", 18700), TargetHandler)
server.socket = wrap_socket(server.socket)
log.info("started server %s", note)

server.timeout = 0.5
Expand Down

0 comments on commit 9fc83fb

Please sign in to comment.