SSL连接dh key too small
问题
在进行SSL连接时,出现dh key too small,至于这种情况,是由 OpenSSL 的更改引起的,但问题实际上出在服务器端。服务器在密钥交换中使用弱 DH 密钥,并且由于Logjam 攻击,最新版本的 OpenSSL 强制执行非弱 DH 密钥。
解决办法
方法1
修改openssl配置文件,在linux下路径为/etc/ssl/openssl.cnf
[system_default_sect]
MinProtocol = TLSv1.2
CipherString = DEFAULT@SECLEVEL=2
修改为
[system_default_sect]
MinProtocol = TLSv1.2
CipherString = DEFAULT@SECLEVEL=1
当然修改这种配置文件,是不建议的。
方法2
通过openssl api进行修改
SSL_CTX_set_security_level(ctx, 1);
方法3
在Qt环境下,qt开放了一个后门接口如下
qt_ForceTlsSecurityLevel();
在进行ssl连接前,调用一下即可,通过看源码,原理同上:
if (q_SSL_CTX_get_security_level(sslContext->ctx) > 1 && *forceSecurityLevel())
q_SSL_CTX_set_security_level(sslContext->ctx, 1);
方法4
在Qt环境下
void QSslConfiguration::setBackendConfigurationOption(const QByteArray &name, const QVariant &value)
Sets the option name in the backend-specific configuration to value.
Options supported by the OpenSSL (>= 1.0.2) backend are available in the supported configuration file commands documentation. The expected type for the value parameter is a QByteArray for all options. The examples show how to use some of the options.
Note: The backend-specific configuration will be applied after the general configuration. Using the backend-specific configuration to set a general configuration option again will overwrite the general configuration option.
This function was introduced in Qt 5.11.
setBackendConfigurationOption(“CipherString”, “DEFAULT@SECLEVEL=1”);
Qt交流群
Qt交流大会 853086607
QQ:3246214072
结尾
不定期上传新作品,解答群中作品相关问题。相关外,能解答则解答。欢迎大家一起探索Qt世界!