Created
June 23, 2022 14:23
-
-
Save istairbn/379264c7406bed870762d5587186fe3b to your computer and use it in GitHub Desktop.
For a Windows machine, generates a Cacerts file that can be used by Requests and Python
This file contains 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
<# | |
.SYNOPSIS | |
Generate a cacerts.crt file. This allows you to use Requests with an SSL Termination proxy your machine already trusts | |
#> | |
[CmdletBinding()] | |
Param( | |
$Path = "C:\Tools\cacerts.crt" | |
) | |
$Output = "" | |
$Certs = Get-ChildItem -Path Cert:\CurrentUser\Root | |
ForEach($Cert in $Certs){ | |
$Output += "#$($Cert.Issuer)`n`n" | |
$Output += "-----BEGIN CERTIFICATE-----`n" | |
$Output += [convert]::ToBase64String($Cert.RawData,"InsertLineBreaks") | |
$Output += "`n-----END CERTIFICATE-----`n`n`n" | |
} | |
$Output | Out-File -FilePath $Path -Force -Encoding utf8 | |
[System.Environment]::SetEnvironmentVariable("REQUESTS_CA_BUNDLE","$Path",[System.EnvironmentVariableTarget]::Machine) | |
[System.Environment]::SetEnvironmentVariable("REQUESTS_CA_BUNDLE","$Path",[System.EnvironmentVariableTarget]::User) | |
pip config set global.cert $Path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment