Skip to content

Instantly share code, notes, and snippets.

@xpando
Created June 15, 2015 20:13
Show Gist options
  • Select an option

  • Save xpando/f510f76a0a7b97f35906 to your computer and use it in GitHub Desktop.

Select an option

Save xpando/f510f76a0a7b97f35906 to your computer and use it in GitHub Desktop.
param(
[string] $certName
)
# get the directory that vagrant is installed in
$bin = Split-Path (Get-Command vagrant).Path
# get the embedded folder that contains ruby and curl
$embedded = (Resolve-Path (Join-Path $bin '..\embedded')).ProviderPath
# get the cacert.pem file that is used when vagrant curls urls
$cacert = "$embedded\cacert.pem"
# get the ruby gems ssl_cert directory
$ssl_certs = "$embedded\lib\ruby\2.0.0\rubygems\ssl_certs"
# get the root certificate
$cert = dir Cert:\LocalMachine\ca |? { $_.Subject -match "CN=$certName," } | select -First 1
$cer = "-----BEGIN CERTIFICATE-----`n$([Convert]::ToBase64String($cert.RawData, 'InsertLineBreaks'))`n-----END CERTIFICATE-----"
# update certificate stores used by vagrant
"`n$certName`n===========`n$cer" | Out-File $cacert -Append -Encoding ascii
$cer | Out-File "$ssl_certs\Mary-Kay-CA.pem" -Encoding ascii
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment