东方通THS、Nginx配置SSL证书提示SSL_CTX:ca md too weak报错、适配国密SM2算法【测试成功】

艺帆风顺 发布于 2025-04-02 19 次阅读


一、问题背景

    nginx证书配置完毕之后,提示信息如下:

    error:140AB18E:SSL routines:SSL_CTX_use_certificate:ca md too weak)

报错为:SSL 证书(zhdj.crt)的签名算法太弱。

    [root@host-192-168-66-18 ~]# nginx -tnginx: [emerg] SSL_CTX_use_certificate("/data/nginx/ssl/zhdj.pem") failed (SSL: error:140AB18E:SSL routines:SSL_CTX_use_certificate:ca md too weak)nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

    二、问题排查

        1、排查openSSL版本

      [root@host-192-168-66-18 ~]# opensslOpenSSL> versionOpenSSL 1.1.1f 31 Mar 2020OpenSSL> quit

      2、查看加密签名算法【Nginx默认不支持国密算法

        [root@host-192-168-66-18 ssl]# openssl x509 -text -in zhdj.pem|grep Signature  Signature Algorithm: 1.2.156.10197.1.501 Digital Signature, Non Repudiation    Signature Algorithm: 1.2.156.10197.1.501    

        证书的签名算法是 1.2.156.10197.1.501。这是一个国密算法,标识为 SM2。

        这个签名算法是基于椭圆曲线密码学的,与传统的 RSA 或 DSA 不同。在使用 SM2 签名算法的证书中,可能会遇到某些软件和库不支持的问题。

            在 Nginx 中使用这个证书,并且遇到了 "ca md too weak" 的问题,可能是因为某些系统或软件版本的 OpenSSL 不支持这个特定的 SM2 签名算法。

        三、问题处理【Nginx适配国密SM2算法】

            参考:https://www.gmssl.cn/gmssl/index.jsp

            不支持商用,商用需要单独收费。

        四、东方通THS适配国密SM2证书

            东方通TongHttpServer安装,略。

            东方通常用命令:

          cd /root/ths/bin./start.sh./startHA.sh./startConsole.shadminths#123.comvim /root/ths/conf/httpserver.conf

          东方通THS证书配置:

                国密证书包含四个文件:

          conf/httpserver.conf文件配置

            ssl_protocols GMTLSv1.1;ssl_certificate crt/SS.cer;ssl_certificate_key crt/SS.key.pem;ssl_certificate crt/SE.cer;ssl_certificate_key crt/SE.key.pem;

            四、Nginx迁移东方通THS报错信息

             1、报错信息: httpserver: [emerg] named location "arouter" can be on the server level only in/root/ths/conf/httpserver.conf:115

            解决:将该内容写在server头上,写在末尾则无法正常识别

              location @router { rewrite ^.*$ /index.html last;}