我们从Python开源项目中,提取了以下30个代码示例,用于说明如何使用OpenSSL.__version__()。
def openssl_set_session_cache_mode(context, mode): assert isinstance(context, OpenSSL.SSL.Context) try: import ctypes SSL_CTRL_SET_SESS_CACHE_MODE = 44 SESS_CACHE_OFF = 0x0 SESS_CACHE_CLIENT = 0x1 SESS_CACHE_SERVER = 0x2 SESS_CACHE_BOTH = 0x3 c_mode = {'off':SESS_CACHE_OFF, 'client':SESS_CACHE_CLIENT, 'server':SESS_CACHE_SERVER, 'both':SESS_CACHE_BOTH}[mode.lower()] if hasattr(context, 'set_session_cache_mode'): context.set_session_cache_mode(c_mode) elif OpenSSL.__version__ == '0.13': # http://bazaar.launchpad.net/~exarkun/pyopenssl/release-0.13/view/head:/OpenSSL/ssl/context.h#L27 c_context = ctypes.c_void_p.from_address(id(context)+ctypes.sizeof(ctypes.c_int)+ctypes.sizeof(ctypes.c_voidp)) if os.name == 'nt': # https://github.com/openssl/openssl/blob/92c78463720f71e47c251ffa58493e32cd793e13/ssl/ssl.h#L884 ctypes.c_int.from_address(c_context.value+ctypes.sizeof(ctypes.c_voidp)*7+ctypes.sizeof(ctypes.c_ulong)).value = c_mode else: import ctypes.util # FIXME # ctypes.cdll.LoadLibrary(ctypes.util.find_library('ssl')).SSL_CTX_ctrl(c_context, SSL_CTRL_SET_SESS_CACHE_MODE, c_mode, None) except Exception as e: logging.warning('openssl_set_session_cache_mode failed: %r', e)
def info(self): info = '' info += '------------------------------------------------------\n' info += 'PHP Proxy Version : %s (python/%s gevent/%s pyopenssl/%s)\n' % (__version__, platform.python_version(), gevent.__version__, OpenSSL.__version__) info += 'Uvent Version : %s (pyuv/%s libuv/%s)\n' % (__import__('uvent').__version__, __import__('pyuv').__version__, __import__('pyuv').LIBUV_VERSION) if all(x in sys.modules for x in ('pyuv', 'uvent')) else '' info += 'Local Proxy : %s:%s\n' % (self.PROXY_HOST, self.PROXY_PORT) if self.PROXY_ENABLE else '' info += 'Debug INFO : %s\n' % self.LISTEN_DEBUGINFO if self.LISTEN_DEBUGINFO else '' if common.GAE_ENABLE: info += 'Listen Address : %s:%d\n' % (self.LISTEN_IP, self.LISTEN_PORT) info += 'GAE Mode : %s\n' % self.GAE_MODE info += 'GAE IPv6 : %s\n' % self.GAE_IPV6 if self.GAE_IPV6 else '' info += 'GAE APPID : %s\n' % '|'.join(self.GAE_APPIDS) info += 'GAE Validate : %s\n' % self.GAE_VALIDATE if self.GAE_VALIDATE else '' info += 'GAE Obfuscate : %s\n' % self.GAE_OBFUSCATE if self.GAE_OBFUSCATE else '' if common.PAC_ENABLE: info += 'Pac Server : http://%s:%d/%s\n' % (self.PAC_IP if self.PAC_IP and self.PAC_IP != '0.0.0.0' else ProxyUtil.get_listen_ip(), self.PAC_PORT, self.PAC_FILE) info += 'Pac File : file://%s\n' % os.path.abspath(self.PAC_FILE) if common.PHP_ENABLE: info += 'PHP Listen : %s\n' % common.PHP_LISTEN info += 'PHP FetchServers : %s\n' % common.PHP_FETCHSERVERS if common.DNS_ENABLE: info += 'DNS Listen : %s\n' % common.DNS_LISTEN info += 'DNS Servers : %s\n' % '|'.join(common.DNS_SERVERS) info += '------------------------------------------------------\n' return info
def _ssl_wrap_socket(sock, host): if sys.version_info < (2, 7, 9): if sys.version_info >= (2, 7, 0): try: import backports.ssl except ImportError: raise RuntimeError( "In order to use secure websockets with " "Python 2.7.8 and earlier please install " " the backports.ssl package.") try: import OpenSSL assert OpenSSL except ImportError: raise RuntimeError( "Please make sure PyOpenSSL >= 0.15 is installed") try: openssl_version = OpenSSL.__version__ from distutils.version import LooseVersion assert LooseVersion(openssl_version) >= LooseVersion('0.15.0') except Exception: raise RuntimeError( "Please make sure that PyOpenSSL version is" "at least 0.15, found only {0}".format(openssl_version)) ctx = backports.ssl.SSLContext(backports.ssl.PROTOCOL_SSLv23) ctx.verify_mode = backports.ssl.CERT_REQUIRED ctx.check_hostname = True ctx.ca_file = certifi.where() else: raise RuntimeError("Python 2.6 is not supported") else: import ssl ctx = ssl.create_default_context( purpose=ssl.Purpose.SERVER_AUTH, cafile=certifi.where()) return ctx.wrap_socket(sock, server_hostname=host)
def summary(self): info = '' info += '------------------------------------------------------\n' info += 'GoAgent Version : %s (python/%s gevent/%s pyopenssl/%s)\n' % (__version__, sys.version[:5], gevent.__version__, OpenSSL.__version__) info += 'Uvent Version : %s (pyuv/%s libuv/%s)\n' % (__import__('uvent').__version__, __import__('pyuv').__version__, __import__('pyuv').LIBUV_VERSION) if all(x in sys.modules for x in ('pyuv', 'uvent')) else '' info += 'Listen Address : %s:%d\n' % (self.LISTEN_IP, self.LISTEN_PORT) info += 'Local Proxy : %s:%s\n' % (self.PROXY_HOST, self.PROXY_PORT) if self.PROXY_ENABLE else '' info += 'Debug INFO : %s\n' % self.LISTEN_DEBUGINFO if self.LISTEN_DEBUGINFO else '' info += 'GAE Mode : %s\n' % ('%s (%s)' % (self.GAE_MODE, self.GAE_SSLVERSION) if common.GAE_MODE == 'https' else self.GAE_MODE) info += 'GAE IPv6 : %s\n' % self.GAE_IPV6 if self.GAE_IPV6 else '' info += 'GAE APPID : %s\n' % '|'.join(self.GAE_APPIDS) info += 'GAE Validate : %s\n' % self.GAE_VALIDATE if self.GAE_VALIDATE else '' info += 'GAE Obfuscate : %s\n' % self.GAE_OBFUSCATE if self.GAE_OBFUSCATE else '' if common.PAC_ENABLE: info += 'Pac Server : http://%s:%d/%s\n' % (self.PAC_IP if self.PAC_IP and self.PAC_IP != '0.0.0.0' else ProxyUtil.get_listen_ip(), self.PAC_PORT, self.PAC_FILE) info += 'Pac File : file://%s\n' % os.path.abspath(self.PAC_FILE) if common.PHP_ENABLE: info += 'PHP Listen : %s\n' % common.PHP_LISTEN info += 'PHP FetchServer : %s\n' % common.PHP_FETCHSERVER if common.VPS_ENABLE: info += 'VPS Listen : %s\n' % common.VPS_LISTEN info += 'VPS FetchServer : %s\n' % common.VPS_FETCHSERVER if common.DNS_ENABLE: info += 'DNS Listen : %s\n' % common.DNS_LISTEN info += 'DNS Servers : %s\n' % '|'.join(common.DNS_SERVERS) info += '------------------------------------------------------\n' return info
def info(): """Generate information for a bug report.""" try: platform_info = { 'system': platform.system(), 'release': platform.release(), } except IOError: platform_info = { 'system': 'Unknown', 'release': 'Unknown', } implementation_info = _implementation() urllib3_info = {'version': urllib3.__version__} chardet_info = {'version': chardet.__version__} pyopenssl_info = { 'version': None, 'openssl_version': '', } if OpenSSL: pyopenssl_info = { 'version': OpenSSL.__version__, 'openssl_version': '%x' % OpenSSL.SSL.OPENSSL_VERSION_NUMBER, } cryptography_info = { 'version': getattr(cryptography, '__version__', ''), } idna_info = { 'version': getattr(idna, '__version__', ''), } # OPENSSL_VERSION_NUMBER doesn't exist in the Python 2.6 ssl module. system_ssl = getattr(ssl, 'OPENSSL_VERSION_NUMBER', None) system_ssl_info = { 'version': '%x' % system_ssl if system_ssl is not None else '' } return { 'platform': platform_info, 'implementation': implementation_info, 'system_ssl': system_ssl_info, 'using_pyopenssl': pyopenssl is not None, 'pyOpenSSL': pyopenssl_info, 'urllib3': urllib3_info, 'chardet': chardet_info, 'cryptography': cryptography_info, 'idna': idna_info, 'requests': { 'version': requests_version, }, }
def info(): """Generate information for a bug report.""" try: platform_info = { 'system': platform.system(), 'release': platform.release(), } except IOError: platform_info = { 'system': 'Unknown', 'release': 'Unknown', } implementation_info = _implementation() urllib3_info = {'version': urllib3.__version__} chardet_info = {'version': chardet.__version__} pyopenssl_info = { 'version': None, 'openssl_version': '', } if OpenSSL: pyopenssl_info = { 'version': OpenSSL.__version__, 'openssl_version': '%x' % OpenSSL.SSL.OPENSSL_VERSION_NUMBER, } cryptography_info = { 'version': getattr(cryptography, '__version__', ''), } return { 'platform': platform_info, 'implementation': implementation_info, 'system_ssl': { 'version': '%x' % ssl.OPENSSL_VERSION_NUMBER, }, 'using_pyopenssl': pyopenssl is not None, 'pyOpenSSL': pyopenssl_info, 'urllib3': urllib3_info, 'chardet': chardet_info, 'cryptography': cryptography_info, 'requests': { 'version': requests_version, }, }
def info(): """Generate information for a bug report.""" try: platform_info = { 'system': platform.system(), 'release': platform.release(), } except IOError: platform_info = { 'system': 'Unknown', 'release': 'Unknown', } implementation_info = _implementation() urllib3_info = {'version': urllib3.__version__} chardet_info = {'version': chardet.__version__} pyopenssl_info = { 'version': None, 'openssl_version': '', } if OpenSSL: pyopenssl_info = { 'version': OpenSSL.__version__, 'openssl_version': '%x' % OpenSSL.SSL.OPENSSL_VERSION_NUMBER, } cryptography_info = { 'version': getattr(cryptography, '__version__', ''), } # OPENSSL_VERSION_NUMBER doesn't exist in the Python 2.6 ssl module. system_ssl = getattr(ssl, 'OPENSSL_VERSION_NUMBER', None) system_ssl_info = { 'version': '%x' % system_ssl if system_ssl is not None else '' } return { 'platform': platform_info, 'implementation': implementation_info, 'system_ssl': system_ssl_info, 'using_pyopenssl': pyopenssl is not None, 'pyOpenSSL': pyopenssl_info, 'urllib3': urllib3_info, 'chardet': chardet_info, 'cryptography': cryptography_info, 'requests': { 'version': requests_version, }, }