lib/evil-proxy/quickcert.rb
##
# Creates a new Certificate Signing Request for the keypair in
# +keypair_file+, generating and saving new keypair if nil.
Creates a new Certificate Signing Request for the keypair in
+keypair_file+, generating and saving new keypair if nil.
Creates a new Certificate Signing Request for the keypair in + keypair_file + generating and saving new keypair if nil .
def create_csr(cert_config, keypair_file = nil)
    keypair = nil
    dest = cert_config[:hostname] || cert_config[:user]
    csr_file = "#{CERT_DIR}/#{dest}/csr_#{dest}.pem"
    name = @ca_config[:name].dup
    case cert_config[:type]
    when 'server' then
      name << ['OU', 'CA']
      name << ['CN', cert_config[:hostname]]
    when 'client' then
      name << ['CN', cert_config[:user]]
      name << ['emailAddress', cert_config[:email]]
    end
    name = OpenSSL::X509::Name.new name
    if File.exists? keypair_file then
      keypair = OpenSSL::PKey::RSA.new(File.read(keypair_file),
                                       cert_config[:password])
    else
      keypair = create_key cert_config
    end
    puts "Generating CSR for #{name}" if $DEBUG
    req = OpenSSL::X509::Request.new
    req.version = 0
    req.subject = name
    req.public_key = keypair.public_key
    req.sign keypair, OpenSSL::Digest::MD5.new
    puts "Writing CSR to #{csr_file}" if $DEBUG
    File.open csr_file, "w" do |f|
      f << req.to_pem
    end
    return csr_file
  end
def create_csr ( cert_config , keypair_file = nil ) keypair = nil dest = cert_config [ :hostname ] || cert_config [ :user ] csr_file = "#{CERT_DIR}/#{dest}/csr_#{dest}.pem" name = @ca_config [ :name ] . dup case cert_config [ :type ] when 'server' then name << [ 'OU' , 'CA' ] name << [ 'CN' , cert_config [ :hostname ] ] when 'client' then name << [ 'CN' , cert_config [ :user ] ] name << [ 'emailAddress' , cert_config [ :email ] ] end name = OpenSSL :: X509 :: Name . new name if File . exists? keypair_file then keypair = OpenSSL :: PKey :: RSA . new ( File . read ( keypair_file ) , cert_config [ :password ] ) else keypair = create_key cert_config end puts "Generating CSR for #{name}" if $DEBUG req = OpenSSL :: X509 :: Request . new req . version = 0 req . subject = name req . public_key = keypair . public_key req . sign keypair , OpenSSL :: Digest :: MD5 . new puts "Writing CSR to #{csr_file}" if $DEBUG File . open csr_file , "w" do | f | f << req . to_pem end return csr_file end
Creates a new Certificate Signing Request for the keypair in
+keypair_file+, generating and saving new keypair if nil.
Creates a new Certificate Signing Request for the keypair in + keypair_file + generating and saving new keypair if nil .
cert_config
keypair_file