如何在使用openssl生成自签名证书时设置密钥规范或KEYEXCHANGE属性



我在'windows2012R2'上使用开放ssl生成自签名证书。使用下面的命令,我已经生成了证书

openssl genrsa -des3 -out ab.key 
openssl req -new -x509 -key ab.key -out ab.crt
openssl pkcs12 -inkey ab.key -in ab.crt -export -out ab.pkcs12
openssl x509 -in ab.crt -out ab.pem
Getting the error while import the certificate - The selected certificate  does not have the KeySpec 
Exchange property. This property is required by SQL Server to import a certificat Import error: 0x2, Windows Native Error: 0x80092004
I have checked the opennssl config file but could not get like where to set this property.

一种方法是将证书转换为pfx(pkcs12(格式,它将获得KeySpec的默认值,即KeySpec=1--At_KEYEXCHANGE

使用openssl命令"pkcs12"如下:

openssl pkcs12 -inkey mssql-key.pem -in mssql-cert.crt -export -out mssql-cert.pfx

您将在certutil的输出中得到以下操作:

certutil -dump -v .mssql-cert.pfx

输出提取:

hCryptProv=000001372C300D00

KeySpec=1--AT_KEYEXCHANGE

经过多次尝试和错误,我发现如果您的证书包含证书链,SQL Server将无法正常工作,或者至少这是我的问题所在。我的CA是Microsoft,我使用主机的FQDN为我的服务器颁发了一个新证书,一切都很好。但是,当我将证书从MMC导出到PFX文件时,证书路径中的所有证书都默认导出。SQL Server正在导入主机证书上方的颁发证书,而该证书没有设置KEYSPEC=1选项。如果你知道去哪里找的话,这是一个简单的解决方案。在MMC中的导出证书向导中,只需清除选项";包括认证路径中的所有证书";然后SQL Server导入正确的。

最新更新