【问题标题】:PKCS11 Windows invalid engine YubiHSM2PKCS11 Windows 无效引擎 YubiHSM2
【发布时间】:2018-10-08 14:09:59
【问题描述】:

又是我。 我正在使用 YubiHSM2 HSM 模块,我正在尝试将其设置为使用 pkcs11 引擎,这将允许我将 OpenSSL 与 HSM 一起使用。

我在 Windows 上实现这个,给我带来了很多麻烦。 我已经安装了 OpenSSL 32,64、OpenSC、YubiHSM2 驱动程序以及 libp11(使用 MSYS2 构建)。

我的 OpenSSL.cnf 中有趣的部分如下所示:

openssl_conf = openssl_init

[openssl_init]
engines = engine_section

[engine_section]
pkcs11 = pkcs11_section

[pkcs11_section]
engine_id = pkcs11
dynamic_path = "C:\Windows\System32\opensc-pkcs11.dll"
MODULE_path = "C:\Users\myUser\Desktop\SecureTemial\yubihsm2-sdk\bin\yubihsm_pkcs11.dll"
PIN = "0001password"
init = 0

当我尝试时:

 C:\OpenSSL-Win64\bin\openssl.exe req -new -x509 -days 365 -sha256 -config C:\Users\myUser\Desktop\SecureTemial\openssl.cnf -engine pkcs11 -keyform engine -key slot_0-label_my_key -out cert.pem

我收到以下信息:

