Skip to content

Instantly share code, notes, and snippets.

@dayne
Created April 5, 2017 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dayne/d029606d7a917fd29e6e475e70278646 to your computer and use it in GitHub Desktop.
Save dayne/d029606d7a917fd29e6e475e70278646 to your computer and use it in GitHub Desktop.
grab ca certs for use on windows box.. sigh
$ cat ../win_fetch_cacerts.rb
require 'net/http'
require 'openssl'
require 'fileutils'
cert_dir = '/C/Ruby23-x64/lib/ruby/site_ruby/2.3.0/rubygems/ssl_certs/curl.haxx.se'
FileUtils.mkdir cert_dir unless File.directory?(cert_dir)
# create a path to the file "C:\RailsInstaller\cacert.pem"
cacert_file = File.join(cert_dir, 'cacert.pem')
uri = URI.parse("https://curl.haxx.se")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
resp = http.get("/ca/cacert.pem")
if resp.code == "200"
open(cacert_file, "wb") { |file| file.write(resp.body) }
puts "\n\nA bundle of certificate authorities has been installed to"
puts cert_dir
puts "* Please set SSL_CERT_FILE in your current command prompt session with:"
puts " export SSL_CERT_FILE="+cacert_file
puts "* To make this a permanent setting, add it to Environment Variables"
puts " under Control Panel -> Advanced -> Environment Variables"
else
abort "\n\n>>>> A cacert.pem bundle could not be downloaded."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment