-1

i need help with php script to get certificate from the windows certificate store and make php curl request with that certificate from the windows certificate store, please help...

i trying a lot of ways and i can read the certificate information from the cerificate store, but i dont know how to send them in php curl request POST method to external URL

i got error Curl error: could not load PEM client certificate, OpenSSL error error:02001002:system library:fopen:No such file or directory, (no key found, wrong pass phrase, or wrong file format?)

to get the certificate i am using powershell script this is the script to get the certificate

$storeName = "CurrentUser\Root"; // Change this to match the desired store name
$thumbprint = "648c2c506ebb85cdb163653913c2d5fb79f19614"; // Change this to the desired certificate's thumbprint

// Escape double quotes in the thumbprint for PowerShell script
$thumbprint = str_replace('"', '\"', $thumbprint);

// Construct the PowerShell command
$psCommand = "powershell -NoProfile -ExecutionPolicy Bypass -File get_cert.ps1";

// Execute the PowerShell command
$output = shell_exec($psCommand);
$curl = curl_init();
curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://external_URL',
        CURLOPT_SSLCERT => $output,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS =>'{

and this is the powershell script

param (
    [string]$storeName,
    [string]$thumbprint
)

$certificate = Get-ChildItem -Path $storeName\*$thumbprint -Recurse

if ($certificate) {
    Write-Output "Subject: $($certificate.Subject)"
    Write-Output "Issuer: $($certificate.Issuer)"
    Write-Output "Serial Number: $($certificate.SerialNumber)"
    Write-Output "Valid From: $($certificate.NotBefore)"
    Write-Output "Valid To: $($certificate.NotAfter)"
} else {
    Write-Output "Certificate not found."
}
  • [Passing .PEM and .KEY as string in Curl using PHP](https://stackoverflow.com/q/7958892/1427878) – CBroe Aug 31 '23 at 12:36
  • 1
    You can start by posting what you attempted to do that didn't work so people can figure out where your issues are. – esQmo_ Aug 31 '23 at 12:36

0 Answers0