if Rails.env.development? key_file = Rails.root.join("config", "certs", "localhost.key") cert_file = Rails.root.join("config", "certs", "localhost.cert") unless key_file.exist? root_key = OpenSSL::PKey::RSA.new(2048) key_file.write(root_key) root_cert = OpenSSL::X509::Certificate.new.tap do |root_ca| root_ca.version = 2 # cf. RFC 5280 - to make it a "v3" certificate root_ca.serial = 0x0 root_ca.su