Module: OpenSSL::Win::Root

Defined in:
lib/openssl/win/root/version.rb,
lib/openssl/win/root.rb

Defined Under Namespace

Modules: Crypt

Constant Summary collapse

VERSION =
"1.0.2"
On =
Gem.win_platform?

Class Method Summary collapse

Class Method Details

.go!Object



84
85
86
87
88
89
# File 'lib/openssl/win/root.rb', line 84

def self.go!
  t = Thread.new{ save }
  t.abort_on_exception=true
  at_exit{t.join}
  inject
end

.injectObject

Instruct OpenSSL to use fetched certificates



79
80
81
82
# File 'lib/openssl/win/root.rb', line 79

def self.inject
  OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE.add_path path
  path
end

.pathObject

Path where certificates will be



45
46
47
48
49
50
51
52
# File 'lib/openssl/win/root.rb', line 45

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 = x
end

.save(path = self.path) ⇒ Object

Almost c_rehash



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/openssl/win/root.rb', line 55

def self.save(path=self.path)
  names={}
  hashes={}
  Crypt.each do |crt|
    peers=hashes[hash=crt.subject.hash]||={}
    id=OpenSSL::Digest::SHA1.new.digest crt.to_der
    next if peers[id]
    names[name='%08x.%i' % [hash, peers.length]]=1
    peers[id]=1
    File.open File.join(path, name), 'w' do |f|
      f.puts "Subject: \#{crt.subject}\nValid:   \#{crt.not_before} - \#{crt.not_after}\nSaved:   \#{Time.now} by \#{self} v\#{VERSION}\n\#{crt.to_pem}\n      EOT\n    end\n  end\n  Dir.glob File.join path, '*' do |f|\n    File.unlink f rescue nil unless names[File.basename f]\n  end\nend\n"