1Panel使用GMSSL+Openresty实现国密/RSA单向自适应

2024-02-19 09:20

本文主要是介绍1Panel使用GMSSL+Openresty实现国密/RSA单向自适应,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本文 首发于 Anyeの小站,转载请取得作者同意。

前言

国密算法是国家商用密码算法的简称。自2012年以来,国家密码管理局以《中华人民共和国密码行业标准》的方式,陆续公布了SM2/SM3/SM4等密码算法标准及其应用规范。其中“SM”代表“商密”,即用于商用的、不涉及国家秘密的密码技术。其中SM2为基于椭圆曲线密码的公钥密码算法标准,包含数字签名、密钥交换和公钥加密,用于替换RSA/Diffie-Hellman/ECDSA/ECDH等国际算法;SM3为密码哈希算法,用于替代MD5/SHA-1/SHA-256等国际算法;SM4为分组密码,用于替代DES/AES等国际算法;SM9为基于身份的密码算法,可以替代基于数字证书的PKI/CA体系。通过部署国密算法,可以降低由弱密码和错误实现带来的安全风险和部署PKI/CA带来的开销。

——The GmSSL Project

本着学习的态度,本文将尝试为 1Panel 所使用的 Web 平台:OpenResty 来适配 GMSSL。

Demo

Anye导航站

该站点已部署国密证书,实现国密/RSA单向自适应,国密证书于2024-5-15日到期,仅供参考。

准备工作

  • 安装好 1Panel 的服务器一台
  • 优良的网络环境
  • 相关基础知识

误区说明

https://www.gmssl.cn/ 与 http://gmssl.org/ 并非同一项目,本文中所使用的为前者。

警告!!!

本教程中所使用的 openssl国密版 来自 GMSSL - 国密SSL实验室 ,免费版本每年年底失效,程序会自动退出,需更新库,重新链接。请勿用于正式/生产环境,后果自负。

正片开始

Docker 兼容

为了使自编译的 OpenResty 能够与 1Panel 的相关组件完美配合,首先得找到 1Panel所使用的 OpenResty Dockerfile,可以找到:https://github.com/openresty/docker-openresty ,找到当前版本:1.21.4.3-0-focal

# Dockerfile - Ubuntu Focal
# https://github.com/openresty/docker-openrestyARG RESTY_IMAGE_BASE="ubuntu"
ARG RESTY_IMAGE_TAG="focal"FROM ${RESTY_IMAGE_BASE}:${RESTY_IMAGE_TAG}LABEL maintainer="Evan Wies <evan@neomantra.net>"# Docker Build Arguments
ARG RESTY_IMAGE_BASE="ubuntu"
ARG RESTY_IMAGE_TAG="focal"
ARG RESTY_VERSION="1.21.4.3"
ARG RESTY_LUAROCKS_VERSION="3.9.2"
ARG RESTY_OPENSSL_VERSION="1.1.1w"
ARG RESTY_OPENSSL_PATCH_VERSION="1.1.1f"
ARG RESTY_OPENSSL_URL_BASE="https://www.openssl.org/source"
ARG RESTY_PCRE_VERSION="8.45"
ARG RESTY_PCRE_BUILD_OPTIONS="--enable-jit"
ARG RESTY_PCRE_SHA256="4e6ce03e0336e8b4a3d6c2b70b1c5e18590a5673a98186da90d4f33c23defc09"
ARG RESTY_J="1"
ARG RESTY_CONFIG_OPTIONS="\--with-compat \--with-file-aio \--with-http_addition_module \--with-http_auth_request_module \--with-http_dav_module \--with-http_flv_module \--with-http_geoip_module=dynamic \--with-http_gunzip_module \--with-http_gzip_static_module \--with-http_image_filter_module=dynamic \--with-http_mp4_module \--with-http_random_index_module \--with-http_realip_module \--with-http_secure_link_module \--with-http_slice_module \--with-http_ssl_module \--with-http_stub_status_module \--with-http_sub_module \--with-http_v2_module \--with-http_xslt_module=dynamic \--with-ipv6 \--with-mail \--with-mail_ssl_module \--with-md5-asm \--with-sha1-asm \--with-stream \--with-stream_ssl_module \--with-threads \"
ARG RESTY_CONFIG_OPTIONS_MORE=""
ARG RESTY_LUAJIT_OPTIONS="--with-luajit-xcflags='-DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT'"
ARG RESTY_PCRE_OPTIONS="--with-pcre-jit"ARG RESTY_ADD_PACKAGE_BUILDDEPS=""
ARG RESTY_ADD_PACKAGE_RUNDEPS=""
ARG RESTY_EVAL_PRE_CONFIGURE=""
ARG RESTY_EVAL_POST_DOWNLOAD_PRE_CONFIGURE=""
ARG RESTY_EVAL_POST_MAKE=""# These are not intended to be user-specified
ARG _RESTY_CONFIG_DEPS="--with-pcre \--with-cc-opt='-DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl/include' \--with-ld-opt='-L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl/lib -Wl,-rpath,/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl/lib' \"LABEL resty_image_base="${RESTY_IMAGE_BASE}"
LABEL resty_image_tag="${RESTY_IMAGE_TAG}"
LABEL resty_version="${RESTY_VERSION}"
LABEL resty_luarocks_version="${RESTY_LUAROCKS_VERSION}"
LABEL resty_openssl_version="${RESTY_OPENSSL_VERSION}"
LABEL resty_openssl_patch_version="${RESTY_OPENSSL_PATCH_VERSION}"
LABEL resty_openssl_url_base="${RESTY_OPENSSL_URL_BASE}"
LABEL resty_pcre_version="${RESTY_PCRE_VERSION}"
LABEL resty_pcre_build_options="${RESTY_PCRE_BUILD_OPTIONS}"
LABEL resty_pcre_sha256="${RESTY_PCRE_SHA256}"
LABEL resty_config_options="${RESTY_CONFIG_OPTIONS}"
LABEL resty_config_options_more="${RESTY_CONFIG_OPTIONS_MORE}"
LABEL resty_config_deps="${_RESTY_CONFIG_DEPS}"
LABEL resty_add_package_builddeps="${RESTY_ADD_PACKAGE_BUILDDEPS}"
LABEL resty_add_package_rundeps="${RESTY_ADD_PACKAGE_RUNDEPS}"
LABEL resty_eval_pre_configure="${RESTY_EVAL_PRE_CONFIGURE}"
LABEL resty_eval_post_download_pre_configure="${RESTY_EVAL_POST_DOWNLOAD_PRE_CONFIGURE}"
LABEL resty_eval_post_make="${RESTY_EVAL_POST_MAKE}"
LABEL resty_luajit_options="${RESTY_LUAJIT_OPTIONS}"
LABEL resty_pcre_options="${RESTY_PCRE_OPTIONS}"RUN DEBIAN_FRONTEND=noninteractive apt-get update \&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \build-essential \ca-certificates \curl \gettext-base \libgd-dev \libgeoip-dev \libncurses5-dev \libperl-dev \libreadline-dev \libxslt1-dev \make \perl \unzip \wget \zlib1g-dev \${RESTY_ADD_PACKAGE_BUILDDEPS} \${RESTY_ADD_PACKAGE_RUNDEPS} \&& cd /tmp \&& if [ -n "${RESTY_EVAL_PRE_CONFIGURE}" ]; then eval $(echo ${RESTY_EVAL_PRE_CONFIGURE}); fi \&& curl -fSL "${RESTY_OPENSSL_URL_BASE}/openssl-${RESTY_OPENSSL_VERSION}.tar.gz" -o openssl-${RESTY_OPENSSL_VERSION}.tar.gz \&& tar xzf openssl-${RESTY_OPENSSL_VERSION}.tar.gz \&& cd openssl-${RESTY_OPENSSL_VERSION} \&& if [ $(echo ${RESTY_OPENSSL_VERSION} | cut -c 1-5) = "1.1.1" ] ; then \echo 'patching OpenSSL 1.1.1 for OpenResty' \&& curl -s https://raw.githubusercontent.com/openresty/openresty/master/patches/openssl-${RESTY_OPENSSL_PATCH_VERSION}-sess_set_get_cb_yield.patch | patch -p1 ; \fi \&& if [ $(echo ${RESTY_OPENSSL_VERSION} | cut -c 1-5) = "1.1.0" ] ; then \echo 'patching OpenSSL 1.1.0 for OpenResty' \&& curl -s https://raw.githubusercontent.com/openresty/openresty/ed328977028c3ec3033bc25873ee360056e247cd/patches/openssl-1.1.0j-parallel_build_fix.patch | patch -p1 \&& curl -s https://raw.githubusercontent.com/openresty/openresty/master/patches/openssl-${RESTY_OPENSSL_PATCH_VERSION}-sess_set_get_cb_yield.patch | patch -p1 ; \fi \&& ./config \no-threads shared zlib -g \enable-ssl3 enable-ssl3-method \--prefix=/usr/local/openresty/openssl \--libdir=lib \-Wl,-rpath,/usr/local/openresty/openssl/lib \&& make -j${RESTY_J} \&& make -j${RESTY_J} install_sw \&& cd /tmp \&& curl -fSL https://downloads.sourceforge.net/project/pcre/pcre/${RESTY_PCRE_VERSION}/pcre-${RESTY_PCRE_VERSION}.tar.gz -o pcre-${RESTY_PCRE_VERSION}.tar.gz \&& echo "${RESTY_PCRE_SHA256}  pcre-${RESTY_PCRE_VERSION}.tar.gz" | shasum -a 256 --check \&& tar xzf pcre-${RESTY_PCRE_VERSION}.tar.gz \&& cd /tmp/pcre-${RESTY_PCRE_VERSION} \&& ./configure \--prefix=/usr/local/openresty/pcre \--disable-cpp \--enable-utf \--enable-unicode-properties \${RESTY_PCRE_BUILD_OPTIONS} \&& make -j${RESTY_J} \&& make -j${RESTY_J} install \&& cd /tmp \&& curl -fSL https://openresty.org/download/openresty-${RESTY_VERSION}.tar.gz -o openresty-${RESTY_VERSION}.tar.gz \&& tar xzf openresty-${RESTY_VERSION}.tar.gz \&& cd /tmp/openresty-${RESTY_VERSION} \&& if [ -n "${RESTY_EVAL_POST_DOWNLOAD_PRE_CONFIGURE}" ]; then eval $(echo ${RESTY_EVAL_POST_DOWNLOAD_PRE_CONFIGURE}); fi \&& eval ./configure -j${RESTY_J} ${_RESTY_CONFIG_DEPS} ${RESTY_CONFIG_OPTIONS} ${RESTY_CONFIG_OPTIONS_MORE} ${RESTY_LUAJIT_OPTIONS} ${RESTY_PCRE_OPTIONS} \&& make -j${RESTY_J} \&& make -j${RESTY_J} install \&& cd /tmp \&& rm -rf \openssl-${RESTY_OPENSSL_VERSION}.tar.gz openssl-${RESTY_OPENSSL_VERSION} \pcre-${RESTY_PCRE_VERSION}.tar.gz pcre-${RESTY_PCRE_VERSION} \openresty-${RESTY_VERSION}.tar.gz openresty-${RESTY_VERSION} \&& curl -fSL https://luarocks.github.io/luarocks/releases/luarocks-${RESTY_LUAROCKS_VERSION}.tar.gz -o luarocks-${RESTY_LUAROCKS_VERSION}.tar.gz \&& tar xzf luarocks-${RESTY_LUAROCKS_VERSION}.tar.gz \&& cd luarocks-${RESTY_LUAROCKS_VERSION} \&& ./configure \--prefix=/usr/local/openresty/luajit \--with-lua=/usr/local/openresty/luajit \--lua-suffix=jit-2.1.0-beta3 \--with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1 \&& make build \&& make install \&& cd /tmp \&& if [ -n "${RESTY_EVAL_POST_MAKE}" ]; then eval $(echo ${RESTY_EVAL_POST_MAKE}); fi \&& rm -rf luarocks-${RESTY_LUAROCKS_VERSION} luarocks-${RESTY_LUAROCKS_VERSION}.tar.gz \&& if [ -n "${RESTY_ADD_PACKAGE_BUILDDEPS}" ]; then DEBIAN_FRONTEND=noninteractive apt-get remove -y --purge ${RESTY_ADD_PACKAGE_BUILDDEPS} ; fi \&& DEBIAN_FRONTEND=noninteractive apt-get autoremove -y \&& mkdir -p /var/run/openresty \&& ln -sf /dev/stdout /usr/local/openresty/nginx/logs/access.log \&& ln -sf /dev/stderr /usr/local/openresty/nginx/logs/error.log# Add additional binaries into PATH for convenience
ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin# Add LuaRocks paths
# If OpenResty changes, these may need updating:
#    /usr/local/openresty/bin/resty -e 'print(package.path)'
#    /usr/local/openresty/bin/resty -e 'print(package.cpath)'
ENV LUA_PATH="/usr/local/openresty/site/lualib/?.ljbc;/usr/local/openresty/site/lualib/?/init.ljbc;/usr/local/openresty/lualib/?.ljbc;/usr/local/openresty/lualib/?/init.ljbc;/usr/local/openresty/site/lualib/?.lua;/usr/local/openresty/site/lualib/?/init.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/lualib/?/init.lua;./?.lua;/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/openresty/luajit/share/lua/5.1/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?/init.lua"ENV LUA_CPATH="/usr/local/openresty/site/lualib/?.so;/usr/local/openresty/lualib/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/openresty/luajit/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so;/usr/local/openresty/luajit/lib/lua/5.1/?.so"# Copy nginx configuration files
COPY nginx.conf /usr/local/openresty/nginx/conf/nginx.conf
COPY nginx.vh.default.conf /etc/nginx/conf.d/default.confCMD ["/usr/local/openresty/bin/openresty", "-g", "daemon off;"]# Use SIGQUIT instead of default SIGTERM to cleanly drain requests
# See https://github.com/openresty/docker-openresty/blob/master/README.md#tips--pitfalls
STOPSIGNAL SIGQUIT

分析后可知,我们只需替换其中的 Openssl 模块即可。

GMSSL 简述

GMSSL - 国密SSL实验室 官网为 Nginx 作出了国密支持,OpenResty 作为 Nginx 的衍生项目,理论上同样支持使用 GMSSL 提供的 openssl 国密版。所以采用同样的方式进行替换。

cd /tmp \&& curl -fSL "${RESTY_OPENSSL_URL_BASE}/gmssl_openssl_${RESTY_OPENSSL_VERSION}.tar.gz" -o gmssl_openssl_${RESTY_OPENSSL_VERSION}.tar.gz \&& tar xzfm gmssl_openssl_${RESTY_OPENSSL_VERSION}.tar.gz -C /usr/local \&& ln -s /usr/local/gmssl /usr/local/openssl \

在编译配置中添加:

ARG RESTY_CONFIG_OPTIONS="\--with-openssl=/usr/local/gmssl \

将 Nginx 目录中的 auto/lib/openssl/conf,全部 $OPENSSL/.openssl/ 修改为 $OPENSSL/ 并保存。

sed -i 's/\$OPENSSL\/\.openssl\//\$OPENSSL\//g' ./bundle/nginx-1.21.4/auto/lib/openssl/conf \

修改后的完整 Dockerfile 如下

