2

我想使用私钥和存储在 PIV 数字签名槽中的证书签署证书签名请求。

我正在使用最新版本的 OpenSC for MacOS(https://github.com/OpenSC/OpenSC/releases/tag/0.19.0)。

我已经尝试过 pkcs11-tool、pkcs15-tool 和 yubikey-piv-tool。这三个工具都提供了一个 --sign API,但它们对从数据生成的摘要进行签名。

我的要求是签署证书签名请求以生成证书。

我唯一的选择是将 PKCS#11 引擎用于 OpenSSL。PKCS#11 引擎:brew install engine_pkcs11 PKCS#11 模块:opensc-pkcs11.so

我将使用常规 OpenSSL 命令签署 CSR,使用引擎选项提供密钥和存储在 Yubikey 上的证书。(可能使用 PKCS#11 URI)

使用 OpenSSL 1.0.2,我尝试了以下命令。

engine -t dynamic -pre SO_PATH:/usr/local/Cellar/engine_pkcs11/0.1.8/lib/engines/engine_pkcs11.so -pre ID:pkcs11 -pre LIST_ADD:1 -pre LOAD -pre MODULE_PATH:/Library/OpenSC/lib/opensc-pkcs11.so

回复:

(dynamic) Dynamic engine loading support
[Success]: SO_PATH:/usr/local/Cellar/engine_pkcs11/0.1.8/lib/engines/engine_pkcs11.so
[Success]: ID:pkcs11
[Success]: LIST_ADD:1
[Success]: LOAD
[Success]: MODULE_PATH:/Library/OpenSC/lib/opensc-pkcs11.so
Loaded: (pkcs11) pkcs11 engine
     [ available ]

要签署 CSR,我正在使用此命令,

req -engine pkcs11 -keyform engine -key 02 -new -x509 -in ~/Desktop/sample.csr -out cert.pem 

回复:

engine "pkcs11" set.
PKCS#11 token PIN:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields, there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []: a.com
Email Address []:
4536252012:error:8000A101:PKCS11 library:PKCS11_rsa_sign:User not logged in:p11_ops.c:131:
4536252012:error:0D0DC006:asn1 encoding routines:ASN1_item_sign_ctx:EVP lib:a_sign.c:306:

即使输入正确的 PIN,我也会收到此错误。Yubikey 证书上的 CA 密钥/证书也没有密码。

在 PyKCS#11 示例中出现类似错误: https ://github.com/LudovicRousseau/PyKCS11/issues/61

使用另一个类似的 OpenSSL 命令。

OPENSSL_CONF=engine.conf openssl x509 -req -engine pkcs11 -in ~/Desktop/sample.csr -CAkeyform engine -CAkey 02 -CA rootCA.pem -sha256 -out cert.pem

回复:

engine "pkcs11" set.
Signature ok
subject=/CN=C44F3320626D/C=IN/ST=MH/O=test
Getting CA Private Key
PKCS#11 token PIN:
4394223212:error:06067099:digital envelope routines:EVP_PKEY_copy_parameters:different parameters:p_lib.c:137:
4394223212:error:8000A101:PKCS11 library:PKCS11_rsa_sign:User not logged in:p11_ops.c:131:
4394223212:error:0D0DC006:asn1 encoding routines:ASN1_item_sign_ctx:EVP lib:a_sign.c:306:

我想知道问题是否出在 macOS OpenSSL、Yubikey、PKCS#11 或 OpenSSL-PKCS#11 引擎中。

我期望 CSR 使用 Yubikey 在 MacOS 上签署证书。请帮忙。

4

1 回答 1

4

-CAkey 02应该-CAkey slot_0-id_2用于 yubikey 上的插槽9c/索引02,其他一切看起来都不错(尽管请注意插槽 9c 上的引脚要求存在问题,这可能会影响您)。

对于带有 pkcs#11 的 yubikeys 的工作示例,您可能想查看https://github.com/ryankurte/pki

祝你好运!

于 2019-11-12T01:24:14.283 回答