我在寻找简单的方法如何使用客户端证书通过HTTPS检查网页内容。 我有VBScript定义客户端证书,跳过服务器证书,并定义我正在搜索(字符串“正在运行”)。我的观点是重写脚本到PowerShell。PowerShell HTTPS GET使用证书库中的客户端证书
这里是VBScode:
device = "10.10.10.10"
link = "5001/test"
Set Http = CreateObject("WinHttp.WinHttpRequest.5.1")
Http.SetClientCertificate "LOCAL_MACHINE\MY\test"
Http.Option(4) = 256 + 512 + 4096 + 8192
Http.Open "GET", "https://" & device & ":" & link, false
Http.Send
output = Http.ResponseText
If InStr(1,output,"running") Then
wscript.echo "OK"
Else
wscript.echo "Error"
End If
Set Http = Nothing
这里是PowerShell的语法来获取HTTP网页内容(而不是HTTPS):
$page = (New-Object System.Net.WebClient).DownloadString("http://10.10.10.10:5001/test")
"$page"
下面是PowerShell的语法使用.CRT文件,以获得HTTPS contetn(但不从的CertStore)
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::CreateFromCertFile("C:\Cert\test.crt")
$url = "https://10.10.10.10:5001/test"
$web = [System.Net.WebRequest]::Create($url)
$web.ClientCertificates.Add($Cert)
这是我最新的尝试获得网络contetn。没有成功。
#ignore untrusted certificate
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
#load my client certificate defined by thumbprint
$cert = Get-Childitem cert:\LocalMachine\My\5AA55B7B8D99
#get web contetn
$web = [System.Net.WebRequest]::Create($url)
#use my client certificate
$web.ClientCertificates.Add($Cert)
任何想法? 最好的问候
您不能使用HTTPS客户端验证是CRT文件。它只包含一个证书,但不包含私钥。 – Robert
是的,这是使用certstore的原因。 – user1728814
所以我有脚本下面的波纹管,但仍然无法正常工作。任何想法?问候 – user1728814