# Dockerfile - Ubuntu Focal
# https://github.com/openresty/docker-openrestyARG RESTY_IMAGE_BASE="ubuntu"
ARG RESTY_IMAGE_TAG="focal"FROM ${RESTY_IMAGE_BASE}:${RESTY_IMAGE_TAG}LABEL maintainer="Anyexyz <anyexyz@foxmail.com>"# 构建参数
ARG RESTY_IMAGE_BASE="ubuntu"
ARG RESTY_IMAGE_TAG="focal"
ARG RESTY_VERSION="1.21.4.3"
ARG RESTY_LUAROCKS_VERSION="3.9.2"
ARG RESTY_OPENSSL_VERSION="1.1_b2024_x64_1"
ARG RESTY_OPENSSL_URL_BASE="https://www.gmssl.cn/gmssl/down/"
ARG RESTY_PCRE_VERSION="8.45"
ARG RESTY_PCRE_BUILD_OPTIONS="--enable-jit"
ARG RESTY_PCRE_SHA256="4e6ce03e0336e8b4a3d6c2b70b1c5e18590a5673a98186da90d4f33c23defc09"
ARG RESTY_J="2"
ARG RESTY_CONFIG_OPTIONS="\--with-openssl=/usr/local/gmssl \--with-compat \--with-file-aio \--with-http_addition_module \--with-http_auth_request_module \--with-http_dav_module \--with-http_flv_module \--with-http_geoip_module=dynamic \--with-http_gunzip_module \--with-http_gzip_static_module \--with-http_image_filter_module=dynamic \--with-http_mp4_module \--with-http_random_index_module \--with-http_realip_module \--with-http_secure_link_module \--with-http_slice_module \--with-http_ssl_module \--with-http_stub_status_module \--with-http_sub_module \--with-http_v2_module \--with-http_xslt_module=dynamic \--with-ipv6 \--with-mail \--with-mail_ssl_module \--with-md5-asm \--with-sha1-asm \--with-stream \--with-stream_ssl_module \--with-threads \"
ARG RESTY_CONFIG_OPTIONS_MORE=""
ARG RESTY_LUAJIT_OPTIONS="--with-luajit-xcflags='-DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT'"
ARG RESTY_PCRE_OPTIONS="--with-pcre-jit"ARG RESTY_ADD_PACKAGE_BUILDDEPS=""
ARG RESTY_ADD_PACKAGE_RUNDEPS=""
ARG RESTY_EVAL_PRE_CONFIGURE=""
ARG RESTY_EVAL_POST_DOWNLOAD_PRE_CONFIGURE=""
ARG RESTY_EVAL_POST_MAKE=""# 以下不需要修改
ARG _RESTY_CONFIG_DEPS="--with-pcre \--with-cc-opt='-DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl/include' \--with-ld-opt='-L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl/lib -Wl,-rpath,/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl/lib' \"LABEL resty_image_base="${RESTY_IMAGE_BASE}"
LABEL resty_image_tag="${RESTY_IMAGE_TAG}"
LABEL resty_version="${RESTY_VERSION}"
LABEL resty_luarocks_version="${RESTY_LUAROCKS_VERSION}"
LABEL resty_openssl_version="${RESTY_OPENSSL_VERSION}"
LABEL resty_openssl_patch_version="${RESTY_OPENSSL_PATCH_VERSION}"
LABEL resty_openssl_url_base="${RESTY_OPENSSL_URL_BASE}"
LABEL resty_pcre_version="${RESTY_PCRE_VERSION}"
LABEL resty_pcre_build_options="${RESTY_PCRE_BUILD_OPTIONS}"
LABEL resty_pcre_sha256="${RESTY_PCRE_SHA256}"
LABEL resty_config_options="${RESTY_CONFIG_OPTIONS}"
LABEL resty_config_options_more="${RESTY_CONFIG_OPTIONS_MORE}"
LABEL resty_config_deps="${_RESTY_CONFIG_DEPS}"
LABEL resty_add_package_builddeps="${RESTY_ADD_PACKAGE_BUILDDEPS}"
LABEL resty_add_package_rundeps="${RESTY_ADD_PACKAGE_RUNDEPS}"
LABEL resty_eval_pre_configure="${RESTY_EVAL_PRE_CONFIGURE}"
LABEL resty_eval_post_download_pre_configure="${RESTY_EVAL_POST_DOWNLOAD_PRE_CONFIGURE}"
LABEL resty_eval_post_make="${RESTY_EVAL_POST_MAKE}"
LABEL resty_luajit_options="${RESTY_LUAJIT_OPTIONS}"
LABEL resty_pcre_options="${RESTY_PCRE_OPTIONS}"RUN DEBIAN_FRONTEND=noninteractive apt-get update \&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \build-essential \ca-certificates \curl \gettext-base \libgd-dev \libgeoip-dev \libncurses5-dev \libperl-dev \libreadline-dev \libxslt1-dev \make \perl \unzip \wget \zlib1g-dev \${RESTY_ADD_PACKAGE_BUILDDEPS} \${RESTY_ADD_PACKAGE_RUNDEPS} \&& cd /tmp \&& curl -fSL "${RESTY_OPENSSL_URL_BASE}/gmssl_openssl_${RESTY_OPENSSL_VERSION}.tar.gz" -o gmssl_openssl_${RESTY_OPENSSL_VERSION}.tar.gz \&& tar xzfm gmssl_openssl_${RESTY_OPENSSL_VERSION}.tar.gz -C /usr/local \&& ln -s /usr/local/gmssl /usr/local/openssl \&& cd /tmp \&& curl -fSL https://downloads.sourceforge.net/project/pcre/pcre/${RESTY_PCRE_VERSION}/pcre-${RESTY_PCRE_VERSION}.tar.gz -o pcre-${RESTY_PCRE_VERSION}.tar.gz \&& echo "${RESTY_PCRE_SHA256}  pcre-${RESTY_PCRE_VERSION}.tar.gz" | shasum -a 256 --check \&& tar xzf pcre-${RESTY_PCRE_VERSION}.tar.gz \&& cd /tmp/pcre-${RESTY_PCRE_VERSION} \&& ./configure \--prefix=/usr/local/openresty/pcre \--disable-cpp \--enable-utf \--enable-unicode-properties \${RESTY_PCRE_BUILD_OPTIONS} \&& make -j${RESTY_J} \&& make -j${RESTY_J} install \&& cd /tmp \&& curl -fSL https://openresty.org/download/openresty-${RESTY_VERSION}.tar.gz -o openresty-${RESTY_VERSION}.tar.gz \&& tar xzf openresty-${RESTY_VERSION}.tar.gz \&& cd /tmp/openresty-${RESTY_VERSION} \&& sed -i 's/\$OPENSSL\/\.openssl\//\$OPENSSL\//g' ./bundle/nginx-1.21.4/auto/lib/openssl/conf \&& if [ -n "${RESTY_EVAL_POST_DOWNLOAD_PRE_CONFIGURE}" ]; then eval $(echo ${RESTY_EVAL_POST_DOWNLOAD_PRE_CONFIGURE}); fi \&& eval ./configure -j${RESTY_J} ${_RESTY_CONFIG_DEPS} ${RESTY_CONFIG_OPTIONS} ${RESTY_CONFIG_OPTIONS_MORE} ${RESTY_LUAJIT_OPTIONS} ${RESTY_PCRE_OPTIONS} \&& make -j${RESTY_J} \&& make -j${RESTY_J} install \&& cd /tmp \&& rm -rf \openssl-${RESTY_OPENSSL_VERSION}.tar.gz openssl-${RESTY_OPENSSL_VERSION} \pcre-${RESTY_PCRE_VERSION}.tar.gz pcre-${RESTY_PCRE_VERSION} \openresty-${RESTY_VERSION}.tar.gz openresty-${RESTY_VERSION} \&& curl -fSL https://luarocks.github.io/luarocks/releases/luarocks-${RESTY_LUAROCKS_VERSION}.tar.gz -o luarocks-${RESTY_LUAROCKS_VERSION}.tar.gz \&& tar xzf luarocks-${RESTY_LUAROCKS_VERSION}.tar.gz \&& cd luarocks-${RESTY_LUAROCKS_VERSION} \&& ./configure \--prefix=/usr/local/openresty/luajit \--with-lua=/usr/local/openresty/luajit \--lua-suffix=jit-2.1.0-beta3 \--with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1 \&& make build \&& make install \&& cd /tmp \&& if [ -n "${RESTY_EVAL_POST_MAKE}" ]; then eval $(echo ${RESTY_EVAL_POST_MAKE}); fi \&& rm -rf luarocks-${RESTY_LUAROCKS_VERSION} luarocks-${RESTY_LUAROCKS_VERSION}.tar.gz \&& if [ -n "${RESTY_ADD_PACKAGE_BUILDDEPS}" ]; then DEBIAN_FRONTEND=noninteractive apt-get remove -y --purge ${RESTY_ADD_PACKAGE_BUILDDEPS} ; fi \&& DEBIAN_FRONTEND=noninteractive apt-get autoremove -y \&& mkdir -p /var/run/openresty \&& ln -sf /dev/stdout /usr/local/openresty/nginx/logs/access.log \&& ln -sf /dev/stderr /usr/local/openresty/nginx/logs/error.log# Add additional binaries into PATH for convenience
ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin# Add LuaRocks paths
# If OpenResty changes, these may need updating:
#    /usr/local/openresty/bin/resty -e 'print(package.path)'
#    /usr/local/openresty/bin/resty -e 'print(package.cpath)'
ENV LUA_PATH="/usr/local/openresty/site/lualib/?.ljbc;/usr/local/openresty/site/lualib/?/init.ljbc;/usr/local/openresty/lualib/?.ljbc;/usr/local/openresty/lualib/?/init.ljbc;/usr/local/openresty/site/lualib/?.lua;/usr/local/openresty/site/lualib/?/init.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/lualib/?/init.lua;./?.lua;/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/openresty/luajit/share/lua/5.1/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?/init.lua"ENV LUA_CPATH="/usr/local/openresty/site/lualib/?.so;/usr/local/openresty/lualib/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/openresty/luajit/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so;/usr/local/openresty/luajit/lib/lua/5.1/?.so"# Copy nginx configuration files
COPY nginx.conf /usr/local/openresty/nginx/conf/nginx.conf
COPY nginx.vh.default.conf /etc/nginx/conf.d/default.confCMD ["/usr/local/openresty/bin/openresty", "-g", "daemon off;"]# Use SIGQUIT instead of default SIGTERM to cleanly drain requests
# See https://github.com/openresty/docker-openresty/blob/master/README.md#tips--pitfalls
STOPSIGNAL SIGQUIT

修改源码:https://github.com/Anyexyz/gm-docker-openresty

编译成品:https://hub.docker.com/r/anyexyz/gm-docker-openrest

1Panel 应用重建

在 1Panel 中,打开 应用商店 ,找到已安装的 OpenResty,点击 参数编辑高级设置 ,将 image 更改为自己构建/拉取的镜像,例:

image: anyexyz/gm-docker-openresty:1.21.4.3-0-focal

确认,重建应用。

申请证书

我这里选用的 CerSign 证签 的免费 SSL 证书,点击在其官网申请90天证书:

https://www.cersign.com/free-ssl-certificate.html

根据提示进行操作,我们会得到一个证书压缩包和自己生成的密钥,保存备用。

部署证书

  • 在 1Panel 网站中找到需要部署国密证书的网站,将证书和密钥上传到 网站目录 中,点击 配置 - HTTPS ,这里的 证书配置 只能选择非国密证书,在下方的 SSL 协议设置 中把 TLS 1.3、1.2、1.2;SSL V3、V2 打勾,将 加密算法 后面添加
:ECDHE-RSA-AES128-GCM-SHA256:AES128-SHA:DES-CBC3-SHA:ECC-SM4-CBC-SM3:ECC-SM4-GCM-SM3:ECC-SM4-GCM-SM2

点击保存。

  • 配置文件 中,找到 ssl_certificatessl_certificate_key 所在的位置,复制后面原有的路径,这个是在 1Panel 中配置的非国密证书的路径,类别添加国密证书配置
ssl_certificate /www/sites/<网站域名>/ssl/sm2_encrypt.crt;
ssl_certificate_key /www/sites/<网站域名>/ssl/sm2_encrypt.key;ssl_certificate /www/sites/<网站域名>/ssl/sm2_sign.crt;
ssl_certificate_key /www/sites/<网站域名>/ssl/sm2_sign.key;ssl_certificate /www/sites/<网站域名>/ssl/fullchain.pem;
ssl_certificate_key /www/sites/<网站域名>/ssl/privkey.pem; 

保存并重载。

测试

使用 零信国密浏览器 访问:
如图,即为激活国密。

请添加图片描述

再次提醒

本教程中所使用的 openssl国密版 来自 GMSSL - 国密SSL实验室 ,免费版本每年年底失效,程序会自动退出,需更新库,重新链接。

请勿用于正式/生产环境!!!

请勿用于正式/生产环境!!!

请勿用于正式/生产环境!!!

如需用于生产用途,请从正常渠道购买国密证书并寻求相关单位的帮助。

这篇关于1Panel使用GMSSL+Openresty实现国密/RSA单向自适应的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/724236

相关文章

中文分词jieba库的使用与实景应用(一)

知识星球:https://articles.zsxq.com/id_fxvgc803qmr2.html 目录 一.定义: 精确模式(默认模式): 全模式: 搜索引擎模式: paddle 模式(基于深度学习的分词模式): 二 自定义词典 三.文本解析   调整词出现的频率 四. 关键词提取 A. 基于TF-IDF算法的关键词提取 B. 基于TextRank算法的关键词提取

使用SecondaryNameNode恢复NameNode的数据

1)需求: NameNode进程挂了并且存储的数据也丢失了,如何恢复NameNode 此种方式恢复的数据可能存在小部分数据的丢失。 2)故障模拟 (1)kill -9 NameNode进程 [lytfly@hadoop102 current]$ kill -9 19886 (2)删除NameNode存储的数据(/opt/module/hadoop-3.1.4/data/tmp/dfs/na

Hadoop数据压缩使用介绍

一、压缩原则 (1)运算密集型的Job,少用压缩 (2)IO密集型的Job,多用压缩 二、压缩算法比较 三、压缩位置选择 四、压缩参数配置 1)为了支持多种压缩/解压缩算法,Hadoop引入了编码/解码器 2)要在Hadoop中启用压缩,可以配置如下参数

Makefile简明使用教程

