Skip to content

Commit 637dc59

Browse files
Garvit ShahGarvit Shah
Garvit Shah
authored and
Garvit Shah
committed
updated docker file to use openssl3
1 parent 33d5fd4 commit 637dc59

File tree

1 file changed

+87
-25
lines changed

1 file changed

+87
-25
lines changed

docker/Dockerfile

+87-25
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,127 @@
11
# Multi-stage build: First the full builder image:
22

3-
# liboqs build type variant; maximum portability of image; no openssl dependency:
4-
ARG LIBOQS_BUILD_DEFINES="-DOQS_DIST_BUILD=ON -DBUILD_SHARED_LIBS=ON -DOQS_USE_OPENSSL=OFF"
3+
# define the liboqs tag to be used
4+
ARG LIBOQS_TAG=main
55

6-
# make build arguments: Adding -j here speeds up build but may tax hardware
7-
ARG MAKE_DEFINES="-j 2"
6+
# define the oqsprovider tag to be used
7+
ARG OQSPROVIDER_TAG=main
88

9-
FROM alpine:3.16 as intermediate
9+
# Default location where all binaries wind up:
10+
ARG INSTALLDIR=/opt/oqssa
11+
12+
# liboqs build type variant; maximum portability of image:
13+
ARG LIBOQS_BUILD_DEFINES="-DOQS_DIST_BUILD=ON -DBUILD_SHARED_LIBS=ON"
14+
15+
# Default root CA signature algorithm; can be set to any listed at https://github.com/open-quantum-safe/oqs-provider#algorithms
16+
ARG SIG_ALG="dilithium2"
17+
18+
# Default KEM algorithms; can be set to any listed at https://github.com/open-quantum-safe/oqs-provider#algorithms
19+
ARG DEFAULT_GROUPS="x25519:x448:kyber512:p256_kyber512:kyber768:p384_kyber768:kyber1024:p521_kyber1024"
20+
21+
# Define the degree of parallelism when building the image; leave the number away only if you know what you are doing
22+
ARG MAKE_DEFINES="-j 4"
23+
24+
ARG PYTHON_VERSION=3.11.0
25+
26+
FROM alpine:latest as intermediate
1027
# Take in all global args
28+
ARG LIBOQS_TAG
29+
ARG OQSPROVIDER_TAG
30+
ARG INSTALLDIR
1131
ARG LIBOQS_BUILD_DEFINES
32+
ARG SIG_ALG
33+
ARG DEFAULT_GROUPS
1234
ARG MAKE_DEFINES
1335

14-
LABEL version="2"
36+
LABEL version="4"
1537

16-
ENV DEBIAN_FRONTEND noninteractive
38+
ENV DEBIAN_FRONTEND=noninteractive
1739

1840
RUN apk update && apk upgrade
1941

2042
# Get all software packages required for builing all components:
21-
RUN apk add build-base linux-headers cmake ninja git
43+
RUN apk add build-base linux-headers \
44+
libffi-dev zlib-dev xz-dev bzip2-dev \
45+
libtool automake autoconf cmake ninja \
46+
make \
47+
openssl3 openssl3-dev \
48+
git wget \
49+
py3-pip python3
2250

2351
# get all sources
2452
WORKDIR /opt
25-
RUN git clone --depth 1 --branch main https://github.com/open-quantum-safe/liboqs && \
26-
git clone --depth 1 --branch main https://github.com/open-quantum-safe/liboqs-python.git
53+
RUN git clone --depth 1 --branch ${LIBOQS_TAG} https://github.com/open-quantum-safe/liboqs && \
54+
git clone --depth 1 --branch master https://github.com/openssl/openssl.git && \
55+
git clone --depth 1 --branch ${OQSPROVIDER_TAG} https://github.com/open-quantum-safe/oqs-provider.git && \
56+
git clone https://github.com/gobbledy-gook/liboqs-python.git
2757

