Skip to content

Commit

Permalink
Use the lib cert or standalone DATA cert as a fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
indirect committed Dec 2, 2010
1 parent 2e83c73 commit 0404c15
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions gist
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ module Gist

http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.ca_file = File.join(File.dirname(__FILE__), "cacert.pem")
http.ca_file = ca_cert

req = Net::HTTP::Post.new(url.path)
req.form_data = data(files, private_gist)
Expand Down Expand Up @@ -276,7 +276,15 @@ private
end

def ca_cert
DATA.read.split("__CACERT__").last
cert_file = File.join(File.dirname(__FILE__), "cacert.pem")
if File.exist?(cert_file)
cert_file
else
require 'tempfile'
t = Tempfile.new("ca_cert")
t << DATA.read.split("__CACERT__").last
t.path
end
end
end
Gist.execute(*ARGV)
Expand Down
12 changes: 10 additions & 2 deletions lib/gist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def write(files, private_gist = false)

http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.ca_file = File.join(File.dirname(__FILE__), "cacert.pem")
http.ca_file = ca_cert

req = Net::HTTP::Post.new(url.path)
req.form_data = data(files, private_gist)
Expand Down Expand Up @@ -237,6 +237,14 @@ def str_to_bool(str)
end

def ca_cert
DATA.read.split("__CACERT__").last
cert_file = File.join(File.dirname(__FILE__), "cacert.pem")
if File.exist?(cert_file)
cert_file
else
require 'tempfile'
t = Tempfile.new("ca_cert")
t << DATA.read.split("__CACERT__").last
t.path
end
end
end

0 comments on commit 0404c15

Please sign in to comment.