5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/mkit/ssl/easy_ssl.rb', line 5
def self.create_self_certificate(cert_dir)
unless File.exist?("#{cert_dir}/#{MKIt::Utils::MKIT_CRT}")
key = OpenSSL::PKey::RSA.new 4096
name = OpenSSL::X509::Name.parse '/CN=MKIt/DC=server'
cert = OpenSSL::X509::Certificate.new
cert.version = 2
cert.serial = 0
cert.not_before = Time.now
cert.not_after = Time.now + 20 * 365 * 24 * 60 * 60
cert.public_key = key.public_key
cert.subject = name
cert.issuer = name
cert.sign key, OpenSSL::Digest.new('SHA256')
open "#{cert_dir}/#{MKIt::Utils::MKIT_CRT}", 'w' do |io| io.write cert.to_pem end
open "#{cert_dir}/#{MKIt::Utils::MKIT_KEY}", 'w' do |io| io.write key.to_pem end
open "#{cert_dir}/#{MKIt::Utils::MKIT_PEM}", 'w' do |io| io.write cert.to_pem end
open "#{cert_dir}/#{MKIt::Utils::MKIT_PEM}", 'a' do |io| io.write key.to_pem end
end
end
|