diff options
author | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-09-04 10:31:29 +0000 |
---|---|---|
committer | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-09-04 10:31:29 +0000 |
commit | 5f84c80fc580bdd64b0f2f67a92a840965148e40 (patch) | |
tree | acc6999a9b0b08b1bd645d0eadb9553d7c034b32 /sample/openssl/gen_csr.rb | |
parent | 11d439a7bdd714a8b3a057be8a7a6afc01249f31 (diff) | |
download | ruby-5f84c80fc580bdd64b0f2f67a92a840965148e40.tar.gz |
* sample/openssl: added. Sample of standard distribution library should be
locate in sample/{module_name}/*.
* ext/openssl/sample/*: removed. move to sample/openssl/*.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample/openssl/gen_csr.rb')
-rw-r--r-- | sample/openssl/gen_csr.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/sample/openssl/gen_csr.rb b/sample/openssl/gen_csr.rb new file mode 100644 index 0000000000..c22073b9b9 --- /dev/null +++ b/sample/openssl/gen_csr.rb @@ -0,0 +1,52 @@ +#!/usr/bin/env ruby + +require 'getopts' +require 'openssl' + +include OpenSSL + +def usage + myname = File::basename($0) + $stderr.puts <<EOS +Usage: #{myname} name [keypair_file] + 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" + +name_str = ARGV.shift or usage() + +$stdout.sync = true + +name_ary = name_str.scan(/\s*([^\/,]+)\s*/).collect { |i| i[0].split("=") } +p name_ary +name = X509::Name.new(name_ary) + +keypair = nil +if keypair_file + keypair = PKey::RSA.new(File.read(keypair_file)) +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_ary.inspect}" + +req = X509::Request.new +req.subject = name +req.public_key = keypair.public_key +req.sign(keypair, Digest::SHA1.new) + +puts "Writing #{csrout}..." +File.open(csrout, "w") do |f| + f << req.to_pem +end |