lib/openssl/win/root.rb in openssl-win-root-0.9.0 vs lib/openssl/win/root.rb in openssl-win-root-0.9.1
- old
+ new
@@ -39,59 +39,44 @@
close store, 0
end
end
end if On
- def self.save(f=STDOUT)
- f.puts <<-EOT
-#
-# Generated by #{self} v#{VERSION} @#{Time.now}
-#
-
- EOT
+ def self.save(path=path)
+ my={}
Crypt.each do |crt|
- f.puts <<-EOT
+ File.open File.join(path, name='%08x.0'%crt.subject.hash), 'w' do |f|
+ my[name]=1
+ f.puts <<-EOT
Subject: #{crt.subject}
Valid: #{crt.not_before} - #{crt.not_after}
+Saved: #{self} v#{VERSION} @#{Time.now}
#{crt.to_pem}
- EOT
+#{crt.to_text}
+ EOT
+ end
end
+ Dir.glob File.join path, '*' do |f|
+ File.unlink f unless my[File.basename f]
+ end
end
def self.path
return @path if @path
x = File.expand_path '..', __FILE__
x = File.dirname x until File.exists? File.join x, 'Gemfile'
x = File.join x, 'pem'
FileUtils.mkdir_p x
- @path = File.join x, 'cacert.pem'
+ @path = x
end
- def self.tmpnam
- File.join File.dirname(path), "#{rand.to_s.gsub /\D+/, ''}.pem"
- end
-
- def self.update
- tmp = tmpnam
- begin
- File.open(tmp, 'w'){|f| save f}
- FileUtils.mv tmp, path, force: true
- inject
- ensure
- File.unlink tmp rescue nil
- end
- end
-
def self.inject
- return unless File.exists? path
- return if @inject
- OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE.add_file path
- @inject = true
+ OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE.add_path path
path
end
def self.go!
- t = Thread.new{ update }
+ t = Thread.new{ save }
at_exit{t.join}
inject
end
go! if On