Service Fabric Local Cluster 无法获取证书私钥
Service Fabric Local Cluster fails to get certificate(s) private key(s)
对于我尝试 运行 使用一个或多个 SecretsCertificate
实例的每个 Service Fabric 应用程序,该应用程序无法在我的本地 Service Fabric 集群中启动,并在节点 > 应用程序上出现以下错误在 SF Explorer 中:
Error event: SourceId='System.Hosting', Property='Activation:1.0'.
There was an error during activation.Failed to configure certificate permissions. Error E_FAIL.
Service Fabric 还将一些相关项目记录到“事件查看器”>“应用程序和服务日志”>“Microsoft-Service Fabric”>“管理”部分:
CryptAcquireCertificatePrivateKey failed. Error:0x8009200b
Can't get private key filename for certificate. Error: 0x8009200b
All tries to get private key filename failed.
Failed to get the Certificate's private key.
Thumbprint:4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXC. Error: E_FAIL
Failed to get private key file. x509FindValue: 4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXC, x509StoreName: My, findType: FindByThumbprint, Error E_FAIL
ACLing private key filename for thumbprint 4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXC. ErrorCode=E_FAIL
ConfigureCertificateACLs: error=E_FAIL
我已经删除并重新安装了证书(确认可以在多个其他开发人员的本地 Service Fabric 集群开发环境中使用),并将私钥设置为对 NETWORK SERVICE
用户具有显式完全控制权限在我的电脑上,这没有帮助。
我已按照 中的说明进行操作,尽管 SF 本地集群无法访问它,但它实际上正确地打印出了私钥详细信息。
我已经重新安装了 Microsoft Service Fabric SDK 和 Microsoft Visual Studio 2017 也没有解决这个问题。
在 C# 和 PowerShell 中重现此错误的所有尝试均无果而终,但 Service Fabric 服务似乎无法从我的证书存储访问私钥。
编辑:进一步进展,无解。
我可以使用 PowerShell Invoke-ServiceFabricDecryptText
cmdlet 成功解密数据,但是 SF 本地集群仍然有同样的错误。
我确定证书元数据中指定的文件(来自 )PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName
在我的磁盘上的路径 C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys\
或任何相邻路径中不存在。有人以前看过这个吗?
正如评论中所讨论的,该问题与(自签名)证书的创建方式有关。使用 Powershell 创建证书时,请确保使用:
So when I specified -Provider "Microsoft Enhanced Cryptographic
Provider v1.0" for the
New-SelfsignedCertificate command to create a cert, it works.
来源:https://github.com/Azure/service-fabric-issues/issues/235#issuecomment-292667379
如果您不能或不想使用自签名证书,另一种方法是“删除”私钥的 CNG 存储(这是 Service Fabric 不能的部分尚未处理)。
本文概述的步骤展示了如何将 CNG 证书转换为非 CNG 证书:
https://blog.davidchristiansen.com/2016/05/521/
- 从您的 PFX 文件中提取您的 public 密钥和完整的证书链
openssl pkcs12 -in "yourcertificate.pfx" -nokeys -out "yourcertificate.cer"
-passin "pass:password"
- 提取 CNG 私钥
openssl pkcs12 -in "yourcertificate.pfx" -nocerts –out “yourcertificate.pem"
-nodes -passin "pass:password" -passout "pass:password"
- 将私钥转换成RSA格式
openssl rsa -inform PEM -in "yourcertificate.pem" -out "yourcertificate.rsa"
-passin "pass:password" -passout "pass:password"
- 将 public 密钥与 RSA 私钥合并到新的 PFX 文件
openssl pkcs12 -export -in "yourcertificate.cer" -inkey "yourcertificate.rsa"
-out "yourcertificate-converted.pfx"
-passin "pass:password" -passout "pass:password"
对于我尝试 运行 使用一个或多个 SecretsCertificate
实例的每个 Service Fabric 应用程序,该应用程序无法在我的本地 Service Fabric 集群中启动,并在节点 > 应用程序上出现以下错误在 SF Explorer 中:
Error event: SourceId='System.Hosting', Property='Activation:1.0'. There was an error during activation.Failed to configure certificate permissions. Error E_FAIL.
Service Fabric 还将一些相关项目记录到“事件查看器”>“应用程序和服务日志”>“Microsoft-Service Fabric”>“管理”部分:
CryptAcquireCertificatePrivateKey failed. Error:0x8009200b
Can't get private key filename for certificate. Error: 0x8009200b
All tries to get private key filename failed.
Failed to get the Certificate's private key.
Thumbprint:4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXC. Error: E_FAIL
Failed to get private key file. x509FindValue: 4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXC, x509StoreName: My, findType: FindByThumbprint, Error E_FAIL
ACLing private key filename for thumbprint 4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXC. ErrorCode=E_FAIL
ConfigureCertificateACLs: error=E_FAIL
我已经删除并重新安装了证书(确认可以在多个其他开发人员的本地 Service Fabric 集群开发环境中使用),并将私钥设置为对 NETWORK SERVICE
用户具有显式完全控制权限在我的电脑上,这没有帮助。
我已按照
我已经重新安装了 Microsoft Service Fabric SDK 和 Microsoft Visual Studio 2017 也没有解决这个问题。
在 C# 和 PowerShell 中重现此错误的所有尝试均无果而终,但 Service Fabric 服务似乎无法从我的证书存储访问私钥。
编辑:进一步进展,无解。
我可以使用 PowerShell Invoke-ServiceFabricDecryptText
cmdlet 成功解密数据,但是 SF 本地集群仍然有同样的错误。
我确定证书元数据中指定的文件(来自 PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName
在我的磁盘上的路径 C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys\
或任何相邻路径中不存在。有人以前看过这个吗?
正如评论中所讨论的,该问题与(自签名)证书的创建方式有关。使用 Powershell 创建证书时,请确保使用:
So when I specified -Provider "Microsoft Enhanced Cryptographic Provider v1.0" for the New-SelfsignedCertificate command to create a cert, it works.
来源:https://github.com/Azure/service-fabric-issues/issues/235#issuecomment-292667379
如果您不能或不想使用自签名证书,另一种方法是“删除”私钥的 CNG 存储(这是 Service Fabric 不能的部分尚未处理)。
本文概述的步骤展示了如何将 CNG 证书转换为非 CNG 证书: https://blog.davidchristiansen.com/2016/05/521/
- 从您的 PFX 文件中提取您的 public 密钥和完整的证书链
openssl pkcs12 -in "yourcertificate.pfx" -nokeys -out "yourcertificate.cer"
-passin "pass:password"
- 提取 CNG 私钥
openssl pkcs12 -in "yourcertificate.pfx" -nocerts –out “yourcertificate.pem"
-nodes -passin "pass:password" -passout "pass:password"
- 将私钥转换成RSA格式
openssl rsa -inform PEM -in "yourcertificate.pem" -out "yourcertificate.rsa"
-passin "pass:password" -passout "pass:password"
- 将 public 密钥与 RSA 私钥合并到新的 PFX 文件
openssl pkcs12 -export -in "yourcertificate.cer" -inkey "yourcertificate.rsa"
-out "yourcertificate-converted.pfx"
-passin "pass:password" -passout "pass:password"