I have created a PowerShell script that is capable of writing the ca-cert.crt
file based on the CA certificates that are installed in your Windows certification store (CurrentUser or LocalMachine). Run the script like this:
CreateCaCert.ps1 -StoreLocation CurrentUser | Out-File -Encoding utf8 curl-ca-cert.crt
This will create the curl-ca-cert.crt
file that should be stored in the same directory as curl.exe
and you should be able to validate the same sites as you can in your Windows applications (note that this file can also be consumed by git
).
The "official" script can be found on GitHub, but the initial version is listed here for reference:
[CmdletBinding()]
Param(
[ValidateSet(
[System.Security.Cryptography.X509Certificates.StoreLocation]::CurrentUser,
[System.Security.Cryptography.X509Certificates.StoreLocation]::LocalMachine)]
[string]
$StoreLocation = [System.Security.Cryptography.X509Certificates.StoreLocation]::CurrentUser
)
$maxLineLength = 77
# Open the store
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store ([System.Security.Cryptography.X509Certificates.StoreName]::Root, $StoreLocation)
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly);
# Write header
Write-Output "# Root certificates ($StoreLocation) generated at $(Get-Date)"
# Write all certificates
Foreach ($certificate in $store.Certificates)
{
# Start with an empty line
Write-Output ""
# Convert the certificate to a BASE64 encoded string
$certString = [Convert]::ToBase64String($certificate.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert));
# Write the actual certificate
Write-Output "# Friendly name: $($certificate.FriendlyName)"
Write-Output "# Issuer: $($certificate.Issuer)"
Write-Output "# Expiration: $($certificate.GetExpirationDateString())"
Write-Output "# Serial: $($certificate.SerialNumber)"
Write-Output "# Thumbprint: $($certificate.Thumbprint)"
Write-Output "-----BEGIN CERTIFICATE-----"
For ($i = 0; $i -lt $certString.Length; $i += $maxLineLength)
{
Write-Output $certString.Substring($i, [Math]::Min($maxLineLength, $certString.Length - $i))
}
Write-Output "-----END CERTIFICATE-----"
}