Class: Win32SSLInit::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/win32_ssl_init/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.execute!Object



4
5
6
# File 'lib/win32_ssl_init/cli.rb', line 4

def self.execute!
  new.execute
end

Instance Method Details

#determine_file_name(cert) ⇒ Object

Uses cert authority to name the cert.



48
49
50
51
# File 'lib/win32_ssl_init/cli.rb', line 48

def determine_file_name(cert)
  cert_name = cert.subject.to_s.split("/").reverse.first { |it| it.include?("CN") }.split("=").last.downcase
  "#{cert_name}.pem"
end

#dump_cert(cert_path, cert) ⇒ Object



42
43
44
# File 'lib/win32_ssl_init/cli.rb', line 42

def dump_cert(cert_path, cert)
  File.write(cert_path, cert)
end

#dump_certsObject



35
36
37
38
39
40
# File 'lib/win32_ssl_init/cli.rb', line 35

def dump_certs
  @certs.each do |cert|
    file_name = determine_file_name(cert)
    dump_cert(ruby_ssl_cert_folder + file_name, cert)
  end
end

#executeObject



8
9
10
11
12
13
# File 'lib/win32_ssl_init/cli.rb', line 8

def execute
  pull_certs
  ruby_instance
  dump_certs
  rehash_certs
end

#pull_certsObject Also known as: certs



15
16
17
# File 'lib/win32_ssl_init/cli.rb', line 15

def pull_certs
  @certs ||= Certs.instance.to_a.uniq
end

#rehash_certsObject



53
54
55
56
57
58
# File 'lib/win32_ssl_init/cli.rb', line 53

def rehash_certs
  Dir.chdir ruby_ssl_cert_folder do
    puts "Certs placed in #{ruby_ssl_cert_folder}, rehashing"
    puts `ruby ./c_rehash.rb`
  end
end

#ruby_instanceObject

Finds the root of the running ruby installation by checking the 2nd to last entry in the load path TODO: Check if this is always true… it seems to be so far.



23
24
25
# File 'lib/win32_ssl_init/cli.rb', line 23

def ruby_instance
  @ruby_instance ||= $LOAD_PATH[-2].split("/")[0..-4].join("/")
end

#ruby_ssl_cert_folderObject



27
28
29
30
31
32
33
# File 'lib/win32_ssl_init/cli.rb', line 27

def ruby_ssl_cert_folder
  if (Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.2.0')) && (Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.4.0'))
    "#{ruby_instance}/bin/etc/ssl/certs/"
  else
    "#{ruby_instance}/ssl/certs/"
  end
end