相关文章推荐
憨厚的火腿肠  ·  [BUG]not shutting ...·  2 月前    · 
鼻子大的生姜  ·  Xp65 conda init fails ...·  1 月前    · 
刚毅的韭菜  ·  Jupyter Docker Stack ...·  1 月前    · 
彷徨的豌豆  ·  【非凡五年】宁静、和谐、美丽、智慧、安全 ...·  8 月前    · 
神勇威武的匕首  ·  拉法福音季凤文讲道 - 抖音·  2 年前    · 
傻傻的楼梯  ·  命运冠位指令神圣圆桌领域 - 抖音·  2 年前    · 
一身肌肉的蛋挞  ·  【文章】致敬大众T1,售价28.8万,松散S ...·  2 年前    · 
俊逸的肉夹馍  ·  【上汽大通MAXUS ...·  2 年前    · 
Code  ›  Libssl Segfaults on python3.6 With Threading开发者社区
python3
https://cloud.tencent.com/developer/article/1562019
睿智的大熊猫
2 年前
作者头像
happy123.me
0 篇文章

Libssl Segfaults on python3.6 With Threading

前往专栏
腾讯云
开发者社区
文档 意见反馈 控制台
首页
学习
活动
专区
工具
TVP
文章/答案/技术大牛
发布
首页
学习
活动
专区
工具
TVP
返回腾讯云官网
社区首页 > 专栏 > 乐享123 > Libssl Segfaults on python3.6 With Threading

Libssl Segfaults on python3.6 With Threading

作者头像
happy123.me
发布 于 2019-12-30 18:12:43
397 0
发布 于 2019-12-30 18:12:43
举报

openssl1.0.0 和 openssl1.0.1 使用Python3.6的绑定:

1 25

import ctypes import logging ssl_library = ctypes.cdll.LoadLibrary('libeay32.dll') except Exception: ssl_library = ctypes.cdll.LoadLibrary('libssl.so') def check_result(val, func, args): if val == 0: raise ValueError else: return ctypes.c_void_p(val) # ssl_library.EC_KEY_new.restype = ctypes.c_void_p ssl_library.EC_KEY_new_by_curve_name.restype = ctypes.c_void_p ssl_library.EC_KEY_new_by_curve_name.errcheck = check_result k = ssl_library.EC_KEY_new_by_curve_name(NID_secp256k1) if ssl_library.EC_KEY_generate_key(k) != 1: raise Exception("internal error") ssl_library.EC_KEY_free(k)

这段代码在多线程的时候会出现segmentation fault error; google一下发现 EC_KEY_generate_key 并不是线程安全的;于是:

1 18

openssl_locks = [threading.Lock() for _ in range(ssl_library.CRYPTO_num_locks())] openssl_locking_function = ctypes.CFUNCTYPE(None, ctypes.c_int, ctypes.c_int, ctypes.c_char_p, ctypes.c_int) openssl_threadid_function = ctypes.CFUNCTYPE(ctypes.c_ulong) @openssl_locking_function def openssl_lock(mode, type, file, line): if (mode & CRYPTO_LOCK) != 0: openssl_locks[type].acquire() else: openssl_locks[type].release() @openssl_threadid_function

 
推荐文章
憨厚的火腿肠  ·  [BUG]not shutting down client, client was created externally · Issue #522 · aertslab/pySCENIC · GitH
2 月前
鼻子大的生姜  ·  Xp65 conda init fails - General - ACCESS Hive Community Forum
1 月前
刚毅的韭菜  ·  Jupyter Docker Stack Advice for Mac - JupyterLab - Jupyter Community Forum
1 月前
彷徨的豌豆  ·  【非凡五年】宁静、和谐、美丽、智慧、安全 五年校园焕新蝶变-华中农业大学南湖新闻网
8 月前
神勇威武的匕首  ·  拉法福音季凤文讲道 - 抖音
2 年前
傻傻的楼梯  ·  命运冠位指令神圣圆桌领域 - 抖音
2 年前
一身肌肉的蛋挞  ·  【文章】致敬大众T1,售价28.8万,松散SS SUMMER上市_车家号_汽车之家
2 年前
俊逸的肉夹馍  ·  【上汽大通MAXUS T90新能源价格】上汽大通MAXUS T90新能源多少钱_上汽大通MAXUS T90新能源优惠多少_太平洋汽车
2 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号