28-
# build liboqs
58+
59+
# build liboqs
2960
WORKDIR /opt/liboqs
30-
RUN mkdir build && cd build && cmake -GNinja .. ${LIBOQS_BUILD_DEFINES} && ninja install
31-
61+
RUN mkdir build && cd build && cmake -G"Ninja" .. ${LIBOQS_BUILD_DEFINES} -DCMAKE_INSTALL_PREFIX=${INSTALLDIR} && ninja install
62+
63+
# build OpenSSL3
64+
WORKDIR /opt/openssl
65+
RUN LDFLAGS="-Wl,-rpath -Wl,${INSTALLDIR}/lib64:${INSTALLDIR}/lib" ./config shared --prefix=${INSTALLDIR} && \
66+
make ${MAKE_DEFINES} && make install_sw install_ssldirs;
67+
68+
# set path to use 'new' openssl. Dyn libs have been properly linked in to match
69+
ENV PATH="${INSTALLDIR}/bin:${PATH}"
70+
71+
# build & install provider (and activate by default)
72+
WORKDIR /opt/oqs-provider
73+
RUN ln -s ../openssl . && cmake -DOPENSSL_ROOT_DIR=${INSTALLDIR} -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=${INSTALLDIR} -S . -B _build && cmake --build _build && cp _build/lib/oqsprovider.so ${INSTALLDIR}/lib64/ossl-modules && sed -i "s/default = default_sect/default = default_sect\noqsprovider = oqsprovider_sect/g" /opt/oqssa/ssl/openssl.cnf && sed -i "s/\[default_sect\]/\[default_sect\]\nactivate = 1\n\[oqsprovider_sect\]\nactivate = 1\n/g" /opt/oqssa/ssl/openssl.cnf && sed -i "s/providers = provider_sect/providers = provider_sect\nssl_conf = ssl_sect\n\n\[ssl_sect\]\nsystem_default = system_default_sect\n\n\[system_default_sect\]\nGroups = \$ENV\:\:DEFAULT_GROUPS\n/g" /opt/oqssa/ssl/openssl.cnf && sed -i "s/\# Use this in order to automatically load providers/\# Set default KEM groups if not set via environment variable\nKDEFAULT_GROUPS = $DEFAULT_GROUPS\n\n# Use this in order to automatically load providers/g" /opt/oqssa/ssl/openssl.cnf && sed -i "s/HOME\t\t\t= ./HOME\t\t= .\nDEFAULT_GROUPS\t= ${DEFAULT_GROUPS}/g" /opt/oqssa/ssl/openssl.cnf
74+
75+
# Building Python using OPENSSL3
76+
# WORKDIR /usr/local
77+
# RUN wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz
78+
# RUN tar -xzf Python-3.11.0.tgz
79+
# RUN cd Python-3.11.0 && ./configure --with-openssl=${INSTALLDIR} --with-openssl-rpath=${INSTALLDIR}/lib64 --enable-optimizations && \
80+
# make && make altinstall
81+
# # Check where Python is installed
82+
# RUN echo "Checking installed binaries:" && ls -l /usr/local/bin && ls -l /usr/bin
83+
# generate certificates for openssl s_server, which is what we will test curl against
84+
ENV OPENSSL=${INSTALLDIR}/bin/openssl
85+
ENV OPENSSL_CONF=${INSTALLDIR}/ssl/openssl.cnf
86+
87+
88+
# Download and integrate LetsEncrypt Root CA to CA bundle
3289
WORKDIR /opt
33-
RUN git clone --depth 1 --branch OQS-OpenSSL_1_1_1-stable https://github.com/open-quantum-safe/openssl.git && cd liboqs && mkdir build-openssl && cd build-openssl && cmake -G"Ninja" .. ${LIBOQS_BUILD_DEFINES} -DCMAKE_INSTALL_PREFIX=/opt/openssl/oqs && ninja install
34-
35-
RUN apk add automake autoconf && cd /opt/openssl && LDFLAGS="-Wl,-rpath -Wl,/usr/local/lib64" ./Configure shared linux-x86_64 -lm && make ${MAKE_DEFINES} && make install_sw
36-
37-
# Get LetsEncrypt root
3890
RUN wget https://letsencrypt.org/certs/isrgrootx1.pem
3991

92+
4093
## second stage: Only create minimal image without build tooling and intermediate build results generated above:
41-
FROM alpine:3.16
94+
FROM alpine:latest
95+
# Take in all global args
96+
ARG INSTALLDIR
97+
ARG SIG_ALG
4298

43-
# Get all software packages required for running all components:
44-
RUN apk update && apk upgrade && apk add python3
99+
RUN apk update && apk upgrade
100+
RUN apk add py3-pip python3
45101

46-
# Only retain the binary contents in the final image
102+
# Only retain the ${INSTALLDIR} contents in the final image
103+
COPY --from=intermediate ${INSTALLDIR} ${INSTALLDIR}
47104
COPY --from=intermediate /usr/local /usr/local
48105
COPY --from=intermediate /opt/liboqs-python /opt/liboqs-python
49106

107+
# set path to use 'new' openssl. Dyn libs have been properly linked in to match
108+
ENV PATH="${INSTALLDIR}/bin:${PATH}"
50109
ENV PYTHONPATH=/opt/liboqs-python
51110

111+
# generate certificates for openssl s_server, which is what we will test curl against
112+
ENV OPENSSL=${INSTALLDIR}/bin/openssl
113+
ENV OPENSSL_CONF=${INSTALLDIR}/ssl/openssl.cnf
114+
52115
# Install liboqs-python
53116
RUN cd /opt/liboqs-python && python3 setup.py install
54117

55-
# Enable a normal user
56118
RUN addgroup -g 1000 -S oqs && adduser --uid 1000 -S oqs -G oqs
57119

58120
USER oqs
59121
WORKDIR /home/oqs
60-
COPY minitest.py /home/oqs/minitest.py
122+
COPY ./liboqs-python/docker/minitest.py /home/oqs/minitest.py
61123
COPY --from=intermediate /opt/isrgrootx1.pem /home/oqs/isrgrootx1.pem
62124

63125
# ensure oqs libs are found. Unset if interested in using stock openssl:
64-
ENV LD_LIBRARY_PATH=/usr/local/lib64
126+
ENV LD_LIBRARY_PATH=${INSTALLDIR}/lib64
65127
CMD ["python3", "minitest.py"]

0 commit comments

Comments
 (0)