在使用docker容器启动netcore3.x的项目连接 mysql5.7 时遇到如下错误
An excepetion has been rasied that is likely due to a transient failure.
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
---> Interop+OpenSsl+SslException: SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.
---> Interop+Crypto+OpenSslCryptographicException: error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small
报错信息大致如下。
这是由于在netcore 3.x的镜像中,该版本的S配置要求 ssl 协议最小版本高于 mysqlserver 主机中的 ssl 版本
[system_default_sect] MinProtocol = TLSv1.2 //需要改成 TLSv1.0 CipherString = DEFAULT@SECLEVEL=2 //需要改成 DEFAULT@SECLEVEL=2
这样你的ssl链接就可以成功了。
但是容器启动后直接修改并不能直接生效。或许应当重启某个服务,我现在还没有查到。
我暂时把配置文件拷贝出来修改后,通过 docker compose 中配置 volume 来map到容器中,覆盖原本的配置来解决。
version: '3.4' services: maomaochatrobot: build: context: . dockerfile: ./Dockerfile volumes: - ./openssl.cnf:/etc/ssl/openssl.cnf #修改后的cnf文件map到容器中
这样就暂时解决了mysqlserver和netcore容器ssl版本不匹配的问题。
这应该不是一个很好的方法。权当抛砖引玉,希望有读者分享更好的解决方法。