文章目录 规则makefile文件的基本语法:加在命令前的特殊符号:.PHONY伪目标: Makefilev1 直观写法v2 加上中间过程v3 伪目标v4 变量 make 选项-f-n-C Make 是一种流行的构建工具,常用于将源代码转换成可执行文件或者其他形式的输出文件(如库文件、文档等)。Make 可以自动化地执行编译、链接等一系列操作。 规则 makefile文件

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu

使用opencv优化图片(画面变清晰)

文章目录 需求影响照片清晰度的因素 实现降噪测试代码 锐化空间锐化Unsharp Masking频率域锐化对比测试 对比度增强常用算法对比测试 需求 对图像进行优化,使其看起来更清晰,同时保持尺寸不变,通常涉及到图像处理技术如锐化、降噪、对比度增强等 影响照片清晰度的因素 影响照片清晰度的因素有很多,主要可以从以下几个方面来分析 1. 拍摄设备 相机传感器:相机传

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

让树莓派智能语音助手实现定时提醒功能

最初的时候是想直接在rasa 的chatbot上实现,因为rasa本身是带有remindschedule模块的。不过经过一番折腾后,忽然发现,chatbot上实现的定时,语音助手不一定会有响应。因为,我目前语音助手的代码设置了长时间无应答会结束对话,这样一来,chatbot定时提醒的触发就不会被语音助手获悉。那怎么让语音助手也具有定时提醒功能呢? 我最后选择的方法是用threading.Time

Android实现任意版本设置默认的锁屏壁纸和桌面壁纸(两张壁纸可不一致)

客户有些需求需要设置默认壁纸和锁屏壁纸  在默认情况下 这两个壁纸是相同的  如果需要默认的锁屏壁纸和桌面壁纸不一样 需要额外修改 Android13实现 替换默认桌面壁纸: 将图片文件替换frameworks/base/core/res/res/drawable-nodpi/default_wallpaper.*  (注意不能是bmp格式) 替换默认锁屏壁纸: 将图片资源放入vendo