[英]Using pem certificate and key for authentication in powershell https request
我有pem格式的證書。 總共2個文件,RSA公鑰和RSA私鑰。 我必須使用這些命令以Powershell腳本向服務器發出https請求。
我嘗試使用X509Certificates證書存儲添加證書。 但是我不確定如何添加客戶端密鑰證書(RSA私鑰)。 我嘗試僅使用證書,但是出現此錯誤:
Exception Message: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure c
hannel。
如何使用Powershell要求客戶證書和密鑰?
我編寫的powershell腳本:
$method = "GET"
# Create a dictionary object that allows header storage in Rest call
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("X-Qlik-Xrfkey",$xrfKey)
$headers.Add("X-Qlik-User", "***")
#Get a selection object for all inactive users
$path = "/qrs/app?xrfkey=$xrfKey"
$theCommand = $senseServerHostName + "/qrs" + $path
$ns = "System.Security.Cryptography.X509Certificates"
$store = New-Object "$ns.X509Store"("My","CurrentUser")
#$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("My", "CurrentUser")
$store.Open("ReadOnly")
#$certs = $store.Certificates.Find("FindByExtension", $certExtension, $false)
#"$store.Certificates"
ForEach($cert in $store.Certificates)
{
$certToUse = $cert
}
"$certToUse"
$response = Invoke-RestMethod $theCommand -Headers $headers -Method $method -Certificate $certToUse
盡管我可以使用node.js節點代碼發出請求:
var https = require('https');
var fs = require('fs');
var options = {
rejectUnauthorized: false,
hostname: '****',
method: 'GET',
path: '/qrs/app?xrfkey=****',
headers: {
//'Accept': 'application/json',
'x-qlik-xrfkey' : '****',
'X-Qlik-User' : '****'
},
key: fs.readFileSync("C:\\client_key.pem"),
cert: fs.readFileSync("C:\\client.pem")
};
https.get(options, function(res) {
console.log("Got response: " + res.statusCode);
res.on("data", function(chunk) {
console.log("BODY: " + chunk);
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
謝謝。
PEM文件到PKCS12的轉換對我有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.