46

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


我需要pip install cryptography在运行 Alpine Linux 的 Docker 容器中使用。实际上,它是另一个模块,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 年 3 月 1 日(昨天)发布,alpine 软件包已经更新到该版本。会不会和这个有关?

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

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

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

4

5 回答 5

74

对于那些仍然遇到像这样cryptography==2.1.4Alpine 3.7中安装问题的人:

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

解决方案

在 Alpine 容器中安装这些依赖项:

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

要使用Dockerfile安装这些依赖项:

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

参考

在 Alpine 上的安装说明cryptography可以在这里找到:

以下是相关部分:

在 Linux 上构建密码学

[跳过非 Alpine Linux 的部分] ...</p>

$ pip install cryptography

如果你在 Alpine 上或者只是想自己编译它,那么 cryptography需要一个编译器、Python 的头文件(如果你不使用pypy),以及 OpenSSL 的头文件和libffi系统上可用的库。

高山

如果您使用的是 Python 2,请替换python3-dev为。python-dev

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

如果您遇到错误,openssl-dev您可能必须使用libressl-dev.

于 2018-11-30T17:43:23.920 回答
14

If it fails because of Rust version, then following is recommended in cryptography's docs:

The Rust available by default in Alpine < 3.12 is older than the 
minimum supported version. See the Rust installation instructions
 for information about installing a newer Rust.
$ sudo apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo

in my case, python3.8-alpine, adding cargo resolved.

于 2021-04-30T18:52:23.037 回答
0

或者使用构建基础:

RUN apk add --no-cache --upgrade --virtual .build-deps build-base

详细信息:https ://git.alpinelinux.org/aports/tree/main/build-base/APKBUILD?h=3.3-stable

于 2021-07-22T03:12:21.630 回答
0

安装前添加:

RUN apk -U upgrade

RUN apk add --no-cache libffi-dev openssl-dev

于 2021-01-18T16:47:40.473 回答
-1

检查您是否正在构建正确的架构!

x86-64 或 amd64 架构运行类似的软件,另一类是 aarch64 或 arm 架构芯片,如 Apple Silicon M1 或您的手机 cpu

于 2021-10-23T23:03:39.610 回答