【发布时间】:2021-04-13 13:21:22
【问题描述】:
我正在编写一个 Powershell 脚本,该脚本需要调用一个带有客户端和服务证书的 Web 服务。 我在 C# .Net 中有连接半工作。 在 .Net app.config 我有这些配置:
...
<security mode="TransportWithMessageCredential">
<message clientCredentialType="Certificate" negotiateServiceCredential="false" establishSecurityContext="false"/>
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="CertificateAuthenticationBehavior">
<clientCredentials>
<clientCertificate findValue="Capital Market FIONAsi" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
<serviceCertificate>
<defaultCertificate findValue="example.dk" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
<authentication certificateValidationMode="PeerTrust" />
</serviceCertificate>
</clientCredentials>
</behavior>
.net 代码。
var stinaProxy = new StinaServiceProxy("StinaService");
var stinaHandshakeResponse = stinaProxy.HandShake(testValueArgument);
这似乎让我通过了 .net 中的证书验证
但如前所述,我实际上需要它在 powershell 中为我工作。 我不知道如何调用 Web 服务并提供客户端和服务证书。
这是我到目前为止在 powershell 中得到的结果,但它以超时结束,我认为是证书问题。
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ClientCertificate = Get-ChildItem Cert:\LocalMachine\My\af4269b1d7190be23f1e48001fc345011f7ade80
$defaultCertificate = Get-ChildItem Cert:\LocalMachine\My\42097f29a5bd2fb4d9960e74f67654d369b7a2e3
$url = "https://example.dk/StinaService.svc?wsdl"
$webserviceex = New-WebServiceProxy -Uri $url -Namespace WebServiceProxy
$webserviceex.Timeout = 5000
$webserviceex.ClientCertificates.Add($ClientCertificate)
$webserviceex.ClientCertificates.Add($defaultCertificate)
$handshakeResult = $webserviceex.HandShake("1234!")
任何帮助表示赞赏:)
【问题讨论】:
-
服务证书是什么意思?看起来您正确地进行了客户端证书身份验证,但我不确定
$defaultCertificate应该用于什么。您是否有权访问网络服务以查看它为什么不响应?通常,错误/丢失的证书应返回 403。 -
我猜您的客户正在检查服务证书的有效性,并且在吊销列表检查中失败或超时。我认为您不需要将
$defaultcertificate添加到ClientCertficates集合中,您只需要信任服务证书即可。您是否尝试将PeerTrust属性添加到您的$webservicexproxy? -
大家好,感谢您的意见。
-
大家好,感谢您的意见。 Cpt.Whale,我想我需要两个证书,但我不擅长这个证书的东西。我无权访问网络服务后端/日志。 RichMoss,实际上我不相信将它添加到 ClientCertificates 集合是诀窍,只是我的尝试。我已将证书添加到机器商店。我看不到在 powershell 中添加 PeerTrust 的可能性。你知道怎么做吗?
标签: powershell web-services certificate servicepointmanager new-webserviceproxy