首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用engine_ssl pkcs11进行Nginx配置以设置TLS连接

使用engine_ssl pkcs11进行Nginx配置以设置TLS连接
EN

Stack Overflow用户
提问于 2019-12-12 22:55:52
回答 2查看 1.1K关注 0票数 1

请帮我在Windows上配置nginx,以便使用基于PKCS#11引擎的TLS连接。

我有来自供应商的driver pkcs11 (C:\nCipher\nfast\toolkits\pkcs11\cknfast-64.dll)。

我的nginx.conf文件如下所示:

代码语言:javascript
运行
复制
worker_processes  1;

events {
    worker_connections  1024;
}

#nShield PKCS#11
ssl_engine pkcs11;


http {
    ...
    server {
        listen       8888;
        server_name localhost;
        return 301 https://$server_name$request_uri;
    }

    server {
        listen       443 ssl;
        listen [::]:443 ssl;

        server_name localhost;

        ssl_certificate      C:/nginx-1.16.1/ssl/test_selfcert;
        ssl_certificate_key  "engine:pkcs11:pkcs11:token=ocs2;object=test_key";

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-256-GCM-SHA384:ECDHE:!COMPLEMENTOFDEFAULT;
        ssl_prefer_server_ciphers on;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;

        location / {
             proxy_pass http://localhost:9999/;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header X-Forwarded-Proto $scheme;
             proxy_set_header X-Forwarded-Port $server_port;
        }
    }

}

我尝试检查此配置,但得到错误:

代码语言:javascript
运行
复制
>nginx -t
nginx: [emerg] ENGINE_by_id("pkcs11") failed (SSL: error:25078067:DSO support routines:win32_load:could not load the shared library:filename(Z:\nginx\nginx-stab
le\objs.msvc8\lib\openssl-1.1.1c\openssl\lib\engines-1_1\pkcs11.dll) error:25070067:DSO support routines:DSO_load:could not load the shared library error:260B60
84:engine routines:dynamic_load:dso not found error:2606A074:engine routines:ENGINE_by_id:no such engine:id=pkcs11)
nginx: configuration file C:\nginx-1.16.1/conf/nginx.conf test failed

我认为我的openssl配置中有一个错误,因为我没有在那里定义pkcs11驱动程序。在默认配置C:\nCipher\nfast\lib\ssleay\openssl.cnf的末尾,我添加了一个块,如下所示:

代码语言:javascript
运行
复制
...
openssl_conf            = openssl_def
[openssl_def]
engines = engine_section

[engine_section]
chil = chil_section

[chil_section]
SO_PATH=c:\\Program Files (x86)\\nCipher\\nfast\\toolkits\\hwcrhk\\nfhwcrhk.dll

#added
[engine_section]
pkcs11 = pkcs11_section
[pkcs11_section]
engine_id = pkcs11
dynamic_path = "C:\\Program Files\\OpenSSLx64\\bin\\pkcs11openssl64x.dll"
MODULE_PATH = "C:\\nCipher\\nfast\\toolkits\\pkcs11\\cknfast-64.dll"
init = 0
...

但是文件pkcs11openssl64x.dll在我的电脑上不存在!在'dynamic_path‘参数中,我尝试下载并使用libpkcs11-helper-1.dll,onepin-opensc-pkcs11.dll,opensc_pkcs11.ddl文件,但它们都不起作用。当我尝试在不使用'dynamic_path‘参数的情况下使用此配置时,我得到错误:

代码语言:javascript
运行
复制
> openssl engine -t -c pkcs11
13112:error:25078067:DSO support routines:WIN32_LOAD:could not load the shared library:dso_win32.c:179:filename(C:\Program Files\Git\mingw64\lib\engines\pkcs11.
dll)
13112:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:233:
13112:error:260B6084:engine routines:DYNAMIC_LOAD:dso not found:eng_dyn.c:467:
13112:error:2606A074:engine routines:ENGINE_by_id:no such engine:eng_list.c:411:id=pkcs11

或使用配置路径:

代码语言:javascript
运行
复制
> openssl engine -t -c pkcs11  -config "C:\nCipher\nfast\lib\ssleay\openssl.cnf"
13572:error:25078067:DSO support routines:WIN32_LOAD:could not load the shared 
library:./crypto/dso/dso_win32.c:179:filename(C:\nCipher\nfast\bin\pkcs11.dll)
13572:error:25070067:DSO support routines:DSO_load:could not load the shared library:./crypto/dso/dso_lib.c:233:
13572:error:260B6084:engine routines:DYNAMIC_LOAD:dso not found:./crypto/engine/eng_dyn.c:467:
13572:error:2606A074:engine routines:ENGINE_by_id:no such engine:./crypto/engine/eng_list.c:391:id=pkcs11
13572:error:25078067:DSO support routines:WIN32_LOAD:could not load the shared library:./crypto/dso/dso_win32.c:179:filename(C:\nCipher\nfast\bin\-config.dll)
13572:error:25070067:DSO support routines:DSO_load:could not load the shared library:./crypto/dso/dso_lib.c:233:
13572:error:260B6084:engine routines:DYNAMIC_LOAD:dso not found:./crypto/engine/eng_dyn.c:467:
13572:error:2606A074:engine routines:ENGINE_by_id:no such engine:./crypto/engine/eng_list.c:391:id=-config
13572:error:25078067:DSO support routines:WIN32_LOAD:could not load the shared library:./crypto/dso/dso_win32.c:179:filename(C:\nCipher\nfast\lib\ssleay\\openss
l.cnf)
13572:error:25070067:DSO support routines:DSO_load:could not load the shared library:./crypto/dso/dso_lib.c:233:
13572:error:260B6084:engine routines:DYNAMIC_LOAD:dso not found:./crypto/engine/eng_dyn.c:467:
13572:error:2606A074:engine routines:ENGINE_by_id:no such engine:./crypto/engine/eng_list.c:391:id=C:\nCipher\nfast\lib\ssleay\openssl.cnf

但我期待的是下一个:

代码语言:javascript
运行
复制
> openssl engine -t -c pkcs11
(pkcs11) pkcs11 engine
[RSA, rsaEncryption, id-ecPublicKey]
[ available ]

输出时也未检测到pkcs#11驱动程序:

代码语言:javascript
运行
复制
>openssl engine -t -c
(dynamic) Dynamic engine loading support
     [ unavailable ]
(chil) CHIL hardware engine support
 [RSA, DH, RAND]
     [ available ]

请帮助我为NGINX设置正确的配置,以便与TLS连接设置一起工作。

EN

回答 2

Stack Overflow用户

发布于 2021-05-15 05:19:52

看起来你遗漏了P11引擎库;关于如何在Windows上获得它,请参阅这个答案:https://stackoverflow.com/a/58287898/7369488

在Linux平台上,该组件通常可以通过发行库获得,这意味着nginx的安装相当容易。

有关nShield设备的帮助,请同时访问:https://nshieldsupport.entrust.com/

票数 0
EN

Stack Overflow用户

发布于 2020-03-05 02:54:33

我猜你有一台nCipher HSM?您运行的是哪个版本的安全世界软件?PKCS#11 dll应该已经在安装ISO中。你已经创建了一个安全世界了吗?

您的配置正在尝试同时使用CHIL引擎和PKCS#11。这是两个不同的API,用于与硬件服务器对话,请选择其中一个,但不能同时使用两者。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59307279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档