]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Configure libpq libcrypto callback
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 27 Jun 2021 15:59:07 +0000 (16:59 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 27 Jun 2021 15:59:07 +0000 (16:59 +0100)
Import the ssl module beforehand and set up libpq callbacks to avoid clobbering
the former ones.

psycopg/psycopg/pq/_pq_ctypes.py
psycopg/psycopg/pq/_pq_ctypes.pyi
psycopg/psycopg/pq/pq_ctypes.py
psycopg_c/psycopg_c/pq.pyx
psycopg_c/psycopg_c/pq/libpq.pxd

index bcc200026cc2e1f08c2987edd8c954e2b1bbfa66..2cbd2fce5ed3c64924a43fd9f99a4707449128e1 100644 (file)
@@ -573,6 +573,13 @@ PQsetNoticeReceiver.argtypes = [PGconn_ptr, PQnoticeReceiver, c_void_p]
 PQsetNoticeReceiver.restype = PQnoticeReceiver
 
 
+# 33.18. SSL Support
+
+PQinitOpenSSL = pq.PQinitOpenSSL
+PQinitOpenSSL.argtypes = [c_int, c_int]
+PQinitOpenSSL.restype = None
+
+
 def generate_stub() -> None:
     import re
     from ctypes import _CFuncPtr
index 05cbbb75d6f4194ed46517f35b4fc160ac667351..dffdd89e7afb19b83077d9e3f92b41405e78a374 100644 (file)
@@ -188,6 +188,7 @@ def PQfreeCancel(arg1: Optional[PGcancel_struct]) -> None: ...
 def PQputCopyData(arg1: Optional[PGconn_struct], arg2: bytes, arg3: int) -> int: ...
 def PQfreemem(arg1: Any) -> None: ...
 def PQmakeEmptyPGresult(arg1: Optional[PGconn_struct], arg2: int) -> PGresult_struct: ...
+def PQinitOpenSSL(arg1: int, arg2: int) -> None: ...
 # autogenerated: end
 # fmt: on
 
index 52f65539f2a33dba7109a852ab7ace15f75852e5..6f4341b6396dc6775db9eca6bf6baefc6164caa6 100644 (file)
@@ -994,3 +994,11 @@ class Escaping:
         rv = string_at(out, len_out.value)
         impl.PQfreemem(out)
         return memoryview(rv)
+
+
+# importing the ssl module sets up Python's libcrypto callbacks
+import ssl  # noqa
+
+# disable libcrypto setup in libpq, so it won't stomp on the callbacks
+# that have already been set up
+impl.PQinitOpenSSL(1, 0)
index f607e4250119fac0839af66863e1d36d0d2c2bc2..c8009272f79914707e11a608a45c21ab2c82ee50 100644 (file)
@@ -23,3 +23,11 @@ include "pq/pgcancel.pyx"
 include "pq/conninfo.pyx"
 include "pq/escaping.pyx"
 include "pq/pqbuffer.pyx"
+
+
+# importing the ssl module sets up Python's libcrypto callbacks
+import ssl  # noqa
+
+# disable libcrypto setup in libpq, so it won't stomp on the callbacks
+# that have already been set up
+libpq.PQinitOpenSSL(1, 0)
index 56d408f624200e4b17734e863d91da5ef2094527..d266a8d5d64335e08e78ccf3b21a101aa6faaa39 100644 (file)
@@ -5,7 +5,6 @@ Libpq header definition for the cython psycopg.pq implementation.
 # Copyright (C) 2020-2021 The Psycopg Team
 
 cdef extern from "libpq-fe.h":
-    int PQlibVersion()
 
     # structures and types
 
@@ -257,3 +256,6 @@ cdef extern from "libpq-fe.h":
     ctypedef void (*PQnoticeReceiver)(void *arg, const PGresult *res)
     PQnoticeReceiver PQsetNoticeReceiver(
         PGconn *conn, PQnoticeReceiver prog, void *arg)
+
+    # 33.18. SSL Support
+    void PQinitOpenSSL(int do_ssl, int do_crypto)