Created
June 10, 2022 22:49
-
-
Save OnceUponALoop/bb1ef85d04569d0e39c0987f6053d5ca to your computer and use it in GitHub Desktop.
Generate ca-bundle from Windows Store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Root CA Bundle - autogenerate from Windows store | |
# Location of bundle | |
# I chose not to override the mingw64 store in /etc/ssl to avoid having to request admin elevation | |
CertFile=$HOME/.certs/ca-bundle.pem | |
# Only recreate once a day | |
if [ "$(date -r $HOME/.certs/ca-bundle.pem +%F 2>/dev/null)" != "$(date +%F)" ]; then | |
mkdir -p $HOME/.certs | |
ps_script=' | |
if (-not $ENV:CertFile) { $ENV:CertFile="$ENV:USERPROFILE\.certs\ca-bundle.pem" } | |
$Comment = "# CA Bundle - Auto-Generated from Windows Certificate Store" | |
$Comment += "`n# Scope: [CurrentUser] - Date: $(Get-Date -Format "dddd yyyy-MM-dd")`n" | |
Set-Content -Path $ENV:CertFile -Value $Comment | |
$oPem=New-Object System.Text.StringBuilder | |
Get-ChildItem -Path Cert:\CurrentUser\Root | Sort-Object -Property FriendlyName | ForEach-Object { | |
if ( $_.FriendlyName ) { $Name = $_.FriendlyName } else { $Name = $_.Subject } | |
$oPem.AppendLine("# $Name ") | |
$oPem.AppendLine("-----BEGIN CERTIFICATE-----") | |
$oPem.AppendLine([System.Convert]::ToBase64String($_.RawData,1)) | |
$oPem.AppendLine("-----END CERTIFICATE-----") | |
$oPem.ToString() | Out-File -Append -FilePath $ENV:CertFile -Encoding ASCII | |
$oPem.Clear() | |
} | Out-Null ' | |
powershell.exe -Command "$ps_script" | |
dos2unix $CertFile 2> /dev/null | |
fi | |
export CURL_CA_BUNDLE=$CertFile | |
export SSL_CERT_FILE=$CertFile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment