不能在Docker Alpine Linux 3.3中使用OpenSSL 1.0.2g和Python 2.7“pip安装加密”

问题描述 投票:11回答:1

解决了哇,这些家伙很快......基本上就是这个https://github.com/pyca/cryptography/issues/2750原来,openssl的安全更新被发布了(DROWN Attack),而且这个更新包含一个意外的功能签名变化导致了不兼容性,所以这只是运气不好我。


我需要在运行Alpine Linux的Docker容器中使用pip install cryptography。实际上,它是另一个模块,service_identity,但问题在于cryptography模块,这是一个依赖。

我有以下Dockerfile

FROM alpine:3.3

RUN apk --update add build-base libffi-dev openssl-dev python-dev py-pip
RUN pip install cryptography

失败,出现以下错误

generating cffi module 'build/temp.linux-x86_64-2.7/_openssl.c'
building '_openssl' extension
creating build/temp.linux-x86_64-2.7/build
creating build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7
gcc -fno-strict-aliasing -Os -fomit-frame-pointer -DNDEBUG -Os -fomit-frame-pointer -fPIC -I/usr/include/python2.7 -c build/temp.linux-x86_64-2.7/_openssl.c -o build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7/_openssl.o
build/temp.linux-x86_64-2.7/_openssl.c:726:6: error: conflicting types for 'BIO_new_mem_buf'
 BIO *BIO_new_mem_buf(void *, int);
      ^
In file included from /usr/include/openssl/asn1.h:65:0,
                 from build/temp.linux-x86_64-2.7/_openssl.c:434:
/usr/include/openssl/bio.h:692:6: note: previous declaration of 'BIO_new_mem_buf' was here
 BIO *BIO_new_mem_buf(const void *buf, int len);
      ^
error: command 'gcc' failed with exit status 1

openssl 1.0.2g于2016-03-01(昨天)发布,alpine软件包已经更新到该版本。它可以与此相关吗?

我该如何解决这个问题?也许我可以设置一些环境变量?

更新我一直在检查GitHub Repo for openssl,事实上BIO *BIO_new_mem_buf(void *buf, int len)openssl/bio.h在1.0.2f到1.0.2g转换期间被改为BIO *BIO_new_mem_buf(const void *buf, int len)(在https://github.com/openssl/openssl/compare/OpenSSL_1_0_2f...OpenSSL_1_0_2g中搜索“BIO_new_mem_buf”)。我不知道这个openssl/asn1.h来自哪里,这是导入过时版本的openssl/bio.h,因为它看起来不像openssl repo中的那个。有任何想法吗?

好的,我看到一些人已经在研究这个:https://github.com/pyca/cryptography/issues/2750

python linux openssl dockerfile alpine
1个回答
8
投票

在高山3.7中仍然遇到密码学问题== 2.1.4

writing manifest file 'src/cryptography.egg-info/SOURCES.txt'
running build_ext
generating cffi module 'build/temp.linux-x86_64-2.7/_padding.c'
creating build/temp.linux-x86_64-2.7
generating cffi module 'build/temp.linux-x86_64-2.7/_constant_time.c'
generating cffi module 'build/temp.linux-x86_64-2.7/_openssl.c'
building '_openssl' extension
creating build/temp.linux-x86_64-2.7/build
creating build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7
gcc -fno-strict-aliasing -Os -fomit-frame-pointer -g -DNDEBUG -Os -fomit-frame-pointer -g -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/include/python2.7 -c build/temp.linux-x86_64-2.7/_openssl.c -o build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7/_openssl.o -Wconversion -Wno-error=sign-conversion
build/temp.linux-x86_64-2.7/_openssl.c:493:30: fatal error: openssl/opensslv.h: No such file or directory
 #include <openssl/opensslv.h>
                              ^
compilation terminated.
error: command 'gcc' failed with exit status 1

解:

apk add --no-cache libressl-dev musl-dev libffi-dev

例:

RUN apk add --no-cache \
        libressl-dev \
        musl-dev \
        libffi-dev \
    pip install --no-cache-dir cryptography==2.1.4 && \
    apk del libressl-dev \
        musl-dev \
        libffi-dev

应该解决它。

参考:

https://github.com/pyca/cryptography/blob/master/docs/installation.rst

如果链接过期,请注意:

$ pip install cryptography如果您在Alpine上或只是想自己编译,那么加密需要一个编译器,Python的头文件(如果你没有使用pypy),以及系统上可用的OpenSSL和libffi库的头文件。

高山

如果你使用Python 2,用python-dev替换python3-dev。

$ sudo apk add gcc musl-dev python3-dev libffi-dev openssl-dev

如果你在使用openssl-dev时出错,你可能需要使用libressl-dev

© www.soinside.com 2019 - 2024. All rights reserved.