【发布时间】:2019-09-22 10:23:21
【问题描述】:
我正在通过 https 协议在 PowerShell 中创建一个 REST api,用于测试目的。我的目标是创建一个伪 https API 并使用它来测试我们应用程序的功能(应用程序需要调用我的测试 https api)。我可以使用以下代码创建自签名证书。
$hostIP = Get-NetIPAddress | where{ ($_.InterfaceAlias -in @('Mgmt', 'Ethernet', 'management')) -and ($_.AddressFamily -eq 'IPv4')}
$win_path= 'c:\my_temp\'
$Cert = New-SelfSignedCertificate -certstorelocation cert:\localmachine\my - dnsname $hostIP.IPAddress -NotAfter (Get-Date).AddYears(2)
$Certname = $hostIP.IPAddress.Replace('.','_')
$pw = ConvertTo-SecureString -String "Pazzword" -Force -AsPlainText
$thumbprint = $Cert.Thumbprint
Export-PfxCertificate -cert cert:\localMachine\my\$thumbprint -FilePath
$win_path\$Certname.pfx -Force -Password $pw
我正在编写的 REST api 看起来像这样
$listener = New-Object System.Net.HttpListener
$httpUrl = "http://" + $givenArgs.HostName + ":" + $givenArgs.Port + "/"
Write-Output $httpUrl
$listener.Prefixes.Add($httpUrl)
$httpsUrl = "https://" + $givenArgs.HostName + ":" + 443 + "/"
Write-Output $httpsUrl
$listener.Prefixes.Add($httpsUrl)
$listener.Start()
我的问题是,如果我手动安装在我的机器中创建的证书,我可以成功地将查询发送到我的 REST api,但只能从我的机器。
我想向客户端发送证书(在不使用任何 CA 的情况下根据初始请求为客户端发送证书副本),以便客户端第一次查询服务器时,它会获得证书副本并可以保存以供进一步交流。
我已尝试在网上查找此内容,但我只能找到导致 1.忽略证书或 2.手动导入证书的解决方案,这不能满足我的需要。
感谢您花时间研究此问题并提供帮助。提前致谢。
【问题讨论】:
标签: powershell https certificate ssl-certificate client-certificates