Skip to content

AttributeError: module 'ssl' has no attribute 'wrap_socket' #1

@greg-minshall

Description

@greg-minshall

i don't know anything about python's ssl module.

but, this line seems to fail:

httpd.socket = ssl.wrap_socket(
DEBUG:__main__:Enabled debug output
Traceback (most recent call last):
  File "/home/minshall/src/import/password-store/passforios/gpg-serve-key/gpg-serve-key", line 330, in <module>
    main()
  File "/usr/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/minshall/src/import/password-store/passforios/gpg-serve-key/gpg-serve-key", line 324, in main
    run_server(
  File "/home/minshall/src/import/password-store/passforios/gpg-serve-key/gpg-serve-key", line 253, in run_server
    httpd.socket = ssl.wrap_socket(
                   ^^^^^^^^^^^^^^^
AttributeError: module 'ssl' has no attribute 'wrap_socket'

the following patch seems to work; as the patch says, i don't really know what i'm doing here.

From d2296f55e30f3b661792b87dd0dd4c6fc51a5edf Mon Sep 17 00:00:00 2001
From: Greg Minshall <minshall@umich.edu>
Date: Fri, 7 Jun 2024 17:53:10 +0300
Subject: [PATCH] try to fix "ssl.wrap_socket: no such attribute" error

but i don't really know what i'm doing
---
 gpg-serve-key | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gpg-serve-key b/gpg-serve-key
index 02fcdb6..9500158 100755
--- a/gpg-serve-key
+++ b/gpg-serve-key
@@ -250,9 +250,10 @@ def run_server(
     httpd = server_class(server_address, handler_class)
     if cert_file is not None or key_file is not None:
         protocol = 'https'
-        httpd.socket = ssl.wrap_socket(
-            httpd.socket, certfile=cert_file, keyfile=key_file,
-            server_side=True)
+        context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
+        context.load_default_certs()
+        context.load_cert_chain(certfile = cert_file, keyfile = key_file)
+        httpd.socket = context.wrap_socket(httpd.socket, server_side=True)
     else:
         protocol = 'http'
     handler_class.have_fork = False
-- 
2.45.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions