.NET App accesses MSSQL to report TLS issue on Linux and Docker

1.使用.NET6开发一程式,它需要访问MSSQL,在Linux和Docker下都报:A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed)

2.初判是MSSQL版本过低,使用较旧的TLS,于是修改Linux和Docker的openssl.cnf文件。

openssl.cnf on Linux

bash 复制代码
# 1.Go to the path of openssl.cnf
  cd /etc/ssl

# 2.Backup the openssl.cnf
  sudo cp openssl.cnf openssl-bakcup.cnf

# 2.Modify the openssl.cnf
  sudo nano openssl.cnf
  #Add at the bottom of the file
    [system_default_sect]
    # CipherString = DEFAULT:@SECLEVEL=2
    MinProtocol = TLSv1
    CipherString = DEFAULT@SECLEVEL=0

openssl.cnf on Linux

bash 复制代码
# 1.Copy the openssl.cnf(/etc/ssl) of Linux to the the same directory as the Dockerfile
    sudo cp /etc/ssl/openssl.cnf {/path/to/file}

# 2.Modify Dockerfile to copy the file to Docker image.
    FROM harbor.xxx.com/dotnet/aspnet:6.0
    MAINTAINER XXX
    ENV ASPNETCORE_ENVIRONMENT=Development
    ENV TZ=Asia/Shanghai
    ENV LANG=en_US.UTF-8
    # RUN sed -i 's|\[openssl_init\]|&\nssl_conf = ssl_configuration\n[ssl_configuration]\nsystem_default = tls_system_default\n[tls_system_default]\nMinProtocol = TLSv1\nCipherString = DEFAULT@SECLEVEL=0|' /etc/ssl/openssl.cnf
    COPY ./openssl.cnf /etc/ssl/openssl.cnf

    WORKDIR /app

    #RUN dotnet restore
    #RUN dotnet publish -c Release -o out -r linux-x64

    COPY ./publish .
    ENV ASPNETCORE_URLS http://0.0.0.0:80
    ENTRYPOINT ["dotnet", "xxx.dll"]

CipherString 选项

CipherString 用于定义可接受的密码套件和安全级别。密码字符串 DEFAULT 表示使用 OpenSSL 内置的默认密码套件。

  • @SECLEVEL=2 为密码套件设置安全级别(Level 2)。OpenSSL 支持以下安全级别:
Level 描述
0 无任何安全保证
1 避免使用弱加密算法,如单 DES 或 40 位 RC4
2 要求 112 位安全强度(默认),禁止使用过时的密码套件,如 SSLv3 和低强度密码套件。
3 要求 128 位安全强度,进一步约束密码套件的选择。
4 要求 192 位安全强度,进一步约束密码套件的选择。
5 要求 256 位安全强度,仅允许最高强度的加密算法。
相关推荐
AndyHeee7 分钟前
【瑞芯微rk3576刷ubuntu根文件系统容量不足问题解决】
linux·数据库·ubuntu
李昊哲小课9 分钟前
Ubuntu 24.04 在线安装 Redis 8.x 完整教程
linux·redis·ubuntu
sao.hk9 分钟前
ubuntu2404,vbox,全屏显示
linux·运维·服务器
危笑ioi9 分钟前
linux配置nfs在ubuntu22.04
linux·运维·服务器
社会零时工18 分钟前
【ROS2】海康相机ROS2设备服务节点开发
linux·c++·相机·ros2
聆风吟º21 分钟前
【顺序表习题|图解|双指针】合并两个有序数组 + 训练计划 I
c语言·数据结构·c++·经验分享·算法
东城绝神23 分钟前
《Linux运维总结:Ubuntu 22.04配置chrony时间同步服务》
linux·运维·ubuntu·chrony
刘程佳25 分钟前
Ubuntu 系统没有识别 Pixel 6 的 USB 设备权限
linux·运维·ubuntu
wa的一声哭了34 分钟前
矩阵分析 单元函数矩阵微积分和多元向量值的导数
linux·c语言·c++·线性代数·算法·矩阵·云计算
陈葛杰42 分钟前
VMware 安装 Rocky Linux 9.6(Minimal 版)超详细图文教程|轻量 · 安全 · 生产级
linux·运维·服务器