C:\OpenSSL-Win64\bin\openssl.exe : invalid engine "pkcs11"
In Zeile:1 Zeichen:2
+  C:\OpenSSL-Win64\bin\openssl.exe req -new -x509 -days 365 -sha256 -c ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (invalid engine "pkcs11":String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

16056:error:25078067:DSO support routines:win32_load:could not load the shared 
library:crypto\dso\dso_win32.c:106:filename(C:\Program Files\OpenSSL\lib\engines-1_1\pkcs11.dll)
16056:error:25070067:DSO support routines:DSO_load:could not load the shared library:crypto\dso\dso_lib.c:161:
16056:error:260B6084:engine routines:dynamic_load:dso not found:crypto\engine\eng_dyn.c:414:
16056:error:2606A074:engine routines:ENGINE_by_id:no such engine:crypto\engine\eng_list.c:339:id=pkcs11
16056:error:25078067:DSO support routines:win32_load:could not load the shared 
library:crypto\dso\dso_win32.c:106:filename(pkcs11.dll)
16056:error:25070067:DSO support routines:DSO_load:could not load the shared library:crypto\dso\dso_lib.c:161:
16056:error:260B6084:engine routines:dynamic_load:dso not found:crypto\engine\eng_dyn.c:414:
Error configuring OpenSSL modules
16056:error:25078067:DSO support routines:win32_load:could not load the shared 
library:crypto\dso\dso_win32.c:106:filename(C:WindowsSystem32opensc-pkcs11.dll)
16056:error:25070067:DSO support routines:DSO_load:could not load the shared library:crypto\dso\dso_lib.c:161:
16056:error:260B6084:engine routines:dynamic_load:dso not found:crypto\engine\eng_dyn.c:414:
16056:error:260BC066:engine routines:int_engine_configure:engine configuration 
error:crypto\engine\eng_cnf.c:141:section=pkcs11_section, name=dynamic_path, value=C:WindowsSystem32opensc-pkcs11.dll
16056:error:0E07606D:configuration file routines:module_run:module initialization 
error:crypto\conf\conf_mod.c:173:module=engines, value=engine_section, retcode=-1   

我已经检查过 dll 是否被锁定并以管理员身份运行等。 如果您有任何线索,请告诉我这里的麻烦是什么原因造成的!

非常感谢!

【问题讨论】:

标签: dll openssl pkcs#11 opensc yubico


【解决方案1】:

当我对类似主题进行一些研究时,这个问题是我的搜索结果中最先出现的问题之一。由于还没有答案,我将概述我的解决方案的结果:

若要将 libp11 的 PKCS#11 引擎与 OpenSSL 一起使用,必须将其编译为动态引擎,该引擎静态链接到您正在使用的 OpenSSL 版本。当您使用binaries from Shining Light Productions(根据您在问题中提到的安装目录的一个很好的猜测)时,使用从第三方资源获得的 MSYS2 版本可能不起作用,使用随附的 PKCS#11 库也可能不起作用OpenSC 项目的Windows installers

幸运的是,Shining Light Productions 的 OpenSSL 版本附带了所有必需的库,因此您可以轻松地自己编译 libp11,例如通过使用NMAKE(点击链接查看如何获取它以及如何正确设置命令行以供其使用):

  1. 下载满足您要求(x86 或 x64)的 OpenSSL binaries 并将它们安装到建议的标准目标位置(例如,C:\OpenSSL-Win32C:\OpenSSL-Win64)。 - libp11 的 makefile 需要这些文件夹进行绑定。
  2. 下载并提取或克隆libp11 项目的源代码。
  3. 打开您的 Windows 命令行并设置 NMAKE 环境变量,然后更改为之前下载的 libp11 文件的位置。
  4. 为 64 位版本的 OpenSSL 构建时,您必须相应地设置 BUILD_FOR 环境变量。运行

    set BUILD_FOR=WIN64
    

    在您的命令行上。

  5. 现在通过运行编译库

    NMAKE /F Makefile.mak
    
  6. 如果一切顺利,您将在 libp11 的 src 文件夹中拥有两个新库:libp11.dllpkcs11.dll。后者是与您的 OpenSSL 一起使用的 PKCS#11 引擎。将其复制到例如 Windows 库文件夹(System32 用于 32 位版本,SysWOW64 用于 x64 版本)。

  7. 相应地调整您的openssl.cnf 文件。复制

    openssl_conf = openssl_init
    

    到文件的开头,其余到文件的结尾:

    [openssl_init]
    engines = engine_section
    
    [engine_section]
    pkcs11 = pkcs11_section
    
    [pkcs11_section]
    dynamic_path = "C:\\Windows\\SysWOW64\\pkcs11.dll"
    module_path = "C:\\Users\\myUser\\Desktop\\SecureTemial\\yubihsm2-sdk\\bin\\yubihsm_pkcs11.dll"
    PIN = "0001password"
    

一些最后的笔记:

  1. 确保经过调整的openssl.cnf 文件确实被OpenSSL 拾取。 OpenSSL 安装附带了几个示例文件。默认情况下,上述二进制文件的配置文件位置对于 x64 版本是 C:\Program Files\Common Files\SSL\openssl.cnf,对于 x86 版本是 C:\Program Files (x86)\Common Files\SSL\openssl.cnf。但是您系统上的其他 OpenSSL 安装(例如,来自捆绑 OpenSSL 的 OpenVPN、MingW、MSYS2 等)可能会干扰设置文件的位置。您可以通过相应地设置 OPENSSL_CONF 环境变量来确保使用正确的设置文件。
  2. 在 Windows 路径中使用双引号时,请确保使用 \\ 而不是 \ 正确转义反斜杠。
  3. 您可以放心地省略openssl.cnf[pkcs11_section] 中的engine_idinit 部分。
  4. 虽然 libp11 的动态 PKCS#11 引擎需要针对与 OpenSSL 相同的架构(x86 或 x64)和库进行编译,但模块库可能需要 32 位版本(即使在运行 OpenSSL 的 64 位构建时)。 - 至少在我们的系统场景中发生了这种情况(我们使用金雅拓 Safenet 电子令牌,因此使用 Safenet 身份验证客户端随附的 Aladdin 模块库)。

【讨论】:

    猜你喜欢
    • 2021-12-07
    • 2013-06-26
    • 1970-01-01
    • 1970-01-01
    • 2016-03-22
    • 2020-03-04
    • 2013-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多