首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >网络服务用户无法读取证书windows server 2012

网络服务用户无法读取证书windows server 2012
EN

Stack Overflow用户
提问于 2017-06-02 17:20:44
回答 1查看 2.3K关注 0票数 2

我的windows 2012服务器机器上有一个本地服务正在运行。它是一个带有一个节点的蔚蓝服务结构集群,但这对此问题并不重要。

该服务运行在“网络服务:用户”下,并具有访问存储在本地计算机上的证书的代码。使用X509Certificate2Collection.Find方法查找证书的代码。

例外是:

引发的异常:“System.AggregateException”在mscorlib.dll中 其他信息:无法使用指纹成功获取访问令牌: 80CEA40A62FFA0116FCB40B7B5985ADCD3E5AC39

当我在本地执行与管理员用户相同的Find函数时,它可以工作。

我已经尝试显式地授予网络服务用户对证书的读取权限,但这并没有解决这个问题。

我还尝试在获得证书的网络服务用户上下文(不是已部署的本地服务,而是本地可执行代码段)下在本地执行代码,这是很奇怪的。

EN

回答 1

Stack Overflow用户

发布于 2017-06-07 12:54:12

我认为问题是网络服务无法访问私钥。在将证书导入到我自己的商店后,我使用下面的代码设置权限,并且我可以访问私钥

代码语言:javascript
复制
Import-PfxCertificate -CertStoreLocation Cert:\LocalMachine\My -FilePath "path to the pfx file"
$certs = Get-ChildItem -Path cert:\LocalMachine\My

Foreach ($cert in $certs)
{
 # Specify the user, the permissions and the permission type
 $permission = "Network Service","FullControl","Allow"
 $accessRule = New-Object -TypeName 
 System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permission

 # Location of the machine related keys
 $keyPath = Join-Path -Path $env:ProgramData -ChildPath "\Microsoft\Crypto\RSA\MachineKeys"
 $keyName = $cert.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName
 $keyFullPath = Join-Path -Path $keyPath -ChildPath $keyName

 # Get the current acl of the private key
 $acl = (Get-Item $keyFullPath).GetAccessControl('Access')

 # Add the new ace to the acl of the private key
 $acl.SetAccessRule($accessRule)

 # Write back the new acl
 Set-Acl -Path $keyFullPath -AclObject $acl -ErrorAction Stop

 # Observe the access rights currently assigned to this certificate.
 get-acl $keyFullPath| fl
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44334327

复制
相关文章

相似问题

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