-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Dave Kelsey <[email protected]>
- Loading branch information
Showing
3 changed files
with
127 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
# This Dockerfile is made by Chia-Chin Chung <[email protected]> | ||
# Multi-stage build | ||
# Original Dockerfile made by Chia-Chin Chung <[email protected]> | ||
# Multi-stage build: First the full builder image: | ||
|
||
# Global build arguments: | ||
# define the openssl tag to be used | ||
ARG OPENSSL_TAG=openssl-3.3.2 | ||
|
||
# define the installation paths | ||
ARG SOURCE_PATH="/usr/local/src" | ||
ARG OPENSSL_LIB_PATH="/usr/local/ssl" | ||
# define the liboqs tag to be used | ||
ARG LIBOQS_TAG=0.11.0 | ||
|
||
# define the oqsprovider tag to be used | ||
ARG OQSPROVIDER_TAG=0.7.0 | ||
|
||
# Default location where all binaries wind up: | ||
ARG INSTALLDIR=/opt/oqssa | ||
|
||
# liboqs build type variant; maximum portability of image: | ||
ARG LIBOQS_BUILD_DEFINES="-DOQS_DIST_BUILD=ON" | ||
|
||
# openssl build defines (https://github.com/open-quantum-safe/openssl#build-options) | ||
ARG OPENSSL_BUILD_DEFINES="-DOQS_DEFAULT_GROUPS=kyber512:X25519:p384_kyber768" | ||
# Default KEM algorithms to be utilized | ||
ARG KEM_ALGLIST="kyber768:p384_kyber768" | ||
|
||
# define the QSC signature algorithm used for the certificates | ||
ARG SIG_ALG="dilithium2" | ||
# Default Signature algorithm to be used | ||
ARG SIG_ALG="dilithium3" | ||
|
||
ARG MOSQUITTO_TAG=v2.0.20 | ||
|
||
# define IP addresses or Domain Name | ||
ARG BROKER_IP=localhost | ||
|
@@ -24,57 +32,83 @@ ARG SUB_IP=localhost | |
# choose the shell script(simple example) | ||
ARG EXAMPLE=broker-start.sh | ||
|
||
|
||
# First stage: the full build image: | ||
|
||
FROM ubuntu:20.04 AS builder | ||
# FROM debian:buster AS builder | ||
FROM ubuntu:22.04 AS builder | ||
|
||
# Set timezone | ||
ENV TZ=Asia/Taipei | ||
ARG TZ=Europe/London | ||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
ARG SOURCE_PATH | ||
ARG OPENSSL_LIB_PATH | ||
ARG OPENSSL_TAG | ||
ARG LIBOQS_TAG | ||
ARG OQSPROVIDER_TAG | ||
ARG INSTALLDIR | ||
ARG HAPROXYDIR | ||
ARG LIBOQS_BUILD_DEFINES | ||
ARG OPENSSL_BUILD_DEFINES | ||
ARG KEM_ALGLIST | ||
ARG MOSQUITTO_TAG | ||
|
||
# Update image and install all prerequisites | ||
RUN apt update && apt install build-essential vim cmake gcc libtool libssl-dev make ninja-build git doxygen \ | ||
libcjson1 libcjson-dev uthash-dev libcunit1-dev libsqlite3-dev xsltproc docbook-xsl -y && apt clean | ||
|
||
# Get the fork of OQS-OpenSSL_1_1_1-stable | ||
WORKDIR $SOURCE_PATH | ||
RUN git clone --depth 1 --branch OQS-OpenSSL_1_1_1-stable https://github.com/open-quantum-safe/openssl.git OQS-OpenSSL | ||
|
||
# Get and build liboqs, then install it into a subdirectory inside the OQS-OpenSSL folder | ||
RUN git clone --depth 1 --branch main https://github.com/open-quantum-safe/liboqs.git liboqs && \ | ||
cd liboqs && mkdir build && cd build && \ | ||
cmake -GNinja $LIBOQS_BUILD_DEFINES -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$SOURCE_PATH/OQS-OpenSSL/oqs .. && \ | ||
ninja && ninja install && echo "liboqs installed successfully" || exit 1 | ||
|
||
# Build and install OQS-OpenSSL_1_1_1-stable | ||
WORKDIR $SOURCE_PATH/OQS-OpenSSL | ||
## OS type: x86_64, aarch64 | ||
RUN ./Configure shared linux-x86_64 -lm --prefix=$OPENSSL_LIB_PATH/ \ | ||
--openssldir=$OPENSSL_LIB_PATH/ $OPENSSL_BUILD_DEFINES && \ | ||
make -j$(nproc) && make install && echo "OQS-OpenSSL installed successfully" || exit 1 | ||
# RUN ./Configure shared no-asm linux-aarch64 -lm --prefix=$OPENSSL_LIB_PATH/ \ | ||
# --openssldir=$OPENSSL_LIB_PATH/ $OPENSSL_BUILD_DEFINES && \ | ||
# make -j$(nproc) && make install && echo "OQS-OpenSSL installed successfully" || exit 1 | ||
RUN apt update && apt install -y build-essential \ | ||
cmake \ | ||
gcc \ | ||
libtool \ | ||
libssl-dev \ | ||
make \ | ||
ninja-build \ | ||
git \ | ||
doxygen \ | ||
libcjson1 \ | ||
libcjson-dev \ | ||
uthash-dev \ | ||
libcunit1-dev \ | ||
libsqlite3-dev \ | ||
xsltproc \ | ||
docbook-xsl && \ | ||
apt clean | ||
|
||
# get all sources | ||
WORKDIR /opt | ||
RUN git clone --depth 1 --branch ${LIBOQS_TAG} https://github.com/open-quantum-safe/liboqs && \ | ||
git clone --depth 1 --branch ${OPENSSL_TAG} https://github.com/openssl/openssl.git && \ | ||
git clone --depth 1 --branch ${OQSPROVIDER_TAG} https://github.com/open-quantum-safe/oqs-provider.git && \ | ||
git clone --depth 1 --branch ${MOSQUITTO_TAG} https://github.com/eclipse/mosquitto.git | ||
|
||
# build liboqs | ||
WORKDIR /opt/liboqs | ||
RUN mkdir build && cd build && \ | ||
cmake -G"Ninja" .. ${LIBOQS_BUILD_DEFINES} -DCMAKE_INSTALL_PREFIX=${INSTALLDIR} && \ | ||
ninja install | ||
|
||
# build OpenSSL3 | ||
WORKDIR /opt/openssl | ||
RUN LDFLAGS="-Wl,-rpath -Wl,${INSTALLDIR}/lib64" ./config shared --prefix=${INSTALLDIR} && \ | ||
make -j $(nproc) && \ | ||
make install_sw install_ssldirs && \ | ||
if [ -d ${INSTALLDIR}/lib64 ]; then ln -s ${INSTALLDIR}/lib64 ${INSTALLDIR}/lib; fi && \ | ||
if [ -d ${INSTALLDIR}/lib ]; then ln -s ${INSTALLDIR}/lib ${INSTALLDIR}/lib64; fi | ||
|
||
# set path to use 'new' openssl. Dyn libs have been properly linked in to match | ||
ENV PATH="${INSTALLDIR}/bin:${PATH}" | ||
|
||
# build & install provider (and activate by default) | ||
WORKDIR /opt/oqs-provider | ||
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 = ${KEM_ALGLIST}\n/g" /opt/oqssa/ssl/openssl.cnf | ||
|
||
# Build and install Mosquitto | ||
WORKDIR $SOURCE_PATH | ||
RUN git clone -b master https://github.com/eclipse/mosquitto.git mosquitto && cd mosquitto && \ | ||
make -j$(nproc) && make install && echo "Mosquitto installed successfully" || exit 1 | ||
|
||
WORKDIR /opt/mosquitto | ||
RUN make -j$(nproc) && \ | ||
make install | ||
|
||
# Second stage: Only create minimal image: | ||
FROM ubuntu:22.04 | ||
RUN apt update && apt install -y libcjson1 | ||
|
||
FROM ubuntu:20.04 | ||
# FROM debian:buster | ||
|
||
ARG OPENSSL_LIB_PATH | ||
ARG SIG_ALG | ||
ENV SIG_ALG=${SIG_ALG} | ||
ARG BROKER_IP | ||
|
@@ -86,37 +120,38 @@ ENV SUB_IP=${SUB_IP} | |
ARG EXAMPLE | ||
ENV EXAMPLE=${EXAMPLE} | ||
|
||
# Set the TLS_DEFAULT_GROUPS environment variable to permit selection of QSC KEMs(https://github.com/open-quantum-safe/openssl#build-options) | ||
ENV TLS_DEFAULT_GROUPS="kyber512" | ||
ARG KEM_ALGLIST | ||
# Set the TLS_DEFAULT_GROUPS environment variable to permit selection of QSC KEMs, by default the ones associated with the openssl configuration are chosen | ||
ENV TLS_DEFAULT_GROUPS=${KEM_ALGLIST} | ||
|
||
ARG INSTALLDIR | ||
|
||
# Copy files from the local storage to a destination in the Docker image | ||
WORKDIR / | ||
RUN mkdir test | ||
ADD . /test | ||
RUN chmod 777 /test/* && sed -i 's/\r//' /test/* | ||
|
||
# Only keep the necessary library contents in the final image | ||
# OQS-OpenSSL | ||
COPY --from=builder $OPENSSL_LIB_PATH $OPENSSL_LIB_PATH | ||
# openssl | ||
COPY --from=builder ${INSTALLDIR} ${INSTALLDIR} | ||
# Mosquitto | ||
COPY --from=builder /usr/local/lib /usr/local/lib | ||
COPY --from=builder /usr/local/bin /usr/local/bin | ||
COPY --from=builder /usr/local/sbin /usr/local/sbin | ||
COPY --from=builder /lib/x86_64-linux-gnu/libcjson.so.1 /lib/x86_64-linux-gnu | ||
|
||
# Dynamically link to mosquitto | ||
RUN ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1 && ldconfig | ||
|
||
# Dynamically link to OQS-OpenSSL library | ||
ENV LD_LIBRARY_PATH=$OPENSSL_LIB_PATH/lib | ||
# Dynamically link to Newly built OpenSSL | ||
ENV LD_LIBRARY_PATH=$INSTALLDIR/lib64 | ||
|
||
# Set path | ||
ENV PATH="/usr/local/bin:/usr/local/sbin:$OPENSSL_LIB_PATH/bin:$PATH" | ||
# Set path | ||
ENV PATH="/usr/local/bin:/usr/local/sbin:${INSTALLDIR}/bin:$PATH" | ||
|
||
# Generate the CA key and the cert | ||
RUN openssl req -x509 -new -newkey $SIG_ALG -keyout /test/CA.key -out /test/CA.crt -nodes -subj "/O=test-ca" -days 3650 | ||
|
||
# MQTTS port | ||
# MQTTS port | ||
EXPOSE 8883 | ||
|
||
# Run shell script | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters