在基于Alpine的Docker镜像中,未使用oscrypto库找到libcrypto



我得到的错误与->找不到库libcrypto

我理解这个问题,但我想不出解决办法。我需要更新lambda配置还是需要升级Python库?

PFB我的需求.txt文件

cryptography==36.0.2
botocore==1.20.0
azure-storage-blob==2.1.0
azure-storage-common==2.1.0
boto3==1.17.0
asn1crypto==1.5.1
certifi==2022.9.14
cffi==1.15.1
charset-normalizer==2.1.1
filelock==3.8.0
idna==3.4
oscrypto==1.3.0
pycparser==2.21
pycryptodomex==3.15.0
PyJWT==2.5.0
pyOpenSSL==22.0.0
pytz==2022.2.1
requests==2.28.1
typing_extensions==4.3.0
urllib3==1.26.12

我的docker文件-

FROM python:3.9-alpine3.16
COPY requirements.txt requirements.txt
RUN apk --update --no-cache add --virtual build-dependencies gcc python3-dev musl-dev libc-dev linux-headers libxslt-dev libxml2-dev py-pip ca-certificates wget libffi-dev openssl-dev python3-dev expat==2.4.9-r0 py-pip build-base zlib zlib-dev libressl libressl-dev 
&& apk add python3 make g++ 
&& pip install --upgrade pip 
&& pip install --upgrade pip setuptools 
&& pip install -r requirements.txt 
&& apk del build-dependencies
RUN pip install snowflake-connector-python==2.8.0 --no-use-pep517
RUN python -c 'from oscrypto import asymmetric'

使用上面的Dockerfile尝试docker build会导致失败

Step 4/4 : RUN python -c 'from oscrypto import asymmetric'
---> Running in dc8f8b8920ac
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/oscrypto/asymmetric.py", line 19, in <module>
from ._asymmetric import _unwrap_private_key_info
File "/usr/local/lib/python3.9/site-packages/oscrypto/_asymmetric.py", line 27, in <module>
from .kdf import pbkdf1, pbkdf2, pkcs12_kdf
File "/usr/local/lib/python3.9/site-packages/oscrypto/kdf.py", line 9, in <module>
from .util import rand_bytes
File "/usr/local/lib/python3.9/site-packages/oscrypto/util.py", line 14, in <module>
from ._openssl.util import rand_bytes
File "/usr/local/lib/python3.9/site-packages/oscrypto/_openssl/util.py", line 6, in <module>
from ._libcrypto import libcrypto, libcrypto_version_info, handle_openssl_error
File "/usr/local/lib/python3.9/site-packages/oscrypto/_openssl/_libcrypto.py", line 9, in <module>
from ._libcrypto_cffi import (
File "/usr/local/lib/python3.9/site-packages/oscrypto/_openssl/_libcrypto_cffi.py", line 27, in <module>
raise LibraryNotFoundError('The library libcrypto could not be found')
oscrypto.errors.LibraryNotFoundError: The library libcrypto could not be found
The command '/bin/sh -c python -c 'from oscrypto import asymmetric'' returned a non-zero code: 1

异常发生在https://github.com/wbond/oscrypto/blob/1.3.0/oscrypto/_openssl/_libcrypto_cffi.py

通过oscrypto._ffi跟踪,问题归结为使用ctypes库打开libcrypto的问题:

>>> import ctypes.util
>>> ctypes.util.find_library('crypto')
>>>

为什么?因为/usr/lib只有libcrypto.so.1.1,而没有指向它的libcrypto.so符号链接。只需在Dockerfile中添加一行即可轻松修复:

RUN ln -s libcrypto.so.1.1 /usr/lib/libcrypto.so

之后Python的ctypes的行为:

>>> from ctypes.util import find_library
>>> find_library('crypto')
'libcrypto.so.1.1'

oscrypto:也是如此

>>> from oscrypto import asymmetric
>>>

根据oscrypto文档,您应该使用相应.so文件的libcryptolibssl路径调用oscrypto.use_openssl()

oscrypto.use_openssl(libcrypto_path="/usr/lib/libcrypto.so", libssl_path="/usr/lib/libssl.so")

相关内容

  • 没有找到相关文章

最新更新