From: Daniele Varrazzo Date: Sun, 27 Jun 2021 15:59:07 +0000 (+0100) Subject: Configure libpq libcrypto callback X-Git-Tag: 3.0.dev0~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6d8eceb386d97879fd3d8fe1da5ae743f0b719df;p=thirdparty%2Fpsycopg.git Configure libpq libcrypto callback Import the ssl module beforehand and set up libpq callbacks to avoid clobbering the former ones. --- diff --git a/psycopg/psycopg/pq/_pq_ctypes.py b/psycopg/psycopg/pq/_pq_ctypes.py index bcc200026..2cbd2fce5 100644 --- a/psycopg/psycopg/pq/_pq_ctypes.py +++ b/psycopg/psycopg/pq/_pq_ctypes.py @@ -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 diff --git a/psycopg/psycopg/pq/_pq_ctypes.pyi b/psycopg/psycopg/pq/_pq_ctypes.pyi index 05cbbb75d..dffdd89e7 100644 --- a/psycopg/psycopg/pq/_pq_ctypes.pyi +++ b/psycopg/psycopg/pq/_pq_ctypes.pyi @@ -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 diff --git a/psycopg/psycopg/pq/pq_ctypes.py b/psycopg/psycopg/pq/pq_ctypes.py index 52f65539f..6f4341b63 100644 --- a/psycopg/psycopg/pq/pq_ctypes.py +++ b/psycopg/psycopg/pq/pq_ctypes.py @@ -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) diff --git a/psycopg_c/psycopg_c/pq.pyx b/psycopg_c/psycopg_c/pq.pyx index f607e4250..c8009272f 100644 --- a/psycopg_c/psycopg_c/pq.pyx +++ b/psycopg_c/psycopg_c/pq.pyx @@ -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) diff --git a/psycopg_c/psycopg_c/pq/libpq.pxd b/psycopg_c/psycopg_c/pq/libpq.pxd index 56d408f62..d266a8d5d 100644 --- a/psycopg_c/psycopg_c/pq/libpq.pxd +++ b/psycopg_c/psycopg_c/pq/libpq.pxd @@ -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)