.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 位安全强度,仅允许最高强度的加密算法。
相关推荐
ChaITSimpleLove2 小时前
使用 Dockerfile 构建基于 .NET9 的跨平台基础镜像
.net·dockerfile·.net aspire·dotnet-sdk·pwsh·docker image·docker buildx
M4K03 小时前
Linux百度网盘优化三板斧
linux
June bug3 小时前
【软考中级·软件评测师】下午题·面向对象测试之架构考点全析:分层、分布式、微内核与事件驱动
经验分享·分布式·职场和发展·架构·学习方法·测试·软考
好奇的菜鸟3 小时前
如何在 Ubuntu 24.04 (Noble) 上使用阿里源
linux·运维·ubuntu
bcbobo21cn3 小时前
初步了解Linux etc/profile文件
linux·运维·服务器·shell·profile
望获linux4 小时前
【实时Linux实战系列】CPU 隔离与屏蔽技术
java·linux·运维·服务器·操作系统·开源软件·嵌入式软件
0wioiw04 小时前
C#基础(项目结构和编译运行)
linux·运维·服务器
2401_873587825 小时前
Linux常见指令以及权限理解
linux·运维·服务器
Arthurmoo5 小时前
Linux系统之MySQL数据库基础
linux·数据库·mysql
李洋-蛟龙腾飞公司5 小时前
HarmonyOS NEXT应用元服务常见列表操作分组吸顶场景
linux·运维·windows