Windows 10 winrm 不接受证书身份验证

Windows 10 winrm 不接受证书身份验证

我想使用证书而不是用户名和密码远程连接到 Windows 机器。连接将主要使用 ansible 或 pywinrm 模块从 Linux 服务器进行。

我能够使用用户名或密码从远程机器连接,但不能使用证书。

我使用 Linux 上的 openssl 生成了一个客户端证书,其内容如下:

extended key usage: Client Authentication (1.3.6.1.5.5.7.3.2)
subject alternative name: Other Name:
     Principal Name=user@localhost

我将证书导入到根证书存储区和受信任的人员证书存储区

Get-Item Cert:\LocalMachine\TrustedPeople\28DB272759BB411B49EB8E1CEAA29A2704DC2D17)


   PSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\TrustedPeople

Thumbprint                                Subject
----------                                -------
28DB272759BB411B49EB8E1CEAA29A2704DC2D17  CN=user

我得到了证书指纹:

(get-ChildItem -Path cert:\LocalMachine\root | Where-Object { $_.Subject -eq "CN=user" }).Thumbprint
 28db272759bb411b49eb8e1ceaa29a2704dc2d17

并添加了一个到属于管理员组成员的用户的映射

New-Item -Path WSMan:\localhost\ClientCertificate `
         -Subject 'user@localhost' `
         -URI * `
         -Issuer 28db272759bb411b49eb8e1ceaa29a2704dc2d17 `
         -Credential (Get-Credential) `
         -Force

get-item -path WSMan:\localhost\ClientCertificate\ClientCertificate_130594957\| fl *


PSPath            : Microsoft.WSMan.Management\WSMan::localhost\ClientCertificate\ClientCertificate_130594957
PSParentPath      : Microsoft.WSMan.Management\WSMan::localhost\ClientCertificate
PSChildName       : ClientCertificate_130594957
PSDrive           : WSMan
PSProvider        : Microsoft.WSMan.Management\WSMan
PSIsContainer     : True
Keys              : {URI=*, Issuer=28db272759bb411b49eb8e1ceaa29a2704dc2d17, Subject=user@localhost}
Name              : ClientCertificate_130594957
TypeNameOfElement : Container
Type              : Container

我可以使用用户名和密码连接到服务器,但使用证书时却不行,当我尝试测试本地连接时它仍然不起作用。https 端口已打开

在本地测试也不起作用:

Test-WSMan -ComputerName . -Authentication ClientCertificate -CertificateThumbprint <thumbprint>

我收到此错误:

Test-WSMan : The WS-Management service cannot find the certificate that was requested.
At line:1 char:1
+ Test-WSMan -ComputerName . -Authentication ClientCertificate -Certifi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Test-WSMan], InvalidOperationException
    + FullyQualifiedErrorId : WsManError,Microsoft.WSMan.Management.TestWSManCommand

Python脚本说:

  File "/usr/local/lib/python3.6/site-packages/winrm/transport.py", line 333, in _send_message_request
    raise InvalidCredentialsError("the specified credentials were rejected by the server")
winrm.exceptions.InvalidCredentialsError: the specified credentials were rejected by the server

我不知道如何调试这个,我在 Windows 日志中看不到任何内容。我对 Windows 的了解非常有限。

我怎样才能解决这个问题?

答案1

我在使用 Python 客户端脚本时遇到了类似的问题。我花了几个小时才解决。我发现这是由于远程服务器的本地计算机证书存储的受信任根证书颁发机构文件夹中存在一些中间证书。这很奇怪,因为两个证书都是自签名的(WinRM 侦听器和客户端身份验证)。

警告

相关内容