def DisableSSLCompression(): # Why? Disabling compression in OpenSSL may reduce memory usage *lots*. # If there is a sslzliboff module available, prefer that. # See https://github.com/hausen/SSLZlibOff for working code. try: import sslzliboff sslzliboff.disableZlib() return except: pass # Otherwise, fall through to the following hack. # Source: # http://journal.paul.querna.org/articles/2011/04/05/openssl-memory-use/ try: import ctypes import glob openssl = ctypes.CDLL(None, ctypes.RTLD_GLOBAL) try: f = openssl.SSL_COMP_get_compression_methods except AttributeError: ssllib = sorted(glob.glob("/usr/lib/libssl.so.*"))[0] openssl = ctypes.CDLL(ssllib, ctypes.RTLD_GLOBAL) openssl.SSL_COMP_get_compression_methods.restype = ctypes.c_void_p openssl.sk_zero.argtypes = [ctypes.c_void_p] openssl.sk_zero(openssl.SSL_COMP_get_compression_methods()) except Exception: if DEBUG: DEBUG('disableSSLCompression: Failed')
#!/usr/bin/python # Tests if sslzliboff has been built and installed correctly. try: import sslzliboff sslzliboff.disableZlib() print("OK. sslzliboff loaded correctly.") except Exception as e: print("ERROR: sslzliboff not loaded. This shouldn't have happened.")