Sha256: 36d6bec9bea9da514b1426274d1289e0a2e9021546ec371322ff005f4467eb6b

Contents?: true

Size: 1009 Bytes

Versions: 57

Compression:

Stored size: 1009 Bytes

Contents

#!/usr/bin/env ruby

require 'getopts'
require 'openssl'

include OpenSSL

def usage
  myname = File::basename($0)
  $stderr.puts <<EOS
Usage: #{myname} [--key keypair_file] name
  name ... ex. /C=JP/O=RRR/OU=CA/CN=NaHi/emailAddress=nahi@example.org
EOS
  exit
end

getopts nil, "key:", "csrout:", "keyout:"
keypair_file = $OPT_key
csrout = $OPT_csrout || "csr.pem"
keyout = $OPT_keyout || "keypair.pem"

$stdout.sync = true
name_str = ARGV.shift or usage()
p name_str
name = X509::Name.parse(name_str)

keypair = nil
if keypair_file
  keypair = PKey::RSA.new(File.open(keypair_file).read)
else
  keypair = PKey::RSA.new(1024) { putc "." }
  puts
  puts "Writing #{keyout}..."
  File.open(keyout, "w", 0400) do |f|
    f << keypair.to_pem
  end
end

puts "Generating CSR for #{name_str}"

req = X509::Request.new
req.version = 0
req.subject = name
req.public_key = keypair.public_key
req.sign(keypair, OpenSSL::Digest::MD5.new)

puts "Writing #{csrout}..."
File.open(csrout, "w") do |f|
  f << req.to_pem
end

Version data entries

57 entries across 57 versions & 4 rubygems

Version Path
jruby-openssl-0.8.0.pre3 test/fixture/purpose/scripts/gen_csr.rb
jruby-openssl-0.8.0.pre2 test/fixture/purpose/scripts/gen_csr.rb
jruby-openssl-0.8.0.pre1 test/fixture/purpose/scripts/gen_csr.rb
jruby-openssl-maven-0.7.6.1 test/fixture/purpose/scripts/gen_csr.rb
jruby-openssl-0.7.7 test/fixture/purpose/scripts/gen_csr.rb
jruby-openssl-0.7.6.1 test/fixture/purpose/scripts/gen_csr.rb
jruby-openssl-0.7.5 test/fixture/purpose/scripts/gen_csr.rb
jruby-openssl-maven-0.7.4.1 test/fixture/purpose/scripts/gen_csr.rb
redcar-dev-0.12.1dev-java lib/openssl/test/fixture/purpose/scripts/gen_csr.rb
redcar-dev-0.12.0dev-java lib/openssl/test/fixture/purpose/scripts/gen_csr.rb
jruby-openssl-0.7.5.dev test/fixture/purpose/scripts/gen_csr.rb
jruby-openssl-0.7.4 test/fixture/purpose/scripts/gen_csr.rb
redcar-0.11 lib/openssl/test/fixture/purpose/scripts/gen_csr.rb
redcar-0.11.0dev lib/openssl/test/fixture/purpose/scripts/gen_csr.rb
jruby-openssl-0.7.3 test/fixture/purpose/scripts/gen_csr.rb
redcar-0.10 lib/openssl/test/fixture/purpose/scripts/gen_csr.rb
redcar-0.9.2 lib/openssl/test/fixture/purpose/scripts/gen_csr.rb
redcar-0.9.1 lib/openssl/test/fixture/purpose/scripts/gen_csr.rb
redcar-0.9.0 lib/openssl/test/fixture/purpose/scripts/gen_csr.rb
jruby-openssl-0.7.2 test/fixture/purpose/scripts/gen_csr.rb