Skip to content

Instantly share code, notes, and snippets.

@istairbn
Created June 23, 2022 14:23
Show Gist options
  • Save istairbn/379264c7406bed870762d5587186fe3b to your computer and use it in GitHub Desktop.
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
<#
.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