【问题标题】:"OpenSSL: EC_KEY_generate_key FAIL ... error:00000000:lib(0):func(0):reason(0)" on pyelliptic.ECC()pyelliptic.ECC() 上的“OpenSSL:EC_KEY_generate_key FAIL ... 错误:00000000:lib(0):func(0):reason(0)”
【发布时间】:2017-01-23 19:27:09
【问题描述】:

我在使用pyelliptic(下面给出的版本)时遇到上述错误。

触发它的python代码:

print("Salt: %s" % salt)
server_key = pyelliptic.ECC(curve="prime256v1")  # ----->> Line2
print("Server_key: %s" % server_key)   # ----->> Line3
server_key_id = base64.urlsafe_b64encode(server_key.get_pubkey()[1:])

"Salt: ..." 消息显示正常,错误在 pyelliptic.ECC() 调用中。

追溯:

File "/usr/local/lib/python2.7/dist-packages/pyelliptic/ecc.py", line 89, in __init__
self.privkey, self.pubkey_x, self.pubkey_y = self._generate()
File "/usr/local/lib/python2.7/dist-packages/pyelliptic/ecc.py", line 231, in _generate
raise Exception("[OpenSSL] EC_KEY_generate_key FAIL ... " + OpenSSL.get_error())

我得到的错误是(第二个可能相关也可能不相关):

  1. Exception('[OpenSSL] EC_KEY_generate_key FAIL ... error:00000000:lib(0):func(0):reason(0)',) (参考文件链接:https://github.com/yann2192/pyelliptic/blob/master/pyelliptic/ecc.py#L214
  2. extern "Python": function Cryptography_rand_bytes() called, but @ffi.def_extern() was not called in the current subinterpreter. Returning 0.

Requirements.txt(部分):

setuptools==27.1.2
cryptography==1.5
pyelliptic==1.5.7
pyOpenSSL==16.1.0

https://github.com/yann2192/pyelliptic/issues/39 表示pyelliptic v1.5.7 与旧版本存在一些问题(不确定这是否适用于此处)。

其他详情:

Python 版本:2.7。

仅在 Google Compute Engine VM 实例上出现此错误。

在本地开发服务器上运行良好。 在 python shell 中也能正常工作 Google Compute Engine VM。

(问题是'EntryPoint' object has no attribute 'resolve' when using Google Compute Engine的后续,讨论可能有用)

【问题讨论】:

  • 好的,我们开始吧。你说你得到一个异常,但代码并没有停止?是否执行了以下行 (print("Server_key:<...>)?如果“错误”实际上是 Django 错误日志条目,here's how you include a stacktrace into it.
  • 代码停在 Line2 本身。 Line3 根本不执行。 (实际上有时,可能 10 次中有 1 次,这段代码执行得非常好,完全没有任何错误)
  • 这意味着第二个错误是由一些不相关的代码块产生的(它可能是也可能不是第一个的结果),因此堆栈跟踪在这里最有帮助。
  • 解决第一个错误的最简单方法是在pdb 下运行整个 Django,在故障线路上中断并调查发生了什么。只有你能做到;但我会尝试在此处重现该问题。
  • 我不确定如何在 pdb 下运行整个 django,因为代码是从浏览器的“执行”按钮执行的。此外,这个问题似乎不是因为 Python 代码。这似乎是与 pyelliptic 库和其他一些相关软件包有关的问题。

标签: python django google-compute-engine


【解决方案1】:

刚刚添加了以下内容:WSGIApplicationGroup %{GLOBAL}

/etc/apache2/sites-available/default-ssl.conf 文件中,所有这些错误都得到了解决。

【讨论】:

  • 没有得到您想要表达的确切内容?如果可能的话,你能用简单的话解释一下吗? :P
  • 你给makes the code run in the main interpreter instance的行。这意味着根本原因是pyelliptic 与 CPython 的子解释器架构不兼容(这并不意味着它很糟糕,CPython 功能目前相当不完整,甚至几乎没有文档记录)。这里的要点是,这个解决方案也可以应用于许多其他 C 扩展。
猜你喜欢
  • 2016-04-01
  • 2016-12-12
  • 1970-01-01
  • 1970-01-01
  • 2016-03-03
  • 2018-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多