Last active
November 21, 2016 16:37
-
-
Save Splat/f61cebd1b67832c0978b269b89676ec5 to your computer and use it in GitHub Desktop.
Loading certificate chain from a CA directory to use for validation to a certain depth.
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
require 'net/http' | |
require 'net/https' | |
require 'uri' | |
API_URI = 'some.site.com' | |
root_ca_path = '/etc/ssl/certs' | |
root_ca_depth = 5 | |
api_user = 'username' | |
api_password = 'password' | |
url = URI.parse "https://#{API_URI}" | |
http = Net::HTTP.new(url.host, url.port) | |
http.use_ssl = (url.scheme == 'https') | |
if (File.directory?(root_ca_path) && http.use_ssl?) | |
http.ca_path = RootCA | |
http.verify_mode = OpenSSL::SSL::VERIFY_PEER | |
http.verify_depth = root_ca_depth | |
else | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
end | |
request = Net::HTTP::Get.new(url.path) | |
request.basic_auth api_user, api_password | |
response = http.request(request) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment